@emqo/claudebridge 0.4.0 → 0.5.1
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 +243 -84
- package/config.yaml.example +17 -0
- package/dist/adapters/discord.d.ts +6 -1
- package/dist/adapters/discord.js +88 -11
- package/dist/adapters/telegram.d.ts +7 -1
- package/dist/adapters/telegram.js +132 -13
- package/dist/core/agent.d.ts +3 -0
- package/dist/core/agent.js +119 -0
- package/dist/core/config.d.ts +16 -0
- package/dist/core/config.js +3 -0
- package/dist/core/i18n.js +32 -18
- package/dist/core/store.d.ts +45 -1
- package/dist/core/store.js +63 -2
- package/dist/ctl.js +32 -3
- package/dist/index.js +9 -0
- package/dist/skills/bridge.js +32 -0
- package/dist/webhook.d.ts +18 -0
- package/dist/webhook.js +160 -0
- package/package.json +13 -5
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2025-2026 Emqo
|
|
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
|
@@ -8,25 +8,36 @@
|
|
|
8
8
|
|
|
9
9
|
<a name="english"></a>
|
|
10
10
|
|
|
11
|
-
Bridge the `claude` CLI to chat platforms (Telegram, Discord). Spawns `claude` as a subprocess with `--output-format stream-json`
|
|
11
|
+
Bridge the `claude` CLI to chat platforms (Telegram, Discord). Spawns `claude` as a subprocess with `--output-format stream-json` — no SDK dependency, just raw CLI power.
|
|
12
12
|
|
|
13
13
|
## Features
|
|
14
14
|
|
|
15
|
+
### Core
|
|
15
16
|
- **Multi-platform**: Telegram (raw Bot API long polling) + Discord (discord.js)
|
|
16
17
|
- **Streaming responses**: Real-time message editing as Claude thinks
|
|
17
18
|
- **Multi-endpoint rotation**: Round-robin with auto-cooldown on 429/401/529
|
|
18
19
|
- **Session persistence**: SQLite-backed session resume via `-r <session_id>`
|
|
19
20
|
- **Per-user workspace isolation**: Each user gets their own working directory
|
|
20
|
-
- **Memory system**: Manual + auto-summary memories per user
|
|
21
|
-
- **Task & reminder system**: Create tasks, set timed reminders
|
|
22
|
-
- **Natural language intent detection**: Say "remind me in 5 min to check server" — no commands needed
|
|
23
|
-
- Regex-first (zero cost, zero latency) + Claude fallback (~$0.005/call)
|
|
24
|
-
- **Auto tasks**: Queue background tasks that execute when idle
|
|
25
21
|
- **File uploads**: Send files to Claude for analysis
|
|
26
22
|
- **Access control**: User/group whitelist
|
|
27
23
|
- **Hot reload**: Edit `config.yaml`, changes apply instantly
|
|
28
24
|
- **i18n**: English + Chinese
|
|
29
25
|
|
|
26
|
+
### Skill System (v0.2.0+)
|
|
27
|
+
Instead of hardcoded commands, ClaudeBridge injects a **skill document** into Claude's system prompt. Claude naturally understands it can manage memories, tasks, reminders, and auto-tasks by calling `claudebridge-ctl` through the Bash tool. Just talk naturally:
|
|
28
|
+
|
|
29
|
+
- "remember I like TypeScript" → Claude calls `ctl memory add`
|
|
30
|
+
- "remind me in 5 minutes" → Claude calls `ctl reminder add`
|
|
31
|
+
- "optimize the whole project" → Claude decomposes into multiple auto-tasks
|
|
32
|
+
|
|
33
|
+
### v0.5.0: Agent Gateway Features
|
|
34
|
+
|
|
35
|
+
- **Human-in-the-Loop (HITL)**: Critical tasks require user approval via inline buttons (Telegram) or commands (Discord) before execution
|
|
36
|
+
- **Conditional Branching**: Scout pattern — task 1 analyzes, saves results, dynamically creates follow-up tasks with `--parent` linking
|
|
37
|
+
- **Webhook Triggers**: HTTP API + GitHub webhooks + cron scheduler — trigger auto-tasks from external systems
|
|
38
|
+
- **Parallel Execution**: Multiple `claude` instances running simultaneously (`max_parallel` config)
|
|
39
|
+
- **Observability**: `/status` command shows task queue, chain progress, and execution stats
|
|
40
|
+
|
|
30
41
|
## Quick Start
|
|
31
42
|
|
|
32
43
|
### Global Install (npm)
|
|
@@ -35,8 +46,8 @@ Bridge the `claude` CLI to chat platforms (Telegram, Discord). Spawns `claude` a
|
|
|
35
46
|
npm i -g @emqo/claudebridge
|
|
36
47
|
claudebridge init # generate config.yaml from template
|
|
37
48
|
# edit config.yaml — set endpoints, tokens, whitelist
|
|
38
|
-
claudebridge start
|
|
39
|
-
claudebridge start
|
|
49
|
+
claudebridge start -f # foreground
|
|
50
|
+
claudebridge start # background (daemon)
|
|
40
51
|
claudebridge status # check if running
|
|
41
52
|
claudebridge reload # hot reload config
|
|
42
53
|
claudebridge stop # stop daemon
|
|
@@ -45,22 +56,23 @@ claudebridge stop # stop daemon
|
|
|
45
56
|
### From Source
|
|
46
57
|
|
|
47
58
|
```bash
|
|
59
|
+
git clone https://github.com/Emqo/ClaudeBridge.git
|
|
60
|
+
cd ClaudeBridge
|
|
48
61
|
npm install
|
|
49
62
|
cp config.yaml.example config.yaml
|
|
63
|
+
# edit config.yaml
|
|
50
64
|
npm run build
|
|
51
65
|
npm start
|
|
52
|
-
# or dev mode
|
|
53
|
-
npm run dev
|
|
54
66
|
```
|
|
55
67
|
|
|
56
68
|
## Configuration
|
|
57
69
|
|
|
58
|
-
All config lives in `config.yaml
|
|
70
|
+
All config lives in `config.yaml` ([full template](config.yaml.example)):
|
|
59
71
|
|
|
60
72
|
```yaml
|
|
61
73
|
endpoints:
|
|
62
74
|
- name: "my-endpoint"
|
|
63
|
-
base_url: ""
|
|
75
|
+
base_url: ""
|
|
64
76
|
api_key: "sk-..."
|
|
65
77
|
model: "claude-sonnet-4-20250514"
|
|
66
78
|
|
|
@@ -71,15 +83,14 @@ agent:
|
|
|
71
83
|
permission_mode: "acceptEdits"
|
|
72
84
|
max_turns: 50
|
|
73
85
|
max_budget_usd: 2.0
|
|
74
|
-
|
|
86
|
+
max_parallel: 1 # concurrent auto-task execution (1 = sequential)
|
|
75
87
|
timeout_seconds: 300
|
|
76
88
|
memory:
|
|
77
89
|
enabled: true
|
|
78
90
|
auto_summary: true
|
|
79
91
|
max_memories: 50
|
|
80
|
-
|
|
81
|
-
enabled: true
|
|
82
|
-
use_claude_fallback: true # use Claude when regex doesn't match
|
|
92
|
+
skill:
|
|
93
|
+
enabled: true
|
|
83
94
|
|
|
84
95
|
workspace:
|
|
85
96
|
base_dir: "./workspaces"
|
|
@@ -98,11 +109,26 @@ platforms:
|
|
|
98
109
|
enabled: false
|
|
99
110
|
token: ""
|
|
100
111
|
chunk_size: 1900
|
|
112
|
+
|
|
113
|
+
# Webhook server for external triggers
|
|
114
|
+
webhook:
|
|
115
|
+
enabled: false
|
|
116
|
+
port: 3100
|
|
117
|
+
token: "your-bearer-token"
|
|
118
|
+
github_secret: ""
|
|
119
|
+
|
|
120
|
+
# Scheduled auto-tasks
|
|
121
|
+
cron:
|
|
122
|
+
- schedule_minutes: 60
|
|
123
|
+
user_id: "123456"
|
|
124
|
+
platform: "telegram"
|
|
125
|
+
chat_id: "123456"
|
|
126
|
+
description: "Generate daily status report"
|
|
101
127
|
```
|
|
102
128
|
|
|
103
|
-
|
|
129
|
+
Leave `endpoints` empty to use `claude` CLI's own authentication.
|
|
104
130
|
|
|
105
|
-
## Commands
|
|
131
|
+
## Platform Commands
|
|
106
132
|
|
|
107
133
|
| Telegram | Discord | Action |
|
|
108
134
|
|----------|---------|--------|
|
|
@@ -111,60 +137,133 @@ Environment variables (`.env`) work as fallback for single-endpoint setup.
|
|
|
111
137
|
| /allusage | !allusage | All users stats |
|
|
112
138
|
| /history | !history | Recent conversations |
|
|
113
139
|
| /model | !model | Endpoint info |
|
|
140
|
+
| /status | !status | Auto task status & progress |
|
|
114
141
|
| /reload | !reload | Hot reload config |
|
|
115
|
-
| /
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
142
|
+
| /help | !help | Show help |
|
|
143
|
+
|
|
144
|
+
Discord also supports: `!approve <id>`, `!reject <id>` for HITL approval.
|
|
145
|
+
|
|
146
|
+
All other interactions are handled naturally by Claude through the skill system — no command prefix needed.
|
|
147
|
+
|
|
148
|
+
## HITL (Human-in-the-Loop)
|
|
149
|
+
|
|
150
|
+
When Claude determines a task is critical (deployment, deletion, production changes), it uses `ctl auto add-approval` instead of `ctl auto add`. The task enters `approval_pending` status:
|
|
151
|
+
|
|
152
|
+
- **Telegram**: Inline keyboard with Approve / Reject buttons
|
|
153
|
+
- **Discord**: Bot sends approval request, user replies `!approve <id>` or `!reject <id>`
|
|
154
|
+
|
|
155
|
+
Only after approval does the task enter the execution queue.
|
|
156
|
+
|
|
157
|
+
## Conditional Branching (Scout Pattern)
|
|
158
|
+
|
|
159
|
+
Tasks can be linked via `--parent <id>` to form chains:
|
|
160
|
+
|
|
161
|
+
```
|
|
162
|
+
Task #1 (scout): "Analyze performance bottlenecks"
|
|
163
|
+
→ Finds 3 issues, creates child tasks:
|
|
164
|
+
Task #2: "Fix N+1 queries" (--parent 1)
|
|
165
|
+
Task #3: "Add caching layer" (--parent 1)
|
|
166
|
+
Task #4: "Run benchmarks" (--parent 1)
|
|
167
|
+
```
|
|
168
|
+
|
|
169
|
+
Chain progress is reported automatically: `Chain #1 progress: 2/4 done`
|
|
170
|
+
|
|
171
|
+
Results are persisted via `ctl auto result <id> "summary"` and cross-task context flows through the memory system.
|
|
172
|
+
|
|
173
|
+
## Webhook & Cron
|
|
174
|
+
|
|
175
|
+
### HTTP API
|
|
176
|
+
|
|
177
|
+
```bash
|
|
178
|
+
# Health check
|
|
179
|
+
curl http://localhost:3100/health
|
|
180
|
+
|
|
181
|
+
# Create auto-task
|
|
182
|
+
curl -X POST http://localhost:3100/api/task \
|
|
183
|
+
-H "Authorization: Bearer your-token" \
|
|
184
|
+
-H "Content-Type: application/json" \
|
|
185
|
+
-d '{"user_id":"123","platform":"telegram","chat_id":"123","description":"analyze logs"}'
|
|
186
|
+
|
|
187
|
+
# Create approval-required task
|
|
188
|
+
curl -X POST http://localhost:3100/api/task \
|
|
189
|
+
-H "Authorization: Bearer your-token" \
|
|
190
|
+
-H "Content-Type: application/json" \
|
|
191
|
+
-d '{"user_id":"123","platform":"telegram","chat_id":"123","description":"deploy to prod","approval":true}'
|
|
192
|
+
```
|
|
193
|
+
|
|
194
|
+
### GitHub Webhooks
|
|
195
|
+
|
|
196
|
+
```
|
|
197
|
+
POST http://your-server:3100/webhook/github?user_id=123&platform=telegram&chat_id=123
|
|
198
|
+
```
|
|
199
|
+
|
|
200
|
+
Configure in GitHub repo Settings → Webhooks. Supports `push`, `pull_request`, `issues` events with HMAC-SHA256 signature verification.
|
|
201
|
+
|
|
202
|
+
### Cron
|
|
203
|
+
|
|
204
|
+
```yaml
|
|
205
|
+
cron:
|
|
206
|
+
- schedule_minutes: 60
|
|
207
|
+
user_id: "123"
|
|
208
|
+
platform: "telegram"
|
|
209
|
+
chat_id: "123"
|
|
210
|
+
description: "Check server health and report anomalies"
|
|
211
|
+
```
|
|
212
|
+
|
|
213
|
+
## Parallel Execution
|
|
214
|
+
|
|
215
|
+
Set `max_parallel: N` to run N auto-tasks simultaneously. Each spawns an independent `claude` process with:
|
|
216
|
+
- No session sharing (prevents conflicts)
|
|
217
|
+
- Shared memories (cross-task context via SQLite)
|
|
218
|
+
- Endpoint rotation (distributes load)
|
|
219
|
+
|
|
220
|
+
```yaml
|
|
221
|
+
agent:
|
|
222
|
+
max_parallel: 3 # 3 concurrent claude instances
|
|
223
|
+
```
|
|
141
224
|
|
|
142
225
|
## Architecture
|
|
143
226
|
|
|
144
227
|
```
|
|
145
|
-
src/
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
228
|
+
src/
|
|
229
|
+
cli.ts CLI: start/stop/status/reload/init with PID management
|
|
230
|
+
index.ts Entry point, config loading, hot reload, webhook startup
|
|
231
|
+
ctl.ts claudebridge-ctl: memory/task/reminder/auto ops via SQLite
|
|
232
|
+
webhook.ts HTTP server + GitHub webhooks + cron scheduler
|
|
233
|
+
core/
|
|
234
|
+
agent.ts Claude CLI subprocess spawner (runStream + runParallel)
|
|
235
|
+
config.ts YAML config with env fallback
|
|
236
|
+
keys.ts Endpoint round-robin with cooldown
|
|
237
|
+
lock.ts Per-user concurrency mutex (Redis or in-memory)
|
|
238
|
+
store.ts SQLite (WAL): sessions, usage, history, memories, tasks
|
|
239
|
+
permissions.ts Whitelist access control
|
|
240
|
+
markdown.ts Markdown → Telegram MarkdownV2
|
|
241
|
+
i18n.ts Internationalization (en/zh)
|
|
242
|
+
adapters/
|
|
243
|
+
base.ts Adapter interface + chunkText utility
|
|
244
|
+
telegram.ts Telegram Bot API (raw fetch, long polling, inline buttons)
|
|
245
|
+
discord.ts Discord.js (@mentions + DMs + approval commands)
|
|
246
|
+
skills/
|
|
247
|
+
bridge.ts Skill document generator (bilingual, injected via --append-system-prompt)
|
|
248
|
+
```
|
|
249
|
+
|
|
250
|
+
### Data Flow
|
|
251
|
+
|
|
252
|
+
```
|
|
253
|
+
User message → Adapter → Access check → Claude subprocess → Stream response back
|
|
254
|
+
↓
|
|
255
|
+
Reads skill doc → calls ctl via Bash
|
|
256
|
+
↓
|
|
257
|
+
SQLite: memories, tasks, reminders
|
|
258
|
+
↓
|
|
259
|
+
Bridge timers: auto-execute, remind, approve
|
|
161
260
|
```
|
|
162
261
|
|
|
163
262
|
## Prerequisites
|
|
164
263
|
|
|
165
264
|
- Node.js 18+
|
|
166
|
-
- `claude` CLI installed and authenticated
|
|
167
|
-
- Telegram bot token (from @BotFather) and/or Discord bot token
|
|
265
|
+
- `claude` CLI installed and authenticated ([Claude Code](https://docs.anthropic.com/en/docs/claude-code))
|
|
266
|
+
- Telegram bot token (from [@BotFather](https://t.me/BotFather)) and/or Discord bot token
|
|
168
267
|
|
|
169
268
|
## License
|
|
170
269
|
|
|
@@ -180,21 +279,32 @@ MIT
|
|
|
180
279
|
|
|
181
280
|
## 功能特性
|
|
182
281
|
|
|
282
|
+
### 核心
|
|
183
283
|
- **多平台**:Telegram(原生 Bot API 长轮询)+ Discord(discord.js)
|
|
184
284
|
- **流式响应**:Claude 思考时实时编辑消息
|
|
185
285
|
- **多端点轮转**:Round-robin,429/401/529 自动冷却切换
|
|
186
286
|
- **会话持久化**:SQLite 存储,通过 `-r <session_id>` 恢复会话
|
|
187
287
|
- **用户工作区隔离**:每个用户独立工作目录
|
|
188
|
-
- **记忆系统**:手动 + 自动摘要记忆
|
|
189
|
-
- **任务与提醒**:创建任务、设置定时提醒
|
|
190
|
-
- **自然语言意图识别**:直接说"提醒我5分钟后检查服务器",无需打命令
|
|
191
|
-
- 正则优先(零成本零延迟)+ Claude 兜底(~$0.005/次)
|
|
192
|
-
- **自动任务**:排队后台任务,空闲时自动执行
|
|
193
288
|
- **文件上传**:发送文件给 Claude 分析
|
|
194
289
|
- **访问控制**:用户/群组白名单
|
|
195
290
|
- **热重载**:编辑 `config.yaml` 即时生效
|
|
196
291
|
- **国际化**:英文 + 中文
|
|
197
292
|
|
|
293
|
+
### 技能系统 (v0.2.0+)
|
|
294
|
+
无需硬编码命令,ClaudeBridge 将**技能文档**注入 Claude 的系统提示。Claude 自然理解它可以通过 Bash 工具调用 `claudebridge-ctl` 来管理记忆、任务、提醒和自动任务。直接对话即可:
|
|
295
|
+
|
|
296
|
+
- "记住我喜欢 TypeScript" → Claude 调用 `ctl memory add`
|
|
297
|
+
- "5分钟后提醒我" → Claude 调用 `ctl reminder add`
|
|
298
|
+
- "优化整个项目" → Claude 分解为多个自动任务
|
|
299
|
+
|
|
300
|
+
### v0.5.0:Agent Gateway 特性
|
|
301
|
+
|
|
302
|
+
- **人机协同 (HITL)**:关键任务需要用户通过内联按钮(Telegram)或命令(Discord)审批后才执行
|
|
303
|
+
- **条件分支**:侦查模式 — 任务1分析,保存结果,动态创建后续任务并通过 `--parent` 关联
|
|
304
|
+
- **Webhook 触发**:HTTP API + GitHub webhooks + 定时任务 — 从外部系统触发自动任务
|
|
305
|
+
- **并行执行**:多个 `claude` 实例同时运行(`max_parallel` 配置)
|
|
306
|
+
- **可观测性**:`/status` 命令显示任务队列、链路进度和执行统计
|
|
307
|
+
|
|
198
308
|
## 快速开始
|
|
199
309
|
|
|
200
310
|
### 全局安装(npm)
|
|
@@ -203,8 +313,8 @@ MIT
|
|
|
203
313
|
npm i -g @emqo/claudebridge
|
|
204
314
|
claudebridge init # 从模板生成 config.yaml
|
|
205
315
|
# 编辑 config.yaml,配置端点、Token、白名单
|
|
206
|
-
claudebridge start
|
|
207
|
-
claudebridge start
|
|
316
|
+
claudebridge start -f # 前台启动
|
|
317
|
+
claudebridge start # 后台启动(守护进程)
|
|
208
318
|
claudebridge status # 查看运行状态
|
|
209
319
|
claudebridge reload # 热重载配置
|
|
210
320
|
claudebridge stop # 停止进程
|
|
@@ -213,33 +323,82 @@ claudebridge stop # 停止进程
|
|
|
213
323
|
### 从源码
|
|
214
324
|
|
|
215
325
|
```bash
|
|
326
|
+
git clone https://github.com/Emqo/ClaudeBridge.git
|
|
327
|
+
cd ClaudeBridge
|
|
216
328
|
npm install
|
|
217
329
|
cp config.yaml.example config.yaml
|
|
330
|
+
# 编辑 config.yaml
|
|
218
331
|
npm run build && npm start
|
|
219
|
-
# 或开发模式
|
|
220
|
-
npm run dev
|
|
221
332
|
```
|
|
222
333
|
|
|
223
|
-
##
|
|
334
|
+
## 平台命令
|
|
335
|
+
|
|
336
|
+
| Telegram | Discord | 功能 |
|
|
337
|
+
|----------|---------|------|
|
|
338
|
+
| /new | !new | 清除会话 |
|
|
339
|
+
| /usage | !usage | 你的用量 |
|
|
340
|
+
| /allusage | !allusage | 所有用量 |
|
|
341
|
+
| /history | !history | 最近对话 |
|
|
342
|
+
| /model | !model | 端点信息 |
|
|
343
|
+
| /status | !status | 自动任务状态与进度 |
|
|
344
|
+
| /reload | !reload | 热重载配置 |
|
|
345
|
+
| /help | !help | 显示帮助 |
|
|
346
|
+
|
|
347
|
+
Discord 还支持:`!approve <id>`、`!reject <id>` 用于 HITL 审批。
|
|
348
|
+
|
|
349
|
+
所有其他交互由 Claude 通过技能系统自然处理,无需命令前缀。
|
|
350
|
+
|
|
351
|
+
## 人机协同 (HITL)
|
|
352
|
+
|
|
353
|
+
当 Claude 判定任务为关键操作(部署、删除、生产变更)时,使用 `ctl auto add-approval` 代替 `ctl auto add`。任务进入 `approval_pending` 状态:
|
|
354
|
+
|
|
355
|
+
- **Telegram**:内联键盘显示 Approve / Reject 按钮
|
|
356
|
+
- **Discord**:Bot 发送审批请求,用户回复 `!approve <id>` 或 `!reject <id>`
|
|
357
|
+
|
|
358
|
+
只有审批通过后,任务才进入执行队列。
|
|
359
|
+
|
|
360
|
+
## 条件分支(侦查模式)
|
|
361
|
+
|
|
362
|
+
任务可通过 `--parent <id>` 形成链路:
|
|
363
|
+
|
|
364
|
+
```
|
|
365
|
+
任务 #1(侦查):"分析性能瓶颈"
|
|
366
|
+
→ 发现3个问题,创建子任务:
|
|
367
|
+
任务 #2:"修复 N+1 查询" (--parent 1)
|
|
368
|
+
任务 #3:"添加缓存层" (--parent 1)
|
|
369
|
+
任务 #4:"运行基准测试" (--parent 1)
|
|
370
|
+
```
|
|
371
|
+
|
|
372
|
+
链路进度自动报告:`Chain #1 progress: 2/4 done`
|
|
373
|
+
|
|
374
|
+
## Webhook 与定时任务
|
|
375
|
+
|
|
376
|
+
```bash
|
|
377
|
+
# 健康检查
|
|
378
|
+
curl http://localhost:3100/health
|
|
379
|
+
|
|
380
|
+
# 创建自动任务
|
|
381
|
+
curl -X POST http://localhost:3100/api/task \
|
|
382
|
+
-H "Authorization: Bearer your-token" \
|
|
383
|
+
-H "Content-Type: application/json" \
|
|
384
|
+
-d '{"user_id":"123","platform":"telegram","chat_id":"123","description":"分析日志"}'
|
|
385
|
+
|
|
386
|
+
# 创建需审批的任务
|
|
387
|
+
curl -X POST http://localhost:3100/api/task \
|
|
388
|
+
-d '{"user_id":"123","platform":"telegram","chat_id":"123","description":"部署到生产","approval":true}'
|
|
389
|
+
```
|
|
224
390
|
|
|
225
|
-
|
|
391
|
+
GitHub Webhooks 支持 `push`、`pull_request`、`issues` 事件,使用 HMAC-SHA256 签名验证。
|
|
226
392
|
|
|
227
|
-
|
|
228
|
-
|------|--------|
|
|
229
|
-
| "提醒我5分钟后检查服务器" | 提醒:5分钟后,检查服务器 |
|
|
230
|
-
| "remind me 10 min later to deploy" | 提醒:10分钟后,部署 |
|
|
231
|
-
| "添加任务买牛奶" | 任务:买牛奶 |
|
|
232
|
-
| "记住我喜欢TypeScript" | 记忆:我喜欢TypeScript |
|
|
233
|
-
| "忘记所有" | 清除所有记忆 |
|
|
234
|
-
| "新会话" | 清除会话 |
|
|
393
|
+
## 并行执行
|
|
235
394
|
|
|
236
|
-
|
|
395
|
+
设置 `max_parallel: N` 同时运行 N 个自动任务。每个任务 spawn 独立的 `claude` 进程,无 session 共享,通过 SQLite 记忆系统传递上下文。
|
|
237
396
|
|
|
238
397
|
## 前置要求
|
|
239
398
|
|
|
240
399
|
- Node.js 18+
|
|
241
|
-
- `claude` CLI
|
|
242
|
-
- Telegram bot token(从 @BotFather 获取)和/或 Discord bot token
|
|
400
|
+
- `claude` CLI 已安装并认证([Claude Code](https://docs.anthropic.com/en/docs/claude-code))
|
|
401
|
+
- Telegram bot token(从 [@BotFather](https://t.me/BotFather) 获取)和/或 Discord bot token
|
|
243
402
|
|
|
244
403
|
## 许可证
|
|
245
404
|
|
package/config.yaml.example
CHANGED
|
@@ -20,6 +20,7 @@ agent:
|
|
|
20
20
|
permission_mode: "acceptEdits"
|
|
21
21
|
max_turns: 50
|
|
22
22
|
max_budget_usd: 2.0
|
|
23
|
+
max_parallel: 1 # Number of concurrent auto-task executions (1 = sequential)
|
|
23
24
|
system_prompt: ""
|
|
24
25
|
cwd: ""
|
|
25
26
|
timeout_seconds: 300
|
|
@@ -51,3 +52,19 @@ platforms:
|
|
|
51
52
|
enabled: false
|
|
52
53
|
token: ""
|
|
53
54
|
chunk_size: 1900
|
|
55
|
+
|
|
56
|
+
# Webhook server for external triggers (GitHub, API, etc.)
|
|
57
|
+
webhook:
|
|
58
|
+
enabled: false
|
|
59
|
+
port: 3100
|
|
60
|
+
token: "your-secret-token" # Bearer token for /api/task
|
|
61
|
+
github_secret: "" # HMAC secret for GitHub webhooks
|
|
62
|
+
|
|
63
|
+
# Cron-like scheduled auto-tasks
|
|
64
|
+
# cron:
|
|
65
|
+
# - schedule_minutes: 60
|
|
66
|
+
# user_id: "123456"
|
|
67
|
+
# platform: "telegram"
|
|
68
|
+
# chat_id: "123456"
|
|
69
|
+
# description: "Generate daily status report"
|
|
70
|
+
cron: []
|
|
@@ -10,7 +10,9 @@ export declare class DiscordAdapter implements Adapter {
|
|
|
10
10
|
private client;
|
|
11
11
|
private reminderTimer?;
|
|
12
12
|
private autoTimer?;
|
|
13
|
-
private
|
|
13
|
+
private approvalTimer?;
|
|
14
|
+
private activeAutoTasks;
|
|
15
|
+
private maxParallel;
|
|
14
16
|
constructor(engine: AgentEngine, store: Store, config: DiscordConfig, locale?: string);
|
|
15
17
|
private setup;
|
|
16
18
|
private handlePrompt;
|
|
@@ -18,4 +20,7 @@ export declare class DiscordAdapter implements Adapter {
|
|
|
18
20
|
stop(): void;
|
|
19
21
|
private checkReminders;
|
|
20
22
|
private processAutoTasks;
|
|
23
|
+
private runAutoTask;
|
|
24
|
+
private checkApprovals;
|
|
25
|
+
private handleStatusCommand;
|
|
21
26
|
}
|