tellrun 1.0.1 → 1.1.2
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/LICENSE +21 -0
- package/README.md +144 -108
- package/README.zh-CN.md +207 -0
- package/dist/agents/codex.js +225 -80
- package/dist/agents/codex.js.map +1 -1
- package/dist/cli.js +39 -39
- package/dist/cli.js.map +1 -1
- package/dist/config.js +3 -3
- package/dist/config.js.map +1 -1
- package/dist/core/relay.js +80 -44
- package/dist/core/relay.js.map +1 -1
- package/dist/im/telegram.js +90 -14
- package/dist/im/telegram.js.map +1 -1
- package/dist/logger.js +1 -1
- package/dist/logger.js.map +1 -1
- package/dist/main.js +12 -12
- package/dist/main.js.map +1 -1
- package/dist/storage/schema.js +8 -1
- package/dist/storage/schema.js.map +1 -1
- package/dist/storage/store.js +88 -21
- package/dist/storage/store.js.map +1 -1
- package/dist/systemd.js +17 -17
- package/dist/systemd.js.map +1 -1
- package/docs/architecture.md +32 -18
- package/docs/prd.md +9 -9
- package/package.json +32 -5
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 chaoyue1998
|
|
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
CHANGED
|
@@ -1,171 +1,207 @@
|
|
|
1
|
-
# Tellrun
|
|
1
|
+
# Tellrun — Telegram Bot for OpenAI Codex
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
**Tellrun is a self-hosted Telegram bot for remote AI coding with OpenAI Codex CLI, persistent sessions, and streaming replies.**
|
|
4
4
|
|
|
5
|
-
Tellrun
|
|
5
|
+
Run Tellrun on your server and use Telegram on your phone or desktop to send coding tasks, continue conversations, and read results without keeping an SSH terminal open.
|
|
6
6
|
|
|
7
|
-
|
|
7
|
+
**English** | [简体中文](https://github.com/chaoyue1998/tellrun/blob/main/README.zh-CN.md)
|
|
8
8
|
|
|
9
|
-
|
|
10
|
-
- 通过 `npm install -g tellrun` 安装,命令行交互配置后在服务器后台运行。
|
|
11
|
-
- Telegram 私聊接入,采用长轮询。
|
|
12
|
-
- Codex 通过 `app-server` 接入。
|
|
13
|
-
- 支持多会话、任务排队、审批、停止和异常恢复。
|
|
14
|
-
- 暂不提供项目选择,Tellrun 不设置项目目录白名单。
|
|
15
|
-
- 后续逐步接入其他 IM、Claude 等 Agent。
|
|
9
|
+
[npm](https://www.npmjs.com/package/tellrun) · [GitHub](https://github.com/chaoyue1998/tellrun) · [Report an issue](https://github.com/chaoyue1998/tellrun/issues)
|
|
16
10
|
|
|
17
|
-
|
|
11
|
+
[Quick start](#install-and-connect-codex-to-telegram) · [Telegram commands](#telegram-commands) · [Configuration](#configuration-and-data) · [FAQ](#faq)
|
|
18
12
|
|
|
19
|
-
|
|
20
|
-
- [架构与技术选型](docs/architecture.md):架构图、框架与库、模块、数据模型、协议、恢复和部署方案。
|
|
13
|
+
## Features
|
|
21
14
|
|
|
22
|
-
|
|
15
|
+
- **Remote coding**: send tasks in a private Telegram chat and let Codex execute them on your server.
|
|
16
|
+
- **Continuous conversations**: keep the current conversation context, select a project with `/cwd`, and start fresh with `/new`.
|
|
17
|
+
- **Live feedback**: see typing indicators and streaming replies, and send additional instructions while a task is running.
|
|
18
|
+
- **Task control**: check status and recent results, stop a task and pause new work, and retain conversation and task records across restarts.
|
|
19
|
+
- **Personal deployment**: only the configured user's private messages are accepted. Long polling requires no webhook or inbound port configuration.
|
|
23
20
|
|
|
24
|
-
|
|
21
|
+
Currently supports **Telegram + Codex** for one user, with one task at a time. A session picker, a queue of separate tasks, approval and structured question interfaces, and image or file input are not yet supported.
|
|
25
22
|
|
|
26
|
-
|
|
23
|
+
|
|
24
|
+
## Install and connect Codex to Telegram
|
|
25
|
+
|
|
26
|
+
### 1. Prerequisites
|
|
27
|
+
|
|
28
|
+
- **Node.js ≥ 24.5.0**.
|
|
29
|
+
- **[Codex CLI](https://github.com/openai/codex)**: install and sign in as the same operating system user that will run Tellrun. Confirm that Codex works in your terminal.
|
|
30
|
+
- **Telegram Bot Token**: send `/newbot` to [@BotFather](https://t.me/BotFather), follow the prompts, and save the token. See the [official Telegram tutorial](https://core.telegram.org/bots/tutorial#obtain-your-bot-token).
|
|
31
|
+
- **Your numeric Telegram user ID**: this is not your `@username`. See [how to find it](#how-do-i-find-my-telegram-user-id).
|
|
32
|
+
|
|
33
|
+
Background service management requires **Linux with systemd user services**. Use `tellrun run` in the foreground for local development or with another process manager.
|
|
34
|
+
|
|
35
|
+
### 2. Install and configure
|
|
27
36
|
|
|
28
37
|
```sh
|
|
29
38
|
npm install -g tellrun
|
|
30
|
-
tellrun setup
|
|
31
|
-
tellrun start # 后续启动
|
|
32
|
-
tellrun status # 查看后台服务状态
|
|
33
|
-
tellrun logs # 查看日志
|
|
34
|
-
tellrun logs -f # 持续跟随日志
|
|
35
|
-
tellrun restart # 重启服务
|
|
36
|
-
tellrun stop # 停止后台服务
|
|
39
|
+
tellrun setup
|
|
37
40
|
```
|
|
38
41
|
|
|
39
|
-
|
|
42
|
+
Enter your Bot Token, numeric user ID, and Codex command or executable path. On Linux, the setup wizard can start the background service and optionally enable it at boot.
|
|
40
43
|
|
|
41
|
-
|
|
44
|
+
If you choose to save the configuration without starting the service, run this later:
|
|
42
45
|
|
|
43
|
-
|
|
46
|
+
```sh
|
|
47
|
+
tellrun start --enable
|
|
48
|
+
```
|
|
44
49
|
|
|
45
|
-
|
|
50
|
+
To run in the foreground instead:
|
|
51
|
+
|
|
52
|
+
```sh
|
|
53
|
+
tellrun run
|
|
54
|
+
```
|
|
46
55
|
|
|
47
|
-
|
|
56
|
+
### 3. Start chatting in Telegram
|
|
48
57
|
|
|
49
|
-
|
|
58
|
+
Open a private chat with your bot and send these messages one at a time. Replace the example path with an existing absolute project path on your server:
|
|
50
59
|
|
|
51
|
-
|
|
60
|
+
```text
|
|
61
|
+
/start
|
|
62
|
+
/cwd /home/you/projects/my-app
|
|
63
|
+
Help me understand this project. Explain its main modules and how to run it.
|
|
64
|
+
```
|
|
52
65
|
|
|
53
|
-
|
|
66
|
+
Send more text to continue the same conversation. Messages sent while a task is running become additional instructions for that task. For example:
|
|
54
67
|
|
|
55
68
|
```text
|
|
56
|
-
|
|
57
|
-
├── cli.ts # 全局命令与交互配置向导
|
|
58
|
-
├── systemd.ts # systemd 用户服务的启停、状态和日志
|
|
59
|
-
├── main.ts # 组件组装、启动和退出
|
|
60
|
-
├── config.ts # 用户配置、环境变量覆盖与校验
|
|
61
|
-
├── logger.ts # 结构化日志与敏感字段隐藏
|
|
62
|
-
├── agents/
|
|
63
|
-
│ └── codex.ts # Codex app-server 连接、续聊、执行和中断
|
|
64
|
-
├── im/
|
|
65
|
-
│ └── telegram.ts # Telegram 鉴权、消息转换和发送
|
|
66
|
-
├── core/
|
|
67
|
-
│ ├── relay.ts # 命令处理与单任务执行
|
|
68
|
-
│ └── types.ts # 跨模块共用的消息与 Agent 接口
|
|
69
|
-
└── storage/
|
|
70
|
-
├── store.ts # 状态读写、恢复和单实例锁
|
|
71
|
-
├── schema.ts # JSON 状态结构校验
|
|
72
|
-
└── json.ts # 配置与状态共用的原子写入
|
|
69
|
+
Focus on the login flow. Analyze the problem and suggest changes first.
|
|
73
70
|
```
|
|
74
71
|
|
|
75
|
-
|
|
72
|
+
Without `/cwd`, the working directory defaults to the directory where the service starts. The systemd service starts in the current user's home directory. Changing directories starts a new conversation.
|
|
76
73
|
|
|
77
|
-
|
|
78
|
-
`state.json` 保存聊天与当前会话、工作目录、任务输入与最终结果、入站去重标识和待发送回复;发送成功或被永久拒绝后移除回复副本。Codex 自己管理完整会话历史,Tellrun 不保存流式文本、思考过程、工具原始输出或 RPC 等待状态。
|
|
74
|
+
## Telegram commands
|
|
79
75
|
|
|
80
|
-
|
|
76
|
+
| Command | Purpose |
|
|
77
|
+
| --------------------- | ------------------------------------------------------------ |
|
|
78
|
+
| `/start`, `/help` | Show usage instructions |
|
|
79
|
+
| `/cwd` | Show the current working directory |
|
|
80
|
+
| `/cwd /absolute/path` | Change the working directory and start a new conversation |
|
|
81
|
+
| `/new` | Start a new conversation while keeping the working directory |
|
|
82
|
+
| `/status` | Show connection, conversation, directory, and task status |
|
|
83
|
+
| `/last` | Show the latest task's status and result |
|
|
84
|
+
| `/stop` | Request that the current task stop and pause new tasks |
|
|
85
|
+
| `/resume` | Accept new tasks again without rerunning an interrupted task |
|
|
81
86
|
|
|
82
|
-
|
|
87
|
+
Wait for the current task to finish before changing directories or starting a new conversation. After `/stop`, check the final status, then send `/resume` followed by your next task.
|
|
83
88
|
|
|
84
|
-
|
|
89
|
+
## Background service
|
|
85
90
|
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
91
|
+
These commands manage a Linux systemd user service:
|
|
92
|
+
|
|
93
|
+
| Command | Purpose |
|
|
94
|
+
| --------------------------- | ------------------------------------------------------------ |
|
|
95
|
+
| `tellrun start` | Start the background service |
|
|
96
|
+
| `tellrun start --enable` | Start the service and enable it at boot |
|
|
97
|
+
| `tellrun status` | Show service status and data paths |
|
|
98
|
+
| `tellrun logs` | Show the latest 100 log entries |
|
|
99
|
+
| `tellrun logs -f` | Follow logs |
|
|
100
|
+
| `tellrun restart` | Restart with the current configuration or installed version |
|
|
101
|
+
| `tellrun stop` | Stop the background service |
|
|
102
|
+
| `tellrun service uninstall` | Stop and remove the service, keeping configuration and state |
|
|
92
103
|
|
|
93
|
-
|
|
104
|
+
On startup, Tellrun checks and enables user lingering so the service can continue after you disconnect from SSH. If permissions are insufficient, the CLI prints the command to run on your server. Use `tellrun --help` for full CLI help.
|
|
94
105
|
|
|
95
|
-
|
|
106
|
+
### Upgrade
|
|
96
107
|
|
|
97
|
-
|
|
108
|
+
Wait for the current task to finish, then run:
|
|
98
109
|
|
|
99
110
|
```sh
|
|
100
|
-
|
|
111
|
+
tellrun stop
|
|
112
|
+
npm install -g tellrun@latest
|
|
113
|
+
tellrun restart
|
|
101
114
|
```
|
|
102
115
|
|
|
103
|
-
|
|
116
|
+
Configuration and state live in `~/.tellrun/` and are preserved when upgrading the global package. After upgrading Node.js or Tellrun, `restart` updates the Node and CLI paths used by the service.
|
|
104
117
|
|
|
105
|
-
|
|
118
|
+
## Configuration and data
|
|
106
119
|
|
|
107
|
-
|
|
108
|
-
hi
|
|
109
|
-
```
|
|
120
|
+
Run `tellrun setup` to create or update your configuration. Leave the Bot Token blank to keep the existing value.
|
|
110
121
|
|
|
111
|
-
|
|
122
|
+
| Path | Contents |
|
|
123
|
+
| ---------------------------- | ------------------------------------------------------------------------------------- |
|
|
124
|
+
| `~/.tellrun/config.json` | Bot Token, authorized user ID, Codex path, and optional proxy |
|
|
125
|
+
| `~/.tellrun/state.json` | Current conversation, working directory, task inputs and results, and pending replies |
|
|
126
|
+
| `~/.tellrun/tellrun.service` | Linux background service definition |
|
|
112
127
|
|
|
113
|
-
Codex
|
|
128
|
+
Codex uses the same operating system user's authentication and model configuration, and manages its own full conversation history. Tellrun does not maintain a project directory allowlist. Access depends on operating system permissions and the Codex sandbox; Tellrun defaults to workspace write access and approvals on request.
|
|
114
129
|
|
|
115
|
-
|
|
130
|
+
### Environment variables
|
|
116
131
|
|
|
117
|
-
|
|
132
|
+
When running in the foreground or managing the process yourself, you can override configuration with environment variables:
|
|
118
133
|
|
|
119
|
-
|
|
134
|
+
| Variable | Purpose |
|
|
135
|
+
| -------------------- | ----------------------------------------------------------------------------- |
|
|
136
|
+
| `TELEGRAM_BOT_TOKEN` | Bot token |
|
|
137
|
+
| `TELEGRAM_OWNER_ID` | Numeric ID of the user allowed to interact with the bot |
|
|
138
|
+
| `CODEX_PATH` | Codex command name or executable path |
|
|
139
|
+
| `TELEGRAM_PROXY_URL` | HTTP/HTTPS proxy for Telegram; overrides the configuration file when nonempty |
|
|
120
140
|
|
|
121
|
-
|
|
141
|
+
The built-in background service does not automatically load your current terminal's environment variables or a project's `.env` file. Save the required configuration with `tellrun setup`.
|
|
122
142
|
|
|
123
|
-
|
|
143
|
+
### Telegram proxy
|
|
124
144
|
|
|
125
|
-
|
|
126
|
-
npm ci # 首次安装依赖
|
|
127
|
-
npm run build # 生成 CLI 入口并设置执行权限
|
|
128
|
-
npm link
|
|
129
|
-
tellrun --help
|
|
130
|
-
tellrun setup
|
|
131
|
-
tellrun run
|
|
132
|
-
```
|
|
145
|
+
To use a proxy, add `"proxyUrl": "http://127.0.0.1:7890"` to the existing `telegram` object in `~/.tellrun/config.json`, then restart the service. Adjust the address and port to match your proxy. Set it to `""` to explicitly connect directly.
|
|
133
146
|
|
|
134
|
-
|
|
147
|
+
Proxy precedence is: nonempty `TELEGRAM_PROXY_URL` → `telegram.proxyUrl` in the configuration file → the running process's `https_proxy` / `HTTPS_PROXY`. Proxy connections honor `no_proxy` / `NO_PROXY`; lowercase variables take precedence. This setting only affects Telegram. Codex uses its own process's proxy environment.
|
|
135
148
|
|
|
136
|
-
|
|
149
|
+
## FAQ
|
|
137
150
|
|
|
138
|
-
|
|
139
|
-
|
|
151
|
+
### Can I use Codex for coding from my phone?
|
|
152
|
+
|
|
153
|
+
Yes. Install Codex CLI and Tellrun on your server, then chat with your bot through Telegram on your phone or desktop. Code inspection, file edits, and commands run on the server. Telegram is the interface for sending tasks, reading replies, and continuing the conversation.
|
|
154
|
+
|
|
155
|
+
### How do I find my Telegram user ID?
|
|
156
|
+
|
|
157
|
+
Before starting Tellrun, send a private message to your new bot. Use Telegram's [getUpdates](https://core.telegram.org/bots/api#getupdates) endpoint and find `message.from.id` for that message:
|
|
158
|
+
|
|
159
|
+
```text
|
|
160
|
+
https://api.telegram.org/bot<BOT_TOKEN>/getUpdates
|
|
140
161
|
```
|
|
141
162
|
|
|
142
|
-
|
|
163
|
+
Replace `<BOT_TOKEN>` with your token. If Tellrun is already running, stop it first to avoid polling conflicts.
|
|
164
|
+
|
|
165
|
+
### Why is the bot not replying?
|
|
166
|
+
|
|
167
|
+
Check that you are using a private chat and that your configured user ID is correct. Inspect `tellrun logs`, or the terminal output if running in the foreground. The same bot cannot be used by multiple polling instances at once, and Tellrun cannot start while the bot has an active webhook.
|
|
168
|
+
|
|
169
|
+
### What happens when a task needs approval?
|
|
170
|
+
|
|
171
|
+
Telegram interfaces for approvals and structured questions are not available yet. Tellrun interrupts the task and explains why. Handle the request locally first, check the task state, then send `/resume` and a new message with the work you want to continue.
|
|
143
172
|
|
|
144
|
-
|
|
173
|
+
### Will tasks run again after a restart?
|
|
174
|
+
|
|
175
|
+
Tasks that have not been dispatched are retained. Tasks with uncertain execution status are not automatically rerun. Check `/status` and `/last`, then use `/resume` to accept new tasks and send a new message.
|
|
176
|
+
|
|
177
|
+
## Local development
|
|
145
178
|
|
|
146
179
|
```sh
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
180
|
+
git clone https://github.com/chaoyue1998/tellrun.git
|
|
181
|
+
cd tellrun
|
|
182
|
+
npm ci
|
|
183
|
+
npm run build
|
|
184
|
+
node dist/cli.js setup
|
|
185
|
+
npm run dev
|
|
150
186
|
```
|
|
151
187
|
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
## 开发命令
|
|
188
|
+
Choose to save configuration without starting a background service in the setup wizard, then start the development process. Development and global installations share `~/.tellrun/`, so stop any existing instance first. You can also create a `.env` file using the repository's [.env.example](https://github.com/chaoyue1998/tellrun/blob/main/.env.example) for development configuration.
|
|
155
189
|
|
|
156
|
-
|
|
|
157
|
-
|
|
|
158
|
-
| `npm run dev`
|
|
159
|
-
| `npm run check`
|
|
160
|
-
| `npm run
|
|
161
|
-
| `npm
|
|
162
|
-
| `npm start` | 运行编译产物 |
|
|
190
|
+
| Command | Purpose |
|
|
191
|
+
| --------------- | ------------------------------------------------ |
|
|
192
|
+
| `npm run dev` | Watch source files and restart automatically |
|
|
193
|
+
| `npm run check` | Run formatting, static analysis, and type checks |
|
|
194
|
+
| `npm run build` | Compile to `dist/` |
|
|
195
|
+
| `npm start` | Run the compiled application |
|
|
163
196
|
|
|
197
|
+
When asking Codex to modify Tellrun itself, run `npm run build` followed by `npm start` so source changes do not trigger a restart during the task.
|
|
164
198
|
|
|
165
|
-
|
|
199
|
+
## Documentation and feedback
|
|
166
200
|
|
|
167
|
-
|
|
201
|
+
- [Architecture and technical design](https://github.com/chaoyue1998/tellrun/blob/main/docs/architecture.md) (Chinese): implementation, storage, and deployment details.
|
|
202
|
+
- [Product requirements and roadmap](https://github.com/chaoyue1998/tellrun/blob/main/docs/prd.md) (Chinese): includes planned features; this README describes what is currently available.
|
|
203
|
+
- [GitHub Issues](https://github.com/chaoyue1998/tellrun/issues): report bugs or suggest improvements. Include versions, reproduction steps, and logs with credentials removed.
|
|
168
204
|
|
|
169
|
-
##
|
|
205
|
+
## License
|
|
170
206
|
|
|
171
|
-
|
|
207
|
+
[MIT](https://github.com/chaoyue1998/tellrun/blob/main/LICENSE)
|
package/README.zh-CN.md
ADDED
|
@@ -0,0 +1,207 @@
|
|
|
1
|
+
# Tellrun — 通过 Telegram 远程使用 OpenAI Codex
|
|
2
|
+
|
|
3
|
+
**Tellrun 是可自行部署的 Telegram 机器人,基于 OpenAI Codex CLI 提供远程 AI 编程、持久化会话和流式回复。**
|
|
4
|
+
|
|
5
|
+
在服务器上运行 Tellrun,即可通过手机或电脑上的 Telegram 提交编码任务、继续对话和查看执行结果,无需一直保持 SSH 终端连接。
|
|
6
|
+
|
|
7
|
+
[English](https://github.com/chaoyue1998/tellrun/blob/main/README.md) | **简体中文**
|
|
8
|
+
|
|
9
|
+
[npm](https://www.npmjs.com/package/tellrun) · [GitHub](https://github.com/chaoyue1998/tellrun) · [问题反馈](https://github.com/chaoyue1998/tellrun/issues)
|
|
10
|
+
|
|
11
|
+
[快速开始](#安装并通过-telegram-使用-codex) · [Telegram 命令](#telegram-命令) · [配置](#配置与数据) · [常见问题](#常见问题)
|
|
12
|
+
|
|
13
|
+
## 功能
|
|
14
|
+
|
|
15
|
+
- **远程编码**:在 Telegram 私聊中发送任务,由服务器上的 Codex 执行。
|
|
16
|
+
- **连续对话**:保留当前会话上下文,通过 `/cwd` 指定项目目录,通过 `/new` 开始新会话。
|
|
17
|
+
- **即时反馈**:显示输入状态与流式回复,执行期间可以继续发送文字补充要求。
|
|
18
|
+
- **任务控制**:查看状态和最近结果,停止任务并暂停接收;重启后保留会话与任务记录。
|
|
19
|
+
- **个人部署**:仅响应指定用户的私聊,使用长轮询接收消息,无需配置 Webhook 或开放入站端口。
|
|
20
|
+
|
|
21
|
+
当前支持 **Telegram + Codex**,面向单用户,每次处理一个任务。多会话列表、独立任务排队、审批与结构化提问交互、图片和文件输入暂未支持。
|
|
22
|
+
|
|
23
|
+
|
|
24
|
+
## 安装并通过 Telegram 使用 Codex
|
|
25
|
+
|
|
26
|
+
### 1. 准备环境
|
|
27
|
+
|
|
28
|
+
- **Node.js ≥ 24.5.0**。
|
|
29
|
+
- **[Codex CLI](https://github.com/openai/codex)**:在运行 Tellrun 的同一系统用户下安装并完成登录,确认可以在终端正常使用。
|
|
30
|
+
- **Telegram Bot Token**:向 [@BotFather](https://t.me/BotFather) 发送 `/newbot`,按提示创建机器人并获取 Token。参见 [Telegram 官方教程](https://core.telegram.org/bots/tutorial#obtain-your-bot-token)。
|
|
31
|
+
- **本人 Telegram 数字用户 ID**:不是 `@用户名`,参见[获取方法](#如何获取-telegram-用户-id)。
|
|
32
|
+
|
|
33
|
+
后台管理需要支持 **systemd 用户服务的 Linux**。本地调试或使用其他进程管理器时,可通过 `tellrun run` 前台运行。
|
|
34
|
+
|
|
35
|
+
### 2. 安装并配置
|
|
36
|
+
|
|
37
|
+
```sh
|
|
38
|
+
npm install -g tellrun
|
|
39
|
+
tellrun setup
|
|
40
|
+
```
|
|
41
|
+
|
|
42
|
+
按向导填写 Bot Token、本人数字用户 ID 和 Codex 命令或可执行文件路径。Linux 下可以在配置完成后直接启动后台服务,并选择开机自启。
|
|
43
|
+
|
|
44
|
+
如果选择了仅保存配置,之后运行:
|
|
45
|
+
|
|
46
|
+
```sh
|
|
47
|
+
tellrun start --enable
|
|
48
|
+
```
|
|
49
|
+
|
|
50
|
+
前台运行时使用:
|
|
51
|
+
|
|
52
|
+
```sh
|
|
53
|
+
tellrun run
|
|
54
|
+
```
|
|
55
|
+
|
|
56
|
+
### 3. 在 Telegram 中开始对话
|
|
57
|
+
|
|
58
|
+
打开与机器人的私聊,依次发送以下消息,将示例目录替换为服务器上实际存在的项目绝对路径:
|
|
59
|
+
|
|
60
|
+
```text
|
|
61
|
+
/start
|
|
62
|
+
/cwd /home/you/projects/my-app
|
|
63
|
+
帮我了解这个项目,说明主要模块和启动方式。
|
|
64
|
+
```
|
|
65
|
+
|
|
66
|
+
之后直接发送文字即可继续当前会话;任务执行中发送的新消息会补充到当前任务。例如:
|
|
67
|
+
|
|
68
|
+
```text
|
|
69
|
+
重点看一下登录流程,先分析问题并给出修改建议。
|
|
70
|
+
```
|
|
71
|
+
|
|
72
|
+
未设置 `/cwd` 时,工作目录默认为服务启动目录;systemd 服务默认使用当前用户的主目录。切换目录会开始新会话。
|
|
73
|
+
|
|
74
|
+
## Telegram 命令
|
|
75
|
+
|
|
76
|
+
| 命令 | 作用 |
|
|
77
|
+
| --------------------- | ------------------------------------------ |
|
|
78
|
+
| `/start`、`/help` | 查看使用说明 |
|
|
79
|
+
| `/cwd` | 查看当前工作目录 |
|
|
80
|
+
| `/cwd /absolute/path` | 切换工作目录并开始新会话 |
|
|
81
|
+
| `/new` | 开始新会话,保留工作目录 |
|
|
82
|
+
| `/status` | 查看连接、会话、目录和任务状态 |
|
|
83
|
+
| `/last` | 查看最近任务的状态与结果 |
|
|
84
|
+
| `/stop` | 请求停止当前任务,并暂停接收新任务 |
|
|
85
|
+
| `/resume` | 恢复接收新任务,不会重新执行此前中断的任务 |
|
|
86
|
+
|
|
87
|
+
切换目录或新建会话前,需要等待当前任务结束。使用 `/stop` 后,先检查最终状态,再发送 `/resume` 和新的任务内容。
|
|
88
|
+
|
|
89
|
+
## 后台服务
|
|
90
|
+
|
|
91
|
+
以下命令用于 Linux systemd 用户服务:
|
|
92
|
+
|
|
93
|
+
| 命令 | 作用 |
|
|
94
|
+
| --------------------------- | ------------------------------ |
|
|
95
|
+
| `tellrun start` | 启动后台服务 |
|
|
96
|
+
| `tellrun start --enable` | 启动服务并启用开机自启 |
|
|
97
|
+
| `tellrun status` | 查看服务状态与数据路径 |
|
|
98
|
+
| `tellrun logs` | 查看最近 100 条日志 |
|
|
99
|
+
| `tellrun logs -f` | 持续跟随日志 |
|
|
100
|
+
| `tellrun restart` | 重启服务,加载新配置或新版本 |
|
|
101
|
+
| `tellrun stop` | 停止后台服务 |
|
|
102
|
+
| `tellrun service uninstall` | 停止并移除服务,保留配置和状态 |
|
|
103
|
+
|
|
104
|
+
启动时会检查并启用用户 linger,使服务在退出 SSH 后继续运行。若权限不足,CLI 会显示需要在服务器执行的命令。完整命令帮助见 `tellrun --help`。
|
|
105
|
+
|
|
106
|
+
### 升级
|
|
107
|
+
|
|
108
|
+
等待当前任务结束后执行:
|
|
109
|
+
|
|
110
|
+
```sh
|
|
111
|
+
tellrun stop
|
|
112
|
+
npm install -g tellrun@latest
|
|
113
|
+
tellrun restart
|
|
114
|
+
```
|
|
115
|
+
|
|
116
|
+
配置与状态保存在 `~/.tellrun/`,全局包升级会保留这些数据。升级 Node.js 或 Tellrun 后,`restart` 会更新服务使用的 Node 和 CLI 入口路径。
|
|
117
|
+
|
|
118
|
+
## 配置与数据
|
|
119
|
+
|
|
120
|
+
运行 `tellrun setup` 创建或更新配置,已有 Bot Token 可留空保留原值。
|
|
121
|
+
|
|
122
|
+
| 路径 | 内容 |
|
|
123
|
+
| ---------------------------- | ---------------------------------------------- |
|
|
124
|
+
| `~/.tellrun/config.json` | Bot Token、授权用户 ID、Codex 路径和可选代理 |
|
|
125
|
+
| `~/.tellrun/state.json` | 当前会话、工作目录、任务输入与结果、待发送回复 |
|
|
126
|
+
| `~/.tellrun/tellrun.service` | Linux 后台服务定义 |
|
|
127
|
+
|
|
128
|
+
Codex 使用同一系统用户的登录和模型配置,完整会话历史由 Codex 管理。Tellrun 不设置项目目录白名单;可访问范围由运行用户权限和 Codex 沙箱共同决定,默认采用工作区写入与按需审批策略。
|
|
129
|
+
|
|
130
|
+
### 环境变量
|
|
131
|
+
|
|
132
|
+
前台运行或自行托管进程时,可以使用环境变量覆盖配置:
|
|
133
|
+
|
|
134
|
+
| 变量 | 用途 |
|
|
135
|
+
| -------------------- | ----------------------------------------------- |
|
|
136
|
+
| `TELEGRAM_BOT_TOKEN` | 机器人 Token |
|
|
137
|
+
| `TELEGRAM_OWNER_ID` | 允许操作机器人的数字用户 ID |
|
|
138
|
+
| `CODEX_PATH` | Codex 命令名或可执行文件路径 |
|
|
139
|
+
| `TELEGRAM_PROXY_URL` | Telegram 的 HTTP/HTTPS 代理,非空时覆盖配置文件 |
|
|
140
|
+
|
|
141
|
+
内置后台服务不会自动读取当前终端的环境变量或项目 `.env`,请使用 `tellrun setup` 保存必要配置。
|
|
142
|
+
|
|
143
|
+
### Telegram 代理
|
|
144
|
+
|
|
145
|
+
需要代理时,在已有 `~/.tellrun/config.json` 的 `telegram` 对象中添加 `"proxyUrl": "http://127.0.0.1:7890"`,再重启服务。端口和地址按实际代理调整;设置为 `""` 表示明确直连。
|
|
146
|
+
|
|
147
|
+
代理优先级为:非空 `TELEGRAM_PROXY_URL` → 配置文件中的 `telegram.proxyUrl` → 运行进程的 `https_proxy` / `HTTPS_PROXY`。使用代理时遵循 `no_proxy` / `NO_PROXY`,同名变量以小写优先。此配置仅影响 Telegram;Codex 使用其进程自身的代理环境。
|
|
148
|
+
|
|
149
|
+
## 常见问题
|
|
150
|
+
|
|
151
|
+
### 可以在手机上使用 Codex 编程吗?
|
|
152
|
+
|
|
153
|
+
可以。先在服务器上安装 Codex CLI 和 Tellrun,再通过手机或电脑上的 Telegram 与机器人私聊。代码读取、修改和命令执行都在服务器上完成,Telegram 用于发送任务、查看回复和继续对话。
|
|
154
|
+
|
|
155
|
+
### 如何获取 Telegram 用户 ID?
|
|
156
|
+
|
|
157
|
+
在启动 Tellrun 前,先向新建的机器人发送一条私聊消息,再通过 Telegram 的 [getUpdates](https://core.telegram.org/bots/api#getupdates) 接口查看该消息的 `message.from.id`:
|
|
158
|
+
|
|
159
|
+
```text
|
|
160
|
+
https://api.telegram.org/bot<BOT_TOKEN>/getUpdates
|
|
161
|
+
```
|
|
162
|
+
|
|
163
|
+
将 `<BOT_TOKEN>` 替换为自己的 Token。若 Tellrun 已在运行,先停止服务,避免同时轮询。
|
|
164
|
+
|
|
165
|
+
### 机器人没有回复怎么办?
|
|
166
|
+
|
|
167
|
+
确认是在私聊中使用、配置的用户 ID 正确,并查看 `tellrun logs`;前台运行时查看终端输出。同一个 Bot 不能同时由多个轮询实例使用,也不能在已有 Webhook 的情况下启动 Tellrun。
|
|
168
|
+
|
|
169
|
+
### 任务需要审批时会怎样?
|
|
170
|
+
|
|
171
|
+
当前还没有 Telegram 审批和结构化提问界面。遇到这类请求时,Tellrun 会中断任务并提示原因。请先在本机处理,确认状态后发送 `/resume`,再提交需要继续的内容。
|
|
172
|
+
|
|
173
|
+
### 服务重启后会重新执行任务吗?
|
|
174
|
+
|
|
175
|
+
尚未派发的任务会保留;执行状态不确定的任务不会自动重跑。通过 `/status` 和 `/last` 检查结果后,发送 `/resume` 恢复接收,再发送新消息。
|
|
176
|
+
|
|
177
|
+
## 本地开发
|
|
178
|
+
|
|
179
|
+
```sh
|
|
180
|
+
git clone https://github.com/chaoyue1998/tellrun.git
|
|
181
|
+
cd tellrun
|
|
182
|
+
npm ci
|
|
183
|
+
npm run build
|
|
184
|
+
node dist/cli.js setup
|
|
185
|
+
npm run dev
|
|
186
|
+
```
|
|
187
|
+
|
|
188
|
+
在配置向导中选择仅保存配置,再启动开发进程。开发环境与全局安装共用 `~/.tellrun/`,请先停止已有实例。也可参考仓库中的 [.env.example](https://github.com/chaoyue1998/tellrun/blob/main/.env.example),创建 `.env` 提供开发配置。
|
|
189
|
+
|
|
190
|
+
| 命令 | 用途 |
|
|
191
|
+
| --------------- | ------------------------ |
|
|
192
|
+
| `npm run dev` | 监听源码并自动重启 |
|
|
193
|
+
| `npm run check` | 格式、静态检查与类型检查 |
|
|
194
|
+
| `npm run build` | 编译到 `dist/` |
|
|
195
|
+
| `npm start` | 运行编译产物 |
|
|
196
|
+
|
|
197
|
+
如果让 Codex 修改 Tellrun 自身,使用 `npm run build` 后执行 `npm start`,避免源码监听重启打断任务。
|
|
198
|
+
|
|
199
|
+
## 文档与反馈
|
|
200
|
+
|
|
201
|
+
- [架构与技术选型](https://github.com/chaoyue1998/tellrun/blob/main/docs/architecture.md):实现、存储和部署细节。
|
|
202
|
+
- [产品需求与规划](https://github.com/chaoyue1998/tellrun/blob/main/docs/prd.md):包含尚未实现的功能,当前能力以本 README 为准。
|
|
203
|
+
- [GitHub Issues](https://github.com/chaoyue1998/tellrun/issues):提交问题或建议,请附上版本、复现步骤和去除凭据后的日志。
|
|
204
|
+
|
|
205
|
+
## 许可证
|
|
206
|
+
|
|
207
|
+
[MIT](https://github.com/chaoyue1998/tellrun/blob/main/LICENSE)
|