@coremail/lunkr-openclaw 1.0.0 → 1.0.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.
@@ -1,239 +0,0 @@
1
- # Lunkr Extension 开发指南
2
-
3
- 本文档提供 Lunkr 扩展的完整开发、测试和部署命令参考。
4
-
5
- ## 快速参考
6
-
7
- | 场景 | 命令 |
8
- |------|------|
9
- | 安装依赖 | `npm install` |
10
- | 运行测试 | `npm test` |
11
- | 测试监视模式 | `npm run test:watch` |
12
- | 编译 | `npm run build` |
13
- | 快速部署 | `npm run deploy:local` |
14
- | 完整部署 | `npm run deploy:local:full` |
15
- | 打包发布 | `npm run pack` |
16
-
17
- ## 开发工作流
18
-
19
- ### 1. 日常开发
20
-
21
- ```bash
22
- # 终端 1: 运行测试监视器
23
- npm run test:watch
24
-
25
- # 终端 2: 编辑代码...
26
- # 测试会自动运行
27
- ```
28
-
29
- ### 2. 调试 CLI 命令
30
-
31
- 直接运行 TypeScript,无需编译:
32
-
33
- ```bash
34
- # 使用 tsx 直接运行
35
- npx tsx src/bin/lunkr-cli.ts status
36
- npx tsx src/bin/lunkr-cli.ts login --email your@email.com
37
- npx tsx src/bin/lunkr-cli.ts search-contact test
38
- ```
39
-
40
- ### 3. 在 OpenClaw 中测试
41
-
42
- ```bash
43
- # 快速部署(假设已编译)
44
- npm run deploy:local
45
-
46
- # 或完整流程:清理 → 测试 → 编译 → 部署
47
- npm run deploy:local:full
48
-
49
- # 测试
50
- openclaw lunkr status
51
- ```
52
-
53
- ## 命令详解
54
-
55
- ### 开发命令
56
-
57
- | 命令 | 说明 |
58
- |------|------|
59
- | `npm run dev` | 热重载开发模式(监视文件变化) |
60
- | `npm run dev:cli` | 直接运行 CLI(不编译) |
61
-
62
- ### 测试命令
63
-
64
- | 命令 | 说明 |
65
- |------|------|
66
- | `npm test` | 运行所有测试 |
67
- | `npm run test:watch` | 监视模式,文件变化自动重跑 |
68
- | `npm run lint` | 代码检查 |
69
-
70
- ### 构建命令
71
-
72
- | 命令 | 说明 |
73
- |------|------|
74
- | `npm run clean` | 清理 dist/ 目录 |
75
- | `npm run build` | 编译 TypeScript → dist/ |
76
- | `npm run build:release` | 生产构建(esbuild 打包) |
77
-
78
- ### 部署命令
79
-
80
- | 命令 | 说明 |
81
- |------|------|
82
- | `npm run deploy:local` | 快速部署到本地 OpenClaw(仅复制) |
83
- | `npm run deploy:local:full` | 完整部署:clean → test → build → deploy |
84
-
85
- ### 发布命令
86
-
87
- | 命令 | 说明 |
88
- |------|------|
89
- | `npm run pack` | 打包为 .tgz 文件 |
90
- | `npm publish` | 发布到 npm registry |
91
-
92
- ## 部署目标配置
93
-
94
- 默认部署路径:
95
- ```
96
- ~/work/ai/openclaw/extensions/lunkr
97
- ```
98
-
99
- 可通过环境变量自定义:
100
-
101
- ```bash
102
- # 自定义 OpenClaw 根目录
103
- export OPENCLAW_ROOT=/path/to/openclaw
104
- npm run deploy:local
105
-
106
- # 或自定义扩展目录
107
- export OPENCLAW_EXT=/custom/extensions/path
108
- npm run deploy:local
109
- ```
110
-
111
- ## 典型工作日
112
-
113
- ```bash
114
- # 早上开始工作
115
- cd extensions/lunkr
116
- npm run test:watch # 终端 1: 开着测试
117
-
118
- # 编写代码...
119
- # 测试自动运行
120
-
121
- # 中午想集成测试
122
- npm run deploy:local # 快速部署(跳过测试,因为刚才测过了)
123
-
124
- # 继续开发...
125
-
126
- # 下班前提交
127
- npm run deploy:local:full # 完整流程确保没问题
128
- ```
129
-
130
- ## 发布流程
131
-
132
- ### 版本管理
133
-
134
- 使用语义化版本号 (SemVer):`MAJOR.MINOR.PATCH`
135
-
136
- ```bash
137
- # 补丁版本 - bug fixes
138
- npm version patch # 1.0.0 → 1.0.1
139
-
140
- # 小版本 - 新功能,向后兼容
141
- npm version minor # 1.0.1 → 1.1.0
142
-
143
- # 大版本 - 破坏性变更
144
- npm version major # 1.1.0 → 2.0.0
145
- ```
146
-
147
- `npm version` 命令会:
148
- 1. 更新 `package.json` 中的版本号
149
- 2. 自动创建 git commit
150
- 3. 自动创建 git tag
151
-
152
- ### 打包测试
153
-
154
- ```bash
155
- # 打包为 tar.gz
156
- npm run pack
157
-
158
- # 输出: coremail-lunkr-openclaw-1.0.0.tgz
159
-
160
- # 在其他地方测试安装
161
- npm install ./coremail-lunkr-openclaw-1.0.0.tgz
162
- ```
163
-
164
- ### 发布到 npm
165
-
166
- ```bash
167
- # 1. 确保测试通过
168
- npm test
169
-
170
- # 2. 提升版本号
171
- npm version patch # 或 minor / major
172
-
173
- # 3. 推送代码和标签
174
- git push --follow-tags
175
-
176
- # 4. 发布到 npm
177
- npm publish --access public
178
- ```
179
-
180
- ## 项目结构
181
-
182
- ```
183
- extensions/lunkr/
184
- ├── src/ # TypeScript 源码
185
- │ ├── adapters/ # OpenClaw 适配器
186
- │ ├── cli/ # CLI 命令
187
- │ ├── core/ # 核心逻辑
188
- │ ├── i18n/ # 国际化
189
- │ ├── internal/ # 内部模块
190
- │ └── index.ts # 入口
191
- ├── dist/ # 编译输出
192
- ├── skills/ # OpenClaw 技能
193
- ├── docs/ # 文档
194
- ├── scripts/ # 构建脚本
195
- │ ├── deploy-local.mjs # 本地部署
196
- │ └── build-release.js # 生产构建
197
- ├── package.json
198
- ├── tsconfig.json
199
- └── README.md
200
- ```
201
-
202
- ## 环境要求
203
-
204
- - **Node.js**: v22+
205
- - **npm**: v10+
206
- - **TypeScript**: v5+
207
-
208
- ## 故障排除
209
-
210
- ### 编译失败
211
-
212
- ```bash
213
- # 清理后重试
214
- npm run clean
215
- npm run build
216
- ```
217
-
218
- ### 部署后不生效
219
-
220
- ```bash
221
- # 确保 OpenClaw gateway 重启
222
- openclaw gateway restart
223
-
224
- # 或重启整个服务
225
- openclaw restart
226
- ```
227
-
228
- ### 测试失败
229
-
230
- ```bash
231
- # 查看详细输出
232
- npm test -- --reporter=verbose
233
- ```
234
-
235
- ## 相关文档
236
-
237
- - [README.md](../README.md) - 项目介绍和配置
238
- - [USAGE.md](./USAGE.md) - 使用指南
239
- - [AUTHENTICATION.md](./AUTHENTICATION.md) - 认证说明
package/docs/USAGE.md DELETED
@@ -1,337 +0,0 @@
1
- # Lunkr Channel Plugin - Usage Guide
2
-
3
- This document provides detailed information on using the Lunkr channel plugin for OpenClaw.
4
-
5
- ## Bot Simulation
6
-
7
- The Lunkr plugin simulates a bot by using the authenticated user's account to send and receive messages. This approach is called "Bot Simulation" because:
8
-
9
- 1. **The bot is you**: The AI responds using your Lunkr account
10
- 2. **Bot replies are marked**: Bot messages are prefixed with `[@!BotName]` to distinguish them from your regular messages
11
- 3. **Self-triggering**: In normal chats, you trigger the bot by sending a message that starts with the command prefix
12
-
13
- ### How Bot Simulation Works
14
-
15
- ```
16
- User (You) Lunkr Server OpenClaw
17
- | | |
18
- |-- "Hello" ----------------->| |
19
- | | |
20
- | |-- "Hello" ------------------>|
21
- | | |
22
- | | (Bot triggers AI) |
23
- | | |
24
- | |<-- "[@!Bot] Hi there!" ------|
25
- | | |
26
- |<-- "[@!Bot] Hi there!" ------| |
27
- ```
28
-
29
- ## Trigger Rules
30
-
31
- The bot triggers based on where the message is sent and who sends it.
32
-
33
- ### Bot Discussions (Recommended)
34
-
35
- Bot Discussions are dedicated discussion groups where **all messages** trigger the AI agent.
36
-
37
- ```
38
- +---------------------------+
39
- | Bot Discussion Group |
40
- | |
41
- | Alice: How do I reset? | --> Triggers AI
42
- | Bob: Check settings | --> Triggers AI
43
- | Bot: [@!Bot] To reset... | --> Does NOT trigger (bot reply)
44
- +---------------------------+
45
- ```
46
-
47
- **Setup:**
48
- ```yaml
49
- channels:
50
- lunkr:
51
- botDiscussions:
52
- "group-id-abc123":
53
- name: "AI Assistant"
54
- creatorUid: "admin-uid"
55
- createdAt: "2024-01-01T00:00:00Z"
56
- ```
57
-
58
- ### Normal Groups and DMs
59
-
60
- In regular groups and direct messages, only **you** can trigger the bot by prefixing your message with the command prefix (default: `/bot`).
61
-
62
- ```
63
- +---------------------------+
64
- | Regular Group Chat |
65
- | |
66
- | Alice: Hello everyone | --> No trigger
67
- | Bob: /bot What is AI? | --> Triggers AI (if Bob is you)
68
- | You: /bot Explain X | --> Triggers AI
69
- | Bot: [@!Bot] X is... | --> Does NOT trigger (bot reply)
70
- +---------------------------+
71
- ```
72
-
73
- ### Trigger Summary Table
74
-
75
- | Scenario | Message From | Message Content | Triggers AI? |
76
- |----------|-------------|-----------------|--------------|
77
- | Bot Discussion | Anyone | Anything | Yes |
78
- | Bot Discussion | You (Bot reply) | `[@!BotName] ...` | No |
79
- | Normal Group/DM | You | `/bot help` | Yes |
80
- | Normal Group/DM | You | `Hello` | No |
81
- | Normal Group/DM | Others | `/bot help` | No |
82
- | Normal Group/DM | Others | `Hello` | No |
83
-
84
- ## Configuration Reference
85
-
86
- ### Complete Configuration Schema
87
-
88
- ```yaml
89
- channels:
90
- lunkr:
91
- # Enable this channel
92
- enabled: true
93
-
94
- # Bot display name (appears in bot replies)
95
- botName: "AI Assistant"
96
-
97
- # Command prefix for normal chats
98
- commandPrefix: "/bot"
99
-
100
- # Bot discussion groups (all messages trigger AI)
101
- botDiscussions:
102
- "discussion-id-1":
103
- name: "Support Channel"
104
- agentId: "support-agent" # Optional: route to specific agent
105
- creatorUid: "user-123"
106
- createdAt: "2024-01-15T10:30:00Z"
107
-
108
- # Direct message policy
109
- dmPolicy: "allow" # allow | deny | whitelist
110
- allowFrom: # Whitelisted users (for dmPolicy: whitelist)
111
- - "user-id-1"
112
- - "user-id-2"
113
-
114
- # Group message policy
115
- groupPolicy: "allow" # allow | deny | whitelist
116
- groups: # Whitelisted groups (for groupPolicy: whitelist)
117
- - "group-id-1"
118
- - "group-id-2"
119
- ```
120
-
121
- ### Policy Values
122
-
123
- #### `dmPolicy`
124
-
125
- | Value | Description |
126
- |-------|-------------|
127
- | `allow` | Accept DMs from all users (default) |
128
- | `deny` | Reject all DMs to the bot |
129
- | `whitelist` | Only accept DMs from users in `allowFrom` list |
130
-
131
- #### `groupPolicy`
132
-
133
- | Value | Description |
134
- |-------|-------------|
135
- | `allow` | Respond in all groups when triggered (default) |
136
- | `deny` | Never respond in groups |
137
- | `whitelist` | Only respond in groups in `groups` list |
138
-
139
- ### Bot Discussion Configuration
140
-
141
- Each bot discussion entry requires:
142
-
143
- | Field | Type | Required | Description |
144
- |-------|------|----------|-------------|
145
- | `name` | string | Yes | Display name for this discussion |
146
- | `agentId` | string | No | Agent ID to route messages to |
147
- | `creatorUid` | string | Yes | User ID of the creator |
148
- | `createdAt` | string/number | Yes | Creation timestamp (ISO or epoch ms) |
149
-
150
- ## Multi-Agent Routing
151
-
152
- You can route different Bot Discussions to different AI agents:
153
-
154
- ```yaml
155
- # In your OpenClaw config
156
- agents:
157
- sales-agent:
158
- # Sales-specific agent configuration
159
- support-agent:
160
- # Support-specific agent configuration
161
-
162
- channels:
163
- lunkr:
164
- botDiscussions:
165
- "sales-group-id":
166
- name: "Sales Bot"
167
- agentId: "sales-agent"
168
- creatorUid: "admin"
169
- createdAt: "2024-01-01"
170
- "support-group-id":
171
- name: "Support Bot"
172
- agentId: "support-agent"
173
- creatorUid: "admin"
174
- createdAt: "2024-01-01"
175
- ```
176
-
177
- When a message arrives in a Bot Discussion with an `agentId` configured, it is automatically routed to that specific agent.
178
-
179
- ## Message Handling
180
-
181
- ### Inbound Messages
182
-
183
- Messages from Lunkr are processed as follows:
184
-
185
- 1. **Receive**: Message arrives via Socket.IO real-time connection
186
- 2. **Analyze**: Determine if message should trigger the bot
187
- 3. **Convert**: Transform Lunkr format to OpenClaw format
188
- 4. **Route**: Send to appropriate agent for processing
189
-
190
- ### Outbound Messages
191
-
192
- Bot replies are formatted with the `[@!BotName]` prefix:
193
-
194
- ```
195
- [@!AI Assistant] Here is my response to your question...
196
- ```
197
-
198
- This prefix helps distinguish bot messages from your regular messages.
199
-
200
- ### Message Types Supported
201
-
202
- | Type | Support |
203
- |------|---------|
204
- | Text | Full support |
205
- | Images | Supported |
206
- | Files | Supported |
207
- | Reactions | Supported |
208
- | Edits | Supported |
209
- | Replies | Supported |
210
-
211
- ## Security Considerations
212
-
213
- ### Bot Reply Detection
214
-
215
- The plugin identifies bot replies by checking if:
216
- - The message is from the authenticated user (self)
217
- - The content starts with `[@!<botName>]`
218
-
219
- These messages are never re-processed by the bot to prevent loops.
220
-
221
- ### Self-Message Triggering
222
-
223
- In normal chats, only messages from the authenticated user that start with the command prefix trigger the bot. This prevents:
224
- - Accidental triggers from other users
225
- - Message loops from bot replies
226
-
227
- ### Whitelist Security
228
-
229
- When using whitelist policies:
230
-
231
- ```yaml
232
- dmPolicy: whitelist
233
- allowFrom:
234
- - "trusted-user-1"
235
- - "trusted-user-2"
236
- ```
237
-
238
- Only messages from whitelisted users will be processed.
239
-
240
- ### Pairing Flow
241
-
242
- Users can request to be whitelisted via pairing:
243
-
244
- 1. User sends a pairing request
245
- 2. Admin approves with: `openclaw pairing approve lunkr <code>`
246
- 3. User's ID is added to `allowFrom`
247
-
248
- ## Examples
249
-
250
- ### Example 1: Simple Bot Discussion
251
-
252
- ```yaml
253
- channels:
254
- lunkr:
255
- enabled: true
256
- botName: "Helper"
257
- botDiscussions:
258
- "abc123":
259
- name: "Help Channel"
260
- creatorUid: "admin"
261
- createdAt: "2024-01-01"
262
- ```
263
-
264
- Any message in group `abc123` triggers the bot.
265
-
266
- ### Example 2: Restricted DM Access
267
-
268
- ```yaml
269
- channels:
270
- lunkr:
271
- enabled: true
272
- dmPolicy: whitelist
273
- allowFrom:
274
- - "user-001"
275
- - "user-002"
276
- groupPolicy: deny
277
- ```
278
-
279
- Only `user-001` and `user-002` can DM the bot. No group messages are processed.
280
-
281
- ### Example 3: Multi-Agent Setup
282
-
283
- ```yaml
284
- agents:
285
- code-reviewer:
286
- model: "claude-3"
287
- systemPrompt: "You are a code reviewer..."
288
-
289
- translator:
290
- model: "gpt-4"
291
- systemPrompt: "You are a translator..."
292
-
293
- channels:
294
- lunkr:
295
- botDiscussions:
296
- "code-review-group":
297
- name: "Code Reviews"
298
- agentId: "code-reviewer"
299
- creatorUid: "dev-team"
300
- createdAt: 1704067200000
301
- "translation-group":
302
- name: "Translations"
303
- agentId: "translator"
304
- creatorUid: "intl-team"
305
- createdAt: 1704067200000
306
- ```
307
-
308
- ### Example 4: Custom Command Prefix
309
-
310
- ```yaml
311
- channels:
312
- lunkr:
313
- enabled: true
314
- commandPrefix: "!"
315
- ```
316
-
317
- Now use `! help` instead of `/bot help` to trigger the bot in normal chats.
318
-
319
- ## Troubleshooting
320
-
321
- ### Bot Not Responding in Bot Discussion
322
-
323
- 1. Verify the discussion ID matches your configuration
324
- 2. Check that the message is not a bot reply (starts with `[@!...]`)
325
- 3. Review gateway logs for errors
326
-
327
- ### Wrong Agent Receiving Messages
328
-
329
- 1. Check the `agentId` in the bot discussion configuration
330
- 2. Verify the agent ID exists in your agents configuration
331
- 3. Check for typos in the discussion ID mapping
332
-
333
- ### DM Whitelist Not Working
334
-
335
- 1. Ensure `dmPolicy` is set to `whitelist` (not `allow`)
336
- 2. Verify user IDs in `allowFrom` are correct
337
- 3. Remember to restart the gateway after config changes