codeclaw 0.2.1 → 0.2.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/README.md CHANGED
@@ -8,7 +8,6 @@ IM 交互体验最好的远程编程工具。没有之一。
8
8
 
9
9
  [![License: MIT](https://img.shields.io/badge/License-MIT-blue.svg)](LICENSE)
10
10
  [![Node.js 18+](https://img.shields.io/badge/Node.js-18+-green.svg)](https://nodejs.org)
11
- [![Zero Dependencies](https://img.shields.io/badge/Dependencies-0-brightgreen.svg)]()
12
11
  [![npm](https://img.shields.io/npm/v/codeclaw)](https://www.npmjs.com/package/codeclaw)
13
12
 
14
13
  [English](#english) | [中文](#中文)
@@ -25,10 +24,9 @@ Most "AI + IM" bridges just forward messages. codeclaw is built from scratch for
25
24
 
26
25
  - **Real-time streaming** — token-by-token output via Telegram message edits; you see the AI thinking live, not a wall of text after 2 minutes
27
26
  - **System-level keep-alive** — triggers OS-level power assertions to prevent your laptop from sleeping, so long-running tasks finish even when you walk away
28
- - **Dual engine hot-switch** — Claude Code + Codex CLI, switch with a single command
29
- - **Battle mode** — run both engines in parallel on the same prompt, compare side-by-side
27
+ - **Multi-agent hot-switch** — Claude Code + Codex CLI, switch with a single `/agents` command
30
28
  - **True multi-session** — named sessions with persistent thread IDs; restart codeclaw, resume exactly where you left off
31
- - **Zero dependencies, one command** — pure Node.js stdlib, `npx codeclaw` and you're running
29
+ - **One command** — `npx codeclaw` and you're running
32
30
 
33
31
  ```
34
32
  Telegram (your phone / desktop)
@@ -42,62 +40,21 @@ your codebase
42
40
 
43
41
  No server. No Docker. No config files. Just one process bridging Telegram to your local AI agent.
44
42
 
45
- ## Comparison with Alternatives
46
-
47
- ### vs. Claude Code + Telegram Projects
48
-
49
- | Feature | codeclaw | claude-code-telegram | claudecode-telegram | claude-telegram-bot-bridge | ccbot | claudegram |
50
- |---------|----------|---------------------|--------------------|-----------------------------|-------|------------|
51
- | Streaming output (live edits) | **Yes** | Yes | Partial | Partial | No | No |
52
- | Dual engine (Claude + Codex) | **Yes** | No | No | No | No | No |
53
- | Battle mode (parallel compare) | **Yes** | No | No | No | No | No |
54
- | Multi-session management | **Yes** | Yes | No | No | Partial (tmux) | No |
55
- | Session persistence (resume after restart) | **Yes** | Yes | No | No | Partial | No |
56
- | Keep-alive (prevent system sleep) | **Yes** | No | No | No | No | No |
57
- | Zero dependencies | **Yes** | No | No | No | No (tmux) | No |
58
- | npx one-command start | **Yes** | No | No | No | No | No |
59
- | Image/photo input support | **Yes** | Partial | No | No | No | No |
60
- | Paginated long output | **Yes** | No | No | No | N/A | No |
61
- | Access control (user/chat whitelist) | **Yes** | Partial | No | No | No | No |
62
-
63
- ### vs. Multi-IM / Multi-Engine Platforms
64
-
65
- | Feature | codeclaw | cc-connect | OpenClaw | Claude-to-IM-skill | heyagent |
66
- |---------|----------|------------|----------|---------------------|----------|
67
- | IM platforms | Telegram | Telegram, Slack, Discord, 飞书, 钉钉, LINE, 企业微信 | 20+ (Telegram, WhatsApp, Slack, Discord, Signal, iMessage...) | Telegram, Discord, 飞书 | Telegram |
68
- | AI engines | Claude Code, Codex | Claude Code, Codex, Gemini, Cursor | Claude, Codex, local LLM | Claude Code, Codex | Claude Code, Codex |
69
- | Streaming (live token output) | **Yes** | Partial | Partial | No | No |
70
- | Battle mode | **Yes** | No | No | No | No |
71
- | Keep-alive (prevent sleep) | **Yes** | No | No | No | No |
72
- | Zero dependencies | **Yes** | No | No | No | No |
73
- | Setup time | **~10 seconds** | Minutes | Minutes | Minutes | Minutes |
74
- | Config files needed | **0** | YAML | YAML + plugins | Config | Config |
75
-
76
- > **Our philosophy:** codeclaw intentionally focuses on **one IM channel done right** rather than many done poorly. If you need 20 IM platforms, use OpenClaw or cc-connect. If you want **the best Telegram remote coding experience** — the fastest streaming, the smoothest interaction, and zero setup friction — use codeclaw.
77
-
78
- ### Keep-Alive: Your Laptop Stays Awake
79
-
80
- When codeclaw is running, it triggers **OS-level power assertions** to prevent your machine from sleeping. This means:
81
-
82
- - Long-running AI tasks (refactoring, large codegen, test suites) **complete reliably** even if you walk away from the keyboard
83
- - No more coming back to find your screen locked, SSH session dropped, or AI agent frozen mid-task due to idle sleep
84
- - Works on **macOS** (caffeinate) and **Linux** (systemd-inhibit)
85
-
86
- This is a critical feature for remote coding — you send a task from your phone, the laptop stays awake and keeps working. (Note: closing the lid on most laptops will still trigger hardware-level sleep — keep the lid open for best results.)
87
-
88
43
  ## Features
89
44
 
90
- - **Dual engine** — Claude Code + Codex CLI, hot-switch with `/engine`
45
+ - **Multi-agent** — Claude Code + Codex CLI, hot-switch via `/agents` inline keyboard
91
46
  - **Streaming** — real-time token-by-token output via Telegram message edits
92
- - **Battle mode** — `/battle <prompt>` runs both engines in parallel, compare side-by-side
93
- - **Multi-session** — per-chat session management with named sessions and thread resume
94
- - **Keep-alive** — OS-level sleep prevention ensures long tasks complete uninterrupted
95
- - **Full access / safe mode** — let the agent run freely, or lock it down
96
- - **Zero dependencies** — pure Node.js stdlib, no npm install needed
47
+ - **Multi-session** — per-chat session management with named sessions, pagination, and resume
48
+ - **Keep-alive** — OS-level sleep prevention (macOS `caffeinate`, Linux `systemd-inhibit`)
49
+ - **Directory browser** — switch working directory interactively via `/switch` with inline navigation
97
50
  - **Image input** — send photos to the bot for visual context (screenshots, diagrams)
98
- - **Paginated output** — long responses are split into navigable pages with inline buttons
99
- - **Auto-start notice** — sends online status to all known chats on startup
51
+ - **Quick replies** — auto-detects yes/no questions and numbered options, shows inline buttons
52
+ - **Long output** — responses exceeding Telegram limits are split with a full `.md` file attachment
53
+ - **Thinking display** — shows agent thinking/reasoning process in collapsible blocks
54
+ - **Token tracking** — per-turn and cumulative input/output/cached token counts
100
55
  - **Access control** — restrict by chat/user ID whitelist
56
+ - **Startup notice** — sends online status to all known chats on startup
57
+ - **Full access / safe mode** — let the agent run freely, or require confirmation before destructive actions
101
58
 
102
59
  ## Quick Start
103
60
 
@@ -116,7 +73,7 @@ cd your-project/
116
73
  codeclaw -t YOUR_BOT_TOKEN
117
74
  ```
118
75
 
119
- > **Prerequisites:** Node.js 18+, `claude` CLI and/or `codex` CLI in PATH, a Telegram Bot Token from [@BotFather](https://t.me/BotFather).
76
+ > **Prerequisites:** Node.js 18+, `claude` CLI and/or `codex` CLI installed, a Telegram Bot Token from [@BotFather](https://t.me/BotFather).
120
77
 
121
78
  ## CLI Options
122
79
 
@@ -128,31 +85,39 @@ codeclaw [options]
128
85
 
129
86
  | Flag | Env | Default | Description |
130
87
  |------|-----|---------|-------------|
131
- | `-c, --channel` | `CODECLAW_CHANNEL` | `telegram` | IM channel |
132
- | `-t, --token` | `CODECLAW_TOKEN` | — | Bot token |
133
- | `-e, --engine` | `DEFAULT_ENGINE` | `claude` | AI engine: `claude` or `codex` |
134
- | `-w, --workdir` | `CODECLAW_WORKDIR` | `.` | Working directory |
135
- | `-m, --model` | `CLAUDE_MODEL` / `CODEX_MODEL` | | Model override |
88
+ | `-c, --channel` | `CODECLAW_CHANNEL` | `telegram` | IM channel: `telegram` (feishu, whatsapp planned) |
89
+ | `-t, --token` | `CODECLAW_TOKEN` | — | Bot token (or channel-specific env below) |
90
+ | `-a, --agent` | `DEFAULT_AGENT` | `claude` | AI agent: `claude` or `codex` |
91
+ | `-m, --model` | — | `claude-opus-4-6` / `gpt-5.4` | Model override (maps to agent-specific env) |
92
+ | `-w, --workdir` | `CODECLAW_WORKDIR` | `.` | Working directory for the agent |
136
93
 
137
94
  ### Access Control
138
95
 
139
96
  | Flag | Env | Default | Description |
140
97
  |------|-----|---------|-------------|
141
98
  | `--full-access` | `CODECLAW_FULL_ACCESS` | `true` | Agent can read/write/execute without confirmation |
142
- | `--safe-mode` | `CODECLAW_SAFE_MODE` | `false` | Agent asks before destructive operations |
143
- | `--allowed-ids` | `CODECLAW_ALLOWED_IDS` | — | Comma-separated user/chat IDs whitelist |
144
- | `--timeout` | `CODECLAW_TIMEOUT` | `300` | Max seconds per request |
99
+ | `--safe-mode` | | `false` | Require confirmation before destructive operations |
100
+ | `--allowed-ids` | `TELEGRAM_ALLOWED_CHAT_IDS` | — | Comma-separated chat/user ID whitelist |
101
+ | `--timeout` | `CODECLAW_TIMEOUT` | `300` | Max seconds per agent request |
145
102
 
146
- ### Engine-specific
103
+ ### Channel-specific Environment Variables
147
104
 
148
105
  | Env | Description |
149
106
  |-----|-------------|
150
- | `CLAUDE_MODEL` | Claude model (e.g. `sonnet`, `opus`) |
151
- | `CLAUDE_PERMISSION_MODE` | `bypassPermissions` (default) or `default` |
152
- | `CLAUDE_EXTRA_ARGS` | Extra CLI args passed to `claude` |
153
- | `CODEX_MODEL` | Codex model (e.g. `o3`, `o4-mini`) |
154
- | `CODEX_REASONING_EFFORT` | `none` / `minimal` / `low` / `medium` / `high` / `xhigh` |
155
- | `CODEX_EXTRA_ARGS` | Extra CLI args passed to `codex` |
107
+ | `TELEGRAM_BOT_TOKEN` | Telegram bot token (from @BotFather) |
108
+ | `TELEGRAM_ALLOWED_CHAT_IDS` | Comma-separated allowed Telegram chat IDs |
109
+
110
+ ### Agent-specific Environment Variables
111
+
112
+ | Env | Default | Description |
113
+ |-----|---------|-------------|
114
+ | `CLAUDE_MODEL` | `claude-opus-4-6` | Claude model name |
115
+ | `CLAUDE_PERMISSION_MODE` | `bypassPermissions` | `bypassPermissions` or `default` |
116
+ | `CLAUDE_EXTRA_ARGS` | — | Extra CLI args passed to `claude` |
117
+ | `CODEX_MODEL` | `gpt-5.4` | Codex model name |
118
+ | `CODEX_REASONING_EFFORT` | `xhigh` | `none` / `minimal` / `low` / `medium` / `high` / `xhigh` |
119
+ | `CODEX_FULL_ACCESS` | `true` | Bypass sandbox and approval prompts |
120
+ | `CODEX_EXTRA_ARGS` | — | Extra CLI args passed to `codex` |
156
121
 
157
122
  ### Examples
158
123
 
@@ -160,31 +125,63 @@ codeclaw [options]
160
125
  # Basic: Telegram + Claude Code, full access
161
126
  npx codeclaw -t $BOT_TOKEN
162
127
 
163
- # Codex engine, safe mode, restricted users
164
- npx codeclaw -t $BOT_TOKEN -e codex --safe-mode --allowed-ids 123456,789012
128
+ # Codex agent, safe mode, restricted users
129
+ npx codeclaw -t $BOT_TOKEN -a codex --safe-mode --allowed-ids 123456,789012
165
130
 
166
131
  # Custom model, custom working directory
167
132
  npx codeclaw -t $BOT_TOKEN -m sonnet -w ~/projects/my-app
168
133
 
169
- # Validate setup without starting
170
- npx codeclaw -t $BOT_TOKEN --self-check
134
+ # Using environment variables
135
+ TELEGRAM_BOT_TOKEN=xxx CODEX_MODEL=o3 npx codeclaw -a codex
171
136
  ```
172
137
 
173
138
  ## Bot Commands
174
139
 
140
+ Once running, these commands are available in Telegram:
141
+
175
142
  | Command | Description |
176
143
  |---------|-------------|
177
- | `/ask <prompt>` | Ask the AI agent |
178
- | `/engine [codex\|claude]` | Show or switch engine |
179
- | `/battle <prompt>` | Run both engines, compare results |
180
- | `/new [prompt]` | Reset session (optionally start new one) |
181
- | `/session list\|use\|new\|del` | Multi-session management |
182
- | `/status` | Show current session / engine / thread info |
183
- | `/stop` | Clear current session thread |
184
- | `/clear [N]` | Delete bot's recent messages (default 50) |
185
- | `/help` | Show all commands |
186
-
187
- > In private/DM chats, just send text directly — no command prefix needed.
144
+ | `/sessions` | List, switch, or create sessions (paginated inline keyboard) |
145
+ | `/agents` | List installed agents, switch between them |
146
+ | `/switch` | Browse and change working directory (interactive file browser) |
147
+ | `/status` | Bot status: uptime, memory, agent, session, token usage |
148
+ | `/host` | Host machine info: CPU, memory, disk, top processes |
149
+ | `/start` | Welcome message with command list |
150
+
151
+ > In private chats, just send text directly — no command prefix needed. Any unrecognized `/command` is forwarded to the agent as a prompt.
152
+
153
+ ## Development
154
+
155
+ ```bash
156
+ # 1. Install dependencies
157
+ npm install
158
+
159
+ # 2. Create .env file with your tokens
160
+ echo "TELEGRAM_BOT_TOKEN=your_token_here" > .env
161
+
162
+ # 3. Run locally
163
+ set -a && source .env && npx tsx src/cli.ts
164
+
165
+ # 4. Run tests
166
+ npm test
167
+ ```
168
+
169
+ ## Architecture
170
+
171
+ See [ARCHITECTURE.md](ARCHITECTURE.md) for the layered design:
172
+
173
+ ```
174
+ cli.ts → bot-telegram.ts → bot.ts → code-agent.ts
175
+
176
+ channel-telegram.ts
177
+ ```
178
+
179
+ - **bot.ts** — channel-agnostic business logic, state, streaming bridge
180
+ - **bot-telegram.ts** — Telegram-specific rendering, keyboards, callbacks
181
+ - **channel-telegram.ts** — pure Telegram API transport (polling, sending, file download)
182
+ - **code-agent.ts** — AI agent abstraction (spawn CLI, parse JSONL stream)
183
+
184
+ Adding a new IM channel means creating `channel-xxx.ts` + `bot-xxx.ts` without touching shared logic.
188
185
 
189
186
  ## License
190
187
 
@@ -208,10 +205,9 @@ npx codeclaw -t $BOT_TOKEN --self-check
208
205
 
209
206
  - **实时流式输出** — 通过 Telegram 消息编辑逐 token 推送;你能实时看到 AI 的思考过程,而不是等 2 分钟后收到一大段文字
210
207
  - **系统级保活** — 触发操作系统级电源断言,防止笔记本休眠,确保长时间任务在你离开后依然完整执行
211
- - **双引擎热切换** — Claude Code + Codex CLI,一条命令即可切换
212
- - **对战模式** — 同一个 prompt 同时跑两个引擎,结果并排对比
208
+ - **多 Agent 热切换** — Claude Code + Codex CLI,一条 `/agents` 命令即可切换
213
209
  - **真正的多会话** — 命名会话 + 持久化线程 ID;重启 codeclaw 后可以无缝恢复之前的对话
214
- - **零依赖、一条命令**纯 Node.js 标准库,`npx codeclaw` 即可运行
210
+ - **一条命令启动**`npx codeclaw` 即可运行
215
211
 
216
212
  ```
217
213
  Telegram(手机 / 桌面端)
@@ -225,62 +221,21 @@ claude / codex CLI
225
221
 
226
222
  不需要服务器,不需要 Docker,不需要配置文件。一个进程把 Telegram 桥接到你本地的 AI 编程助手。
227
223
 
228
- ## 竞品对比
229
-
230
- ### vs. Claude Code + Telegram 专项工具
231
-
232
- | 特性 | codeclaw | claude-code-telegram | claudecode-telegram | claude-telegram-bot-bridge | ccbot | claudegram |
233
- |------|----------|---------------------|--------------------|-----------------------------|-------|------------|
234
- | 流式输出(实时编辑) | **支持** | 支持 | 部分 | 部分 | 不支持 | 不支持 |
235
- | 双引擎(Claude + Codex) | **支持** | 不支持 | 不支持 | 不支持 | 不支持 | 不支持 |
236
- | 对战模式(并行对比) | **支持** | 不支持 | 不支持 | 不支持 | 不支持 | 不支持 |
237
- | 多会话管理 | **支持** | 支持 | 不支持 | 不支持 | 部分(tmux) | 不支持 |
238
- | 会话持久化(重启恢复) | **支持** | 支持 | 不支持 | 不支持 | 部分 | 不支持 |
239
- | 保活(防止系统休眠) | **支持** | 不支持 | 不支持 | 不支持 | 不支持 | 不支持 |
240
- | 零依赖 | **是** | 否(Node.js) | 否 | 否 | 否(tmux) | 否 |
241
- | npx 一键启动 | **是** | 否 | 否 | 否 | 否 | 否 |
242
- | 图片输入支持 | **支持** | 部分 | 不支持 | 不支持 | 不支持 | 不支持 |
243
- | 长文本分页 | **支持** | 不支持 | 不支持 | 不支持 | N/A | 不支持 |
244
- | 访问控制(白名单) | **支持** | 部分 | 不支持 | 不支持 | 不支持 | 不支持 |
245
-
246
- ### vs. 多 IM / 多引擎平台
247
-
248
- | 特性 | codeclaw | cc-connect | OpenClaw | Claude-to-IM-skill | heyagent |
249
- |------|----------|------------|----------|---------------------|----------|
250
- | IM 平台 | Telegram | Telegram、Slack、Discord、飞书、钉钉、LINE、企业微信 | 20+(Telegram、WhatsApp、Slack、Discord、Signal、iMessage…) | Telegram、Discord、飞书 | Telegram |
251
- | AI 引擎 | Claude Code、Codex | Claude Code、Codex、Gemini、Cursor | Claude、Codex、本地 LLM | Claude Code、Codex | Claude Code、Codex |
252
- | 流式输出(实时 token) | **支持** | 部分 | 部分 | 不支持 | 不支持 |
253
- | 对战模式 | **支持** | 不支持 | 不支持 | 不支持 | 不支持 |
254
- | 保活(防休眠) | **支持** | 不支持 | 不支持 | 不支持 | 不支持 |
255
- | 零依赖 | **是** | 否 | 否 | 否 | 否 |
256
- | 部署时间 | **约 10 秒** | 数分钟 | 数分钟 | 数分钟 | 数分钟 |
257
- | 需要配置文件 | **0 个** | YAML | YAML + 插件 | 配置文件 | 配置文件 |
258
-
259
- > **我们的理念:** codeclaw 有意专注于 **把一个 IM 渠道做到极致**,而非什么都做但都做不好。如果你需要 20 个 IM 平台,用 OpenClaw 或 cc-connect。如果你想要 **最好的 Telegram 远程编程体验** —— 最快的流式输出、最流畅的交互、零配置摩擦 —— 用 codeclaw。
260
-
261
- ### 保活:你的笔记本始终亮屏
262
-
263
- codeclaw 运行时会触发 **操作系统级电源断言**,防止你的机器进入休眠。这意味着:
264
-
265
- - 长时间 AI 任务(重构、大量代码生成、测试套件)即使你 **离开键盘** 也能可靠完成
266
- - 不再出现回来发现屏幕锁定、SSH 断开、AI 跑到一半因空闲休眠而卡住的情况
267
- - 支持 **macOS**(caffeinate)和 **Linux**(systemd-inhibit)
268
-
269
- 这是远程编程的关键功能 —— 你从手机上发一个任务,笔记本保持唤醒状态持续工作。(注意:合上盖子在大多数笔记本上仍会触发硬件级休眠,建议保持开盖。)
270
-
271
224
  ## 功能特性
272
225
 
273
- - **双引擎** — Claude Code + Codex CLI,用 `/engine` 命令热切换
226
+ - **多 Agent** — Claude Code + Codex CLI,通过 `/agents` 内联键盘热切换
274
227
  - **流式输出** — 通过 Telegram 消息编辑实时逐 token 输出
275
- - **对战模式**`/battle <prompt>` 同时运行两个引擎,结果并排对比
276
- - **多会话**每个聊天支持命名会话管理和线程恢复
277
- - **系统保活**操作系统级防休眠,确保长任务不中断
278
- - **完全访问 / 安全模式** — 让 AI 自由运行,或限制危险操作需确认
279
- - **零依赖** — 纯 Node.js 标准库,无需 npm install
228
+ - **多会话**每个聊天支持命名会话管理、分页浏览和线程恢复
229
+ - **系统保活**操作系统级防休眠(macOS `caffeinate`、Linux `systemd-inhibit`)
230
+ - **目录浏览器**通过 `/switch` 交互式切换工作目录,内联导航
280
231
  - **图片输入** — 向机器人发送图片提供视觉上下文(截图、设计图)
281
- - **长文本分页**长回复自动分页,内联按钮翻页浏览
282
- - **启动通知**启动时向所有已知聊天发送在线状态
232
+ - **快捷回复**自动检测是/否问题和编号选项,显示内联按钮
233
+ - **长文本处理**超出 Telegram 限制的回复自动拆分,并附带完整 `.md` 文件
234
+ - **思考展示** — 在可折叠区块中显示 Agent 的思考/推理过程
235
+ - **Token 统计** — 每轮和累计的输入/输出/缓存 token 计数
283
236
  - **访问控制** — 按聊天/用户 ID 白名单限制
237
+ - **启动通知** — 启动时向所有已知聊天发送在线状态
238
+ - **完全访问 / 安全模式** — 让 AI 自由运行,或限制危险操作需确认
284
239
 
285
240
  ## 快速开始
286
241
 
@@ -299,7 +254,7 @@ cd your-project/
299
254
  codeclaw -t YOUR_BOT_TOKEN
300
255
  ```
301
256
 
302
- > **前置条件:** Node.js 18+,`claude` CLI 和/或 `codex` CLI PATH 中,从 [@BotFather](https://t.me/BotFather) 获取 Telegram Bot Token。
257
+ > **前置条件:** Node.js 18+,`claude` CLI 和/或 `codex` CLI 已安装,从 [@BotFather](https://t.me/BotFather) 获取 Telegram Bot Token。
303
258
 
304
259
  ## 命令行选项
305
260
 
@@ -311,31 +266,39 @@ codeclaw [选项]
311
266
 
312
267
  | 参数 | 环境变量 | 默认值 | 说明 |
313
268
  |------|---------|--------|------|
314
- | `-c, --channel` | `CODECLAW_CHANNEL` | `telegram` | IM 渠道 |
315
- | `-t, --token` | `CODECLAW_TOKEN` | — | Bot token |
316
- | `-e, --engine` | `DEFAULT_ENGINE` | `claude` | AI 引擎:`claude` 或 `codex` |
269
+ | `-c, --channel` | `CODECLAW_CHANNEL` | `telegram` | IM 渠道:`telegram`(feishu、whatsapp 规划中) |
270
+ | `-t, --token` | `CODECLAW_TOKEN` | — | Bot token(或下方渠道专属环境变量) |
271
+ | `-a, --agent` | `DEFAULT_AGENT` | `claude` | AI Agent:`claude` 或 `codex` |
272
+ | `-m, --model` | — | `claude-opus-4-6` / `gpt-5.4` | 模型覆盖(映射到 Agent 专属环境变量) |
317
273
  | `-w, --workdir` | `CODECLAW_WORKDIR` | `.` | 工作目录 |
318
- | `-m, --model` | `CLAUDE_MODEL` / `CODEX_MODEL` | — | 模型覆盖 |
319
274
 
320
275
  ### 访问控制
321
276
 
322
277
  | 参数 | 环境变量 | 默认值 | 说明 |
323
278
  |------|---------|--------|------|
324
- | `--full-access` | `CODECLAW_FULL_ACCESS` | `true` | AI 可以无需确认地读写执行 |
325
- | `--safe-mode` | `CODECLAW_SAFE_MODE` | `false` | AI 在执行危险操作前需确认 |
326
- | `--allowed-ids` | `CODECLAW_ALLOWED_IDS` | — | 允许交互的用户/聊天 ID,逗号分隔 |
279
+ | `--full-access` | `CODECLAW_FULL_ACCESS` | `true` | Agent 可以无需确认地读写执行 |
280
+ | `--safe-mode` | | `false` | 执行危险操作前需确认 |
281
+ | `--allowed-ids` | `TELEGRAM_ALLOWED_CHAT_IDS` | — | 允许交互的聊天/用户 ID,逗号分隔 |
327
282
  | `--timeout` | `CODECLAW_TIMEOUT` | `300` | 每次请求最大秒数 |
328
283
 
329
- ### 引擎专属配置
284
+ ### 渠道专属环境变量
330
285
 
331
286
  | 环境变量 | 说明 |
332
287
  |---------|------|
333
- | `CLAUDE_MODEL` | Claude 模型(如 `sonnet`、`opus`) |
334
- | `CLAUDE_PERMISSION_MODE` | `bypassPermissions`(默认)或 `default` |
335
- | `CLAUDE_EXTRA_ARGS` | 传递给 `claude` CLI 的额外参数 |
336
- | `CODEX_MODEL` | Codex 模型(如 `o3`、`o4-mini`) |
337
- | `CODEX_REASONING_EFFORT` | `none` / `minimal` / `low` / `medium` / `high` / `xhigh` |
338
- | `CODEX_EXTRA_ARGS` | 传递给 `codex` CLI 的额外参数 |
288
+ | `TELEGRAM_BOT_TOKEN` | Telegram Bot Token(来自 @BotFather) |
289
+ | `TELEGRAM_ALLOWED_CHAT_IDS` | 允许的 Telegram 聊天 ID,逗号分隔 |
290
+
291
+ ### Agent 专属环境变量
292
+
293
+ | 环境变量 | 默认值 | 说明 |
294
+ |---------|--------|------|
295
+ | `CLAUDE_MODEL` | `claude-opus-4-6` | Claude 模型名 |
296
+ | `CLAUDE_PERMISSION_MODE` | `bypassPermissions` | `bypassPermissions` 或 `default` |
297
+ | `CLAUDE_EXTRA_ARGS` | — | 传递给 `claude` CLI 的额外参数 |
298
+ | `CODEX_MODEL` | `gpt-5.4` | Codex 模型名 |
299
+ | `CODEX_REASONING_EFFORT` | `xhigh` | `none` / `minimal` / `low` / `medium` / `high` / `xhigh` |
300
+ | `CODEX_FULL_ACCESS` | `true` | 跳过沙箱和确认提示 |
301
+ | `CODEX_EXTRA_ARGS` | — | 传递给 `codex` CLI 的额外参数 |
339
302
 
340
303
  ### 使用示例
341
304
 
@@ -343,31 +306,63 @@ codeclaw [选项]
343
306
  # 基本用法:Telegram + Claude Code,完全访问
344
307
  npx codeclaw -t $BOT_TOKEN
345
308
 
346
- # Codex 引擎,安全模式,限制用户
347
- npx codeclaw -t $BOT_TOKEN -e codex --safe-mode --allowed-ids 123456,789012
309
+ # Codex Agent,安全模式,限制用户
310
+ npx codeclaw -t $BOT_TOKEN -a codex --safe-mode --allowed-ids 123456,789012
348
311
 
349
312
  # 自定义模型和工作目录
350
313
  npx codeclaw -t $BOT_TOKEN -m sonnet -w ~/projects/my-app
351
314
 
352
- # 验证配置(不启动)
353
- npx codeclaw -t $BOT_TOKEN --self-check
315
+ # 使用环境变量
316
+ TELEGRAM_BOT_TOKEN=xxx CODEX_MODEL=o3 npx codeclaw -a codex
354
317
  ```
355
318
 
356
319
  ## 机器人命令
357
320
 
321
+ 运行后,以下命令可在 Telegram 中使用:
322
+
358
323
  | 命令 | 说明 |
359
324
  |------|------|
360
- | `/ask <prompt>` | AI 提问 |
361
- | `/engine [codex\|claude]` | 查看或切换引擎 |
362
- | `/battle <prompt>` | 同时运行两个引擎,对比结果 |
363
- | `/new [prompt]` | 重置会话(可选带 prompt 开始新对话) |
364
- | `/session list\|use\|new\|del` | 多会话管理 |
365
- | `/status` | 查看当前会话/引擎/线程信息 |
366
- | `/stop` | 清除当前会话线程 |
367
- | `/clear [N]` | 删除机器人最近的消息(默认 50 条) |
368
- | `/help` | 显示所有命令 |
369
-
370
- > 在私聊中直接发送文字即可,无需命令前缀。
325
+ | `/sessions` | 列出、切换或创建会话(分页内联键盘) |
326
+ | `/agents` | 列出已安装的 Agent,切换使用 |
327
+ | `/switch` | 浏览和切换工作目录(交互式文件浏览器) |
328
+ | `/status` | 机器人状态:运行时间、内存、Agent、会话、Token 用量 |
329
+ | `/host` | 宿主机信息:CPU、内存、磁盘、进程排行 |
330
+ | `/start` | 欢迎消息和命令列表 |
331
+
332
+ > 在私聊中直接发送文字即可,无需命令前缀。未识别的 `/命令` 会作为 prompt 转发给 Agent。
333
+
334
+ ## 本地开发
335
+
336
+ ```bash
337
+ # 1. 安装依赖
338
+ npm install
339
+
340
+ # 2. 创建 .env 文件写入 token
341
+ echo "TELEGRAM_BOT_TOKEN=your_token_here" > .env
342
+
343
+ # 3. 本地运行
344
+ set -a && source .env && npx tsx src/cli.ts
345
+
346
+ # 4. 运行测试
347
+ npm test
348
+ ```
349
+
350
+ ## 架构
351
+
352
+ 详见 [ARCHITECTURE.md](ARCHITECTURE.md):
353
+
354
+ ```
355
+ cli.ts → bot-telegram.ts → bot.ts → code-agent.ts
356
+
357
+ channel-telegram.ts
358
+ ```
359
+
360
+ - **bot.ts** — 渠道无关的业务逻辑、状态管理、流式桥接
361
+ - **bot-telegram.ts** — Telegram 专属渲染、键盘、回调处理
362
+ - **channel-telegram.ts** — 纯 Telegram API 传输层(轮询、发送、文件下载)
363
+ - **code-agent.ts** — AI Agent 抽象(启动 CLI 子进程、解析 JSONL 流)
364
+
365
+ 添加新 IM 渠道只需创建 `channel-xxx.ts` + `bot-xxx.ts`,无需修改共享逻辑。
371
366
 
372
367
  ## 许可证
373
368