telecoder 0.0.0-stage → 1.2.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 +363 -0
- package/CHANGELOG.md +1186 -0
- package/LICENSE +22 -0
- package/README.md +126 -2
- package/dist/audio/transcribe.js +50 -0
- package/dist/bin/mcp-server.js +378 -0
- package/dist/bin/tool-result.js +22 -0
- package/dist/bot/access/group-access.js +147 -0
- package/dist/bot/bot.js +592 -0
- package/dist/bot/file-access.js +141 -0
- package/dist/bot/handlers/command/access.js +407 -0
- package/dist/bot/handlers/command/admin.js +827 -0
- package/dist/bot/handlers/command/auto-approve.js +138 -0
- package/dist/bot/handlers/command/btw.js +224 -0
- package/dist/bot/handlers/command/cost.js +409 -0
- package/dist/bot/handlers/command/media.js +197 -0
- package/dist/bot/handlers/command/model.js +305 -0
- package/dist/bot/handlers/command/prefs-scope.js +197 -0
- package/dist/bot/handlers/command/project.js +536 -0
- package/dist/bot/handlers/command/resume.js +321 -0
- package/dist/bot/handlers/command/session.js +438 -0
- package/dist/bot/handlers/command/settings.js +1012 -0
- package/dist/bot/handlers/command/shared.js +210 -0
- package/dist/bot/handlers/command/streaming-mode.js +16 -0
- package/dist/bot/handlers/command/tasks.js +513 -0
- package/dist/bot/handlers/command/topic-store.js +113 -0
- package/dist/bot/handlers/command/topic.js +80 -0
- package/dist/bot/handlers/command.handler.js +772 -0
- package/dist/bot/handlers/fork.handler.js +1109 -0
- package/dist/bot/handlers/media-fallback.js +121 -0
- package/dist/bot/handlers/message/replies.js +133 -0
- package/dist/bot/handlers/message/shared.js +117 -0
- package/dist/bot/handlers/message/throttle.js +49 -0
- package/dist/bot/handlers/message/turn-notify.js +169 -0
- package/dist/bot/handlers/message/turn-runner.js +141 -0
- package/dist/bot/handlers/message.handler.js +107 -0
- package/dist/bot/handlers/newbot.handler.js +221 -0
- package/dist/bot/handlers/photo.handler.js +327 -0
- package/dist/bot/handlers/prompts.handler.js +343 -0
- package/dist/bot/handlers/running-note.js +44 -0
- package/dist/bot/handlers/schedule.handler.js +303 -0
- package/dist/bot/handlers/session-guard.js +78 -0
- package/dist/bot/handlers/suggestion.handler.js +84 -0
- package/dist/bot/handlers/tree.handler.js +480 -0
- package/dist/bot/handlers/view.js +41 -0
- package/dist/bot/handlers/voice.handler.js +209 -0
- package/dist/bot/middleware/admin-only.js +49 -0
- package/dist/bot/middleware/auth.middleware.js +122 -0
- package/dist/bot/middleware/group-mention.middleware.js +139 -0
- package/dist/bot/middleware/group-role.middleware.js +75 -0
- package/dist/bot/middleware/message-batcher.js +87 -0
- package/dist/bot/middleware/queued-messages.js +971 -0
- package/dist/bot/middleware/stale-filter.js +31 -0
- package/dist/build-info.json +8 -0
- package/dist/claude/agent-watchdog.js +162 -0
- package/dist/claude/agent.js +1458 -0
- package/dist/claude/ask-user.js +295 -0
- package/dist/claude/auto-approve.js +225 -0
- package/dist/claude/auto-topic-haiku.js +126 -0
- package/dist/claude/available-commands.js +153 -0
- package/dist/claude/carry-over.js +27 -0
- package/dist/claude/ccr-shim.js +46 -0
- package/dist/claude/charter-judge.js +214 -0
- package/dist/claude/claude-auth.js +121 -0
- package/dist/claude/command-parser.js +200 -0
- package/dist/claude/cost-overlay-scraper.js +129 -0
- package/dist/claude/enabled-plugins.js +56 -0
- package/dist/claude/fork-tree.js +393 -0
- package/dist/claude/held-query.js +190 -0
- package/dist/claude/in-flight-tracker.js +61 -0
- package/dist/claude/ipc-server.js +192 -0
- package/dist/claude/mcp-bridge.js +453 -0
- package/dist/claude/mcp-tools.js +354 -0
- package/dist/claude/message-offsets.js +88 -0
- package/dist/claude/modal-relay.js +450 -0
- package/dist/claude/model-catalog.js +85 -0
- package/dist/claude/monitor-relay.js +597 -0
- package/dist/claude/pending-forks.js +93 -0
- package/dist/claude/pending-suggestions.js +50 -0
- package/dist/claude/permission-gate.js +337 -0
- package/dist/claude/permission-mode.js +178 -0
- package/dist/claude/poll-user.js +51 -0
- package/dist/claude/project-commands.js +69 -0
- package/dist/claude/prompt-hold.js +124 -0
- package/dist/claude/prompt-suggestion-scraper.js +89 -0
- package/dist/claude/pty-provider.js +2214 -0
- package/dist/claude/pty-spawn-config.js +296 -0
- package/dist/claude/pty-stream.js +363 -0
- package/dist/claude/request-queue.js +135 -0
- package/dist/claude/scheduled-runner.js +91 -0
- package/dist/claude/scheduler.js +237 -0
- package/dist/claude/scope-guard.js +274 -0
- package/dist/claude/sdk-permission-gate.js +77 -0
- package/dist/claude/secret-request.js +576 -0
- package/dist/claude/session-cost.js +41 -0
- package/dist/claude/session-history.js +286 -0
- package/dist/claude/session-jsonl.js +920 -0
- package/dist/claude/session-manager.js +195 -0
- package/dist/claude/session-scan.js +270 -0
- package/dist/claude/setup-token.js +285 -0
- package/dist/claude/side-call-options.js +45 -0
- package/dist/claude/side-question.js +249 -0
- package/dist/claude/stage-images.js +62 -0
- package/dist/claude/subagent-tools.js +12 -0
- package/dist/claude/synthetic-ctx.js +51 -0
- package/dist/claude/system-prompt.js +162 -0
- package/dist/claude/tasks-overlay-scraper.js +94 -0
- package/dist/claude/tip-scraper.js +78 -0
- package/dist/claude/tui-modal.js +501 -0
- package/dist/claude/tui-state.js +384 -0
- package/dist/claude/turn-end.js +91 -0
- package/dist/claude/turn-prose.js +64 -0
- package/dist/claude/update-banner-relay.js +70 -0
- package/dist/cli/commands/doctor.js +305 -0
- package/dist/cli/commands/help.js +25 -0
- package/dist/cli/commands/init.js +123 -0
- package/dist/cli/commands/service.js +678 -0
- package/dist/cli/commands/start.js +53 -0
- package/dist/cli/commands/version.js +11 -0
- package/dist/cli/dispatch.js +79 -0
- package/dist/cli/init/env-file.js +99 -0
- package/dist/cli/init/flow.js +638 -0
- package/dist/cli/init/prompter.js +116 -0
- package/dist/cli/init/telegram.js +94 -0
- package/dist/cli/service/render.js +212 -0
- package/dist/cli.js +18 -0
- package/dist/config-report.js +107 -0
- package/dist/config.js +500 -0
- package/dist/index.js +367 -0
- package/dist/launcher.js +933 -0
- package/dist/node-version-check.js +27 -0
- package/dist/providers/ccr-health.js +119 -0
- package/dist/providers/ccr-introspect.js +149 -0
- package/dist/providers/ccr-provider.js +60 -0
- package/dist/providers/claude-provider.js +63 -0
- package/dist/providers/prefs-sync.js +164 -0
- package/dist/providers/project-favorites.js +74 -0
- package/dist/providers/provider-router.js +127 -0
- package/dist/providers/provider-switch.js +91 -0
- package/dist/providers/sdk-provider.js +37 -0
- package/dist/providers/types.js +8 -0
- package/dist/providers/user-preferences.js +214 -0
- package/dist/restart-when-idle.js +153 -0
- package/dist/startup/auto-continue.js +67 -0
- package/dist/startup/auto-resume.js +173 -0
- package/dist/startup/notices.js +120 -0
- package/dist/startup/shared.js +44 -0
- package/dist/startup/verify-token.js +31 -0
- package/dist/telegram/access-request.js +153 -0
- package/dist/telegram/action-logger.js +684 -0
- package/dist/telegram/admin-mention.js +107 -0
- package/dist/telegram/background-activity-card.js +502 -0
- package/dist/telegram/botname-settings.js +336 -0
- package/dist/telegram/button-text.js +26 -0
- package/dist/telegram/client-options.js +27 -0
- package/dist/telegram/deduplication.js +33 -0
- package/dist/telegram/entities.js +295 -0
- package/dist/telegram/force-reply-tracker.js +57 -0
- package/dist/telegram/lettered-options.js +87 -0
- package/dist/telegram/markdown.js +362 -0
- package/dist/telegram/message-sender.js +1287 -0
- package/dist/telegram/prompt-label.js +142 -0
- package/dist/telegram/prompt-suggestion.js +54 -0
- package/dist/telegram/send.js +123 -0
- package/dist/telegram/streaming-turn.js +105 -0
- package/dist/telegram/suggestions-settings.js +30 -0
- package/dist/telegram/task-list.js +367 -0
- package/dist/telegram/task-tracker.js +209 -0
- package/dist/telegram/telegraph-settings.js +31 -0
- package/dist/telegram/telegraph.js +453 -0
- package/dist/telegram/terminal-renderer.js +671 -0
- package/dist/telegram/terminal-settings.js +25 -0
- package/dist/telegram/thread-titles.js +190 -0
- package/dist/telegram/threads-setup.js +117 -0
- package/dist/tts/tts-settings.js +62 -0
- package/dist/tts/tts.js +245 -0
- package/dist/tts/voice-reply.js +78 -0
- package/dist/utils/admins.js +143 -0
- package/dist/utils/agent-timer.js +55 -0
- package/dist/utils/atomic-write.js +24 -0
- package/dist/utils/bot-token.js +74 -0
- package/dist/utils/bounded-map.js +55 -0
- package/dist/utils/build-info.js +57 -0
- package/dist/utils/caffeinate.js +50 -0
- package/dist/utils/claude-env.js +54 -0
- package/dist/utils/claude-version.js +48 -0
- package/dist/utils/config-home.js +62 -0
- package/dist/utils/debug-agent.js +117 -0
- package/dist/utils/debug-watchdog.js +121 -0
- package/dist/utils/download.js +111 -0
- package/dist/utils/exit-codes.js +48 -0
- package/dist/utils/file-type.js +149 -0
- package/dist/utils/format.js +81 -0
- package/dist/utils/home-project.js +30 -0
- package/dist/utils/host-stall.js +51 -0
- package/dist/utils/id-list.js +44 -0
- package/dist/utils/idle-restart.js +92 -0
- package/dist/utils/install-mode.js +63 -0
- package/dist/utils/instance-config.js +148 -0
- package/dist/utils/instances.js +95 -0
- package/dist/utils/json-store.js +140 -0
- package/dist/utils/keyed-settings.js +62 -0
- package/dist/utils/legacy-env.js +35 -0
- package/dist/utils/npm-version.js +134 -0
- package/dist/utils/prefs-relay.js +107 -0
- package/dist/utils/proc-children.js +102 -0
- package/dist/utils/project-data-dir.js +33 -0
- package/dist/utils/reasoning-summary.js +12 -0
- package/dist/utils/resolve-bin.js +86 -0
- package/dist/utils/resolve-claude-bin.js +63 -0
- package/dist/utils/respawn-backoff.js +19 -0
- package/dist/utils/sanitize.js +91 -0
- package/dist/utils/session-key.js +37 -0
- package/dist/utils/stale-launcher.js +109 -0
- package/dist/utils/state-dir-migration.js +92 -0
- package/dist/utils/systemd.js +126 -0
- package/dist/utils/user-roster.js +275 -0
- package/dist/utils/verbosity.js +118 -0
- package/dist/utils/version-check.js +166 -0
- package/dist/utils/workspace-guard.js +44 -0
- package/dist/worker-restart.js +141 -0
- package/instances.json.example +41 -0
- package/package.json +76 -4
package/LICENSE
ADDED
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Nacho Mascort (Claudegram, the original work)
|
|
4
|
+
Copyright (c) 2026 Rik Wanders (TeleCoder, this derivative work)
|
|
5
|
+
|
|
6
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
7
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
8
|
+
in the Software without restriction, including without limitation the rights
|
|
9
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
10
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
11
|
+
furnished to do so, subject to the following conditions:
|
|
12
|
+
|
|
13
|
+
The above copyright notice and this permission notice shall be included in all
|
|
14
|
+
copies or substantial portions of the Software.
|
|
15
|
+
|
|
16
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
17
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
18
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
19
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
20
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
21
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
22
|
+
SOFTWARE.
|
package/README.md
CHANGED
|
@@ -1,3 +1,127 @@
|
|
|
1
|
-
|
|
1
|
+
<div align="center">
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
# TeleCoder
|
|
4
|
+
|
|
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.
|
|
7
|
+
|
|
8
|
+
[](https://github.com/gitaarik/telecoder/actions/workflows/ci.yml)
|
|
9
|
+
[](https://www.npmjs.com/package/telecoder)
|
|
10
|
+
[](https://nodejs.org/)
|
|
11
|
+
[](LICENSE)
|
|
12
|
+
|
|
13
|
+
[Website](https://telecoder.dev) · [Quick start](#quick-start) · [Features](docs/features.md) · [Commands](docs/commands.md) · [Docs](#documentation) · [Changelog](CHANGELOG.md)
|
|
14
|
+
|
|
15
|
+
</div>
|
|
16
|
+
|
|
17
|
+
<!-- Demo GIF goes here: a thread, a fork into a new thread, a permission prompt, a voice note. -->
|
|
18
|
+
|
|
19
|
+
---
|
|
20
|
+
|
|
21
|
+
## Why TeleCoder
|
|
22
|
+
|
|
23
|
+
Claude Code is at its best when you can reach it from anywhere. Browser UIs get you there, but
|
|
24
|
+
they're web pages on a phone. Telegram already has fast, polished apps for Android, iOS, macOS,
|
|
25
|
+
Windows and Linux, with keyboard shortcuts, offline drafts, notifications and voice notes.
|
|
26
|
+
TeleCoder puts Claude Code inside them.
|
|
27
|
+
|
|
28
|
+
- **Native apps, not a web page.** Every device you own already runs a fast Telegram client.
|
|
29
|
+
The bot polls Telegram, so there's no port to open, no tunnel and no web server.
|
|
30
|
+
- **A thread per conversation.** Each thread is its own Claude session, in groups and in
|
|
31
|
+
private chats. Start a thread and you have a new session; run five tasks side by side and
|
|
32
|
+
switch between them like chats.
|
|
33
|
+
- **Forks.** `/fork` copies the conversation into a new thread; `/spinoff` splits a task off
|
|
34
|
+
with a compacted copy of the context; `/tree` draws the branches and lets you jump between
|
|
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.
|
|
40
|
+
- **Claude can reach you.** It can ask with buttons, send you files, ask for an API key
|
|
41
|
+
(your message is deleted the moment it arrives), schedule prompts, and report background
|
|
42
|
+
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.
|
|
46
|
+
- **More than one bot.** Run a bot per project from one process, and make a new one from
|
|
47
|
+
chat with `/newbot`, without a BotFather conversation.
|
|
48
|
+
- **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.
|
|
50
|
+
|
|
51
|
+
The full list is in [docs/features.md](docs/features.md).
|
|
52
|
+
|
|
53
|
+
## How it compares
|
|
54
|
+
|
|
55
|
+
- **Claude Code Channels** (the official Telegram and Discord plugin) pushes chat messages
|
|
56
|
+
into a Claude Code session you started in a terminal. It's a good fit for nudging one running
|
|
57
|
+
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.
|
|
59
|
+
- **Remote Control** lets you look in on a terminal session from the Claude app. Use it when
|
|
60
|
+
you want the session you already have, on Anthropic's own UI.
|
|
61
|
+
- **[claude-code-telegram](https://github.com/RichardAtCT/claude-code-telegram)** is the
|
|
62
|
+
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.
|
|
64
|
+
- **Web UIs** such as [CloudCLI](https://github.com/siteboon/claudecodeui) give you a
|
|
65
|
+
browser dashboard with file trees and diffs. TeleCoder gives up the dashboard for native
|
|
66
|
+
apps, notifications and voice.
|
|
67
|
+
|
|
68
|
+
## Quick start
|
|
69
|
+
|
|
70
|
+
You need Linux or macOS, [Node.js 22+](https://nodejs.org/), the
|
|
71
|
+
[Claude Code CLI](https://platform.claude.com/docs/en/claude-code) installed and logged in, and
|
|
72
|
+
a bot token from [@BotFather](https://t.me/BotFather). On Linux, `npm install` compiles
|
|
73
|
+
`node-pty`, which needs `python3`, `make` and `g++`.
|
|
74
|
+
|
|
75
|
+
```bash
|
|
76
|
+
npm install -g telecoder
|
|
77
|
+
telecoder init # bot token, your user ID, projects folder: about two minutes
|
|
78
|
+
telecoder service install # keep it running, and start it at boot
|
|
79
|
+
```
|
|
80
|
+
|
|
81
|
+
`telecoder init` checks the token with Telegram, learns your user ID when you send the bot
|
|
82
|
+
`/start`, and writes `~/.telecoder/.env`, readable by you only. Then open your bot in Telegram,
|
|
83
|
+
pick a project with `/project` and start talking.
|
|
84
|
+
|
|
85
|
+
`telecoder doctor` checks your setup, `telecoder service logs` follows the output and `/update`
|
|
86
|
+
upgrades from chat. To run from a git checkout instead, see
|
|
87
|
+
[docs/install.md](docs/install.md#from-source).
|
|
88
|
+
|
|
89
|
+
## Documentation
|
|
90
|
+
|
|
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
|
|
100
|
+
- [Roadmap](ROADMAP.md), [changelog](CHANGELOG.md) and [contributing](CONTRIBUTING.md)
|
|
101
|
+
|
|
102
|
+
## Project status
|
|
103
|
+
|
|
104
|
+
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
|
|
106
|
+
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
|
|
108
|
+
the type check, tests and build on every push.
|
|
109
|
+
|
|
110
|
+
TeleCoder is self-hosted: it runs on your machine with your own Claude account, and there is no
|
|
111
|
+
hosted version.
|
|
112
|
+
|
|
113
|
+
## Credits
|
|
114
|
+
|
|
115
|
+
TeleCoder began as a fork of [Claudegram](https://github.com/NachoSEO/claudegram) by
|
|
116
|
+
[@NachoSEO](https://github.com/NachoSEO), MIT-licensed, whose last commit was in March 2026.
|
|
117
|
+
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
|
|
120
|
+
was created in July 2026 when the project was renamed, so its GitHub creation date is later than
|
|
121
|
+
its first commits.
|
|
122
|
+
|
|
123
|
+
TeleCoder is an independent project, not affiliated with or endorsed by Anthropic or Telegram.
|
|
124
|
+
|
|
125
|
+
## License
|
|
126
|
+
|
|
127
|
+
MIT
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
import * as fs from 'fs';
|
|
2
|
+
import * as path from 'path';
|
|
3
|
+
import { config } from '../config.js';
|
|
4
|
+
import { downloadFileSecure, getTelegramFileUrl } from '../utils/download.js';
|
|
5
|
+
const GROQ_WHISPER_ENDPOINT = 'https://api.groq.com/openai/v1/audio/transcriptions';
|
|
6
|
+
const GROQ_WHISPER_MODEL = 'whisper-large-v3-turbo';
|
|
7
|
+
/**
|
|
8
|
+
* Transcribe an audio file using the Groq Whisper API directly via fetch.
|
|
9
|
+
* No Python subprocess - much faster, especially on first call.
|
|
10
|
+
*/
|
|
11
|
+
export async function transcribeFile(filePath, options) {
|
|
12
|
+
if (!config.GROQ_API_KEY) {
|
|
13
|
+
throw new Error('GROQ_API_KEY not configured. Set it in .env to enable voice transcription.');
|
|
14
|
+
}
|
|
15
|
+
const timeoutMs = options?.timeoutMs ?? config.VOICE_TIMEOUT_MS;
|
|
16
|
+
const fileBuffer = fs.readFileSync(filePath);
|
|
17
|
+
const fileName = path.basename(filePath);
|
|
18
|
+
const formData = new FormData();
|
|
19
|
+
formData.append('file', new Blob([fileBuffer]), fileName);
|
|
20
|
+
formData.append('model', GROQ_WHISPER_MODEL);
|
|
21
|
+
formData.append('language', config.VOICE_LANGUAGE);
|
|
22
|
+
formData.append('response_format', 'json');
|
|
23
|
+
const response = await fetch(GROQ_WHISPER_ENDPOINT, {
|
|
24
|
+
method: 'POST',
|
|
25
|
+
headers: {
|
|
26
|
+
Authorization: `Bearer ${config.GROQ_API_KEY}`,
|
|
27
|
+
},
|
|
28
|
+
body: formData,
|
|
29
|
+
signal: AbortSignal.timeout(timeoutMs),
|
|
30
|
+
});
|
|
31
|
+
if (!response.ok) {
|
|
32
|
+
const body = await response.text().catch(() => '');
|
|
33
|
+
throw new Error(`Groq Whisper API error ${response.status}: ${body.slice(0, 300)}`);
|
|
34
|
+
}
|
|
35
|
+
const result = (await response.json());
|
|
36
|
+
const transcript = (result.text || '').trim();
|
|
37
|
+
if (!transcript && !options?.allowEmpty) {
|
|
38
|
+
throw new Error('Empty transcription result');
|
|
39
|
+
}
|
|
40
|
+
return transcript;
|
|
41
|
+
}
|
|
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
|
+
//# sourceMappingURL=transcribe.js.map
|
|
@@ -0,0 +1,378 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* TeleCoder standalone MCP server.
|
|
3
|
+
*
|
|
4
|
+
* Spawned by `claude --mcp-config` when running under PtyProvider, communicates
|
|
5
|
+
* over stdio. Tools that need bot-side context (Telegram send_file / ask_user /
|
|
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.
|
|
8
|
+
*
|
|
9
|
+
* Env vars set by PtyProvider when spawning this process. These are an internal
|
|
10
|
+
* contract between the two — PtyProvider writes them and only this file reads
|
|
11
|
+
* them, both from the same build — so unlike the user-settable vars they carry
|
|
12
|
+
* no pre-rename CLAUDEGRAM_* fallback:
|
|
13
|
+
* TELECODER_IPC_PORT loopback IPC server port
|
|
14
|
+
* TELECODER_IPC_TOKEN secret the IPC server requires on every call;
|
|
15
|
+
* inherited from claude's env, never in args
|
|
16
|
+
* TELECODER_CLAUDE_SESSION_ID claude's session_id; used as the IPC routing key
|
|
17
|
+
* TELECODER_WORKSPACE_ROOT workspace root for security checks
|
|
18
|
+
* TELECODER_TELEGRAPH_ENABLED feature flag for publish_telegraph
|
|
19
|
+
*/
|
|
20
|
+
import { McpServer } from '@modelcontextprotocol/sdk/server/mcp.js';
|
|
21
|
+
import { StdioServerTransport } from '@modelcontextprotocol/sdk/server/stdio.js';
|
|
22
|
+
import { z } from 'zod';
|
|
23
|
+
import * as fs from 'fs';
|
|
24
|
+
import * as path from 'path';
|
|
25
|
+
import * as http from 'http';
|
|
26
|
+
import { toolResult } from './tool-result.js';
|
|
27
|
+
const workspaceRoot = process.env.TELECODER_WORKSPACE_ROOT || path.resolve(process.cwd());
|
|
28
|
+
const ipcPort = process.env.TELECODER_IPC_PORT;
|
|
29
|
+
const claudeSessionId = process.env.TELECODER_CLAUDE_SESSION_ID || '';
|
|
30
|
+
const ipcToken = process.env.TELECODER_IPC_TOKEN || '';
|
|
31
|
+
/**
|
|
32
|
+
* POST a JSON payload to the bot's loopback IPC server. claude's session_id
|
|
33
|
+
* is appended automatically so the IPC server can route to the right active
|
|
34
|
+
* turn. Throws on non-2xx so the calling tool can surface a useful error.
|
|
35
|
+
*
|
|
36
|
+
* Deliberately `node:http` rather than `fetch`. telecoder_ask_user and
|
|
37
|
+
* telecoder_poll_user are long polls: the bot holds the request open — sending
|
|
38
|
+
* no response headers at all — for as long as the question stays open
|
|
39
|
+
* (QUESTION_TIMEOUT_MINUTES, 10 by default) while it waits for a Telegram
|
|
40
|
+
* button tap. undici, which backs global fetch, enforces a 5-minute
|
|
41
|
+
* `headersTimeout` that can only be lifted with a custom dispatcher, so every
|
|
42
|
+
* question left unanswered for 5 minutes died as an opaque `fetch failed`
|
|
43
|
+
* (UND_ERR_HEADERS_TIMEOUT) instead of the intended graceful 10-minute "user
|
|
44
|
+
* did not respond" — and the model, seeing a tool error, tended to re-ask and
|
|
45
|
+
* post a second keyboard while the first was still live.
|
|
46
|
+
*
|
|
47
|
+
* `http.request` applies no timeout unless asked, which puts the deadline back
|
|
48
|
+
* with the layers that actually know it: the bot's own question timer (see
|
|
49
|
+
* createPendingQuestion), with claude's MCP_TOOL_TIMEOUT (set by PtyProvider to
|
|
50
|
+
* five minutes past it) as the outer backstop. The server side already disables its own
|
|
51
|
+
* timeouts for the same reason — see startIpcServer.
|
|
52
|
+
*/
|
|
53
|
+
function ipc(routePath, payload = {}, signal) {
|
|
54
|
+
if (!ipcPort)
|
|
55
|
+
return Promise.reject(new Error('TELECODER_IPC_PORT not set; cannot reach bot'));
|
|
56
|
+
if (signal?.aborted)
|
|
57
|
+
return Promise.reject(new Error(`IPC ${routePath} → cancelled`));
|
|
58
|
+
const body = JSON.stringify({ session_id: claudeSessionId, ...payload });
|
|
59
|
+
return new Promise((resolve, reject) => {
|
|
60
|
+
const req = http.request({
|
|
61
|
+
host: '127.0.0.1',
|
|
62
|
+
port: Number(ipcPort),
|
|
63
|
+
path: routePath,
|
|
64
|
+
method: 'POST',
|
|
65
|
+
headers: {
|
|
66
|
+
'Content-Type': 'application/json',
|
|
67
|
+
'Content-Length': Buffer.byteLength(body),
|
|
68
|
+
'X-TeleCoder-Token': ipcToken,
|
|
69
|
+
},
|
|
70
|
+
}, (res) => {
|
|
71
|
+
const chunks = [];
|
|
72
|
+
res.on('data', (chunk) => chunks.push(chunk));
|
|
73
|
+
res.on('end', () => {
|
|
74
|
+
const status = res.statusCode ?? 0;
|
|
75
|
+
if (status < 200 || status >= 300) {
|
|
76
|
+
reject(new Error(`IPC ${routePath} → HTTP ${status}`));
|
|
77
|
+
return;
|
|
78
|
+
}
|
|
79
|
+
try {
|
|
80
|
+
resolve(JSON.parse(Buffer.concat(chunks).toString('utf8')));
|
|
81
|
+
}
|
|
82
|
+
catch {
|
|
83
|
+
reject(new Error(`IPC ${routePath} → malformed JSON response`));
|
|
84
|
+
}
|
|
85
|
+
});
|
|
86
|
+
res.on('error', (err) => reject(new Error(`IPC ${routePath} → ${err.message}`)));
|
|
87
|
+
});
|
|
88
|
+
// Name the actual failure rather than fetch's opaque "fetch failed". The
|
|
89
|
+
// common one is ECONNREFUSED: the bot restarted (new port) while this pty
|
|
90
|
+
// and its MCP subprocess kept running against the old one.
|
|
91
|
+
req.on('error', (err) => {
|
|
92
|
+
reject(new Error(`IPC ${routePath} → ${err.code ?? err.message}`));
|
|
93
|
+
});
|
|
94
|
+
// A tool call claude cancels hangs up on the bot, which is how a request
|
|
95
|
+
// it holds open for the call learns nobody is waiting for it any more.
|
|
96
|
+
signal?.addEventListener('abort', () => req.destroy(new Error('cancelled')), { once: true });
|
|
97
|
+
req.end(body);
|
|
98
|
+
});
|
|
99
|
+
}
|
|
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
|
+
const server = new McpServer({
|
|
106
|
+
name: 'telecoder-tools',
|
|
107
|
+
version: '1.0.0',
|
|
108
|
+
});
|
|
109
|
+
// ── telecoder_list_projects (no IPC, no flag — always on) ───────────
|
|
110
|
+
server.tool('telecoder_list_projects', 'List all available projects in the workspace directory. Use this to see what projects the user can switch to.', {}, async () => {
|
|
111
|
+
try {
|
|
112
|
+
const entries = fs.readdirSync(workspaceRoot, { withFileTypes: true });
|
|
113
|
+
const projects = entries
|
|
114
|
+
.filter(e => e.isDirectory() && !e.name.startsWith('.'))
|
|
115
|
+
.map(e => e.name);
|
|
116
|
+
return {
|
|
117
|
+
content: [{
|
|
118
|
+
type: 'text',
|
|
119
|
+
text: `Projects in ${workspaceRoot}:\n${projects.join('\n')}`,
|
|
120
|
+
}],
|
|
121
|
+
};
|
|
122
|
+
}
|
|
123
|
+
catch (error) {
|
|
124
|
+
return {
|
|
125
|
+
content: [{
|
|
126
|
+
type: 'text',
|
|
127
|
+
text: `Error listing projects: ${error instanceof Error ? error.message : String(error)}`,
|
|
128
|
+
}],
|
|
129
|
+
isError: true,
|
|
130
|
+
};
|
|
131
|
+
}
|
|
132
|
+
});
|
|
133
|
+
// ── 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).'),
|
|
136
|
+
context: z
|
|
137
|
+
.string()
|
|
138
|
+
.min(1)
|
|
139
|
+
.describe('Required. The multi-line explanation shown above the buttons in the same message (e.g. a comparison table, trade-offs, findings the user needs to make an informed choice). Put decision-relevant detail here, not in prose before the call — that prose is not shown until after the user answers. If the choice genuinely needs no explanation, restate what each option will do.'),
|
|
140
|
+
options: z
|
|
141
|
+
.array(z.object({
|
|
142
|
+
label: z.string().describe('Button label. ≤ 25 chars keeps the label on its own button; longer labels are still shown in full in the message body, keyed A/B/C. Keep it to one line either way.'),
|
|
143
|
+
description: z.string().optional().describe('Optional one-line context shown in the question body.'),
|
|
144
|
+
}))
|
|
145
|
+
.min(2)
|
|
146
|
+
.max(8)
|
|
147
|
+
.describe('Between 2 and 8 options for the user to choose from.'),
|
|
148
|
+
}, async ({ question, context, options }) => {
|
|
149
|
+
try {
|
|
150
|
+
const result = await ipc('/mcp/ask_user', { question, context, options });
|
|
151
|
+
return toolResult(result);
|
|
152
|
+
}
|
|
153
|
+
catch (error) {
|
|
154
|
+
return {
|
|
155
|
+
content: [{ type: 'text', text: `Ask-user error: ${error instanceof Error ? error.message : String(error)}` }],
|
|
156
|
+
isError: true,
|
|
157
|
+
};
|
|
158
|
+
}
|
|
159
|
+
});
|
|
160
|
+
// ── telecoder_request_secret (IPC: long-poll on the user's message) ──
|
|
161
|
+
server.tool('telecoder_request_secret', 'Get a secret from the user (an API key, token or password) without it entering this conversation. The user sends it in Telegram; TeleCoder deletes their message at once and runs `command` with the secret in $SECRET and on stdin. You get the exit code and the output with the secret blanked out, never the value. Use this whenever a task needs a credential from the user: never ask them to paste one into the chat, and don\'t send them to a terminal or a `!` command for it. They see the command before they send anything, so make it do exactly what it says. For a long-lived Claude token (CLAUDE_CODE_OAUTH_TOKEN), set source to "claude-setup-token": TeleCoder runs `claude setup-token` on this machine and walks them through signing in, and the token goes straight into your command without passing through Telegram. Works only in a private chat with an admin of the bot. Blocks until the command has run, the user cancels, or the request times out.', {
|
|
162
|
+
name: z.string().min(1).max(100).describe('What the secret is, as the user knows it: an env var name like CLAUDE_CODE_OAUTH_TOKEN, or a label like "Stripe test key".'),
|
|
163
|
+
purpose: z.string().min(1).describe('One or two sentences for the user: what it is for, and where to get it.'),
|
|
164
|
+
command: z.string().min(1).describe('Bash that consumes the secret, from $SECRET or from stdin (the secret and a newline). It runs once, with no terminal, and has 2 minutes. Prefer stdin where the tool reads it: an argument shows in the process list while the command runs. Example: npx dotenvx set API_KEY "$SECRET" -f .env'),
|
|
165
|
+
cwd: z.string().optional().describe('Directory to run the command in. Defaults to the session\'s working directory; ~ works.'),
|
|
166
|
+
pattern: z.string().optional().describe('A regular expression the secret has to match, e.g. ^sk-ant-oat01-. A message that doesn\'t match is deleted unused and the user asked again, so a stray reply can\'t end up stored as the secret.'),
|
|
167
|
+
source: z.enum(['paste', 'claude-setup-token']).optional().describe('"paste" (the default): the user sends the secret. "claude-setup-token": TeleCoder makes a long-lived Claude OAuth token by running `claude setup-token` here; the user signs in through a link and sends back the code the page shows. A token they already have is accepted too.'),
|
|
168
|
+
}, async (args, extra) => {
|
|
169
|
+
try {
|
|
170
|
+
const result = await ipc('/mcp/request_secret', args, extra.signal);
|
|
171
|
+
return toolResult(result);
|
|
172
|
+
}
|
|
173
|
+
catch (error) {
|
|
174
|
+
return {
|
|
175
|
+
content: [{ type: 'text', text: `Secret request error: ${error instanceof Error ? error.message : String(error)}` }],
|
|
176
|
+
isError: true,
|
|
177
|
+
};
|
|
178
|
+
}
|
|
179
|
+
});
|
|
180
|
+
// ── telecoder_switch_project (IPC: updates session workdir) ─────────
|
|
181
|
+
server.tool('telecoder_switch_project', 'Switch the working directory to a different project. The change takes effect on the next query. Use telecoder_list_projects first to see available projects.', {
|
|
182
|
+
project_name: z.string().describe('Name of the project directory to switch to'),
|
|
183
|
+
}, async ({ project_name }) => {
|
|
184
|
+
try {
|
|
185
|
+
const result = await ipc('/mcp/switch_project', { project_name });
|
|
186
|
+
return toolResult(result);
|
|
187
|
+
}
|
|
188
|
+
catch (error) {
|
|
189
|
+
return {
|
|
190
|
+
content: [{ type: 'text', text: `Switch project error: ${error instanceof Error ? error.message : String(error)}` }],
|
|
191
|
+
isError: true,
|
|
192
|
+
};
|
|
193
|
+
}
|
|
194
|
+
});
|
|
195
|
+
// ── telecoder_create_bot (IPC: needs the bot to send the button) ────
|
|
196
|
+
server.tool('telecoder_create_bot', "Create a Telegram bot for one project: sends the user a button that opens Telegram's create-a-bot screen. Once they confirm, the new bot is added to the launcher and starts in that project. Use when the user asks for a bot for a project. Only from a private chat, and only for an admin.", {
|
|
197
|
+
project_name: z.string().describe('Project directory name in the workspace, or an absolute path'),
|
|
198
|
+
}, async ({ project_name }) => {
|
|
199
|
+
try {
|
|
200
|
+
const result = await ipc('/mcp/create_bot', { project_name });
|
|
201
|
+
return toolResult(result);
|
|
202
|
+
}
|
|
203
|
+
catch (error) {
|
|
204
|
+
return {
|
|
205
|
+
content: [{ type: 'text', text: `Create bot error: ${error instanceof Error ? error.message : String(error)}` }],
|
|
206
|
+
isError: true,
|
|
207
|
+
};
|
|
208
|
+
}
|
|
209
|
+
});
|
|
210
|
+
// ── 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.', {
|
|
212
|
+
file_path: z.string().describe('Absolute or workspace-relative path to the file to send.'),
|
|
213
|
+
caption: z.string().optional().describe('Optional caption to display with the file in Telegram.'),
|
|
214
|
+
}, async ({ file_path, caption }) => {
|
|
215
|
+
try {
|
|
216
|
+
const result = await ipc('/mcp/send_file', { file_path, caption });
|
|
217
|
+
return toolResult(result);
|
|
218
|
+
}
|
|
219
|
+
catch (error) {
|
|
220
|
+
return {
|
|
221
|
+
content: [{ type: 'text', text: `File send error: ${error instanceof Error ? error.message : String(error)}` }],
|
|
222
|
+
isError: true,
|
|
223
|
+
};
|
|
224
|
+
}
|
|
225
|
+
});
|
|
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
|
+
}
|
|
274
|
+
// ── telecoder_poll_user (IPC: Telegram poll) ────────────────────────
|
|
275
|
+
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
|
+
question: z.string().describe('The poll question. ≤ 300 chars (Telegram cap).'),
|
|
277
|
+
options: z.array(z.string()).min(2).max(10).describe('Poll options. Each ≤ 100 chars.'),
|
|
278
|
+
allows_multiple_answers: z.boolean().optional().describe('Whether voters can pick more than one option. Default false.'),
|
|
279
|
+
}, async ({ question, options, allows_multiple_answers }) => {
|
|
280
|
+
try {
|
|
281
|
+
const result = await ipc('/mcp/poll_user', {
|
|
282
|
+
question,
|
|
283
|
+
options,
|
|
284
|
+
allows_multiple_answers: !!allows_multiple_answers,
|
|
285
|
+
});
|
|
286
|
+
return toolResult(result);
|
|
287
|
+
}
|
|
288
|
+
catch (error) {
|
|
289
|
+
return {
|
|
290
|
+
content: [{ type: 'text', text: `Poll error: ${error instanceof Error ? error.message : String(error)}` }],
|
|
291
|
+
isError: true,
|
|
292
|
+
};
|
|
293
|
+
}
|
|
294
|
+
});
|
|
295
|
+
// ── telecoder_loop (IPC: registers an interval schedule) ────────────
|
|
296
|
+
server.tool('telecoder_loop', 'Schedule a prompt to re-fire on a fixed interval, pinging the user via Telegram each time. Use for "every N minutes/hours, do X" tasks (poll a status, check a metric, remind me). The first fire is one interval from now, NOT immediately. Returns the schedule id. Hard caps: 60s minimum interval, default 50 fires (max 500), 10 schedules per chat.', {
|
|
297
|
+
prompt: z.string().describe('Exact prompt to re-fire on each tick. Write it as a complete instruction — the model receives it with no extra context beyond your current session.'),
|
|
298
|
+
interval_seconds: z.number().int().min(60).describe('How often to fire, in seconds. Must be ≥ 60.'),
|
|
299
|
+
max_runs: z.number().int().min(1).max(500).optional().describe('Cap on total fires. Default 50, ceiling 500. Schedule auto-disables after the cap is hit.'),
|
|
300
|
+
label: z.string().optional().describe('Short human-readable title shown in the "🔔 Scheduled" header (≤ 60 chars recommended).'),
|
|
301
|
+
}, async ({ prompt, interval_seconds, max_runs, label }) => {
|
|
302
|
+
try {
|
|
303
|
+
const result = await ipc('/mcp/schedule_loop', {
|
|
304
|
+
prompt,
|
|
305
|
+
interval_seconds,
|
|
306
|
+
max_runs,
|
|
307
|
+
label,
|
|
308
|
+
});
|
|
309
|
+
return toolResult(result);
|
|
310
|
+
}
|
|
311
|
+
catch (error) {
|
|
312
|
+
return {
|
|
313
|
+
content: [{ type: 'text', text: `Loop schedule error: ${error instanceof Error ? error.message : String(error)}` }],
|
|
314
|
+
isError: true,
|
|
315
|
+
};
|
|
316
|
+
}
|
|
317
|
+
});
|
|
318
|
+
// ── telecoder_schedule (IPC: registers a cron-based schedule) ───────
|
|
319
|
+
server.tool('telecoder_schedule', 'Schedule a prompt to fire on a cron expression (e.g. "0 9 * * *" for daily 9am). Use for time-of-day or day-of-week tasks (morning standup, weekly summary, end-of-day report). 5-field cron only (minute hour day-of-month month day-of-week). Returns the schedule id. Same caps as telecoder_loop.', {
|
|
320
|
+
prompt: z.string().describe('Exact prompt to fire on each scheduled time.'),
|
|
321
|
+
cron_expression: z.string().describe('5-field cron expression. Examples: "0 9 * * *" (daily 9am), "0 9 * * 1-5" (weekdays 9am), "*/15 * * * *" (every 15 min on the dot — note: subject to the same 60s minimum).'),
|
|
322
|
+
max_runs: z.number().int().min(1).max(500).optional().describe('Cap on total fires. Default 50, ceiling 500.'),
|
|
323
|
+
label: z.string().optional().describe('Short human-readable title shown in the "🔔 Scheduled" header.'),
|
|
324
|
+
}, async ({ prompt, cron_expression, max_runs, label }) => {
|
|
325
|
+
try {
|
|
326
|
+
const result = await ipc('/mcp/schedule_cron', {
|
|
327
|
+
prompt,
|
|
328
|
+
cron_expression,
|
|
329
|
+
max_runs,
|
|
330
|
+
label,
|
|
331
|
+
});
|
|
332
|
+
return toolResult(result);
|
|
333
|
+
}
|
|
334
|
+
catch (error) {
|
|
335
|
+
return {
|
|
336
|
+
content: [{ type: 'text', text: `Cron schedule error: ${error instanceof Error ? error.message : String(error)}` }],
|
|
337
|
+
isError: true,
|
|
338
|
+
};
|
|
339
|
+
}
|
|
340
|
+
});
|
|
341
|
+
// ── telecoder_list_schedules (IPC: read-only) ───────────────────────
|
|
342
|
+
server.tool('telecoder_list_schedules', 'List active schedules for the current chat. Returns each schedule\'s id, type, cadence, run count, and prompt preview. Use before creating a new schedule to check existing ones, or to find an id to cancel.', {}, async () => {
|
|
343
|
+
try {
|
|
344
|
+
const result = await ipc('/mcp/schedule_list', {});
|
|
345
|
+
return toolResult(result);
|
|
346
|
+
}
|
|
347
|
+
catch (error) {
|
|
348
|
+
return {
|
|
349
|
+
content: [{ type: 'text', text: `List schedules error: ${error instanceof Error ? error.message : String(error)}` }],
|
|
350
|
+
isError: true,
|
|
351
|
+
};
|
|
352
|
+
}
|
|
353
|
+
});
|
|
354
|
+
// ── telecoder_cancel_schedule (IPC: remove a schedule by id) ────────
|
|
355
|
+
server.tool('telecoder_cancel_schedule', 'Cancel and remove a scheduled task by id. Get the id from telecoder_list_schedules.', {
|
|
356
|
+
id: z.string().describe('The schedule id (looks like sch_xxxxxxxx_xxxxxx).'),
|
|
357
|
+
}, async ({ id }) => {
|
|
358
|
+
try {
|
|
359
|
+
const result = await ipc('/mcp/schedule_cancel', { id });
|
|
360
|
+
return toolResult(result);
|
|
361
|
+
}
|
|
362
|
+
catch (error) {
|
|
363
|
+
return {
|
|
364
|
+
content: [{ type: 'text', text: `Cancel schedule error: ${error instanceof Error ? error.message : String(error)}` }],
|
|
365
|
+
isError: true,
|
|
366
|
+
};
|
|
367
|
+
}
|
|
368
|
+
});
|
|
369
|
+
async function main() {
|
|
370
|
+
const transport = new StdioServerTransport();
|
|
371
|
+
await server.connect(transport);
|
|
372
|
+
console.error(`[telecoder-mcp] connected via stdio (workspace=${workspaceRoot})`);
|
|
373
|
+
}
|
|
374
|
+
main().catch((err) => {
|
|
375
|
+
console.error('[telecoder-mcp] fatal:', err);
|
|
376
|
+
process.exit(1);
|
|
377
|
+
});
|
|
378
|
+
//# sourceMappingURL=mcp-server.js.map
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The MCP tool result for the bot's answer to a tool's IPC request.
|
|
3
|
+
*
|
|
4
|
+
* Kept out of mcp-server.ts, which starts serving on stdio as soon as it is
|
|
5
|
+
* loaded, so it can be tested on its own.
|
|
6
|
+
*/
|
|
7
|
+
/**
|
|
8
|
+
* `reply` as a tool result. An answer without a message — the ack the bot
|
|
9
|
+
* gives a request it ignores — would otherwise make a text block with no text,
|
|
10
|
+
* which the MCP SDK rejects with a -32602 schema dump that says nothing of
|
|
11
|
+
* what went wrong.
|
|
12
|
+
*/
|
|
13
|
+
export function toolResult(reply) {
|
|
14
|
+
if (typeof reply.message !== 'string') {
|
|
15
|
+
return {
|
|
16
|
+
content: [{ type: 'text', text: 'TeleCoder answered without saying what happened, so this may not have been done.' }],
|
|
17
|
+
isError: true,
|
|
18
|
+
};
|
|
19
|
+
}
|
|
20
|
+
return { content: [{ type: 'text', text: reply.message }], isError: !reply.success };
|
|
21
|
+
}
|
|
22
|
+
//# sourceMappingURL=tool-result.js.map
|