opencode-tbot 0.1.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/INSTALL.md ADDED
@@ -0,0 +1,92 @@
1
+ # Install `opencode-tbot`
2
+
3
+ ## Recommended
4
+
5
+ Run:
6
+
7
+ ```bash
8
+ npx opencode-tbot@latest install
9
+ ```
10
+
11
+ The installer will:
12
+
13
+ 1. update `~/.config/opencode/opencode.json`
14
+ 2. ensure the `plugin` array contains `opencode-tbot@latest`
15
+ 3. prompt for the Telegram bot token
16
+ 4. ask whether voice transcription should be enabled
17
+ 5. prompt for the OpenRouter API key when voice transcription is enabled
18
+ 6. write plugin defaults to `~/.config/opencode/opencode-tbot/config.json`
19
+
20
+ Restart OpenCode after installation.
21
+
22
+ ## Non-Interactive
23
+
24
+ Example:
25
+
26
+ ```bash
27
+ npx opencode-tbot@latest install \
28
+ --bot-token <telegram-token> \
29
+ --disable-voice
30
+ ```
31
+
32
+ If voice transcription is enabled:
33
+
34
+ ```bash
35
+ npx opencode-tbot@latest install \
36
+ --bot-token <telegram-token> \
37
+ --enable-voice \
38
+ --openrouter-api-key <openrouter-key>
39
+ ```
40
+
41
+ Useful flags:
42
+
43
+ - `--telegram-api-root <url>`
44
+ - `--skip-register`
45
+ - `--home-dir <path>`
46
+
47
+ `--skip-register` only skips the OpenCode global registration step. The plugin config file is still written.
48
+
49
+ ## Project Overrides
50
+
51
+ The installer writes global defaults to:
52
+
53
+ - `~/.config/opencode/opencode-tbot/config.json`
54
+
55
+ You can override them per worktree with:
56
+
57
+ - `<worktree>/tbot.config.json`
58
+ - legacy fallback: `<worktree>/opencode-tbot.config.json`
59
+
60
+ The runtime loads global defaults first, then deep-merges the project config on top.
61
+
62
+ Example project override:
63
+
64
+ ```json
65
+ {
66
+ "telegram": {
67
+ "allowedChatIds": [123456789]
68
+ },
69
+ "state": {
70
+ "path": "./data/opencode-tbot.state.json"
71
+ },
72
+ "logLevel": "info"
73
+ }
74
+ ```
75
+
76
+ ## Agent Prompt
77
+
78
+ If you want another coding agent to perform the install, give it this:
79
+
80
+ ```text
81
+ Install opencode-tbot for OpenCode by running:
82
+ npx opencode-tbot@latest install
83
+
84
+ If the environment is non-interactive, use:
85
+ - --bot-token for the Telegram bot token
86
+ - --enable-voice or --disable-voice
87
+ - --openrouter-api-key when voice transcription is enabled
88
+
89
+ Do not remove unrelated existing configuration.
90
+ Preserve existing plugins in ~/.config/opencode/opencode.json.
91
+ Show me the final changes and tell me to restart OpenCode.
92
+ ```
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 opencode-tbot contributors
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,190 @@
1
+ # opencode-tbot
2
+
3
+ A Telegram plugin for driving [OpenCode](https://opencode.ai) from chat.
4
+
5
+ [English](./README.md) | [简体中文](./README.zh-CN.md)
6
+
7
+ > This project is not built by the OpenCode team and is not affiliated with them.
8
+
9
+ ## What It Does
10
+
11
+ `opencode-tbot` lets you operate OpenCode from Telegram.
12
+
13
+ - Text messages are forwarded to the active OpenCode session.
14
+ - Telegram images are uploaded as OpenCode file parts.
15
+ - Telegram voice messages can be transcribed through OpenRouter before entering the normal prompt flow.
16
+ - Permission requests raised by OpenCode can be approved or rejected directly from Telegram inline buttons.
17
+ - Session completion and error events can be reported back to the bound Telegram chat.
18
+ - Chat state is stored in a JSON state file that works in both Node and Bun runtimes.
19
+
20
+ This repository runs as an OpenCode plugin. There is no standalone bot service.
21
+
22
+ ## Installation
23
+
24
+ ### Requirements
25
+
26
+ - OpenCode must be installed and able to load plugins.
27
+ - Node.js 22.12.0 or newer is required for local builds and development.
28
+ - You need a Telegram bot token from BotFather.
29
+
30
+ ### Recommended Install Flow
31
+
32
+ Run:
33
+
34
+ ```bash
35
+ npx opencode-tbot@latest install
36
+ ```
37
+
38
+ The installer will:
39
+
40
+ 1. register `opencode-tbot@latest` in `~/.config/opencode/opencode.json`
41
+ 2. ask for your Telegram bot token
42
+ 3. ask whether voice transcription should be enabled
43
+ 4. ask for an OpenRouter API key if voice transcription is enabled
44
+ 5. write plugin defaults to `~/.config/opencode/opencode-tbot/config.json`
45
+
46
+ Restart OpenCode after installation, then message the bot with `/start` or `/status`.
47
+
48
+ ### Non-Interactive Install
49
+
50
+ For CI or scripted setup:
51
+
52
+ ```bash
53
+ npx opencode-tbot@latest install \
54
+ --bot-token <telegram-token> \
55
+ --disable-voice
56
+ ```
57
+
58
+ If voice transcription is enabled, `--openrouter-api-key` is required.
59
+
60
+ Useful flags:
61
+
62
+ - `--enable-voice`
63
+ - `--disable-voice`
64
+ - `--openrouter-api-key <key>`
65
+ - `--telegram-api-root <url>`
66
+ - `--skip-register`
67
+ - `--home-dir <path>`
68
+
69
+ `--skip-register` is mainly for tests or local packaging flows where plugin registration is handled separately.
70
+
71
+ ## Configuration
72
+
73
+ The runtime config is loaded in this order:
74
+
75
+ 1. global defaults from `~/.config/opencode/opencode-tbot/config.json`
76
+ 2. project overrides from `<worktree>/tbot.config.json`
77
+ 3. legacy project filename `<worktree>/opencode-tbot.config.json` if `tbot.config.json` is absent
78
+
79
+ Project config is merged on top of the global config. `telegram`, `state`, and `openrouter` are deep-merged by section.
80
+
81
+ ### Example `tbot.config.json`
82
+
83
+ ```json
84
+ {
85
+ "telegram": {
86
+ "botToken": "your_telegram_bot_token",
87
+ "allowedChatIds": [123456789],
88
+ "apiRoot": "https://api.telegram.org"
89
+ },
90
+ "state": {
91
+ "path": "./data/opencode-tbot.state.json"
92
+ },
93
+ "openrouter": {
94
+ "apiKey": "your_openrouter_api_key",
95
+ "model": "openai/gpt-audio-mini",
96
+ "timeoutMs": 30000,
97
+ "transcriptionPrompt": ""
98
+ },
99
+ "logLevel": "info"
100
+ }
101
+ ```
102
+
103
+ ### Fields
104
+
105
+ | Field | Required | Default | Description |
106
+ | --- | --- | --- | --- |
107
+ | `telegram.botToken` | Yes | - | Telegram bot token. Normally written by the installer into the global plugin config. |
108
+ | `telegram.allowedChatIds` | No | `[]` | Allowed Telegram chat IDs. If empty, the bot accepts messages from any chat. |
109
+ | `telegram.apiRoot` | No | `https://api.telegram.org` | Telegram Bot API base URL. Useful for tests or self-hosted gateways. |
110
+ | `state.path` | No | `./data/opencode-tbot.state.json` | JSON state file path, resolved relative to the current OpenCode worktree. |
111
+ | `database.path` | Legacy | - | Backward-compatible alias for `state.path`. No sqlite migration is performed. |
112
+ | `openrouter.apiKey` | No | `""` | OpenRouter API key. Required only when voice transcription is enabled. |
113
+ | `openrouter.model` | No | `openai/gpt-audio-mini` | OpenRouter model for voice transcription. |
114
+ | `openrouter.timeoutMs` | No | `30000` | Voice transcription timeout in milliseconds. |
115
+ | `openrouter.transcriptionPrompt` | No | `""` | Optional extra instruction appended to the transcription prompt. |
116
+ | `logLevel` | No | `info` | Plugin log level. Logs are emitted through `client.app.log()`. |
117
+
118
+ ## Features
119
+
120
+ - Send text prompts to OpenCode from Telegram
121
+ - Send Telegram images to OpenCode with optional caption text
122
+ - Transcribe Telegram voice messages through OpenRouter
123
+ - Create and switch OpenCode sessions in chat
124
+ - View and switch agents
125
+ - View and switch models and reasoning levels
126
+ - Approve or reject OpenCode permission requests from Telegram
127
+ - Receive session error and idle notifications in Telegram
128
+ - Restrict access with an optional Telegram allowlist
129
+ - Persist chat bindings and pending actions in a JSON state file
130
+
131
+ ## Commands
132
+
133
+ - `/start` show the welcome message and quick-start steps
134
+ - `/help` show the full command reference and examples
135
+ - `/status` show aggregated OpenCode health, path, LSP, and MCP status
136
+ - `/new [title]` create a new OpenCode session
137
+ - `/agents` or `/agent` list available agents and switch the active one
138
+ - `/sessions` list available sessions and switch the active one
139
+ - `/cancel` cancel session rename or abort the running request for the current session
140
+ - `/model` or `/models` list available models and switch the active one
141
+ - `/language` switch the bot display language
142
+
143
+ Any non-command text message is treated as a prompt and sent to OpenCode. Telegram `voice` messages follow the same prompt flow after transcription when OpenRouter is configured. Telegram images are forwarded as OpenCode file parts.
144
+
145
+ ## Local Development
146
+
147
+ Build the plugin bundle:
148
+
149
+ ```bash
150
+ pnpm build
151
+ ```
152
+
153
+ Type-check:
154
+
155
+ ```bash
156
+ pnpm typecheck
157
+ ```
158
+
159
+ Run tests:
160
+
161
+ ```bash
162
+ pnpm test
163
+ ```
164
+
165
+ For local source-based loading in this repository, OpenCode can use [.opencode/plugins/opencode-tbot.ts](./.opencode/plugins/opencode-tbot.ts), which re-exports `src/plugin.ts`.
166
+
167
+ ## Deployment
168
+
169
+ Supported deployment modes:
170
+
171
+ - Recommended npm installation through `npx opencode-tbot@latest install`
172
+ - Non-interactive install for CI or scripted environments
173
+ - Local development bridge through `.opencode/plugins/opencode-tbot.ts`
174
+ - Unpublished external-project bridge that re-exports `dist/plugin.js`
175
+
176
+ Deployment details are documented in [docs/deployment.md](./docs/deployment.md).
177
+
178
+ ## FAQ
179
+
180
+ ### Do I need a running OpenCode instance?
181
+
182
+ Yes. This repository provides a Telegram integration layer and depends on the OpenCode host process that loads the plugin.
183
+
184
+ ### Is this an official OpenCode project?
185
+
186
+ No. It integrates with OpenCode, but it is not built by the OpenCode team.
187
+
188
+ ### Why is Node.js 22 recommended?
189
+
190
+ The project uses modern Node APIs for the CLI, tests, and local development. Runtime state storage is file-based and works in both Node and Bun-compatible plugin hosts.
@@ -0,0 +1,190 @@
1
+ # opencode-tbot
2
+
3
+ 一个通过 Telegram 驱动 [OpenCode](https://opencode.ai) 的插件。
4
+
5
+ [English](./README.md) | [简体中文](./README.zh-CN.md)
6
+
7
+ > 本项目并非由 OpenCode 团队开发,也不隶属于 OpenCode 官方。
8
+
9
+ ## 项目说明
10
+
11
+ `opencode-tbot` 允许你直接在 Telegram 中操作 OpenCode。
12
+
13
+ - 文本消息会转发到当前 OpenCode 会话。
14
+ - Telegram 图片会作为 OpenCode 文件片段上传。
15
+ - Telegram 语音消息可先通过 OpenRouter 转写,再进入正常 prompt 流程。
16
+ - OpenCode 触发的权限请求可以直接在 Telegram 中通过内联按钮批准或拒绝。
17
+ - 会话完成和错误事件可以主动回推到绑定的 Telegram chat。
18
+ - 聊天状态通过 JSON 状态文件持久化,可同时兼容 Node 和 Bun 运行环境。
19
+
20
+ 当前仓库以 OpenCode 插件形式运行,不再提供独立 bot 进程。
21
+
22
+ ## 安装
23
+
24
+ ### 环境要求
25
+
26
+ - 需要已安装并可加载插件的 OpenCode。
27
+ - 本地构建和开发需要 Node.js 22.12.0 或更高版本。
28
+ - 需要一个由 BotFather 创建的 Telegram bot token。
29
+
30
+ ### 推荐安装方式
31
+
32
+ 执行:
33
+
34
+ ```bash
35
+ npx opencode-tbot@latest install
36
+ ```
37
+
38
+ 安装器会自动完成以下步骤:
39
+
40
+ 1. 在 `~/.config/opencode/opencode.json` 中注册 `opencode-tbot@latest`
41
+ 2. 提示输入 Telegram bot token
42
+ 3. 询问是否启用语音转写
43
+ 4. 如果启用语音转写,则继续提示输入 OpenRouter API key
44
+ 5. 将插件全局默认配置写入 `~/.config/opencode/opencode-tbot/config.json`
45
+
46
+ 安装完成后重启 OpenCode,再向 bot 发送 `/start` 或 `/status` 验证即可。
47
+
48
+ ### 非交互安装
49
+
50
+ 适合 CI 或脚本化环境:
51
+
52
+ ```bash
53
+ npx opencode-tbot@latest install \
54
+ --bot-token <telegram-token> \
55
+ --disable-voice
56
+ ```
57
+
58
+ 如果启用了语音转写,则必须同时提供 `--openrouter-api-key`。
59
+
60
+ 常用参数:
61
+
62
+ - `--enable-voice`
63
+ - `--disable-voice`
64
+ - `--openrouter-api-key <key>`
65
+ - `--telegram-api-root <url>`
66
+ - `--skip-register`
67
+ - `--home-dir <path>`
68
+
69
+ `--skip-register` 主要用于测试或本地打包流程,此时插件注册由外部步骤负责。
70
+
71
+ ## 配置
72
+
73
+ 运行时配置按以下优先级加载:
74
+
75
+ 1. 全局默认配置 `~/.config/opencode/opencode-tbot/config.json`
76
+ 2. 项目覆盖配置 `<worktree>/tbot.config.json`
77
+ 3. 如果不存在 `tbot.config.json`,则兼容旧文件名 `<worktree>/opencode-tbot.config.json`
78
+
79
+ 项目配置会覆盖全局默认值;`telegram`、`state`、`openrouter` 这些分段配置会进行深合并。
80
+
81
+ ### `tbot.config.json` 示例
82
+
83
+ ```json
84
+ {
85
+ "telegram": {
86
+ "botToken": "your_telegram_bot_token",
87
+ "allowedChatIds": [123456789],
88
+ "apiRoot": "https://api.telegram.org"
89
+ },
90
+ "state": {
91
+ "path": "./data/opencode-tbot.state.json"
92
+ },
93
+ "openrouter": {
94
+ "apiKey": "your_openrouter_api_key",
95
+ "model": "openai/gpt-audio-mini",
96
+ "timeoutMs": 30000,
97
+ "transcriptionPrompt": ""
98
+ },
99
+ "logLevel": "info"
100
+ }
101
+ ```
102
+
103
+ ### 配置字段
104
+
105
+ | 字段 | 必填 | 默认值 | 说明 |
106
+ | --- | --- | --- | --- |
107
+ | `telegram.botToken` | 是 | - | Telegram bot token。通常由安装器写入全局插件配置。 |
108
+ | `telegram.allowedChatIds` | 否 | `[]` | 允许访问的 Telegram chat ID 数组。为空时表示接受任意 chat。 |
109
+ | `telegram.apiRoot` | 否 | `https://api.telegram.org` | Telegram Bot API 根地址,适合测试或自托管网关。 |
110
+ | `state.path` | 否 | `./data/opencode-tbot.state.json` | JSON 状态文件路径,相对当前 OpenCode worktree 解析。 |
111
+ | `database.path` | 兼容字段 | - | `state.path` 的旧别名,仅做兼容映射,不迁移 sqlite 数据。 |
112
+ | `openrouter.apiKey` | 否 | `""` | OpenRouter API key。仅在启用语音转写时需要。 |
113
+ | `openrouter.model` | 否 | `openai/gpt-audio-mini` | 语音转写使用的 OpenRouter 模型。 |
114
+ | `openrouter.timeoutMs` | 否 | `30000` | 语音转写超时时间,单位毫秒。 |
115
+ | `openrouter.transcriptionPrompt` | 否 | `""` | 追加到内置转写提示词后的可选说明。 |
116
+ | `logLevel` | 否 | `info` | 插件日志级别。日志统一通过 `client.app.log()` 上报。 |
117
+
118
+ ## 功能
119
+
120
+ - 在 Telegram 中向 OpenCode 发送文本 prompt
121
+ - 将 Telegram 图片连同可选 caption 一起转发给 OpenCode
122
+ - 通过 OpenRouter 转写 Telegram 语音消息
123
+ - 在聊天中创建和切换 OpenCode 会话
124
+ - 查看和切换 agent
125
+ - 查看和切换模型与推理等级
126
+ - 在 Telegram 中审批或拒绝 OpenCode 权限请求
127
+ - 接收会话错误和空闲通知
128
+ - 通过 Telegram allowlist 限制访问
129
+ - 使用 JSON 状态文件持久化聊天绑定和待处理动作
130
+
131
+ ## 命令
132
+
133
+ - `/start` 显示欢迎信息和快速开始说明
134
+ - `/help` 显示完整命令说明和示例
135
+ - `/status` 显示 OpenCode 健康状态、路径、LSP 和 MCP 信息
136
+ - `/new [title]` 创建新的 OpenCode 会话
137
+ - `/agents` 或 `/agent` 列出可用 agent 并切换当前 agent
138
+ - `/sessions` 列出会话并切换当前会话
139
+ - `/cancel` 取消会话重命名,或中止当前会话正在运行的请求
140
+ - `/model` 或 `/models` 列出可用模型并切换当前模型
141
+ - `/language` 切换 bot 显示语言
142
+
143
+ 任意非命令文本都会被当作 prompt 发送给 OpenCode。配置了 OpenRouter 后,Telegram `voice` 消息会先转写再走同一条 prompt 流程。图片会作为 OpenCode 文件片段上传。
144
+
145
+ ## 本地开发
146
+
147
+ 构建插件:
148
+
149
+ ```bash
150
+ pnpm build
151
+ ```
152
+
153
+ 类型检查:
154
+
155
+ ```bash
156
+ pnpm typecheck
157
+ ```
158
+
159
+ 运行测试:
160
+
161
+ ```bash
162
+ pnpm test
163
+ ```
164
+
165
+ 在本仓库中做源码调试时,OpenCode 可以通过 [.opencode/plugins/opencode-tbot.ts](./.opencode/plugins/opencode-tbot.ts) 直接加载 `src/plugin.ts`。
166
+
167
+ ## 部署
168
+
169
+ 支持的部署模式:
170
+
171
+ - 通过 `npx opencode-tbot@latest install` 的推荐安装流
172
+ - 面向 CI 或脚本环境的非交互安装
173
+ - 通过 `.opencode/plugins/opencode-tbot.ts` 的本地开发桥接
174
+ - 在外部项目中通过 re-export `dist/plugin.js` 的构建产物桥接
175
+
176
+ 更完整的部署说明见 [docs/deployment.md](./docs/deployment.md)。
177
+
178
+ ## 常见问题
179
+
180
+ ### 我需要一个正在运行的 OpenCode 实例吗?
181
+
182
+ 需要。这个仓库提供的是 Telegram 集成层,依赖加载它的 OpenCode Host 进程。
183
+
184
+ ### 这是 OpenCode 官方项目吗?
185
+
186
+ 不是。它只是与 OpenCode 集成,并非 OpenCode 官方项目。
187
+
188
+ ### 为什么仍然推荐 Node.js 22?
189
+
190
+ CLI、测试和本地开发仍然使用现代 Node API。插件运行时的状态存储已经改为文件方案,可兼容 Node 和 Bun 风格的宿主环境。
@@ -0,0 +1,2 @@
1
+ #!/usr/bin/env node
2
+ import("../dist/cli.js").then(({ main }) => main());