feishu-bridge 1.0.3 → 1.0.4

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
@@ -1,22 +1,30 @@
1
- # Feishu Bridge
1
+ # 飞书桥接器 (Feishu Bridge)
2
2
 
3
- 🚀 轻量级飞书插件,桥接飞书与各种AI编程IDE/CLI工具
3
+ 🚀 轻量级飞书插件,桥接飞书与各种 AI 编程 IDE/CLI 工具
4
4
 
5
5
  ## ✨ 特性
6
6
 
7
- - **🎯 零依赖**: 无需OpenClaw,独立运行
8
- - **🔌 多IDE支持**: VS Code, Cursor, Trae, OpenCode, Claude Code, Kiro, Antigravity
7
+ - **🎯 零依赖**: 无需 OpenClaw,独立运行
8
+ - **🔌 多 IDE 支持**: VS Code, Cursor, Trae, OpenCode, Claude Code, Kiro, Antigravity
9
9
  - **💬 全交互**: 通过飞书完成所有操作,结果返回飞书
10
- - **🔒 安全**: Webhook签名验证(HMAC-SHA256),防重放攻击
11
- - **📊 监控**: 健康检查端点,Prometheus指标
12
- - **🔧 完整CLI**: 配置管理、守护进程、状态监控
13
- - **⚡ 自动启动**: Shell hook自动检测IDE环境并启动服务
14
- - **🔄 双模式**: WebSocket和Webhook双连接模式支持
15
- - **💾 备用通信**: 文件系统IPC机制确保可靠性
10
+ - **🔒 安全**: Webhook 签名验证(HMAC-SHA256),防重放攻击
11
+ - **📊 监控**: 健康检查端点,Prometheus 指标
12
+ - **🔧 完整 CLI**: 配置管理、守护进程、状态监控
13
+ - **⚡ 自动启动**: Shell hook 自动检测 IDE 环境并启动服务
14
+ - **🔄 双模式**: WebSocket Webhook 双连接模式支持
15
+ - **💾 备用通信**: 文件系统 IPC 机制确保可靠性
16
+
17
+ ---
16
18
 
17
19
  ## 📦 安装
18
20
 
19
- ### 方式一: curl一键安装 (推荐)
21
+ ### 方式一: npm 全局安装(推荐)
22
+
23
+ ```bash
24
+ npm install -g feishu-bridge
25
+ ```
26
+
27
+ ### 方式二: curl 一键安装
20
28
 
21
29
  **Linux/macOS:**
22
30
  ```bash
@@ -28,12 +36,6 @@ curl -fsSL https://install.feishu-bridge.dev | bash
28
36
  iwr -useb https://install.feishu-bridge.dev/install.ps1 | iex
29
37
  ```
30
38
 
31
- ### 方式二: npm全局安装
32
-
33
- ```bash
34
- npm install -g feishu-bridge
35
- ```
36
-
37
39
  ### 方式三: 手动安装
38
40
 
39
41
  ```bash
@@ -44,195 +46,348 @@ npm run build
44
46
  npm link
45
47
  ```
46
48
 
47
- ## Architecture
49
+ ---
48
50
 
49
- ```
50
- ┌─────────────────┐ WebSocket/Webhook ┌─────────────────────────┐
51
- │ Feishu │ ◄──────────────────────► │ Feishu Bot │
52
- │ (手机/PC/Web) │ │ (自建应用机器人) │
53
- └─────────────────┘ └─────────────────────────┘
54
-
55
-
56
- ┌─────────────────────────────────────────────────────────────────────┐
57
- │ Feishu Bridge Core │
58
- │ ┌─────────────┐ ┌─────────────┐ ┌─────────────┐ ┌────────────┐ │
59
- │ │ Message │ │ Session │ │ Tool │ │ Response │
60
- │ │ Handler │ │ Manager │ │ Router │ │ Formatter │ │
61
- │ └─────────────┘ └─────────────┘ └─────────────┘ └────────────┘ │
62
- └─────────────────────────────────────────────────────────────────────┘
63
-
64
-
65
- ┌─────────────────────────────────────────────────────────────────────┐
66
- │ IDE/CLI Adapters Layer │
67
- │ ┌──────────┐ ┌──────────┐ ┌──────────┐ ┌──────────┐ ┌──────────┐ │
68
- │ │ VS Code │ │ Cursor │ │ Trae │ │ OpenCode │ │ Claude │ │
69
- │ │ Adapter │ │ Adapter │ │ Adapter │ │ Adapter │ │ Adapter │ │
70
- │ └──────────┘ └──────────┘ └──────────┘ └──────────┘ └──────────┘ │
71
- └─────────────────────────────────────────────────────────────────────┘
72
- ```
73
-
74
- ## Installation
75
-
76
- ### npm Global Install
51
+ ## 🚀 快速开始
52
+
53
+ ### 1. 配置飞书应用
54
+
55
+ 1. 访问 [飞书开放平台](https://open.feishu.cn/)
56
+ 2. 创建企业自建应用
57
+ 3. 获取 **App ID** 和 **App Secret**
58
+ 4. 启用机器人功能
59
+ 5. 选择连接模式(WebSocket 推荐)
60
+
61
+ ### 2. 配置桥接器
77
62
 
78
63
  ```bash
79
- # Install globally
80
- npm install -g feishu-bridge
64
+ # 设置 App ID
65
+ feishu-bridge config set feishu.appId cli_xxxxxxxxxxxx
66
+
67
+ # 设置 App Secret
68
+ feishu-bridge config set feishu.appSecret xxxxxxxxxxxxxxxxxxxxxxxx
69
+
70
+ # 设置连接模式(推荐 WebSocket,无需公网 IP)
71
+ feishu-bridge config set feishu.connectionMode websocket
72
+
73
+ # 验证配置
74
+ feishu-bridge config list
75
+ ```
81
76
 
82
- # Configure your Feishu app credentials
83
- feishu-bridge config set appId YOUR_APP_ID
84
- feishu-bridge config set appSecret YOUR_APP_SECRET
77
+ ### 3. 启动服务
85
78
 
86
- # Start the server
79
+ ```bash
80
+ # 前台模式(调试用)
87
81
  feishu-bridge start
82
+
83
+ # 或后台模式(生产用)
84
+ feishu-bridge daemon start
88
85
  ```
89
86
 
90
- ### Manual Install
87
+ ### 4. 在飞书使用
88
+
89
+ 在配置了机器人的飞书群组中发送:
90
+
91
+ ```
92
+ @vscode /generate a React button component
93
+ ```
94
+
95
+ ---
96
+
97
+ ## 💬 使用指南
98
+
99
+ ### 命令格式
100
+
101
+ ```
102
+ @<目标> <命令>
103
+ ```
104
+
105
+ ### 支持的目标
106
+
107
+ | 目标 | 说明 | 示例 |
108
+ |------|------|------|
109
+ | `@vscode` | VS Code | `@vscode /generate login form` |
110
+ | `@cursor` | Cursor | `@cursor /run npm test` |
111
+ | `@trae` | Trae | `@trae build project` |
112
+ | `@opencode` | OpenCode | `@opencode fix bug` |
113
+ | `@claude` | Claude Code | `@claude explain code` |
114
+ | `@antigravity` | Antigravity | `@antigravity deploy` |
115
+ | `@kiro` | Kiro | `@kiro generate API` |
116
+
117
+ ### 常用命令
118
+
119
+ **代码生成:**
120
+ ```
121
+ @vscode /generate a React login form with TypeScript
122
+ ```
123
+
124
+ **运行命令:**
125
+ ```
126
+ @cursor /run npm install axios
127
+ ```
128
+
129
+ **打开文件:**
130
+ ```
131
+ @vscode open src/App.tsx
132
+ ```
133
+
134
+ **解释代码:**
135
+ ```
136
+ @claude explain the authentication flow
137
+ ```
138
+
139
+ **搜索代码:**
140
+ ```
141
+ @vscode /search "function handleSubmit"
142
+ ```
143
+
144
+ **构建项目:**
145
+ ```
146
+ @trae /build
147
+ ```
148
+
149
+ ---
150
+
151
+ ## ⚙️ 配置详解
152
+
153
+ ### 配置文件
154
+
155
+ 位置:`~/.config/feishu-bridge/config.json`
156
+
157
+ ```json
158
+ {
159
+ "feishu": {
160
+ "appId": "cli_xxxxxxxxxxxx",
161
+ "appSecret": "xxxxxxxxxxxxxxxxxxxxxxxx",
162
+ "domain": "feishu",
163
+ "connectionMode": "websocket",
164
+ "encryptKey": "可选"
165
+ },
166
+ "server": {
167
+ "port": 3000,
168
+ "host": "0.0.0.0"
169
+ },
170
+ "adapters": {
171
+ "vscode": { "enabled": true },
172
+ "cursor": { "enabled": true },
173
+ "trae": { "enabled": true }
174
+ },
175
+ "behavior": {
176
+ "autoStart": true,
177
+ "maxOutputLength": 2000,
178
+ "sessionTimeout": 30,
179
+ "reverseChannelEnabled": true
180
+ }
181
+ }
182
+ ```
183
+
184
+ ### CLI 命令
91
185
 
92
186
  ```bash
93
- # Clone the repository
94
- git clone https://github.com/your-org/feishu-bridge.git
95
- cd feishu-bridge
187
+ # 服务管理
188
+ feishu-bridge start # 前台启动
189
+ feishu-bridge daemon start # 后台启动
190
+ feishu-bridge daemon stop # 停止服务
191
+ feishu-bridge daemon restart # 重启服务
192
+ feishu-bridge status # 查看状态
193
+
194
+ # 配置管理
195
+ feishu-bridge config set <key> <value> # 设置配置
196
+ feishu-bridge config get <key> # 获取配置
197
+ feishu-bridge config delete <key> # 删除配置
198
+ feishu-bridge config list # 列出所有配置
199
+
200
+ # 其他
201
+ feishu-bridge --version # 查看版本
202
+ feishu-bridge --help # 显示帮助
203
+ ```
96
204
 
97
- # Install dependencies
98
- npm install
205
+ ---
99
206
 
100
- # Build the project
101
- npm run build
207
+ ## 🔌 连接模式
102
208
 
103
- # Start the server
104
- npm start
209
+ ### WebSocket 模式(推荐)
210
+
211
+ **优点:**
212
+ - 无需公网 IP
213
+ - 无需配置 Webhook URL
214
+ - 自动重连
215
+
216
+ **配置:**
217
+ ```bash
218
+ feishu-bridge config set feishu.connectionMode websocket
219
+ ```
220
+
221
+ **飞书端配置:**
222
+ 1. 进入应用 → 事件订阅
223
+ 2. 选择「长连接(WebSocket)」
224
+ 3. 开启连接
225
+
226
+ ### Webhook 模式
227
+
228
+ **适用场景:**
229
+ - 有固定公网 IP
230
+ - 使用内网穿透工具(如 ngrok)
231
+
232
+ **配置:**
233
+ ```bash
234
+ feishu-bridge config set feishu.connectionMode webhook
235
+ feishu-bridge config set server.webhookPath /webhook/feishu
105
236
  ```
106
237
 
107
- ## Configuration
238
+ **飞书端配置:**
239
+ 1. 进入应用 → 事件订阅
240
+ 2. 选择「HTTP 推送」
241
+ 3. 配置 URL: `http://你的IP:3000/webhook/feishu`
242
+
243
+ ---
108
244
 
109
- Create a `.env` file in your project root:
245
+ ## 🏗️ 架构
110
246
 
111
- ```env
112
- FEISHU_APP_ID=your_app_id
113
- FEISHU_APP_SECRET=your_app_secret
114
- FEISHU_ENCRYPT_KEY=your_encrypt_key (optional)
115
- FEISHU_VERIFICATION_TOKEN=your_verification_token (optional)
116
- SERVER_PORT=3000
117
- SERVER_HOST=0.0.0.0
118
247
  ```
248
+ ┌─────────────────┐ WebSocket/Webhook ┌─────────────────────────┐
249
+ │ 飞书用户 │ ───────────────────► │ 桥接器服务 │
250
+ │ (群组消息) │ │ (feishu-bridge) │
251
+ └─────────────────┘ └───────────┬─────────────┘
252
+
253
+ 文件系统 IPC │
254
+ /tmp/feishu-bridge/ ▼
255
+
256
+ ┌────────────────────────────────┴────────────────┐
257
+ │ │
258
+ ┌────────▼─────────┐ ┌──────────▼──────┐ ┌───────▼───────┐
259
+ │ VS Code │ │ Cursor │ │ Trae │
260
+ │ 扩展/脚本 │ │ 脚本 │ │ 脚本 │
261
+ └──────────────────┘ └─────────────────┘ └───────────────┘
262
+ ```
263
+
264
+ **工作流程:**
265
+ 1. 用户在飞书发送 `@vscode /generate button`
266
+ 2. 桥接器接收消息并解析
267
+ 3. 写入指令文件到 `/tmp/feishu-bridge/vscode/`
268
+ 4. IDE 扩展/脚本读取并执行
269
+ 5. 结果写回文件系统
270
+ 6. 桥接器发送回飞书
119
271
 
120
- ## Usage
272
+ ---
121
273
 
122
- ### CLI Commands
274
+ ## 🛠️ 故障排除
123
275
 
276
+ ### 服务无法启动
277
+
278
+ **端口被占用:**
124
279
  ```bash
125
- # Configuration
126
- feishu-bridge config set appId <value>
127
- feishu-bridge config set appSecret <value>
128
- feishu-bridge config list
280
+ # 更换端口
281
+ feishu-bridge config set server.port 3001
282
+ feishu-bridge start
283
+ ```
284
+
285
+ ### 无法接收消息
129
286
 
130
- # Service management
131
- feishu-bridge start # Start service
132
- feishu-bridge start --daemon # Start in daemon mode
133
- feishu-bridge daemon start # Start daemon
134
- feishu-bridge daemon stop # Stop daemon
135
- feishu-bridge status # Check service status
287
+ **检查清单:**
288
+ 1. 服务是否运行:`feishu-bridge status`
289
+ 2. 飞书应用是否已发布
290
+ 3. 机器人是否在群组中
291
+ 4. WebSocket 是否连接成功(查看日志)
136
292
 
137
- # Auto-start hook (install once)
138
- curl -fsSL https://install.feishu-bridge.dev/hook.sh | bash
293
+ **查看日志:**
294
+ ```bash
295
+ # 前台模式直接查看
296
+ feishu-bridge start
297
+
298
+ # 后台模式查看日志
299
+ feishu-bridge daemon logs
300
+ ```
301
+
302
+ ### IDE 无响应
303
+
304
+ **检查指令文件:**
305
+ ```bash
306
+ # Windows
307
+ ls $env:TEMP\feishu-bridge\vscode\
308
+
309
+ # macOS/Linux
310
+ ls /tmp/feishu-bridge/vscode/
139
311
  ```
140
312
 
141
- ### Feishu Commands
313
+ **手动创建测试指令:**
314
+ ```bash
315
+ # 创建指令文件测试 IDE 响应
316
+ echo '{"type":"command","command":"/test","timestamp":'$(date +%s%3N)'}' > /tmp/feishu-bridge/vscode/cmd_test.json
317
+ ```
142
318
 
143
- Once the server is running, interact with your IDEs/CLIs directly from Feishu:
319
+ ### WebSocket 连接失败
144
320
 
321
+ **症状:**
145
322
  ```
146
- @vscode /generate Create a React component for a todo list
147
- @cursor /run npm start
148
- @opencode /ask How do I implement authentication in Express.js?
149
- @claude-code /explain this function
323
+ WebSocket connection failed: Authentication failed
150
324
  ```
151
325
 
152
- ## Supported Commands
326
+ **解决:**
327
+ 1. 检查 App ID 和 App Secret
328
+ 2. 确保应用已发布
329
+ 3. 切换到 Webhook 模式:
330
+ ```bash
331
+ feishu-bridge config set feishu.connectionMode webhook
332
+ feishu-bridge start
333
+ ```
334
+
335
+ ---
336
+
337
+ ## 📊 监控
338
+
339
+ ### 健康检查
340
+
341
+ ```bash
342
+ curl http://localhost:3000/health
343
+ ```
153
344
 
154
- - `@vscode`: Interact with VS Code and GitHub Copilot
155
- - `@cursor`: Interact with Cursor IDE
156
- - `@opencode`: Interact with OpenCode
157
- - `@claude`: Interact with Claude Code
158
- - `@trae`: Interact with Trae
159
- - `@antigravity`: Interact with Antigravity
160
- - `@kiro`: Interact with Kiro
345
+ 响应:
346
+ ```json
347
+ {
348
+ "status": "healthy",
349
+ "version": "1.0.3",
350
+ "timestamp": "2026-02-08T12:00:00.000Z"
351
+ }
352
+ ```
161
353
 
162
- ## Development
354
+ ### Prometheus 指标
163
355
 
164
- ### Prerequisites
356
+ ```bash
357
+ curl http://localhost:3000/metrics
358
+ ```
165
359
 
166
- - Node.js 18+
167
- - npm or yarn
360
+ ---
168
361
 
169
- ### Setup
362
+ ## 🧪 开发
170
363
 
171
364
  ```bash
172
- # Clone the repository
365
+ # 克隆项目
173
366
  git clone https://github.com/your-org/feishu-bridge.git
174
367
  cd feishu-bridge
175
368
 
176
- # Install dependencies
369
+ # 安装依赖
177
370
  npm install
178
371
 
179
- # Build the project
372
+ # 开发模式(热重载)
373
+ npm run dev
374
+
375
+ # 构建
180
376
  npm run build
181
377
 
182
- # Start in development mode
183
- npm run dev
378
+ # 测试
379
+ npm test
380
+
381
+ # 运行
382
+ npm start
184
383
  ```
185
384
 
186
- ### Project Structure
187
-
188
- ```
189
- src/
190
- ├── core/ # Core modules
191
- │ ├── bridge.ts # Main bridge coordinator
192
- │ ├── config.ts # Configuration management
193
- │ ├── logger.ts # Logging system
194
- │ ├── health.ts # Health monitoring & metrics
195
- │ └── daemon.ts # Process daemon & auto-restart
196
- ├── feishu/ # Feishu integration
197
- │ ├── client.ts # Feishu API client
198
- │ ├── webhook.ts # Webhook handler with signature verification
199
- │ ├── websocket.ts # WebSocket connection handler
200
- │ └── types.ts # Feishu type definitions
201
- ├── adapters/ # IDE/CLI adapters (7 implementations)
202
- │ ├── base.ts # Adapter base class
203
- │ ├── vscode.ts # VS Code adapter
204
- │ ├── cursor.ts # Cursor adapter
205
- │ ├── opencode.ts # OpenCode adapter (Socket)
206
- │ └── ...
207
- ├── cli/ # CLI implementation
208
- │ ├── index.ts # CLI entry & commands
209
- │ └── config.ts # Config management
210
- ├── commands/ # Command processing
211
- │ ├── executor.ts # Command executor
212
- │ └── parser.ts # Command parser
213
- ├── session/ # Session management
214
- │ └── manager.ts # Session manager
215
- └── utils/ # Utility functions
216
- └── http.ts # HTTP utilities
217
-
218
- scripts/ # Installation scripts
219
- ├── install.sh # Linux/macOS installer
220
- ├── install.ps1 # Windows installer
221
- └── install-hook.sh # Auto-start hook installer
222
-
223
- tests/ # Test suite (54 tests)
224
- ├── unit/ # Unit tests
225
- └── integration/ # Integration tests
226
- ```
227
-
228
- ## Contributing
229
-
230
- 1. Fork the repository
231
- 2. Create a feature branch (`git checkout -b feature/amazing-feature`)
232
- 3. Commit your changes (`git commit -m 'Add some amazing feature'`)
233
- 4. Push to the branch (`git push origin feature/amazing-feature`)
234
- 5. Open a Pull Request
235
-
236
- ## License
237
-
238
- MIT License
385
+ ---
386
+
387
+ ## 📄 许可证
388
+
389
+ MIT License
390
+
391
+ ---
392
+
393
+ **Happy Coding!** 🚀