cc-ding 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.
package/README.md CHANGED
@@ -37,14 +37,15 @@ pnpm i cc-ding -g
37
37
  #### 初始化
38
38
 
39
39
  ```bash
40
- cc-ding init -ci {clientId} -cs {clientSecret} -m {手机号}
40
+ cc-ding init -ci {clientId} -cs {clientSecret} -u {手机号或工号} -dt {defaultDingToken}
41
41
  ```
42
42
 
43
43
  | 参数 | 说明 |
44
44
  |------|------|
45
45
  | `-ci, --clientId` | 钉钉应用 ClientId |
46
46
  | `-cs, --clientSecret` | 钉钉 Stream 连接密钥 |
47
- | `-m, --mobile` | 管理员手机号(自动加入白名单) |
47
+ | `-u, --user` | 管理员手机号或工号(自动设为 owner 并加入白名单) |
48
+ | `-dt, --defaultDingToken` | 兜底钉钉机器人 Token(必填) |
48
49
  | `-cn, --clientName` | 机器人名称(可选,默认 "cc助手") |
49
50
 
50
51
  #### 编辑配置
@@ -110,6 +111,10 @@ pm2 start --name "cc-ding-{clientId}" npx -- -p cc-ding cc-ding run -ci {clientI
110
111
  | `/reset-apikeycfg` | 重置 API Key 配置 |
111
112
  | `/cfg` | 注册当前群到配置(支持 `--permissionMode` 设置权限模式) |
112
113
  | `/auth [add\|del <用户>]` | 管理群级白名单 |
114
+ | `/destroy` | 注销当前群机器人,删除工作目录和配置 |
115
+ | `/freedom` | 自由模式:开启后所有群成员均可使用机器人(跳过白名单限制,60s 内回复"确认"即可开启) |
116
+ | `/recorder [on\|exit]` | Recorder 模式:记录所有消息到本地(仅 owner 单聊) |
117
+ | `/reboot [--update]` | 重启 cc-ding 应用 |
113
118
 
114
119
  ### 配置说明
115
120
 
@@ -131,7 +136,8 @@ pm2 start --name "cc-ding-{clientId}" npx -- -p cc-ding cc-ding run -ci {clientI
131
136
  "agent": "指定agent(可选)",
132
137
  "useLocalOcr": true,
133
138
  "permissionMode": "bypassPermissions",
134
- "taskCfg": { "skill": "指定技能(可选)" }
139
+ "taskCfg": { "skill": "指定技能(可选)" },
140
+ "freedomMode": false
135
141
  }
136
142
  ],
137
143
  "taskQueueSize": 50,
@@ -147,12 +153,13 @@ pm2 start --name "cc-ding-{clientId}" npx -- -p cc-ding cc-ding run -ci {clientI
147
153
 
148
154
  | 配置 | 说明 |
149
155
  |------|------|
150
- | `whiteUserList` | 全局白名单(手机号或 userId) |
151
- | `conversations[].whiteUserList` | 群级白名单,优先级高于全局 |
156
+ | `whiteUserList` | 全局白名单(手机号、工号或 userId) |
157
+ | `conversations[].whiteUserList` | 群级白名单,优先级高于全局(手机号、工号或 userId) |
152
158
  | `apiKeyCfg` | API Key 池化:429 自动切换、每日 0 点重置 |
153
159
  | `useLocalOcr` | 图片本地 OCR(默认 `true`),模型支持图片时可设 `false` |
154
160
  | `linkConversationId` | 关联群 ID,多群共享同一 Claude 会话上下文 |
155
161
  | `permissionMode` | Claude 进程权限模式(默认 `acceptEdits`;`bypassPermissions` 需显式配置,启动时会告警),可选: `default`、`acceptEdits`、`plan`、`auto`、`bypassPermissions`、`dontAsk` |
162
+ | `freedomMode` | 自由模式开关(默认 `false`,开启后跳过群用户白名单限制) |
156
163
  | `preBash` | 全局 `/bash` 前置命令 |
157
164
 
158
165
  #### 安全说明
@@ -171,7 +178,7 @@ pm2 start --name "cc-ding-{clientId}" npx -- -p cc-ding cc-ding run -ci {clientI
171
178
  | 任务 | `{MD5}/.tasks/{时间戳}/task.{json,log}` |
172
179
  | 定时任务 | `cron.json` |
173
180
  | 图片缓存 | `{MD5}/.images/` |
174
- | 手机号映射 | `phone-map.json` |
181
+ | 用户映射 | `user-map.json` |
175
182
 
176
183
  ### 开发
177
184
 
@@ -182,8 +189,6 @@ pnpm run test
182
189
  pnpm run build
183
190
  ```
184
191
 
185
- **系统要求:** Node.js >= 24
186
-
187
192
  ---
188
193
 
189
194
  ## English
@@ -209,14 +214,15 @@ pnpm i cc-ding -g
209
214
  #### Initialize
210
215
 
211
216
  ```bash
212
- cc-ding init -ci {clientId} -cs {clientSecret} -m {phone_number}
217
+ cc-ding init -ci {clientId} -cs {clientSecret} -u {phone_or_emp_id} -dt {defaultDingToken}
213
218
  ```
214
219
 
215
220
  | Parameter | Description |
216
221
  |-----------|-------------|
217
222
  | `-ci, --clientId` | DingTalk app ClientId |
218
223
  | `-cs, --clientSecret` | DingTalk Stream connection secret |
219
- | `-m, --mobile` | Admin phone number (auto-added to whitelist) |
224
+ | `-u, --user` | Admin phone number or employee ID (set as owner and added to whitelist) |
225
+ | `-dt, --defaultDingToken` | Fallback DingTalk bot Token (required) |
220
226
  | `-cn, --clientName` | Bot name (optional, default "cc助手") |
221
227
 
222
228
  #### Edit Config
@@ -282,6 +288,10 @@ pm2 start --name "cc-ding-{clientId}" npx -- -p cc-ding cc-ding run -ci {clientI
282
288
  | `/reset-apikeycfg` | Reset API Key configuration |
283
289
  | `/cfg` | Register current group to config (supports `--permissionMode` to set permission mode) |
284
290
  | `/auth [add\|del <user>]` | Manage group whitelist |
291
+ | `/destroy` | Unregister group bot, delete working directory and config |
292
+ | `/freedom` | Freedom mode: all group members can use the bot (skip whitelist, reply "confirm" within 60s to activate) |
293
+ | `/recorder [on\|exit]` | Recorder mode: log all messages locally (owner single-chat only) |
294
+ | `/reboot [--update]` | Restart cc-ding application |
285
295
 
286
296
  ### Configuration
287
297
 
@@ -303,7 +313,8 @@ pm2 start --name "cc-ding-{clientId}" npx -- -p cc-ding cc-ding run -ci {clientI
303
313
  "agent": "specified_agent (optional)",
304
314
  "useLocalOcr": true,
305
315
  "permissionMode": "bypassPermissions",
306
- "taskCfg": { "skill": "specified_skill (optional)" }
316
+ "taskCfg": { "skill": "specified_skill (optional)" },
317
+ "freedomMode": false
307
318
  }
308
319
  ],
309
320
  "taskQueueSize": 50,
@@ -319,12 +330,13 @@ pm2 start --name "cc-ding-{clientId}" npx -- -p cc-ding cc-ding run -ci {clientI
319
330
 
320
331
  | Config | Description |
321
332
  |--------|-------------|
322
- | `whiteUserList` | Global whitelist (phone or userId) |
323
- | `conversations[].whiteUserList` | Group-level whitelist, higher priority than global |
333
+ | `whiteUserList` | Global whitelist (phone, employee ID, or userId) |
334
+ | `conversations[].whiteUserList` | Group-level whitelist, higher priority than global (phone, employee ID, or userId) |
324
335
  | `apiKeyCfg` | API Key pooling: auto-switch on 429, daily reset at midnight |
325
336
  | `useLocalOcr` | Local image OCR (default `true`); set `false` if model supports images natively |
326
337
  | `linkConversationId` | Link groups to share one Claude session context |
327
338
  | `permissionMode` | Claude process permission mode (default `acceptEdits`; `bypassPermissions` must be set explicitly and warns at startup), options: `default`, `acceptEdits`, `plan`, `auto`, `bypassPermissions`, `dontAsk` |
339
+ | `freedomMode` | Freedom mode toggle (default `false`; when enabled, skips group whitelist check) |
328
340
  | `preBash` | Global pre-bash command for `/bash` |
329
341
 
330
342
  #### Security Notes
@@ -343,7 +355,7 @@ All data is stored under `~/.cc-ding/{clientId}/`:
343
355
  | Tasks | `{MD5}/.tasks/{timestamp}/task.{json,log}` |
344
356
  | Cron jobs | `cron.json` |
345
357
  | Image cache | `{MD5}/.images/` |
346
- | Phone mapping | `phone-map.json` |
358
+ | User mapping | `user-map.json` |
347
359
 
348
360
  ### Development
349
361
 
@@ -354,8 +366,6 @@ pnpm run test
354
366
  pnpm run build
355
367
  ```
356
368
 
357
- **Requirements:** Node.js >= 24
358
-
359
369
  ---
360
370
 
361
371
  ## Star History
@@ -1,14 +1,14 @@
1
1
  #!/usr/bin/env node
2
- "use strict";var r=exports&&exports.__importDefault||function(e){return e&&e.__esModule?e:{default:e}};Object.defineProperty(exports,"__esModule",{value:!0});const a=require("../src/common"),g=require("commander"),t=require("../src/biz/session"),d=r(require("path")),m=require("../src/biz/cc-ding-cli"),I=require("../src/biz/lock"),u=require("../src/biz/doctor"),p=require("../src/biz/notify"),f=r(require("fs"));(0,a.loadEnv)(),process.removeAllListeners("warning"),process.setMaxListeners(0),process.on("uncaughtException",function(e){console.log("Caught exception: "+e),process.exit(1)});const o=new g.Command;o.addHelpText("before",`
2
+ "use strict";var r=exports&&exports.__importDefault||function(e){return e&&e.__esModule?e:{default:e}};Object.defineProperty(exports,"__esModule",{value:!0});const a=require("../src/common"),g=require("commander"),t=require("../src/biz/session"),d=r(require("path")),m=require("../src/biz/cc-ding-cli"),I=require("../src/biz/lock"),u=require("../src/biz/doctor"),f=require("../src/biz/notify"),p=r(require("fs"));(0,a.loadEnv)(),process.removeAllListeners("warning"),process.setMaxListeners(0),process.on("uncaughtException",function(e){console.log("Caught exception: "+e),process.exit(1)});const o=new g.Command;o.addHelpText("before",`
3
3
  cc-ding for connect ClaudeCode to DingDingRobot
4
4
  `).addHelpText("after",`
5
5
  Examples:
6
- $ cc-ding init -ci {clientId} -cs {clientSecret} -m {mobile}
6
+ $ cc-ding init -ci {clientId} -cs {clientSecret} -u {user} -dt {defaultDingToken}
7
7
  $ cc-ding run -ci {clientId}
8
- `).version((0,a.projUtil)().getPkgVersion()),o.command("init").description("\u521D\u59CB\u5316cc-ding\u914D\u7F6E\u6587\u4EF6, \u751F\u6210\u6700\u7B80config.json").requiredOption("-ci, --clientId <value>","clientId").requiredOption("-cs, --clientSecret <value>","clientSecret (\u9489\u9489Stream\u8FDE\u63A5\u5BC6\u94A5)").requiredOption("-m, --mobile <value>","mobile (\u81EA\u5DF1\u7684\u624B\u673A\u53F7, \u81EA\u52A8\u52A0\u5165\u767D\u540D\u5355)").option("-cn, --clientName <value>","clientName (\u673A\u5668\u4EBA\u540D\u79F0, \u53EF\u9009)").action(async e=>{const n=process.version.slice(1);parseInt(n.split(".")[0],10)<24&&(console.log(`
8
+ `).version((0,a.projUtil)().getPkgVersion()),o.command("init").description("\u521D\u59CB\u5316cc-ding\u914D\u7F6E\u6587\u4EF6, \u751F\u6210\u6700\u7B80config.json").requiredOption("-ci, --clientId <value>","clientId").requiredOption("-cs, --clientSecret <value>","clientSecret (\u9489\u9489Stream\u8FDE\u63A5\u5BC6\u94A5)").requiredOption("-u, --user <value>","user (\u81EA\u5DF1\u7684\u624B\u673A\u53F7\u6216\u5DE5\u53F7, \u81EA\u52A8\u8BBE\u4E3Aowner\u5E76\u52A0\u5165\u767D\u540D\u5355)").requiredOption("-dt, --defaultDingToken <value>","defaultDingToken (\u515C\u5E95\u9489\u9489\u673A\u5668\u4EBAToken)").option("-cn, --clientName <value>","clientName (\u673A\u5668\u4EBA\u540D\u79F0, \u53EF\u9009)").action(async e=>{const n=process.version.slice(1);parseInt(n.split(".")[0],10)<24&&(console.log(`
9
9
  \u274C Node \u7248\u672C\u8FC7\u4F4E\uFF0C\u65E0\u6CD5\u6267\u884C init \u547D\u4EE4`),console.log(` \u5F53\u524D\u7248\u672C\uFF1A${n}`),console.log(" \u8981\u6C42\uFF1ANode >= 24"),console.log(`
10
10
  \u{1F4A1} \u8BF7\u5347\u7EA7 Node \u7248\u672C\u540E\u91CD\u65B0\u8FD0\u884C
11
- `),process.exit(1));const i=`${`${(0,t.getHomeDir)()}/.cc-ding/${e.clientId}`}/config.json`;f.default.existsSync(i)&&(console.log(`\u914D\u7F6E\u6587\u4EF6\u5DF2\u5B58\u5728: ${i}`),console.log("\u5982\u9700\u91CD\u65B0\u521D\u59CB\u5316, \u8BF7\u5148\u5220\u9664\u5DF2\u6709\u914D\u7F6E\u6587\u4EF6"),process.exit(1));const c={clientName:e.clientName||"cc\u52A9\u624B",owner:e.mobile,whiteUserList:[e.mobile],clientSecret:e.clientSecret,defaultDingToken:"<\u515C\u5E95\u9489\u9489\u673A\u5668\u4EBAToken-\u7528\u4E8E\u65E0dingToken\u7FA4\u7684\u6D88\u606F\u63A5\u6536>",conversations:[],includeThinking:!1,resultOnly:!0,debug:!1,taskQueueSize:10,taskHandlerCount:1,sessionMaxConcurrency:20};(0,t.initClientDir)(e.clientId,c),console.log("\u914D\u7F6E\u6587\u4EF6\u5DF2\u751F\u6210:",i),console.log(""),console.log("\u540E\u7EED\u6B65\u9AA4:"),console.log(" 1. \u7F16\u8F91 config.json \u6DFB\u52A0 conversations \u914D\u7F6E(\u7FA4\u804A\u9700\u914D\u7F6EdingToken)"),console.log(" 2. \u542F\u52A8\u673A\u5668\u4EBA: cc-ding run -ci",e.clientId),console.log(" 3. \u63A8\u8350PM2\u542F\u52A8:"),console.log(` pm2 start --name "cc-ding-${e.clientId}" npx -- -p cc-ding cc-ding run -ci ${e.clientId}`)}),o.command("run").description(`
11
+ `),process.exit(1));const i=`${`${(0,t.getHomeDir)()}/.cc-ding/${e.clientId}`}/config.json`;p.default.existsSync(i)&&(console.log(`\u914D\u7F6E\u6587\u4EF6\u5DF2\u5B58\u5728: ${i}`),console.log("\u5982\u9700\u91CD\u65B0\u521D\u59CB\u5316, \u8BF7\u5148\u5220\u9664\u5DF2\u6709\u914D\u7F6E\u6587\u4EF6"),process.exit(1));const c={clientName:e.clientName||"cc\u52A9\u624B",owner:e.user,whiteUserList:[e.user],clientSecret:e.clientSecret,defaultDingToken:e.defaultDingToken,conversations:[],includeThinking:!1,resultOnly:!0,debug:!1,taskQueueSize:10,taskHandlerCount:1,sessionMaxConcurrency:20};(0,t.initClientDir)(e.clientId,c),console.log("\u914D\u7F6E\u6587\u4EF6\u5DF2\u751F\u6210:",i),console.log(""),console.log("\u540E\u7EED\u6B65\u9AA4:"),console.log(" 1. \u7F16\u8F91 config.json \u6DFB\u52A0 conversations \u914D\u7F6E(\u7FA4\u804A\u9700\u914D\u7F6EdingToken)"),console.log(" 2. \u542F\u52A8\u673A\u5668\u4EBA: cc-ding run -ci",e.clientId),console.log(" 3. \u63A8\u8350PM2\u542F\u52A8:"),console.log(` pm2 start --name "cc-ding-${e.clientId}" npx -- -p cc-ding cc-ding run -ci ${e.clientId}`)}),o.command("run").description(`
12
12
  - \u529F\u80FD: \u9489\u9489\u673A\u5668\u4EBA\u5BF9\u63A5\u672C\u5730Claude, \u652F\u6301\u4F1A\u8BDD\u6A21\u5F0F\u548C\u4EFB\u52A1\u961F\u5217\u6A21\u5F0F
13
13
  - \u4F1A\u8BDD\u6570\u636E\u8DEF\u5F84: ~/.cc-ding/{clientId}/{MD5}/.sessions/{claudeSessionId}/session.{json|log}
14
14
  - \u4EFB\u52A1\u6570\u636E\u8DEF\u5F84: ~/.cc-ding/{clientId}/{MD5}/.tasks/{\u65F6\u95F4\u6233}/task.{json|log}
@@ -33,5 +33,5 @@ Examples:
33
33
  - 429\u81EA\u52A8\u5207\u6362: \u81EA\u52A8\u5207\u6362\u5230API Key\u6A21\u5F0F
34
34
  - Key\u8F6E\u6362: API Key\u9047\u5230429\u6216\u8FDE\u7EEDTPM\u4E0D\u7A33\u5B9A\u65F6\u81EA\u52A8\u6362Key
35
35
  - \u8DE8\u5929\u91CD\u7F6E: \u6BCF\u65E5\u81EA\u52A8\u91CD\u7F6EAPI Key\u72B6\u6001
36
- `).requiredOption("-ci, --clientId <value>","clientId").action(async e=>{(0,t.ensureClientDir)(e.clientId);const n=d.default.join((0,t.getHomeDir)(),".cc-ding",e.clientId);(0,I.acquirePidLock)(n,e.clientId),await new m.DingClaude(e.clientId).run()}),o.command("doctor").description("\u68C0\u67E5\u6307\u5B9Aclient\u7684\u914D\u7F6E\u6587\u4EF6schema\u5408\u6CD5\u6027\u548C\u6709\u6548\u6027").requiredOption("-ci, --clientId <value>","clientId").action(async e=>{const n=d.default.join((0,t.getHomeDir)(),".cc-ding",e.clientId),s=(0,u.runDoctor)(n);(0,u.printDoctorResults)(s)}),o.command("notify").description("\u901A\u8FC7\u9489\u9489\u673A\u5668\u4EBA\u53D1\u9001\u6D88\u606F\u5230\u6307\u5B9A\u7FA4\u6216\u5355\u804A").requiredOption("-ci, --clientId <value>","clientId").requiredOption("-c, --conversations <value>","\u76EE\u6807\u4F1A\u8BDDID\uFF08\u591A\u4E2A\u7528\u9017\u53F7\u5206\u9694\uFF09").requiredOption("-m, --message <value>","\u6D88\u606F\u5185\u5BB9").option("-at, --atUserIds <value>","@ \u6307\u5B9A\u7528\u6237\uFF08\u591A\u4E2A\u7528\u9017\u53F7\u5206\u9694\uFF09").option("-mo, --mobile <value>","\u5355\u804A\u76EE\u6807\u624B\u673A\u53F7\uFF08\u591A\u4E2A\u7528\u9017\u53F7\u5206\u9694\uFF0C\u4E0E conversations \u4E00\u4E00\u5BF9\u5E94\uFF09").option("-md, --markdown","\u4F7F\u7528 Markdown \u683C\u5F0F\u53D1\u9001",!1).action(async e=>{const n=e.conversations.split(",").map(c=>c.trim()).filter(Boolean),s=e.atUserIds?e.atUserIds.split(",").map(c=>c.trim()).filter(Boolean):[],l=e.mobile?e.mobile.split(",").map(c=>c.trim()).filter(Boolean):[];console.log(`\u{1F4E4} \u53D1\u9001\u6D88\u606F\u5230 ${n.length} \u4E2A\u4F1A\u8BDD...`);const i=await(0,p.sendNotify)({clientId:e.clientId,message:e.message,conversationIds:n,atUserIds:s,mobiles:l,markdown:e.markdown});console.log(`
36
+ `).requiredOption("-ci, --clientId <value>","clientId").action(async e=>{(0,t.ensureClientDir)(e.clientId);const n=d.default.join((0,t.getHomeDir)(),".cc-ding",e.clientId);(0,I.acquirePidLock)(n,e.clientId),await new m.DingClaude(e.clientId).run()}),o.command("doctor").description("\u68C0\u67E5\u6307\u5B9Aclient\u7684\u914D\u7F6E\u6587\u4EF6schema\u5408\u6CD5\u6027\u548C\u6709\u6548\u6027").requiredOption("-ci, --clientId <value>","clientId").action(async e=>{const n=d.default.join((0,t.getHomeDir)(),".cc-ding",e.clientId),s=(0,u.runDoctor)(n);(0,u.printDoctorResults)(s)}),o.command("notify").description("\u901A\u8FC7\u9489\u9489\u673A\u5668\u4EBA\u53D1\u9001\u6D88\u606F\u5230\u6307\u5B9A\u7FA4\u6216\u5355\u804A").requiredOption("-ci, --clientId <value>","clientId").requiredOption("-c, --conversations <value>","\u76EE\u6807\u4F1A\u8BDDID\uFF08\u591A\u4E2A\u7528\u9017\u53F7\u5206\u9694\uFF09").requiredOption("-m, --message <value>","\u6D88\u606F\u5185\u5BB9").option("-at, --atUserIds <value>","@ \u6307\u5B9A\u7528\u6237\uFF08\u591A\u4E2A\u7528\u9017\u53F7\u5206\u9694\uFF09").option("-mo, --mobile <value>","\u5355\u804A\u76EE\u6807\u624B\u673A\u53F7\uFF08\u591A\u4E2A\u7528\u9017\u53F7\u5206\u9694\uFF0C\u4E0E conversations \u4E00\u4E00\u5BF9\u5E94\uFF09").option("-md, --markdown","\u4F7F\u7528 Markdown \u683C\u5F0F\u53D1\u9001",!1).action(async e=>{const n=e.conversations.split(",").map(c=>c.trim()).filter(Boolean),s=e.atUserIds?e.atUserIds.split(",").map(c=>c.trim()).filter(Boolean):[],l=e.mobile?e.mobile.split(",").map(c=>c.trim()).filter(Boolean):[];console.log(`\u{1F4E4} \u53D1\u9001\u6D88\u606F\u5230 ${n.length} \u4E2A\u4F1A\u8BDD...`);const i=await(0,f.sendNotify)({clientId:e.clientId,message:e.message,conversationIds:n,atUserIds:s,mobiles:l,markdown:e.markdown});console.log(`
37
37
  \u2705 \u6210\u529F: ${i.success}, \u274C \u5931\u8D25: ${i.fail}`),process.exit(i.fail>0?1:0)}),o.parse(process.argv);
@@ -1,89 +1,95 @@
1
- "use strict";var F=exports&&exports.__importDefault||function(E){return E&&E.__esModule?E:{default:E}};Object.defineProperty(exports,"__esModule",{value:!0}),exports.DingClaude=void 0;const B=require("child_process"),Q=require("utils-ok"),S=F(require("fs")),G=F(require("os")),N=F(require("path")),Y=require("../common"),A=require("./quote"),K=require("./messaging"),j=require("./image"),I=require("./commands"),V=require("./messaging"),x=require("./claude-process"),z=require("./recorder"),M=require("./menu"),c=require("./session"),b=require("./task"),C=require("./todo"),X=require("./commands"),L=require("./api-key-manager"),Z=require("./secrets"),v=require("./command-route"),P=require("./cron"),_=require("./platform"),J=(0,Y.projUtil)().getPkgVersion();class ee{constructor(d){this.resolvedPhones={},this.activeSessions=new Map,this.pendingAuthRequests=new Map,this.recorderModeConversations=new Set,this.DEFAULT_SESSION_MAX_CONCURRENCY=5,this.DEFAULT_TASK_HANDLER_COUNT=1,this.DEFAULT_TASK_QUEUE_SIZE=50,this.sendDingMessage=i=>(0,V.sendDingMessage)(this,i),this.sendClaudeResponseToDing=(i,o,a,s)=>(0,V.sendClaudeResponseToDing)(this,i,o,a,s),this.parseClaudeStreamLine=x.parseClaudeStreamLine,this.interruptClaudeProcess=(i,o)=>(0,x.interruptClaudeProcess)(i,o),this.executeClaudeQuery=(i,o,a)=>(0,x.executeClaudeQuery)(this,i,o,a),this.getClientDir=()=>(0,c.getClientDir)(this),this.getClientConfig=()=>(0,c.getClientConfig)(this),this.authCheck=(i,o)=>(0,c.authCheck)(this,i,o),this.isOwner=i=>(0,c.isOwner)(this,i),this.isAdmin=i=>(0,c.isAdmin)(this,i),this.debugLog=(i,...o)=>(0,c.debugLog)(this,i,...o),this.hashConversationId=i=>(0,c.hashConversationId)(this,i),this.getConversationConfig=i=>(0,c.getConversationConfig)(this,i),this.getConversationDir=i=>(0,c.getConversationDir)(this,i),this.getSessionsDir=i=>(0,c.getSessionsDir)(this,i),this.getTasksDir=i=>(0,c.getTasksDir)(this,i),this.getSessionDir=i=>(0,c.getSessionDir)(this,i),this.getSessionId=c.getSessionId,this.formatSessionInfo=i=>(0,c.formatSessionInfo)(this,i),this.readSessionLogTail=(i,o)=>(0,c.readSessionLogTail)(this,i,o),this.findActiveSession=i=>(0,c.findActiveSession)(this,i),this.findHistorySession=(i,o)=>(0,c.findHistorySession)(this,i,o),this.findLatestSession=i=>(0,c.findLatestSession)(this,i),this.updateSessionFile=(i,o)=>(0,c.updateSessionFile)(this,i,o),this.appendSessionLog=c.appendSessionLog,this.getActiveSessionsFile=i=>(0,c.getActiveSessionsFile)(this,i),this.saveActiveSession=i=>(0,c.saveActiveSession)(this,i),this.loadActiveSessions=()=>(0,c.loadActiveSessions)(this),this.endSession=(i,o)=>(0,c.endSession)(this,i,o),this.switchToSession=(i,o,a,s,h)=>(0,c.switchToSession)(this,i,o,a,s,h),this.startNewSession=i=>(0,c.startNewSession)(this,i),this.handleSessionMessage=i=>(0,c.handleSessionMessage)(this,i),this.cleanCache=(i,o=!0)=>(0,c.cleanCache)(this,i,o),this.formatTaskInfo=()=>(0,b.formatTaskInfo)(this),this.cancelTask=(i,o)=>(0,b.cancelTask)(this,i,o),this.countTodoTask=()=>(0,b.countTodoTask)(this),this.getOneTodoTask=()=>(0,b.getOneTodoTask)(this),this.finishTask=i=>(0,b.finishTask)(this,i),this.handleTask=()=>(0,b.handleTask)(this),this.runTaskHandlerLoop=()=>(0,b.runTaskHandlerLoop)(this),this.saveTask=i=>(0,b.saveTask)(this,i),this.clientId=d,this.config=(0,c.getClientConfig)(this);try{this.dingStreamClient=new Q.DingStreamClient({clientId:d,clientSecret:(0,Z.resolveSecret)(this.config.clientSecret),keepAlive:!0,debug:this.config.debug??!1})}catch(i){console.error("Error: DingStreamClient init failed.",i),process.exit(1)}this.cronEngine=new P.CronEngine(this)}async requireOwnerOrAdmin(d,i,o){return this.isOwner(o)||this.isAdmin(o)?!0:(await this.sendDingMessage({conversationId:d,sessionWebhook:i,content:"\u274C \u53EA\u6709\u673A\u5668\u4EBA owner \u6216\u7BA1\u7406\u5458\u624D\u80FD\u6267\u884C\u6B64\u64CD\u4F5C",msgType:"markdown"}),!1)}appendBashAudit(d,i,o){try{const a=N.default.join(this.getClientDir(),"bash-audit.log"),s=`[${(0,c.timestamp)()}] conversation=${d} user=${i} cmd=${JSON.stringify(o)}
2
- `;S.default.appendFileSync(a,s,{encoding:"utf-8",mode:(0,_.isWindows)()?void 0:384})}catch(a){console.error("\u5199\u5165 bash \u5BA1\u8BA1\u65E5\u5FD7\u5931\u8D25:",a)}}async requireOwner(d,i,o){return this.isOwner(o)?!0:(await this.sendDingMessage({conversationId:d,sessionWebhook:i,content:"\u274C \u53EA\u6709\u673A\u5668\u4EBA owner \u624D\u80FD\u6267\u884C\u6B64\u64CD\u4F5C",msgType:"markdown"}),!1)}async requireOwnerOrSingleChat(d,i,o,a){return this.isOwner(o)||a?.conversationType==="1"?!0:(await this.sendDingMessage({conversationId:d,sessionWebhook:i,content:"\u274C \u53EA\u6709\u673A\u5668\u4EBA owner \u624D\u80FD\u6267\u884C\u6B64\u64CD\u4F5C",msgType:"markdown"}),!1)}async handleAuthRequest(d){const{senderStaffId:i,senderNick:o,conversationId:a,conversationType:s,conversationTitle:h,sessionWebhook:n}=d;if(!this.config.ownerConversationId){await this.sendDingMessage({conversationId:a,sessionWebhook:n,content:["\u62B1\u6B49,\u60A8\u6682\u65E0\u4F7F\u7528\u6743\u9650","\u8BF7\u5C06\u4EE5\u4E0B\u4FE1\u606F\u53D1\u9001\u7ED9\u673A\u5668\u4EBA\u7BA1\u7406\u5458,\u7531\u7BA1\u7406\u5458\u901A\u8FC7\u547D\u4EE4\u6CE8\u518C:",`- **\u7FA4ID:** \`${a}\``,`- **\u6CE8\u518C\u547D\u4EE4:** \`/cfg --conversationId ${a}\``].join(`
3
- `),msgType:"markdown"});return}for(const U of this.pendingAuthRequests.values())if(U.senderStaffId===i&&U.conversationId===a){await this.sendDingMessage({conversationId:a,sessionWebhook:n,content:"\u23F3 \u6388\u6743\u7533\u8BF7\u5DF2\u53D1\u9001\uFF0C\u8BF7\u7B49\u5F85\u7BA1\u7406\u5458\u5BA1\u6279...",msgType:"markdown"});return}const l=`r${Date.now().toString(36)}`,w={id:l,senderStaffId:i,senderNick:o,conversationId:a,conversationType:s,conversationTitle:h,requestTime:Date.now()};this.pendingAuthRequests.set(l,w),console.log(`[${(0,c.timestamp)()}] \u65B0\u6388\u6743\u7533\u8BF7: id=${l}, userId=${i}, \u6635\u79F0=${o}, \u4F1A\u8BDD=${a}`);const k=["\u{1F4CB} **\u6536\u5230\u6388\u6743\u7533\u8BF7**",`- **\u7528\u6237ID:** ${i}`,`- **\u6635\u79F0:** ${o}`,`- **\u4F1A\u8BDDID:** ${a}`,h?`- **\u4F1A\u8BDD\u6807\u9898:** ${h}`:"",`- **\u4F1A\u8BDD\u7C7B\u578B:** ${s==="1"?"\u5355\u804A":s==="2"?"\u7FA4\u804A":s||"-"}`,"",`\u56DE\u590D \`/auth approve ${l}\` \u901A\u8FC7`,`\u56DE\u590D \`/auth reject ${l}\` \u62D2\u7EDD`].filter(Boolean).join(`
4
- `);await(0,K.sendOwnerMessage)(this,k,"markdown")?await this.sendDingMessage({conversationId:a,sessionWebhook:n,content:"\u2705 \u5DF2\u5411\u7BA1\u7406\u5458\u53D1\u9001\u6388\u6743\u7533\u8BF7\uFF0C\u8BF7\u7B49\u5F85\u5BA1\u6279...",msgType:"markdown"}):(this.pendingAuthRequests.delete(l),await this.sendDingMessage({conversationId:a,sessionWebhook:n,content:"\u274C \u6388\u6743\u7533\u8BF7\u53D1\u9001\u5931\u8D25\uFF0C\u8BF7\u8054\u7CFB\u7BA1\u7406\u5458\u624B\u52A8\u6388\u6743",msgType:"markdown"}))}async handleCronCommand(d,i){const{conversationId:o,sessionWebhook:a,senderStaffId:s,senderNick:h,conversationConfig:n}=i;switch(d.type){case"list":{const l=await this.getOrCreateLogSession(o,a,s,h,n,!0),w=this.cronEngine.listJobs(o);l.sessionDir&&(this.appendSessionLog(l.sessionDir,"user","/cron list"),this.appendSessionLog(l.sessionDir,"assistant",`\u5217\u51FA ${w.length} \u4E2A\u5B9A\u65F6\u4EFB\u52A1`)),await this.sendDingMessage({conversationId:o,sessionWebhook:a,content:(0,P.formatCronJobList)(w),msgType:"markdown"});return}case"delete":{const l=this.cronEngine.removeJob(d.id),w=await this.getOrCreateLogSession(o,a,s,h,n);w.sessionDir&&(this.appendSessionLog(w.sessionDir,"user",`/cron delete ${d.id}`),this.appendSessionLog(w.sessionDir,"assistant",l?`\u5220\u9664\u5B9A\u65F6\u4EFB\u52A1 ${d.id}`:`\u672A\u627E\u5230\u5B9A\u65F6\u4EFB\u52A1: ${d.id}`)),await this.sendDingMessage({conversationId:o,sessionWebhook:a,content:l?`\u2705 \u5B9A\u65F6\u4EFB\u52A1 **${d.id}** \u5DF2\u5220\u9664`:`\u274C \u672A\u627E\u5230\u5B9A\u65F6\u4EFB\u52A1: ${d.id}`,msgType:"markdown"});return}case"pause":{const l=this.cronEngine.toggleJob(d.id,!1),w=await this.getOrCreateLogSession(o,a,s,h,n);w.sessionDir&&(this.appendSessionLog(w.sessionDir,"user",`/cron pause ${d.id}`),this.appendSessionLog(w.sessionDir,"assistant",l?`\u6682\u505C\u5B9A\u65F6\u4EFB\u52A1 ${d.id}`:`\u672A\u627E\u5230\u5B9A\u65F6\u4EFB\u52A1: ${d.id}`)),await this.sendDingMessage({conversationId:o,sessionWebhook:a,content:l?`\u23F8\uFE0F \u5B9A\u65F6\u4EFB\u52A1 **${d.id}** \u5DF2\u6682\u505C`:`\u274C \u672A\u627E\u5230\u5B9A\u65F6\u4EFB\u52A1: ${d.id}`,msgType:"markdown"});return}case"resume":{const l=this.cronEngine.toggleJob(d.id,!0),w=await this.getOrCreateLogSession(o,a,s,h,n);w.sessionDir&&(this.appendSessionLog(w.sessionDir,"user",`/cron resume ${d.id}`),this.appendSessionLog(w.sessionDir,"assistant",l?`\u6062\u590D\u5B9A\u65F6\u4EFB\u52A1 ${d.id}`:`\u672A\u627E\u5230\u5B9A\u65F6\u4EFB\u52A1: ${d.id}`)),await this.sendDingMessage({conversationId:o,sessionWebhook:a,content:l?`\u25B6\uFE0F \u5B9A\u65F6\u4EFB\u52A1 **${d.id}** \u5DF2\u6062\u590D`:`\u274C \u672A\u627E\u5230\u5B9A\u65F6\u4EFB\u52A1: ${d.id}`,msgType:"markdown"});return}case"create_cron":{if(!(0,P.isValidCronExpression)(d.cronExpression)){await this.sendDingMessage({conversationId:o,sessionWebhook:a,content:`\u274C \u65E0\u6548\u7684cron\u8868\u8FBE\u5F0F: \`${d.cronExpression}\`
1
+ "use strict";var H=exports&&exports.__importDefault||function(N){return N&&N.__esModule?N:{default:N}};Object.defineProperty(exports,"__esModule",{value:!0}),exports.DingClaude=void 0;const B=require("child_process"),Q=require("utils-ok"),C=H(require("fs")),G=H(require("os")),R=H(require("path")),X=require("../common"),P=require("./quote"),K=require("./messaging"),O=require("./image"),$=require("./commands"),z=require("./messaging"),x=require("./claude-process"),V=require("./recorder"),L=require("./menu"),c=require("./session"),b=require("./task"),M=require("./todo"),Z=require("./commands"),S=require("./api-key-manager"),ee=require("./secrets"),I=require("./command-route"),j=require("./cron"),U=require("./platform"),J=(0,X.projUtil)().getPkgVersion();class se{constructor(d){this.resolvedPhones={},this.activeSessions=new Map,this.pendingAuthRequests=new Map,this.recorderModeConversations=new Set,this.pendingFreedomConvs=new Map,this.DEFAULT_SESSION_MAX_CONCURRENCY=5,this.DEFAULT_TASK_HANDLER_COUNT=1,this.DEFAULT_TASK_QUEUE_SIZE=50,this.sendDingMessage=i=>(0,z.sendDingMessage)(this,i),this.sendClaudeResponseToDing=(i,o,r,s)=>(0,z.sendClaudeResponseToDing)(this,i,o,r,s),this.parseClaudeStreamLine=x.parseClaudeStreamLine,this.interruptClaudeProcess=(i,o)=>(0,x.interruptClaudeProcess)(i,o),this.executeClaudeQuery=(i,o,r)=>(0,x.executeClaudeQuery)(this,i,o,r),this.getClientDir=()=>(0,c.getClientDir)(this),this.getClientConfig=()=>(0,c.getClientConfig)(this),this.authCheck=(i,o)=>(0,c.authCheck)(this,i,o),this.isOwner=i=>(0,c.isOwner)(this,i),this.isAdmin=i=>(0,c.isAdmin)(this,i),this.debugLog=(i,...o)=>(0,c.debugLog)(this,i,...o),this.hashConversationId=i=>(0,c.hashConversationId)(this,i),this.getConversationConfig=i=>(0,c.getConversationConfig)(this,i),this.getConversationDir=i=>(0,c.getConversationDir)(this,i),this.getSessionsDir=i=>(0,c.getSessionsDir)(this,i),this.getTasksDir=i=>(0,c.getTasksDir)(this,i),this.getSessionDir=i=>(0,c.getSessionDir)(this,i),this.getSessionId=c.getSessionId,this.formatSessionInfo=i=>(0,c.formatSessionInfo)(this,i),this.readSessionLogTail=(i,o)=>(0,c.readSessionLogTail)(this,i,o),this.findActiveSession=i=>(0,c.findActiveSession)(this,i),this.findHistorySession=(i,o)=>(0,c.findHistorySession)(this,i,o),this.findLatestSession=i=>(0,c.findLatestSession)(this,i),this.updateSessionFile=(i,o)=>(0,c.updateSessionFile)(this,i,o),this.appendSessionLog=c.appendSessionLog,this.getActiveSessionsFile=i=>(0,c.getActiveSessionsFile)(this,i),this.saveActiveSession=i=>(0,c.saveActiveSession)(this,i),this.loadActiveSessions=()=>(0,c.loadActiveSessions)(this),this.endSession=(i,o)=>(0,c.endSession)(this,i,o),this.switchToSession=(i,o,r,s,l)=>(0,c.switchToSession)(this,i,o,r,s,l),this.startNewSession=i=>(0,c.startNewSession)(this,i),this.handleSessionMessage=i=>(0,c.handleSessionMessage)(this,i),this.cleanCache=(i,o=!0)=>(0,c.cleanCache)(this,i,o),this.formatTaskInfo=()=>(0,b.formatTaskInfo)(this),this.cancelTask=(i,o)=>(0,b.cancelTask)(this,i,o),this.countTodoTask=()=>(0,b.countTodoTask)(this),this.getOneTodoTask=()=>(0,b.getOneTodoTask)(this),this.finishTask=i=>(0,b.finishTask)(this,i),this.handleTask=()=>(0,b.handleTask)(this),this.runTaskHandlerLoop=()=>(0,b.runTaskHandlerLoop)(this),this.saveTask=i=>(0,b.saveTask)(this,i),this.clientId=d,this.config=(0,c.getClientConfig)(this);try{this.dingStreamClient=new Q.DingStreamClient({clientId:d,clientSecret:(0,ee.resolveSecret)(this.config.clientSecret),keepAlive:!0,debug:this.config.debug??!1})}catch(i){console.error("Error: DingStreamClient init failed.",i),process.exit(1)}this.cronEngine=new j.CronEngine(this)}async requireOwnerOrAdmin(d,i,o){return this.isOwner(o)||this.isAdmin(o)?!0:(await this.sendDingMessage({conversationId:d,sessionWebhook:i,content:"\u274C \u53EA\u6709\u673A\u5668\u4EBA owner \u6216\u7BA1\u7406\u5458\u624D\u80FD\u6267\u884C\u6B64\u64CD\u4F5C",msgType:"markdown"}),!1)}appendBashAudit(d,i,o){try{const r=R.default.join(this.getClientDir(),"bash-audit.log"),s=`[${(0,c.timestamp)()}] conversation=${d} user=${i} cmd=${JSON.stringify(o)}
2
+ `;C.default.appendFileSync(r,s,{encoding:"utf-8",mode:(0,U.isWindows)()?void 0:384})}catch(r){console.error("\u5199\u5165 bash \u5BA1\u8BA1\u65E5\u5FD7\u5931\u8D25:",r)}}async requireOwner(d,i,o){return this.isOwner(o)?!0:(await this.sendDingMessage({conversationId:d,sessionWebhook:i,content:"\u274C \u53EA\u6709\u673A\u5668\u4EBA owner \u624D\u80FD\u6267\u884C\u6B64\u64CD\u4F5C",msgType:"markdown"}),!1)}async requireOwnerOrSingleChat(d,i,o,r){return this.isOwner(o)||r?.conversationType==="1"?!0:(await this.sendDingMessage({conversationId:d,sessionWebhook:i,content:"\u274C \u53EA\u6709\u673A\u5668\u4EBA owner \u624D\u80FD\u6267\u884C\u6B64\u64CD\u4F5C",msgType:"markdown"}),!1)}async handleAuthRequest(d){const{senderStaffId:i,senderNick:o,conversationId:r,conversationType:s,conversationTitle:l,sessionWebhook:n}=d;if(!this.config.ownerConversationId){await this.sendDingMessage({conversationId:r,sessionWebhook:n,content:["\u62B1\u6B49,\u60A8\u6682\u65E0\u4F7F\u7528\u6743\u9650","\u8BF7\u8054\u7CFB\u673A\u5668\u4EBA owner \u7533\u8BF7\u6388\u6743"].join(`
3
+ `),msgType:"markdown"});return}for(const _ of this.pendingAuthRequests.values())if(_.senderStaffId===i&&_.conversationId===r){await this.sendDingMessage({conversationId:r,sessionWebhook:n,content:"\u23F3 \u6388\u6743\u7533\u8BF7\u5DF2\u53D1\u9001\uFF0C\u8BF7\u7B49\u5F85\u7BA1\u7406\u5458\u5BA1\u6279...",msgType:"markdown"});return}const f=`r${Date.now().toString(36)}`,D={id:f,senderStaffId:i,senderNick:o,conversationId:r,conversationType:s,conversationTitle:l,requestTime:Date.now()};this.pendingAuthRequests.set(f,D),console.log(`[${(0,c.timestamp)()}] \u65B0\u6388\u6743\u7533\u8BF7: id=${f}, userId=${i}, \u6635\u79F0=${o}, \u4F1A\u8BDD=${r}`);const k=["\u{1F4CB} **\u6536\u5230\u6388\u6743\u7533\u8BF7**",`- **\u7528\u6237ID:** ${i}`,`- **\u6635\u79F0:** ${o}`,`- **\u4F1A\u8BDDID:** ${r}`,l?`- **\u4F1A\u8BDD\u6807\u9898:** ${l}`:"",`- **\u4F1A\u8BDD\u7C7B\u578B:** ${s==="1"?"\u5355\u804A":s==="2"?"\u7FA4\u804A":s||"-"}`,"",`\u56DE\u590D \`/auth approve ${f}\` \u901A\u8FC7`,`\u56DE\u590D \`/auth reject ${f}\` \u62D2\u7EDD`].filter(Boolean).join(`
4
+ `);await(0,K.sendOwnerMessage)(this,k,"markdown")?await this.sendDingMessage({conversationId:r,sessionWebhook:n,content:"\u2705 \u5DF2\u5411\u7BA1\u7406\u5458\u53D1\u9001\u6388\u6743\u7533\u8BF7\uFF0C\u8BF7\u7B49\u5F85\u5BA1\u6279...",msgType:"markdown"}):(this.pendingAuthRequests.delete(f),await this.sendDingMessage({conversationId:r,sessionWebhook:n,content:"\u274C \u6388\u6743\u7533\u8BF7\u53D1\u9001\u5931\u8D25\uFF0C\u8BF7\u8054\u7CFB\u7BA1\u7406\u5458\u624B\u52A8\u6388\u6743",msgType:"markdown"}))}async handleCronCommand(d,i){const{conversationId:o,sessionWebhook:r,senderStaffId:s,senderNick:l,conversationConfig:n}=i;switch(d.type){case"list":{const f=await this.getOrCreateLogSession(o,r,s,l,n,!0),D=this.cronEngine.listJobs(o);f.sessionDir&&(this.appendSessionLog(f.sessionDir,"user","/cron list"),this.appendSessionLog(f.sessionDir,"assistant",`\u5217\u51FA ${D.length} \u4E2A\u5B9A\u65F6\u4EFB\u52A1`)),await this.sendDingMessage({conversationId:o,sessionWebhook:r,content:(0,j.formatCronJobList)(D),msgType:"markdown"});return}case"delete":{const f=this.cronEngine.removeJob(d.id),D=await this.getOrCreateLogSession(o,r,s,l,n);D.sessionDir&&(this.appendSessionLog(D.sessionDir,"user",`/cron delete ${d.id}`),this.appendSessionLog(D.sessionDir,"assistant",f?`\u5220\u9664\u5B9A\u65F6\u4EFB\u52A1 ${d.id}`:`\u672A\u627E\u5230\u5B9A\u65F6\u4EFB\u52A1: ${d.id}`)),await this.sendDingMessage({conversationId:o,sessionWebhook:r,content:f?`\u2705 \u5B9A\u65F6\u4EFB\u52A1 **${d.id}** \u5DF2\u5220\u9664`:`\u274C \u672A\u627E\u5230\u5B9A\u65F6\u4EFB\u52A1: ${d.id}`,msgType:"markdown"});return}case"pause":{const f=this.cronEngine.toggleJob(d.id,!1),D=await this.getOrCreateLogSession(o,r,s,l,n);D.sessionDir&&(this.appendSessionLog(D.sessionDir,"user",`/cron pause ${d.id}`),this.appendSessionLog(D.sessionDir,"assistant",f?`\u6682\u505C\u5B9A\u65F6\u4EFB\u52A1 ${d.id}`:`\u672A\u627E\u5230\u5B9A\u65F6\u4EFB\u52A1: ${d.id}`)),await this.sendDingMessage({conversationId:o,sessionWebhook:r,content:f?`\u23F8\uFE0F \u5B9A\u65F6\u4EFB\u52A1 **${d.id}** \u5DF2\u6682\u505C`:`\u274C \u672A\u627E\u5230\u5B9A\u65F6\u4EFB\u52A1: ${d.id}`,msgType:"markdown"});return}case"resume":{const f=this.cronEngine.toggleJob(d.id,!0),D=await this.getOrCreateLogSession(o,r,s,l,n);D.sessionDir&&(this.appendSessionLog(D.sessionDir,"user",`/cron resume ${d.id}`),this.appendSessionLog(D.sessionDir,"assistant",f?`\u6062\u590D\u5B9A\u65F6\u4EFB\u52A1 ${d.id}`:`\u672A\u627E\u5230\u5B9A\u65F6\u4EFB\u52A1: ${d.id}`)),await this.sendDingMessage({conversationId:o,sessionWebhook:r,content:f?`\u25B6\uFE0F \u5B9A\u65F6\u4EFB\u52A1 **${d.id}** \u5DF2\u6062\u590D`:`\u274C \u672A\u627E\u5230\u5B9A\u65F6\u4EFB\u52A1: ${d.id}`,msgType:"markdown"});return}case"create_cron":{if(!(0,j.isValidCronExpression)(d.cronExpression)){await this.sendDingMessage({conversationId:o,sessionWebhook:r,content:`\u274C \u65E0\u6548\u7684cron\u8868\u8FBE\u5F0F: \`${d.cronExpression}\`
5
5
 
6
- \u{1F4A1} \u683C\u5F0F: \`\u5206 \u65F6 \u65E5 \u6708 \u5468\`\uFF0C\u5982 \`0 9 * * *\``,msgType:"markdown"});return}if(!this.hasNotifyCapability(i.conversationConfig)){await this.sendCronNoNotifyError(o,a);return}const l=this.cronEngine.addJob({conversationId:o,cronExpression:d.cronExpression,description:this.sanitizeLogContent(d.prompt.substring(0,50)),prompt:d.prompt,senderStaffId:s,senderNick:h}),w=await this.getOrCreateLogSession(o,a,s,h,n);w.sessionDir&&(this.appendSessionLog(w.sessionDir,"user",`/cron ${d.cronExpression} ${this.sanitizeLogContent(d.prompt)}`),this.appendSessionLog(w.sessionDir,"assistant",`\u521B\u5EFA\u5B9A\u65F6\u4EFB\u52A1: ${l.id} [${l.cronExpression}] ${l.description}`)),await this.sendDingMessage({conversationId:o,sessionWebhook:a,content:(0,P.formatCronJobInfo)(l),msgType:"markdown"});return}case"create_nl":{if(!this.hasNotifyCapability(i.conversationConfig)){await this.sendCronNoNotifyError(o,a);return}await this.sendDingMessage({conversationId:o,sessionWebhook:a,content:"\u23F3 \u6B63\u5728\u5206\u6790\u5B9A\u65F6\u4EFB\u52A1\u63CF\u8FF0..."});const l=await this.cronEngine.analyzeAndCreate(o,d.input,s,h),w=await this.getOrCreateLogSession(o,a,s,h,n);l.job?(w.sessionDir&&(this.appendSessionLog(w.sessionDir,"user",`/cron ${this.sanitizeLogContent(d.input)}`),this.appendSessionLog(w.sessionDir,"assistant",`\u521B\u5EFA\u5B9A\u65F6\u4EFB\u52A1: ${l.job.id} [${l.job.cronExpression}] ${l.job.description}`)),await this.sendDingMessage({conversationId:o,sessionWebhook:a,content:(0,P.formatCronJobInfo)(l.job),msgType:"markdown"})):(w.sessionDir&&(this.appendSessionLog(w.sessionDir,"user",`/cron ${this.sanitizeLogContent(d.input)}`),this.appendSessionLog(w.sessionDir,"assistant",`\u5B9A\u65F6\u4EFB\u52A1\u5206\u6790\u5931\u8D25: ${l.error}`)),await this.sendDingMessage({conversationId:o,sessionWebhook:a,content:`\u274C \u5B9A\u65F6\u4EFB\u52A1\u5206\u6790\u5931\u8D25: ${l.error}
6
+ \u{1F4A1} \u683C\u5F0F: \`\u5206 \u65F6 \u65E5 \u6708 \u5468\`\uFF0C\u5982 \`0 9 * * *\``,msgType:"markdown"});return}if(!this.hasNotifyCapability(i.conversationConfig)){await this.sendCronNoNotifyError(o,r);return}const f=this.cronEngine.addJob({conversationId:o,cronExpression:d.cronExpression,description:this.sanitizeLogContent(d.prompt.substring(0,50)),prompt:d.prompt,senderStaffId:s,senderNick:l}),D=await this.getOrCreateLogSession(o,r,s,l,n);D.sessionDir&&(this.appendSessionLog(D.sessionDir,"user",`/cron ${d.cronExpression} ${this.sanitizeLogContent(d.prompt)}`),this.appendSessionLog(D.sessionDir,"assistant",`\u521B\u5EFA\u5B9A\u65F6\u4EFB\u52A1: ${f.id} [${f.cronExpression}] ${f.description}`)),await this.sendDingMessage({conversationId:o,sessionWebhook:r,content:(0,j.formatCronJobInfo)(f),msgType:"markdown"});return}case"create_nl":{if(!this.hasNotifyCapability(i.conversationConfig)){await this.sendCronNoNotifyError(o,r);return}await this.sendDingMessage({conversationId:o,sessionWebhook:r,content:"\u23F3 \u6B63\u5728\u5206\u6790\u5B9A\u65F6\u4EFB\u52A1\u63CF\u8FF0..."});const f=await this.cronEngine.analyzeAndCreate(o,d.input,s,l),D=await this.getOrCreateLogSession(o,r,s,l,n);f.job?(D.sessionDir&&(this.appendSessionLog(D.sessionDir,"user",`/cron ${this.sanitizeLogContent(d.input)}`),this.appendSessionLog(D.sessionDir,"assistant",`\u521B\u5EFA\u5B9A\u65F6\u4EFB\u52A1: ${f.job.id} [${f.job.cronExpression}] ${f.job.description}`)),await this.sendDingMessage({conversationId:o,sessionWebhook:r,content:(0,j.formatCronJobInfo)(f.job),msgType:"markdown"})):(D.sessionDir&&(this.appendSessionLog(D.sessionDir,"user",`/cron ${this.sanitizeLogContent(d.input)}`),this.appendSessionLog(D.sessionDir,"assistant",`\u5B9A\u65F6\u4EFB\u52A1\u5206\u6790\u5931\u8D25: ${f.error}`)),await this.sendDingMessage({conversationId:o,sessionWebhook:r,content:`\u274C \u5B9A\u65F6\u4EFB\u52A1\u5206\u6790\u5931\u8D25: ${f.error}
7
7
 
8
- \u{1F4A1} \u4F60\u4E5F\u53EF\u4EE5\u76F4\u63A5\u6307\u5B9Acron\u8868\u8FBE\u5F0F: \`/cron 0 9 * * * \u4EFB\u52A1\u63CF\u8FF0\``,msgType:"markdown"}));return}}}async handleMenuCommand(d,i){const{conversationId:o,sessionWebhook:a,senderStaffId:s}=i;if((d.type==="add"||d.type==="del")&&d.isGlobal&&!this.isOwner(s)){await this.sendDingMessage({conversationId:o,sessionWebhook:a,content:"\u274C \u5168\u5C40\u83DC\u5355\u4EC5 owner \u53EF\u7BA1\u7406",msgType:"markdown"});return}switch(d.type){case"show":{const h=(0,M.getMergedMenu)(this,o,s),n=(0,M.loadMenuData)(this).global.length;h.length>0&&(0,M.setPendingSelection)(o,s,a,h),await this.sendDingMessage({conversationId:o,sessionWebhook:a,content:(0,M.formatMenuDisplay)(h,n),msgType:"markdown"});return}case"add":{const h=(0,M.addMenuItem)(this,o,s,d.isGlobal,"",d.command);await this.sendDingMessage({conversationId:o,sessionWebhook:a,content:`\u2705 \u5DF2\u6DFB\u52A0${d.isGlobal?"\u5168\u5C40":"\u4E2A\u4EBA"}\u5FEB\u6377\u6307\u4EE4: **${h.label}** \u2192 \`${h.command}\``,msgType:"markdown"});return}case"del":{const h=(0,M.deleteMenuItem)(this,o,s,d.isGlobal,String(d.index));await this.sendDingMessage({conversationId:o,sessionWebhook:a,content:h.success?`\u2705 \u5DF2\u5220\u9664${d.isGlobal?"\u5168\u5C40":"\u4E2A\u4EBA"}\u5FEB\u6377\u6307\u4EE4: **${h.deletedItem.label}**`:`\u26A0\uFE0F ${h.error}`,msgType:"markdown"});return}case"list":{await this.sendDingMessage({conversationId:o,sessionWebhook:a,content:(0,M.formatMenuList)(this,o,s,d.isGlobal),msgType:"markdown"});return}case"trigger":{(0,M.setUserTrigger)(this,s,d.word),await this.sendDingMessage({conversationId:o,sessionWebhook:a,content:`\u2705 \u83DC\u5355\u89E6\u53D1\u8BCD\u5DF2\u8BBE\u7F6E\u4E3A \`${d.word}\`\uFF0C\u53D1\u9001\u8BE5\u8BCD\u5373\u53EF\u5524\u8D77\u83DC\u5355`,msgType:"markdown"});return}}}async handleTodoCommand(d,i){const{conversationId:o,sessionWebhook:a,senderStaffId:s,senderNick:h}=i;if(d.type==="mode"){(0,C.setIdMode)(this,o,d.mode);const n=d.mode==="staffId"?"\u5DE5\u53F7(staffId)":"\u9489\u9489ID(dingtalkId)";await this.sendDingMessage({conversationId:o,sessionWebhook:a,content:`\u2705 \u7528\u6237\u6807\u8BC6\u6A21\u5F0F\u5DF2\u5207\u6362\u4E3A: **${n}**
8
+ \u{1F4A1} \u4F60\u4E5F\u53EF\u4EE5\u76F4\u63A5\u6307\u5B9Acron\u8868\u8FBE\u5F0F: \`/cron 0 9 * * * \u4EFB\u52A1\u63CF\u8FF0\``,msgType:"markdown"}));return}}}async handleMenuCommand(d,i){const{conversationId:o,sessionWebhook:r,senderStaffId:s}=i;if((d.type==="add"||d.type==="del")&&d.isGlobal&&!this.isOwner(s)){await this.sendDingMessage({conversationId:o,sessionWebhook:r,content:"\u274C \u5168\u5C40\u83DC\u5355\u4EC5 owner \u53EF\u7BA1\u7406",msgType:"markdown"});return}switch(d.type){case"show":{const l=(0,L.getMergedMenu)(this,o,s),n=(0,L.loadMenuData)(this).global.length;l.length>0&&(0,L.setPendingSelection)(o,s,r,l),await this.sendDingMessage({conversationId:o,sessionWebhook:r,content:(0,L.formatMenuDisplay)(l,n),msgType:"markdown"});return}case"add":{const l=(0,L.addMenuItem)(this,o,s,d.isGlobal,"",d.command);await this.sendDingMessage({conversationId:o,sessionWebhook:r,content:`\u2705 \u5DF2\u6DFB\u52A0${d.isGlobal?"\u5168\u5C40":"\u4E2A\u4EBA"}\u5FEB\u6377\u6307\u4EE4: **${l.label}** \u2192 \`${l.command}\``,msgType:"markdown"});return}case"del":{const l=(0,L.deleteMenuItem)(this,o,s,d.isGlobal,String(d.index));await this.sendDingMessage({conversationId:o,sessionWebhook:r,content:l.success?`\u2705 \u5DF2\u5220\u9664${d.isGlobal?"\u5168\u5C40":"\u4E2A\u4EBA"}\u5FEB\u6377\u6307\u4EE4: **${l.deletedItem.label}**`:`\u26A0\uFE0F ${l.error}`,msgType:"markdown"});return}case"list":{await this.sendDingMessage({conversationId:o,sessionWebhook:r,content:(0,L.formatMenuList)(this,o,s,d.isGlobal),msgType:"markdown"});return}case"trigger":{(0,L.setUserTrigger)(this,s,d.word),await this.sendDingMessage({conversationId:o,sessionWebhook:r,content:`\u2705 \u83DC\u5355\u89E6\u53D1\u8BCD\u5DF2\u8BBE\u7F6E\u4E3A \`${d.word}\`\uFF0C\u53D1\u9001\u8BE5\u8BCD\u5373\u53EF\u5524\u8D77\u83DC\u5355`,msgType:"markdown"});return}}}async handleTodoCommand(d,i){const{conversationId:o,sessionWebhook:r,senderStaffId:s,senderNick:l}=i;if(d.type==="mode"){(0,M.setIdMode)(this,o,d.mode);const n=d.mode==="staffId"?"\u5DE5\u53F7(staffId)":"\u9489\u9489ID(dingtalkId)";await this.sendDingMessage({conversationId:o,sessionWebhook:r,content:`\u2705 \u7528\u6237\u6807\u8BC6\u6A21\u5F0F\u5DF2\u5207\u6362\u4E3A: **${n}**
9
9
 
10
- \u65B0\u6DFB\u52A0\u7684\u5F85\u529E\u5C06\u4F7F\u7528\u6B64\u6A21\u5F0F\u8BB0\u5F55\u8D1F\u8D23\u4EBA`,msgType:"markdown"});return}if(d.type==="list"){const n=(0,C.getSortedTodoItems)(this,o),l=(0,C.getReminderHour)(this,o),k=(0,C.getIdMode)(this,o)==="staffId"?"\u5DE5\u53F7\u6A21\u5F0F":"\u9489\u9489ID\u6A21\u5F0F",y=(0,C.formatTodoList)(n,l),U=`\u{1F4CC} \u5F53\u524D\u6807\u8BC6\u6A21\u5F0F: **${k}**
10
+ \u65B0\u6DFB\u52A0\u7684\u5F85\u529E\u5C06\u4F7F\u7528\u6B64\u6A21\u5F0F\u8BB0\u5F55\u8D1F\u8D23\u4EBA`,msgType:"markdown"});return}if(d.type==="list"){const n=(0,M.getSortedTodoItems)(this,o),f=(0,M.getReminderHour)(this,o),k=(0,M.getIdMode)(this,o)==="staffId"?"\u5DE5\u53F7\u6A21\u5F0F":"\u9489\u9489ID\u6A21\u5F0F",y=(0,M.formatTodoList)(n,f),_=`\u{1F4CC} \u5F53\u524D\u6807\u8BC6\u6A21\u5F0F: **${k}**
11
11
 
12
- ${y}`;await this.sendDingMessage({conversationId:o,sessionWebhook:a,content:U,msgType:"markdown"});return}if(d.type==="remind"){(0,C.setReminderHour)(this,o,d.hour);const n=d.hour===null?"\u23F0 \u6BCF\u65E5\u63D0\u9192\u5DF2\u5173\u95ED":`\u23F0 \u6BCF\u65E5\u63D0\u9192\u5DF2\u8BBE\u7F6E\u4E3A ${d.hour}:00`;await this.sendDingMessage({conversationId:o,sessionWebhook:a,content:n});return}if(d.type==="done"){const n=(0,C.doneTodoItem)(this,o,d.index);n.success&&n.item?await this.sendDingMessage({conversationId:o,sessionWebhook:a,content:`\u2705 \u5DF2\u5B8C\u6210: ~~${n.item.content}~~ _@${n.item.assigneeNick}_`,msgType:"markdown"}):await this.sendDingMessage({conversationId:o,sessionWebhook:a,content:`\u274C ${n.error}`});return}if(d.type==="remove"){if(d.index==="all"){const n=(0,C.clearAllTodoItems)(this,o);n.success?await this.sendDingMessage({conversationId:o,sessionWebhook:a,content:`\u{1F5D1}\uFE0F \u5DF2\u6E05\u7A7A ${n.count} \u6761\u5F85\u529E`}):await this.sendDingMessage({conversationId:o,sessionWebhook:a,content:`\u274C ${n.error}`})}else{const n=(0,C.deleteTodoItem)(this,o,d.index);n.success&&n.item?await this.sendDingMessage({conversationId:o,sessionWebhook:a,content:`\u{1F5D1}\uFE0F \u5DF2\u5220\u9664: ~~${n.item.content}~~`,msgType:"markdown"}):await this.sendDingMessage({conversationId:o,sessionWebhook:a,content:`\u274C ${n.error}`})}return}if(d.type==="add"){const n=(0,C.getIdMode)(this,o),l=d.assigneeId||s,w=d.assigneeNick||h,k=d.deadline&&(0,C.parseDeadline)(d.deadline)||(0,C.getDefaultDeadline)(),y=(0,C.addTodoItem)(this,o,{content:d.content,assigneeStaffId:l,assigneeNick:w,deadline:k,assigneeIdType:n}),f=(0,C.getSortedTodoItems)(this,o).findIndex(R=>R.content===y.content&&R.createdAt===y.createdAt)+1,W=(0,C.formatTodoItemCreated)(y,f);await this.sendDingMessage({conversationId:o,sessionWebhook:a,content:W,msgType:"markdown"});return}}sanitizeLogContent(d){return d.replace(/\n/g,"\\n").replace(/\r/g,"\\r")}sanitizeOutput(d){const i=d.replace(/\r\n/g,`
12
+ ${y}`;await this.sendDingMessage({conversationId:o,sessionWebhook:r,content:_,msgType:"markdown"});return}if(d.type==="remind"){(0,M.setReminderHour)(this,o,d.hour);const n=d.hour===null?"\u23F0 \u6BCF\u65E5\u63D0\u9192\u5DF2\u5173\u95ED":`\u23F0 \u6BCF\u65E5\u63D0\u9192\u5DF2\u8BBE\u7F6E\u4E3A ${d.hour}:00`;await this.sendDingMessage({conversationId:o,sessionWebhook:r,content:n});return}if(d.type==="done"){const n=(0,M.doneTodoItem)(this,o,d.index);n.success&&n.item?await this.sendDingMessage({conversationId:o,sessionWebhook:r,content:`\u2705 \u5DF2\u5B8C\u6210: ~~${n.item.content}~~ _@${n.item.assigneeNick}_`,msgType:"markdown"}):await this.sendDingMessage({conversationId:o,sessionWebhook:r,content:`\u274C ${n.error}`});return}if(d.type==="remove"){if(d.index==="all"){const n=(0,M.clearAllTodoItems)(this,o);n.success?await this.sendDingMessage({conversationId:o,sessionWebhook:r,content:`\u{1F5D1}\uFE0F \u5DF2\u6E05\u7A7A ${n.count} \u6761\u5F85\u529E`}):await this.sendDingMessage({conversationId:o,sessionWebhook:r,content:`\u274C ${n.error}`})}else{const n=(0,M.deleteTodoItem)(this,o,d.index);n.success&&n.item?await this.sendDingMessage({conversationId:o,sessionWebhook:r,content:`\u{1F5D1}\uFE0F \u5DF2\u5220\u9664: ~~${n.item.content}~~`,msgType:"markdown"}):await this.sendDingMessage({conversationId:o,sessionWebhook:r,content:`\u274C ${n.error}`})}return}if(d.type==="add"){const n=(0,M.getIdMode)(this,o),f=d.assigneeId||s,D=d.assigneeNick||l,k=d.deadline&&(0,M.parseDeadline)(d.deadline)||(0,M.getDefaultDeadline)(),y=(0,M.addTodoItem)(this,o,{content:d.content,assigneeStaffId:f,assigneeNick:D,deadline:k,assigneeIdType:n}),E=(0,M.getSortedTodoItems)(this,o).findIndex(F=>F.content===y.content&&F.createdAt===y.createdAt)+1,h=(0,M.formatTodoItemCreated)(y,E);await this.sendDingMessage({conversationId:o,sessionWebhook:r,content:h,msgType:"markdown"});return}}sanitizeLogContent(d){return d.replace(/\n/g,"\\n").replace(/\r/g,"\\r")}sanitizeOutput(d){const i=d.replace(/\r\n/g,`
13
13
  `),o=8e3;return i.length>o?i.substring(0,o)+`
14
- ...(\u8F93\u51FA\u5DF2\u622A\u65AD)`:i}truncateMsg(d,i=100){const o=d.replace(/\n/g," ").trim();return o.length>i?o.slice(0,i)+"...":o}async getOrCreateLogSession(d,i,o,a,s,h=!1){const n=this.findActiveSession(d);if(n)return{sessionDir:this.getSessionDir(n.session.session),isNew:!1};if(h)return{sessionDir:null,isNew:!1};const l=Date.now(),w={conversationId:d,sessionWebhook:i,startTime:l,startTimeStr:Q.dateUtil.mm(l).format("YYYY-MM-DD-HH-mm-ss"),startStaffId:o,startNickName:`[cron]${a}`},k=this.getSessionDir(w);return S.default.mkdirSync(k,{recursive:!0}),S.default.writeFileSync(`${k}/session.json`,JSON.stringify(w,null,2),"utf-8"),S.default.appendFileSync(`${k}/session.log`,`[${(0,c.timestamp)()}] [SYSTEM]: \u521B\u5EFA\u4F1A\u8BDD\u7528\u4E8E\u8BB0\u5F55 /cron \u547D\u4EE4\u64CD\u4F5C
15
- `,"utf-8"),{sessionDir:k,isNew:!0}}hasNotifyCapability(d){return!!(d.dingToken||this.config.defaultDingToken)}async sendCronNoNotifyError(d,i){await this.sendDingMessage({conversationId:d,sessionWebhook:i,content:"\u274C \u5F53\u524D\u7FA4\u672A\u914D\u7F6E dingToken \u4E14\u65E0\u5BA2\u6237\u7AEF\u7EA7 defaultDingToken, \u5B9A\u65F6\u4EFB\u52A1\u65E0\u6CD5\u4E3B\u52A8\u53D1\u9001\u6D88\u606F, \u8BF7\u8054\u7CFB\u7BA1\u7406\u5458\u914D\u7F6E",msgType:"markdown"})}async botMsgGetCallback(d){this.dingStreamClient.socketCallBackResponse(d.headers.messageId,"");const i=JSON.parse(d.data),{senderNick:o,senderStaffId:a,conversationId:s,conversationTitle:h,sessionWebhook:n,msgtype:l,conversationType:w}=i,k=i.text?.content?.trim()??"";if(this.debugLog(`\u6536\u5230\u6D88\u606F: \u7FA4=${h}(${s}), \u53D1\u9001\u8005=${o}(${a}), \u7C7B\u578B=${l}, \u5185\u5BB9=${k.substring(0,50)}`),!this.authCheck(a,s)){await this.handleAuthRequest({senderStaffId:a,senderNick:o,conversationId:s,conversationType:w,conversationTitle:i.conversationTitle,sessionWebhook:n});return}const y=this.getConversationConfig(s);let U=(0,I.parseRecorderCommandEnhanced)(k);if(U==="exit"&&/^\/(?:exit|e)$/i.test(k)&&!this.recorderModeConversations.has(s)&&(U=null),U!==null){if(!this.isOwner(a)||w!=="1"){await this.sendDingMessage({conversationId:s,sessionWebhook:n,content:"\u274C Recorder \u6A21\u5F0F\u4EC5\u9650 owner \u5355\u804A\u4F7F\u7528",msgType:"markdown"});return}if(U==="on"){this.recorderModeConversations.add(s);const e=(0,z.getRecorderDir)(this,s);console.log(`[${(0,c.timestamp)()}] [recorder] \u5F00\u542F recorder \u6A21\u5F0F: conversationId=${s}, dir=${e}`),await this.sendDingMessage({conversationId:s,sessionWebhook:n,content:`\u{1F534} Recorder \u6A21\u5F0F\u5DF2\u5F00\u542F
14
+ ...(\u8F93\u51FA\u5DF2\u622A\u65AD)`:i}truncateMsg(d,i=100){const o=d.replace(/\n/g," ").trim();return o.length>i?o.slice(0,i)+"...":o}async getOrCreateLogSession(d,i,o,r,s,l=!1){const n=this.findActiveSession(d);if(n)return{sessionDir:this.getSessionDir(n.session.session),isNew:!1};if(l)return{sessionDir:null,isNew:!1};const f=Date.now(),D={conversationId:d,sessionWebhook:i,startTime:f,startTimeStr:Q.dateUtil.mm(f).format("YYYY-MM-DD-HH-mm-ss"),startStaffId:o,startNickName:`[cron]${r}`},k=this.getSessionDir(D);return C.default.mkdirSync(k,{recursive:!0}),C.default.writeFileSync(`${k}/session.json`,JSON.stringify(D,null,2),"utf-8"),C.default.appendFileSync(`${k}/session.log`,`[${(0,c.timestamp)()}] [SYSTEM]: \u521B\u5EFA\u4F1A\u8BDD\u7528\u4E8E\u8BB0\u5F55 /cron \u547D\u4EE4\u64CD\u4F5C
15
+ `,"utf-8"),{sessionDir:k,isNew:!0}}hasNotifyCapability(d){return!!(d.dingToken||this.config.defaultDingToken)}async sendCronNoNotifyError(d,i){await this.sendDingMessage({conversationId:d,sessionWebhook:i,content:"\u274C \u5F53\u524D\u7FA4\u672A\u914D\u7F6E dingToken \u4E14\u65E0\u5BA2\u6237\u7AEF\u7EA7 defaultDingToken, \u5B9A\u65F6\u4EFB\u52A1\u65E0\u6CD5\u4E3B\u52A8\u53D1\u9001\u6D88\u606F, \u8BF7\u8054\u7CFB\u7BA1\u7406\u5458\u914D\u7F6E",msgType:"markdown"})}async botMsgGetCallback(d){this.dingStreamClient.socketCallBackResponse(d.headers.messageId,"");const i=JSON.parse(d.data),{senderNick:o,senderStaffId:r,conversationId:s,conversationTitle:l,sessionWebhook:n,msgtype:f,conversationType:D}=i,k=i.text?.content?.trim()??"";if(this.debugLog(`\u6536\u5230\u6D88\u606F: \u7FA4=${l}(${s}), \u53D1\u9001\u8005=${o}(${r}), \u7C7B\u578B=${f}, \u5185\u5BB9=${k.substring(0,50)}`),!this.authCheck(r,s)){await this.handleAuthRequest({senderStaffId:r,senderNick:o,conversationId:s,conversationType:D,conversationTitle:i.conversationTitle,sessionWebhook:n});return}const y=this.getConversationConfig(s),_=(0,$.parseRecorderCommandEnhanced)(k);if(_!==null){if(!this.isOwner(r)||D!=="1"){await this.sendDingMessage({conversationId:s,sessionWebhook:n,content:"\u274C Recorder \u6A21\u5F0F\u4EC5\u9650 owner \u5355\u804A\u4F7F\u7528",msgType:"markdown"});return}if(_==="on"){this.recorderModeConversations.add(s);const e=(0,V.getRecorderDir)(this,s);console.log(`[${(0,c.timestamp)()}] [recorder] \u5F00\u542F recorder \u6A21\u5F0F: conversationId=${s}, dir=${e}`),await this.sendDingMessage({conversationId:s,sessionWebhook:n,content:`\u{1F534} Recorder \u6A21\u5F0F\u5DF2\u5F00\u542F
16
16
  - \u6240\u6709\u6D88\u606F\u5C06\u88AB\u5206\u7C7B\u8BB0\u5F55\u5230\u672C\u5730
17
17
  - \u4FDD\u5B58\u76EE\u5F55: \`${e}\`
18
- - \u53D1\u9001 \`/recorder exit\` \u5173\u95ED`,msgType:"markdown"})}else this.recorderModeConversations.delete(s),console.log(`[${(0,c.timestamp)()}] [recorder] \u5173\u95ED recorder \u6A21\u5F0F: conversationId=${s}`),await this.sendDingMessage({conversationId:s,sessionWebhook:n,content:"\u2B1C Recorder \u6A21\u5F0F\u5DF2\u5173\u95ED\uFF0C\u6062\u590D\u6B63\u5E38\u5904\u7406",msgType:"markdown"});return}if(this.recorderModeConversations.has(s)){try{await(0,z.recordMessage)(this,i,s),await this.sendDingMessage({conversationId:s,sessionWebhook:n,content:`\u2705 \u5DF2\u8BB0\u5F55 ${l}`})}catch(e){console.error(`[${(0,c.timestamp)()}] [recorder] \u8BB0\u5F55\u6D88\u606F\u5931\u8D25:`,e),await this.sendDingMessage({conversationId:s,sessionWebhook:n,content:`\u274C \u8BB0\u5F55\u5931\u8D25: ${e instanceof Error?e.message:String(e)}`})}return}let f;if(l==="picture"&&i.pictureDownloadCode){const e=this.getConversationDir(s),r=y?.useLocalOcr!==!1,t=await(0,j.processPictureMessage)(this,i.pictureDownloadCode,i.robotCode,e,r,k||void 0);if(!t){await this.sendDingMessage({conversationId:s,sessionWebhook:n,atUserId:a,content:"\u26A0\uFE0F \u56FE\u7247\u4E0B\u8F7D\u5931\u8D25\uFF0C\u8BF7\u91CD\u8BD5\u6216\u4F7F\u7528\u6587\u5B57\u63CF\u8FF0"});return}f=t}else if(l==="richText"&&i.content?.richText){const e=this.getConversationDir(s),r=y?.useLocalOcr!==!1;f=await(0,j.processRichTextMessage)(this,i.content.richText,i.robotCode,e,r)}else if(l==="file"){const e=(0,j.extractDownloadCode)(i);if(e){const r=this.getConversationDir(s),t=await(0,j.processFileMessage)(this,e,i.robotCode,r,k||void 0);if(!t){await this.sendDingMessage({conversationId:s,sessionWebhook:n,atUserId:a,content:"\u26A0\uFE0F \u6587\u4EF6\u4E0B\u8F7D\u5931\u8D25\uFF0C\u8BF7\u91CD\u8BD5"});return}f=t}else{await this.sendDingMessage({conversationId:s,sessionWebhook:n,atUserId:a,content:"\u26A0\uFE0F \u65E0\u6CD5\u83B7\u53D6\u6587\u4EF6\u4E0B\u8F7D\u94FE\u63A5\uFF0C\u8BF7\u91CD\u65B0\u53D1\u9001"});return}}else{if(f=k,!f){const e=this.getConversationDir(s),r=y?.useLocalOcr!==!1,t=(0,A.extractQuoteInfo)(i);t&&(this.debugLog(`\u68C0\u6D4B\u5230\u5F15\u7528\u6D88\u606F(\u65E0\u6B63\u6587): quoteMessageId=${t.quoteMessageId}`),await(0,A.enrichQuoteInfo)(this,t,i,e,r),t.quoteText&&(f=(0,A.formatPromptWithQuote)("",t)))}if(!f)return}if(!f.startsWith("/")&&l==="text"&&k){const e=this.getConversationDir(s),r=y?.useLocalOcr!==!1,t=(0,A.extractQuoteInfo)(i);t&&(this.debugLog(`\u68C0\u6D4B\u5230\u5F15\u7528\u6D88\u606F: quoteMessageId=${t.quoteMessageId}`),await(0,A.enrichQuoteInfo)(this,t,i,e,r),t.quoteText&&(f=(0,A.formatPromptWithQuote)(f,t)))}if(l==="text"&&f&&!f.startsWith("/")){if(f.toLowerCase()===(0,M.getUserTrigger)(this,a).toLowerCase())f="/menu";else if(/^\d+$/.test(f)&&(0,M.hasPendingSelection)(s,a)){const e=(0,M.getPendingSelection)(s,a);(0,M.clearPendingSelection)(s,a);const r=parseInt(f,10);if(r<1||r>e.mergedItems.length){await this.sendDingMessage({conversationId:s,sessionWebhook:n,atUserId:a,content:`\u26A0\uFE0F \u5E8F\u53F7\u65E0\u6548\uFF0C\u83DC\u5355\u5171 ${e.mergedItems.length} \u9879`});return}const t=e.mergedItems[r-1];console.log(`[${(0,c.timestamp)()}] [menu] ${o} \u9009\u62E9\u5FEB\u6377\u6307\u4EE4: ${t.label} \u2192 ${t.command}`),f=t.command}}const W=[(0,v.route)("/cfg",()=>(0,I.parseCfgCommand)(f),async e=>{if(e.conversationId&&!this.isOwner(a)){await this.sendDingMessage({conversationId:s,sessionWebhook:n,content:"\u274C \u53EA\u6709\u673A\u5668\u4EBA owner \u624D\u80FD\u64CD\u4F5C\u5176\u4ED6\u7FA4\u7684\u914D\u7F6E",msgType:"markdown"});return}if(!await this.requireOwnerOrSingleChat(s,n,a,y))return;const r=e.conversationId||s,t=r!==s,g=t?this.config.conversations.find($=>$.conversationId===r):y,u=!!(e.dingToken||e.linkConversationId||e.whiteUserList&&e.whiteUserList.length>0||e.conversationTitle||e.atSender!==void 0||e.receiveReply!==void 0||e.preBash!==void 0||e.permissionMode!==void 0);if(g&&u){if(e.conversationTitle&&(g.conversationTitle=e.conversationTitle),w&&!t&&(g.conversationType=w),e.dingToken&&(g.dingToken=e.dingToken),e.linkConversationId&&(g.linkConversationId=e.linkConversationId),e.atSender!==void 0&&(g.atSender=e.atSender),e.receiveReply!==void 0&&(g.receiveReply=e.receiveReply),e.preBash!==void 0&&(g.preBash=e.preBash),e.permissionMode!==void 0&&(g.permissionMode=e.permissionMode),e.whiteUserList&&e.whiteUserList.length>0){g.whiteUserList=e.whiteUserList;for(const $ of e.whiteUserList)(0,c.isMobile)($)&&await(0,c.resolveUserId)(this,$)}(0,L.saveClientConfig)(this),console.log(`[${(0,c.timestamp)()}] \u5237\u65B0\u7FA4\u914D\u7F6E: ${g.conversationTitle||r}(${r})`)}else if(!g){const $={conversationId:r,conversationType:t?"1":w,conversationTitle:e.conversationTitle||(t?"":h)};if(e.dingToken&&($.dingToken=e.dingToken),e.linkConversationId&&($.linkConversationId=e.linkConversationId),e.atSender!==void 0&&($.atSender=e.atSender),e.receiveReply!==void 0&&($.receiveReply=e.receiveReply),e.preBash!==void 0&&($.preBash=e.preBash),e.permissionMode!==void 0&&($.permissionMode=e.permissionMode),e.whiteUserList&&e.whiteUserList.length>0){$.whiteUserList=e.whiteUserList;for(const T of e.whiteUserList)(0,c.isMobile)(T)&&await(0,c.resolveUserId)(this,T)}this.config.conversations.push($),(0,L.saveClientConfig)(this),console.log(`[${(0,c.timestamp)()}] \u6CE8\u518C\u65B0\u7FA4: ${$.conversationTitle||r}(${r}) \u7C7B\u578B=${$.conversationType||"-"}`)}const m=this.getConversationDir(r);S.default.existsSync(m)||(S.default.mkdirSync(m,{recursive:!0}),console.log(`[${(0,c.timestamp)()}] \u521B\u5EFA\u5DE5\u4F5C\u76EE\u5F55: ${m}`));const p=g||this.getConversationConfig(r),D=[g?"\u2705 \u7FA4\u914D\u7F6E\u5DF2\u5237\u65B0":"\u2705 \u7FA4\u5DF2\u6CE8\u518C",`- **\u7FA4\u540D\u79F0:** ${p?.conversationTitle||r}`,`- **\u7FA4ID:** ${r}`];if(p?.conversationType&&D.push(`- **\u4F1A\u8BDD\u7C7B\u578B:** ${p.conversationType==="1"?"\u5355\u804A":p.conversationType==="2"?"\u7FA4\u804A":p.conversationType}`),p?.dingToken?D.push(`- **dingToken:** ${p.dingToken.substring(0,8)}...`):D.push("- **dingToken:** (\u672A\u6307\u5B9A, \u4F7F\u7528 defaultDingToken)"),p?.linkConversationId&&D.push(`- **linkConversationId:** ${p.linkConversationId}`),p?.atSender===!1&&D.push("- **atSender:** false (\u4E0D @ \u53D1\u9001\u4EBA)"),p?.receiveReply===!1&&D.push("- **receiveReply:** false (\u4E0D\u56DE\u590D\u786E\u8BA4\u6D88\u606F)"),p?.permissionMode&&D.push(`- **permissionMode:** ${p.permissionMode}`),p?.whiteUserList?.length){const $=p.whiteUserList.map(T=>(0,c.isMobile)(T)?T:(0,c.userIdToPhone)(this,T)||T).join(", ");D.push(`- **whiteUserList:** ${$}`)}D.push(`- **\u5DE5\u4F5C\u76EE\u5F55:** ${m}`),D.push(`
19
- \u{1F4A1} \u53EF\u7F16\u8F91 config.json \u8865\u5145\u66F4\u591A\u914D\u7F6E`),await this.sendDingMessage({conversationId:s,sessionWebhook:n,content:D.join(`
20
- `),msgType:"markdown"})}),(0,v.route)("/help",()=>(0,I.parseHelpCommand)(f),async()=>{await this.sendDingMessage({conversationId:s,sessionWebhook:n,content:(0,I.formatHelpOverview)(J,this.isOwner(a)),msgType:"markdown"})}),(0,v.route)("/version",()=>(0,I.parseVersionCommand)(f),async()=>{let e="\u672A\u5B89\u88C5";try{const{stdout:t}=await new Promise((g,u)=>{(0,B.exec)("claude --version",{timeout:5e3},(m,p,D)=>{m?u(m):g({stdout:p})})});e=t.trim()||"\u672A\u77E5"}catch{}const r=["### \u{1F4E6} cc-ding \u7248\u672C\u4FE1\u606F","",`- **cc-ding:** ${J}`,`- **Claude CLI:** ${e}`,`- **Node.js:** ${process.version}`,`- **\u7CFB\u7EDF:** ${G.default.platform()} ${G.default.release()}`].join(`
21
- `);await this.sendDingMessage({conversationId:s,sessionWebhook:n,content:r,msgType:"markdown"})}),(0,v.route)("cmd-help",()=>(0,I.parseCommandHelp)(f),async e=>{const r=(0,I.getCommandByName)(e);r?await this.sendDingMessage({conversationId:s,sessionWebhook:n,content:(0,I.formatCommandHelp)(r),msgType:"markdown"}):await this.sendDingMessage({conversationId:s,sessionWebhook:n,content:`\u274C \u672A\u627E\u5230\u547D\u4EE4: **${e}**
18
+ - \u53D1\u9001 \`/recorder exit\` \u5173\u95ED`,msgType:"markdown"})}else this.recorderModeConversations.delete(s),console.log(`[${(0,c.timestamp)()}] [recorder] \u5173\u95ED recorder \u6A21\u5F0F: conversationId=${s}`),await this.sendDingMessage({conversationId:s,sessionWebhook:n,content:"\u2B1C Recorder \u6A21\u5F0F\u5DF2\u5173\u95ED\uFF0C\u6062\u590D\u6B63\u5E38\u5904\u7406",msgType:"markdown"});return}const E=this.pendingFreedomConvs.get(s);if(E&&Date.now()-E<6e4){const e=k.trim().toLowerCase();if(e==="\u786E\u8BA4"||e==="confirm"){this.pendingFreedomConvs.delete(s);const a=this.getConversationConfig(s);a&&(a.freedomMode=!0,(0,S.saveClientConfig)(this)),await this.sendDingMessage({conversationId:s,sessionWebhook:n,content:`\u2705 \u81EA\u7531\u6A21\u5F0F\u5DF2\u5F00\u542F
19
+ \u{1F4A1} \u6240\u6709\u7FA4\u6210\u5458\u73B0\u5728\u5747\u53EF\u4F7F\u7528\u673A\u5668\u4EBA`,msgType:"markdown"});return}}else E&&Date.now()-E>=6e4&&this.pendingFreedomConvs.delete(s);if(this.recorderModeConversations.has(s)){try{await(0,V.recordMessage)(this,i,s),await this.sendDingMessage({conversationId:s,sessionWebhook:n,content:`\u2705 \u5DF2\u8BB0\u5F55 ${f}`})}catch(e){console.error(`[${(0,c.timestamp)()}] [recorder] \u8BB0\u5F55\u6D88\u606F\u5931\u8D25:`,e),await this.sendDingMessage({conversationId:s,sessionWebhook:n,content:`\u274C \u8BB0\u5F55\u5931\u8D25: ${e instanceof Error?e.message:String(e)}`})}return}let h;if(f==="picture"&&i.pictureDownloadCode){const e=this.getConversationDir(s),a=y?.useLocalOcr!==!1,t=await(0,O.processPictureMessage)(this,i.pictureDownloadCode,i.robotCode,e,a,k||void 0);if(!t){await this.sendDingMessage({conversationId:s,sessionWebhook:n,atUserId:r,content:"\u26A0\uFE0F \u56FE\u7247\u4E0B\u8F7D\u5931\u8D25\uFF0C\u8BF7\u91CD\u8BD5\u6216\u4F7F\u7528\u6587\u5B57\u63CF\u8FF0"});return}h=t}else if(f==="richText"&&i.content?.richText){const e=this.getConversationDir(s),a=y?.useLocalOcr!==!1;h=await(0,O.processRichTextMessage)(this,i.content.richText,i.robotCode,e,a)}else if(f==="file"){const e=(0,O.extractDownloadCode)(i);if(e){const a=this.getConversationDir(s),t=await(0,O.processFileMessage)(this,e,i.robotCode,a,k||void 0);if(!t){await this.sendDingMessage({conversationId:s,sessionWebhook:n,atUserId:r,content:"\u26A0\uFE0F \u6587\u4EF6\u4E0B\u8F7D\u5931\u8D25\uFF0C\u8BF7\u91CD\u8BD5"});return}h=t}else{await this.sendDingMessage({conversationId:s,sessionWebhook:n,atUserId:r,content:"\u26A0\uFE0F \u65E0\u6CD5\u83B7\u53D6\u6587\u4EF6\u4E0B\u8F7D\u94FE\u63A5\uFF0C\u8BF7\u91CD\u65B0\u53D1\u9001"});return}}else{if(h=k,!h){const e=this.getConversationDir(s),a=y?.useLocalOcr!==!1,t=(0,P.extractQuoteInfo)(i);t&&(this.debugLog(`\u68C0\u6D4B\u5230\u5F15\u7528\u6D88\u606F(\u65E0\u6B63\u6587): quoteMessageId=${t.quoteMessageId}`),await(0,P.enrichQuoteInfo)(this,t,i,e,a),t.quoteText&&(h=(0,P.formatPromptWithQuote)("",t)))}if(!h)return}if(!h.startsWith("/")&&f==="text"&&k){const e=this.getConversationDir(s),a=y?.useLocalOcr!==!1,t=(0,P.extractQuoteInfo)(i);t&&(this.debugLog(`\u68C0\u6D4B\u5230\u5F15\u7528\u6D88\u606F: quoteMessageId=${t.quoteMessageId}`),await(0,P.enrichQuoteInfo)(this,t,i,e,a),t.quoteText&&(h=(0,P.formatPromptWithQuote)(h,t)))}if(f==="text"&&h&&!h.startsWith("/")){if(h.toLowerCase()===(0,L.getUserTrigger)(this,r).toLowerCase())h="/menu";else if(/^\d+$/.test(h)&&(0,L.hasPendingSelection)(s,r)){const e=(0,L.getPendingSelection)(s,r);(0,L.clearPendingSelection)(s,r);const a=parseInt(h,10);if(a<1||a>e.mergedItems.length){await this.sendDingMessage({conversationId:s,sessionWebhook:n,atUserId:r,content:`\u26A0\uFE0F \u5E8F\u53F7\u65E0\u6548\uFF0C\u83DC\u5355\u5171 ${e.mergedItems.length} \u9879`});return}const t=e.mergedItems[a-1];console.log(`[${(0,c.timestamp)()}] [menu] ${o} \u9009\u62E9\u5FEB\u6377\u6307\u4EE4: ${t.label} \u2192 ${t.command}`),h=t.command}}const F=[(0,I.route)("/cfg",()=>(0,$.parseCfgCommand)(h),async e=>{if(e.conversationId&&!this.isOwner(r)){await this.sendDingMessage({conversationId:s,sessionWebhook:n,content:"\u274C \u53EA\u6709\u673A\u5668\u4EBA owner \u624D\u80FD\u64CD\u4F5C\u5176\u4ED6\u7FA4\u7684\u914D\u7F6E",msgType:"markdown"});return}if(!await this.requireOwnerOrSingleChat(s,n,r,y))return;const a=e.conversationId||s,t=a!==s,g=t?this.config.conversations.find(v=>v.conversationId===a):y,p=!!(e.dingToken||e.linkConversationId||e.whiteUserList&&e.whiteUserList.length>0||e.conversationTitle||e.atSender!==void 0||e.receiveReply!==void 0||e.preBash!==void 0||e.permissionMode!==void 0);if(g&&p){if(e.conversationTitle&&(g.conversationTitle=e.conversationTitle),D&&!t&&(g.conversationType=D),e.dingToken&&(g.dingToken=e.dingToken),e.linkConversationId&&(g.linkConversationId=e.linkConversationId),e.atSender!==void 0&&(g.atSender=e.atSender),e.receiveReply!==void 0&&(g.receiveReply=e.receiveReply),e.preBash!==void 0&&(g.preBash=e.preBash),e.permissionMode!==void 0&&(g.permissionMode=e.permissionMode),e.whiteUserList&&e.whiteUserList.length>0){g.whiteUserList=e.whiteUserList;for(const v of e.whiteUserList)(0,c.isMobile)(v)&&await(0,c.resolveUserId)(this,v)}(0,S.saveClientConfig)(this),console.log(`[${(0,c.timestamp)()}] \u5237\u65B0\u7FA4\u914D\u7F6E: ${g.conversationTitle||a}(${a})`)}else if(!g){const v={conversationId:a,conversationType:t?"1":D,conversationTitle:e.conversationTitle||(t?"":l)};if(e.dingToken&&(v.dingToken=e.dingToken),e.linkConversationId&&(v.linkConversationId=e.linkConversationId),e.atSender!==void 0&&(v.atSender=e.atSender),e.receiveReply!==void 0&&(v.receiveReply=e.receiveReply),e.preBash!==void 0&&(v.preBash=e.preBash),e.permissionMode!==void 0&&(v.permissionMode=e.permissionMode),e.whiteUserList&&e.whiteUserList.length>0){v.whiteUserList=e.whiteUserList;for(const w of e.whiteUserList)(0,c.isMobile)(w)&&await(0,c.resolveUserId)(this,w)}this.config.conversations.push(v),(0,S.saveClientConfig)(this),console.log(`[${(0,c.timestamp)()}] \u6CE8\u518C\u65B0\u7FA4: ${v.conversationTitle||a}(${a}) \u7C7B\u578B=${v.conversationType||"-"}`)}const u=this.getConversationDir(a);C.default.existsSync(u)||(C.default.mkdirSync(u,{recursive:!0}),console.log(`[${(0,c.timestamp)()}] \u521B\u5EFA\u5DE5\u4F5C\u76EE\u5F55: ${u}`));const m=g||this.getConversationConfig(a),T=[g?"\u2705 \u7FA4\u914D\u7F6E\u5DF2\u5237\u65B0":"\u2705 \u7FA4\u5DF2\u6CE8\u518C",`- **\u7FA4\u540D\u79F0:** ${m?.conversationTitle||a}`,`- **\u7FA4ID:** ${a}`];if(m?.conversationType&&T.push(`- **\u4F1A\u8BDD\u7C7B\u578B:** ${m.conversationType==="1"?"\u5355\u804A":m.conversationType==="2"?"\u7FA4\u804A":m.conversationType}`),m?.dingToken?T.push(`- **dingToken:** ${m.dingToken.substring(0,8)}...`):T.push("- **dingToken:** (\u672A\u6307\u5B9A, \u4F7F\u7528 defaultDingToken)"),m?.linkConversationId&&T.push(`- **linkConversationId:** ${m.linkConversationId}`),m?.atSender===!1&&T.push("- **atSender:** false (\u4E0D @ \u53D1\u9001\u4EBA)"),m?.receiveReply===!1&&T.push("- **receiveReply:** false (\u4E0D\u56DE\u590D\u786E\u8BA4\u6D88\u606F)"),m?.permissionMode&&T.push(`- **permissionMode:** ${m.permissionMode}`),m?.whiteUserList?.length){const v=m.whiteUserList.map(w=>(0,c.isMobile)(w)?w:(0,c.userIdToPhone)(this,w)||w).join(", ");T.push(`- **whiteUserList:** ${v}`)}T.push(`- **\u5DE5\u4F5C\u76EE\u5F55:** ${u}`),T.push(`
20
+ \u{1F4A1} \u53EF\u7F16\u8F91 config.json \u8865\u5145\u66F4\u591A\u914D\u7F6E`),await this.sendDingMessage({conversationId:s,sessionWebhook:n,content:T.join(`
21
+ `),msgType:"markdown"})}),(0,I.route)("/help",()=>(0,$.parseHelpCommand)(h),async()=>{await this.sendDingMessage({conversationId:s,sessionWebhook:n,content:(0,$.formatHelpOverview)(J,this.isOwner(r)),msgType:"markdown"})}),(0,I.route)("/version",()=>(0,$.parseVersionCommand)(h),async()=>{let e="\u672A\u5B89\u88C5";try{const{stdout:t}=await new Promise((g,p)=>{(0,B.exec)("claude --version",{timeout:5e3},(u,m,T)=>{u?p(u):g({stdout:m})})});e=t.trim()||"\u672A\u77E5"}catch{}const a=["### \u{1F4E6} cc-ding \u7248\u672C\u4FE1\u606F","",`- **cc-ding:** ${J}`,`- **claude:** ${e}`,`- **os:** ${G.default.platform()} ${G.default.release()}`,`- **node:** ${process.version}`].join(`
22
+ `);await this.sendDingMessage({conversationId:s,sessionWebhook:n,content:a,msgType:"markdown"})}),(0,I.route)("cmd-help",()=>(0,$.parseCommandHelp)(h),async e=>{const a=(0,$.getCommandByName)(e);a?await this.sendDingMessage({conversationId:s,sessionWebhook:n,content:(0,$.formatCommandHelp)(a),msgType:"markdown"}):await this.sendDingMessage({conversationId:s,sessionWebhook:n,content:`\u274C \u672A\u627E\u5230\u547D\u4EE4: **${e}**
22
23
 
23
- \u{1F4A1} \u8F93\u5165 \`/help\` \u67E5\u770B\u6240\u6709\u53EF\u7528\u547D\u4EE4`,msgType:"markdown"})}),(0,v.route)("/reboot",()=>(0,I.parseRebootCommand)(f),async e=>{if(!await this.requireOwnerOrAdmin(s,n,a))return;if(e.tag&&!/^[\w.\-]+$/.test(e.tag)){await this.sendDingMessage({conversationId:s,sessionWebhook:n,content:"\u274C \u65E0\u6548\u7684 tag\uFF0C\u4EC5\u5141\u8BB8\u5B57\u6BCD\u3001\u6570\u5B57\u3001\u70B9\u3001\u6A2A\u7EBF\u548C\u4E0B\u5212\u7EBF",msgType:"markdown"});return}const r=e.tag?`@${e.tag}`:"@latest",t=e.update?`pnpm add -g cc-ding${r}`:null,g=`cc-ding-${this.clientId}`;await this.sendDingMessage({conversationId:s,sessionWebhook:n,content:t?`\u2705 \u66F4\u65B0\u5E76\u91CD\u542F\uFF0C\u6B63\u5728\u6267\u884C ${t}...`:"\u2705 cc-ding \u6B63\u5728\u91CD\u542F\u4E2D...",msgType:"markdown"});const u=N.default.join(this.getClientDir(),".reboot_pending");S.default.writeFileSync(u,JSON.stringify({conversationId:s,senderStaffId:a,sessionWebhook:n,update:e.update}),"utf-8"),setTimeout(()=>{console.log(`[${(0,c.timestamp)()}] \u6267\u884C pm2 restart ${g}${t?" (\u542B\u66F4\u65B0)":""}`),(0,B.exec)(`${t?`${t} && `:""}pm2 restart "${g}"`,{timeout:6e4},m=>{m&&console.error(`[${(0,c.timestamp)()}] pm2 restart \u5931\u8D25:`,m)})},1e3)})];for(const e of W)if(await e.tryHandle())return;if(!y){console.log(`\u672A\u6CE8\u518C\u7684\u673A\u5668\u4EBA,\u7FA4:${h},${s}`),this.isOwner(a)?await this.sendDingMessage({conversationId:s,sessionWebhook:n,atUserId:a,content:"\u26A0\uFE0F \u8BE5\u7FA4\u672A\u6CE8\u518C\uFF0C\u8BF7\u5148\u4F7F\u7528 `/cfg` \u547D\u4EE4\u6CE8\u518C",msgType:"markdown"}):await this.sendDingMessage({conversationId:s,sessionWebhook:n,atUserId:a,content:`\u62B1\u6B49,\u8BE5\u7FA4\u7684\u673A\u5668\u4EBA\u672A\u5728\u670D\u52A1\u7AEF\u6CE8\u518C,\u8BF7\u8054\u7CFB\u5E94\u7528\u673A\u5668\u4EBAowner\u6CE8\u518C(${s})...`});return}const R=[(0,v.route)("/clean",()=>(0,I.parseCleanCommand)(f),async e=>{if(e==="all"&&y?.conversationType!=="1"&&!this.isOwner(a)){await this.sendDingMessage({conversationId:s,sessionWebhook:n,content:"\u274C \u53EA\u6709\u673A\u5668\u4EBA owner \u624D\u80FD\u6E05\u9664\u6240\u6709\u7FA4\u7F13\u5B58",msgType:"markdown"});return}if(!await this.requireOwnerOrSingleChat(s,n,a,y))return;const r=e==="all"?null:s,t=this.cleanCache(r,!0),g=[];g.push("\u{1F9F9} \u7F13\u5B58\u6E05\u7406\u5B8C\u6210"),t.sessionsDeleted>0&&g.push(`- \u4F1A\u8BDD\u76EE\u5F55: ${t.sessionsDeleted} \u4E2A`),t.tasksDeleted>0&&g.push(`- \u4EFB\u52A1\u76EE\u5F55: ${t.tasksDeleted} \u4E2A`),t.imagesDeleted>0&&g.push(`- \u56FE\u7247\u6587\u4EF6: ${t.imagesDeleted} \u4E2A`),t.sessionsDeleted===0&&t.tasksDeleted===0&&t.imagesDeleted===0&&g.push("(\u65E0\u5386\u53F2\u6570\u636E)"),g.push(`
24
+ \u{1F4A1} \u8F93\u5165 \`/help\` \u67E5\u770B\u6240\u6709\u53EF\u7528\u547D\u4EE4`,msgType:"markdown"})}),(0,I.route)("/reboot",()=>(0,$.parseRebootCommand)(h),async e=>{if(!await this.requireOwnerOrAdmin(s,n,r))return;if(e.tag&&!/^[\w.\-]+$/.test(e.tag)){await this.sendDingMessage({conversationId:s,sessionWebhook:n,content:"\u274C \u65E0\u6548\u7684 tag\uFF0C\u4EC5\u5141\u8BB8\u5B57\u6BCD\u3001\u6570\u5B57\u3001\u70B9\u3001\u6A2A\u7EBF\u548C\u4E0B\u5212\u7EBF",msgType:"markdown"});return}const a=e.tag?`@${e.tag}`:"@latest",t=e.update?`pnpm add -g cc-ding${a}`:null,g=`cc-ding-${this.clientId}`;await this.sendDingMessage({conversationId:s,sessionWebhook:n,content:t?`\u2705 \u66F4\u65B0\u5E76\u91CD\u542F\uFF0C\u6B63\u5728\u6267\u884C ${t}...`:"\u2705 cc-ding \u6B63\u5728\u91CD\u542F\u4E2D...",msgType:"markdown"});const p=R.default.join(this.getClientDir(),".reboot_pending");C.default.writeFileSync(p,JSON.stringify({conversationId:s,senderStaffId:r,sessionWebhook:n,update:e.update}),"utf-8"),setTimeout(()=>{console.log(`[${(0,c.timestamp)()}] \u6267\u884C pm2 restart ${g}${t?" (\u542B\u66F4\u65B0)":""}`),(0,B.exec)(`${t?`${t} && `:""}pm2 restart "${g}"`,{timeout:6e4},u=>{u&&console.error(`[${(0,c.timestamp)()}] pm2 restart \u5931\u8D25:`,u)})},1e3)})];for(const e of F)if(await e.tryHandle())return;if(!y){console.log(`\u672A\u6CE8\u518C\u7684\u673A\u5668\u4EBA,\u7FA4:${l},${s}`),this.isOwner(r)?await this.sendDingMessage({conversationId:s,sessionWebhook:n,content:"\u26A0\uFE0F \u8BE5\u7FA4\u672A\u6CE8\u518C\uFF0C\u8BF7\u5148\u4F7F\u7528 `/cfg` \u547D\u4EE4\u6CE8\u518C",msgType:"markdown"}):await this.sendDingMessage({conversationId:s,sessionWebhook:n,content:`\u62B1\u6B49,\u8BE5\u7FA4\u7684\u673A\u5668\u4EBA\u672A\u5728\u670D\u52A1\u7AEF\u6CE8\u518C,\u8BF7\u8054\u7CFB\u5E94\u7528\u673A\u5668\u4EBAowner\u6CE8\u518C(${s})...`});return}const Y=[(0,I.route)("/destroy",()=>(0,$.parseDestroyCommand)(h),async e=>{if(!await this.requireOwnerOrSingleChat(s,n,r,y))return;const a=e.conversationId||s;if(a!==s&&!this.isOwner(r)){await this.sendDingMessage({conversationId:s,sessionWebhook:n,content:"\u274C \u53EA\u6709 owner \u624D\u80FD\u64CD\u4F5C\u5176\u4ED6\u7FA4\u7684\u914D\u7F6E",msgType:"markdown"});return}const g=this.config.conversations.findIndex(A=>A.conversationId===a);if(g<0){await this.sendDingMessage({conversationId:s,sessionWebhook:n,content:"\u26A0\uFE0F \u8BE5\u7FA4\u672A\u5728\u914D\u7F6E\u4E2D\u6CE8\u518C\uFF0C\u65E0\u9700\u6CE8\u9500",msgType:"markdown"});return}const u=this.config.conversations[g].conversationTitle||a;this.config.conversations.splice(g,1);const m=this.getConversationDir(a);let T=!1;try{C.default.existsSync(m)&&(C.default.rmSync(m,{recursive:!0,force:!0}),T=!0)}catch(A){console.error(`[${(0,c.timestamp)()}] \u5220\u9664\u5DE5\u4F5C\u76EE\u5F55\u5931\u8D25:`,A)}const v=this.activeSessions.get(a);if(v?.currentProcess)try{v.currentProcess.kill("SIGTERM")}catch{}this.activeSessions.delete(a),this.recorderModeConversations.delete(a),(0,S.saveClientConfig)(this),console.log(`[${(0,c.timestamp)()}] \u5DF2\u6CE8\u9500\u7FA4: ${u}(${a})`);const w=["\u2705 \u7FA4\u673A\u5668\u4EBA\u5DF2\u6CE8\u9500",`- **\u7FA4\u540D\u79F0:** ${u}`,`- **\u7FA4ID:** ${a}`];T?w.push("- **\u5DE5\u4F5C\u76EE\u5F55:** \u5DF2\u5220\u9664"):w.push("- **\u5DE5\u4F5C\u76EE\u5F55:** (\u4E0D\u5B58\u5728\u6216\u65E0\u6CD5\u5220\u9664)"),v&&w.push("- **\u6D3B\u8DC3\u4F1A\u8BDD:** \u5DF2\u6E05\u9664"),w.push(`
25
+ \u26A0\uFE0F \u8BE5\u7FA4\u4E0B\u6B21\u53D1\u9001\u6D88\u606F\u65F6\u5C06\u6536\u5230"\u672A\u6CE8\u518C"\u63D0\u793A`),w.push("\u{1F4A1} \u5982\u9700\u91CD\u65B0\u6CE8\u518C\uFF0C\u8BF7\u4F7F\u7528 `/cfg` \u547D\u4EE4"),await this.sendDingMessage({conversationId:s,sessionWebhook:n,content:w.join(`
26
+ `),msgType:"markdown"})}),(0,I.route)("/freedom",()=>(0,$.parseFreedomCommand)(h),async e=>{if(await this.requireOwnerOrSingleChat(s,n,r,y)){if(e.action==="enter"){if(y?.freedomMode){await this.sendDingMessage({conversationId:s,sessionWebhook:n,content:"\u2139\uFE0F \u5F53\u524D\u5DF2\u5904\u4E8E\u81EA\u7531\u6A21\u5F0F",msgType:"markdown"});return}this.pendingFreedomConvs.set(s,Date.now()),await this.sendDingMessage({conversationId:s,sessionWebhook:n,content:`\u26A0\uFE0F \u5F00\u542F\u81EA\u7531\u6A21\u5F0F\u540E\uFF0C\u6240\u6709\u7FA4\u6210\u5458\u5747\u53EF\u4F7F\u7528\u673A\u5668\u4EBA\uFF08\u8DF3\u8FC7\u767D\u540D\u5355\u9650\u5236\uFF09
27
+
28
+ 60 \u79D2\u5185\u56DE\u590D\u300C\u786E\u8BA4\u300D\u6216\u300Cconfirm\u300D\u5373\u53EF\u5F00\u542F`,msgType:"markdown"})}else if(e.action==="exit"){if(!y?.freedomMode){await this.sendDingMessage({conversationId:s,sessionWebhook:n,content:"\u2139\uFE0F \u5F53\u524D\u672A\u5F00\u542F\u81EA\u7531\u6A21\u5F0F",msgType:"markdown"});return}y.freedomMode=!1,(0,S.saveClientConfig)(this),this.pendingFreedomConvs.delete(s),await this.sendDingMessage({conversationId:s,sessionWebhook:n,content:`\u2705 \u81EA\u7531\u6A21\u5F0F\u5DF2\u5173\u95ED
29
+ \u{1F512} \u5DF2\u6062\u590D\u767D\u540D\u5355\u9650\u5236`,msgType:"markdown"})}}}),(0,I.route)("/clean",()=>(0,$.parseCleanCommand)(h),async e=>{if(e==="all"&&y?.conversationType!=="1"&&!this.isOwner(r)){await this.sendDingMessage({conversationId:s,sessionWebhook:n,content:"\u274C \u53EA\u6709\u673A\u5668\u4EBA owner \u624D\u80FD\u6E05\u9664\u6240\u6709\u7FA4\u7F13\u5B58",msgType:"markdown"});return}if(!await this.requireOwnerOrSingleChat(s,n,r,y))return;const a=e==="all"?null:s,t=this.cleanCache(a,!0),g=[];g.push("\u{1F9F9} \u7F13\u5B58\u6E05\u7406\u5B8C\u6210"),t.sessionsDeleted>0&&g.push(`- \u4F1A\u8BDD\u76EE\u5F55: ${t.sessionsDeleted} \u4E2A`),t.tasksDeleted>0&&g.push(`- \u4EFB\u52A1\u76EE\u5F55: ${t.tasksDeleted} \u4E2A`),t.imagesDeleted>0&&g.push(`- \u56FE\u7247\u6587\u4EF6: ${t.imagesDeleted} \u4E2A`),t.sessionsDeleted===0&&t.tasksDeleted===0&&t.imagesDeleted===0&&g.push("(\u65E0\u5386\u53F2\u6570\u636E)"),g.push(`
24
30
  \u{1F4A1} \u6D3B\u8DC3\u4F1A\u8BDD\u5DF2\u4FDD\u7559`),t.errors.length>0&&g.push(`
25
31
  \u26A0\uFE0F \u9519\u8BEF: ${t.errors.join("; ")}`),await this.sendDingMessage({conversationId:s,sessionWebhook:n,content:g.join(`
26
- `),msgType:"markdown"})}),(0,v.route)("/reset-apikeycfg",()=>(0,I.parseResetApiKeyCfgCommand)(f),async()=>{if(!await this.requireOwner(s,n,a))return;if(!this.config.apiKeyCfg){await this.sendDingMessage({conversationId:s,sessionWebhook:n,content:"\u26A0\uFE0F \u672A\u914D\u7F6E apiKeyCfg\uFF0C\u65E0\u9700\u91CD\u7F6E",msgType:"markdown"});return}(0,L.resetApiKeyCfg)(this);const e=this.config.apiKeyCfg.claudeSettings.filter(r=>r.isValid).length;await this.sendDingMessage({conversationId:s,sessionWebhook:n,content:`\u2705 apiKeyCfg \u5DF2\u91CD\u7F6E
32
+ `),msgType:"markdown"})}),(0,I.route)("/reset-apikeycfg",()=>(0,$.parseResetApiKeyCfgCommand)(h),async()=>{if(!await this.requireOwner(s,n,r))return;if(!this.config.apiKeyCfg){await this.sendDingMessage({conversationId:s,sessionWebhook:n,content:"\u26A0\uFE0F \u672A\u914D\u7F6E apiKeyCfg\uFF0C\u65E0\u9700\u91CD\u7F6E",msgType:"markdown"});return}(0,S.resetApiKeyCfg)(this);const e=this.config.apiKeyCfg.claudeSettings.filter(a=>a.isValid).length;await this.sendDingMessage({conversationId:s,sessionWebhook:n,content:`\u2705 apiKeyCfg \u5DF2\u91CD\u7F6E
27
33
  - \u6709\u6548 Key \u6570: ${e}/${this.config.apiKeyCfg.claudeSettings.length}
28
- - \u91CD\u7F6E\u65F6\u95F4: ${this.config.apiKeyCfg.resetTime||"-"}`,msgType:"markdown"})}),(0,v.route)("/auth",()=>(0,I.parseAuthCommand)(f),async e=>{if(!await this.requireOwner(s,n,a))return;if(e.type==="approve"||e.type==="reject"){const t=this.pendingAuthRequests.get(e.requestId);if(!t){await this.sendDingMessage({conversationId:s,sessionWebhook:n,content:`\u274C \u672A\u627E\u5230\u6388\u6743\u7533\u8BF7: ${e.requestId}`,msgType:"markdown"});return}if(this.pendingAuthRequests.delete(e.requestId),e.type==="approve"){let g=this.config.conversations.find(u=>u.conversationId===t.conversationId);g||(g={conversationId:t.conversationId,conversationType:t.conversationType||"1",conversationTitle:t.conversationTitle},this.config.conversations.push(g)),g.whiteUserList||(g.whiteUserList=[]),g.whiteUserList.includes(t.senderStaffId)||g.whiteUserList.push(t.senderStaffId),(0,L.saveClientConfig)(this),console.log(`[${(0,c.timestamp)()}] \u6388\u6743\u7533\u8BF7\u901A\u8FC7\u5C06: id=${e.requestId}, userId=${t.senderStaffId}`),await(0,K.sendMessageToUser)(this,t.senderStaffId,"\u2705 \u60A8\u7684\u6388\u6743\u7533\u8BF7\u5DF2\u901A\u8FC7\uFF0C\u73B0\u5728\u53EF\u4EE5\u5F00\u59CB\u4F7F\u7528\u4E86","markdown"),await this.sendDingMessage({conversationId:s,sessionWebhook:n,content:`\u2705 \u5DF2\u901A\u8FC7\u6388\u6743\u7533\u8BF7
34
+ - \u91CD\u7F6E\u65F6\u95F4: ${this.config.apiKeyCfg.resetTime||"-"}`,msgType:"markdown"})}),(0,I.route)("/auth",()=>(0,$.parseAuthCommand)(h),async e=>{if(!await this.requireOwner(s,n,r))return;if(e.type==="approve"||e.type==="reject"){const t=this.pendingAuthRequests.get(e.requestId);if(!t){await this.sendDingMessage({conversationId:s,sessionWebhook:n,content:`\u274C \u672A\u627E\u5230\u6388\u6743\u7533\u8BF7: ${e.requestId}`,msgType:"markdown"});return}if(this.pendingAuthRequests.delete(e.requestId),e.type==="approve"){let g=this.config.conversations.find(p=>p.conversationId===t.conversationId);g||(g={conversationId:t.conversationId,conversationType:t.conversationType||"1",conversationTitle:t.conversationTitle},this.config.conversations.push(g)),g.whiteUserList||(g.whiteUserList=[]),g.whiteUserList.includes(t.senderStaffId)||g.whiteUserList.push(t.senderStaffId),(0,S.saveClientConfig)(this),console.log(`[${(0,c.timestamp)()}] \u6388\u6743\u7533\u8BF7\u901A\u8FC7\u5C06: id=${e.requestId}, userId=${t.senderStaffId}`),await(0,K.sendMessageToUser)(this,t.senderStaffId,"\u2705 \u60A8\u7684\u6388\u6743\u7533\u8BF7\u5DF2\u901A\u8FC7\uFF0C\u73B0\u5728\u53EF\u4EE5\u5F00\u59CB\u4F7F\u7528\u4E86","markdown"),await this.sendDingMessage({conversationId:s,sessionWebhook:n,content:`\u2705 \u5DF2\u901A\u8FC7\u6388\u6743\u7533\u8BF7
29
35
  - **\u7528\u6237ID:** ${t.senderStaffId}
30
36
  - **\u6635\u79F0:** ${t.senderNick}
31
37
  - **\u4F1A\u8BDDID:** ${t.conversationId}`,msgType:"markdown"})}else console.log(`[${(0,c.timestamp)()}] \u6388\u6743\u7533\u8BF7\u62D2\u7EDD: id=${e.requestId}, userId=${t.senderStaffId}`),await(0,K.sendMessageToUser)(this,t.senderStaffId,"\u274C \u60A8\u7684\u6388\u6743\u7533\u8BF7\u5DF2\u88AB\u62D2\u7EDD","markdown"),await this.sendDingMessage({conversationId:s,sessionWebhook:n,content:`\u2705 \u5DF2\u62D2\u7EDD\u6388\u6743\u7533\u8BF7
32
38
  - **\u7528\u6237ID:** ${t.senderStaffId}
33
- - **\u6635\u79F0:** ${t.senderNick}`,msgType:"markdown"});return}const r=y.whiteUserList;if(e.type==="list"){const t=r&&r.length>0?r.map(g=>`- ${(0,c.userIdToPhone)(this,g)||g}`).join(`
39
+ - **\u6635\u79F0:** ${t.senderNick}`,msgType:"markdown"});return}const a=y.whiteUserList;if(e.type==="list"){const t=a&&a.length>0?a.map(g=>`- ${(0,c.userIdToPhone)(this,g)||g}`).join(`
34
40
  `):"(\u672A\u914D\u7F6E\u7FA4\u7EA7\u767D\u540D\u5355\uFF0C\u4F7F\u7528\u5168\u5C40\u767D\u540D\u5355)";await this.sendDingMessage({conversationId:s,sessionWebhook:n,content:`\u{1F4CB} **\u5F53\u524D\u7FA4\u767D\u540D\u5355**
35
41
  ${t}`,msgType:"markdown"});return}if(e.type==="adminList"){const t=this.config.adminUserList&&this.config.adminUserList.length>0?this.config.adminUserList.map(g=>`- ${(0,c.userIdToPhone)(this,g)||g}`).join(`
36
42
  `):"(\u672A\u914D\u7F6E\u7BA1\u7406\u5458)";await this.sendDingMessage({conversationId:s,sessionWebhook:n,content:`\u{1F451} **\u7BA1\u7406\u5458\u5217\u8868**
37
- ${t}`,msgType:"markdown"});return}if(e.type==="adminAdd"){let t=e.staffId;if((0,c.isMobile)(e.staffId)&&(t=await(0,c.resolveUserId)(this,e.staffId),!t)){await this.sendDingMessage({conversationId:s,sessionWebhook:n,content:`\u26A0\uFE0F \u65E0\u6CD5\u89E3\u6790\u624B\u673A\u53F7: ${e.staffId}`,msgType:"markdown"});return}if(this.config.adminUserList?.some(m=>(0,c.resolveToUserId)(this,m)===t)){const m=(0,c.userIdToPhone)(this,t)||t;await this.sendDingMessage({conversationId:s,sessionWebhook:n,content:`\u26A0\uFE0F ${m} \u5DF2\u5728\u7BA1\u7406\u5458\u5217\u8868\u4E2D`,msgType:"markdown"});return}this.config.adminUserList||(this.config.adminUserList=[]),this.config.adminUserList.push(e.staffId),(0,L.saveClientConfig)(this);const u=(0,c.isMobile)(e.staffId)?e.staffId:(0,c.userIdToPhone)(this,e.staffId)||e.staffId;await this.sendDingMessage({conversationId:s,sessionWebhook:n,content:`\u2705 \u5DF2\u6DFB\u52A0 ${u} \u5230\u7BA1\u7406\u5458\u5217\u8868`,msgType:"markdown"});return}if(e.type==="adminRm"){let t=e.staffId;if((0,c.isMobile)(e.staffId)&&(t=await(0,c.resolveUserId)(this,e.staffId),!t)){await this.sendDingMessage({conversationId:s,sessionWebhook:n,content:`\u26A0\uFE0F \u65E0\u6CD5\u89E3\u6790\u624B\u673A\u53F7: ${e.staffId}`,msgType:"markdown"});return}const g=this.config.adminUserList?.findIndex(p=>(0,c.resolveToUserId)(this,p)===t)??-1;if(g<0){const p=(0,c.userIdToPhone)(this,t)||t;await this.sendDingMessage({conversationId:s,sessionWebhook:n,content:`\u26A0\uFE0F ${p} \u4E0D\u5728\u7BA1\u7406\u5458\u5217\u8868\u4E2D`,msgType:"markdown"});return}const u=this.config.adminUserList[g];this.config.adminUserList.splice(g,1),this.config.adminUserList.length===0&&delete this.config.adminUserList,(0,L.saveClientConfig)(this);const m=(0,c.userIdToPhone)(this,t)||u;await this.sendDingMessage({conversationId:s,sessionWebhook:n,content:`\u2705 \u5DF2\u79FB\u9664 ${m}`,msgType:"markdown"});return}if(e.type==="add"){let t=e.staffId;if((0,c.isMobile)(e.staffId)&&(t=await(0,c.resolveUserId)(this,e.staffId),!t)){await this.sendDingMessage({conversationId:s,sessionWebhook:n,content:`\u26A0\uFE0F \u65E0\u6CD5\u89E3\u6790\u624B\u673A\u53F7: ${e.staffId}`,msgType:"markdown"});return}if(r?.some(p=>(0,c.resolveToUserId)(this,p)===t)){const p=(0,c.userIdToPhone)(this,t)||t;await this.sendDingMessage({conversationId:s,sessionWebhook:n,content:`\u26A0\uFE0F ${p} \u5DF2\u5728\u5F53\u524D\u7FA4\u767D\u540D\u5355\u4E2D`,msgType:"markdown"});return}y.whiteUserList||(y.whiteUserList=[]),y.whiteUserList.push(e.staffId),(0,L.saveClientConfig)(this);const u=y.whiteUserList.map(p=>{const D=(0,c.resolveToUserId)(this,p);return(0,c.userIdToPhone)(this,D)||p}),m=(0,c.isMobile)(e.staffId)?e.staffId:(0,c.userIdToPhone)(this,e.staffId)||e.staffId;await this.sendDingMessage({conversationId:s,sessionWebhook:n,content:`\u2705 \u5DF2\u6DFB\u52A0 ${m} \u5230\u5F53\u524D\u7FA4\u767D\u540D\u5355
38
- \u5F53\u524D\u767D\u540D\u5355: ${u.join(", ")}`,msgType:"markdown"});return}if(e.type==="del"){let t=e.staffId;if((0,c.isMobile)(e.staffId)&&(t=await(0,c.resolveUserId)(this,e.staffId),!t)){await this.sendDingMessage({conversationId:s,sessionWebhook:n,content:`\u26A0\uFE0F \u65E0\u6CD5\u89E3\u6790\u624B\u673A\u53F7: ${e.staffId}`,msgType:"markdown"});return}const g=r?.findIndex(D=>(0,c.resolveToUserId)(this,D)===t)??-1;if(g<0){const D=(0,c.userIdToPhone)(this,t)||t;await this.sendDingMessage({conversationId:s,sessionWebhook:n,content:`\u26A0\uFE0F ${D} \u4E0D\u5728\u5F53\u524D\u7FA4\u767D\u540D\u5355\u4E2D`,msgType:"markdown"});return}const u=y.whiteUserList[g];y.whiteUserList.splice(g,1),y.whiteUserList.length===0&&delete y.whiteUserList,(0,L.saveClientConfig)(this);const m=y.whiteUserList?.length?y.whiteUserList.map(D=>{const $=(0,c.resolveToUserId)(this,D);return(0,c.userIdToPhone)(this,$)||D}).join(", "):"(\u7A7A\uFF0C\u4F7F\u7528\u5168\u5C40\u767D\u540D\u5355)",p=(0,c.userIdToPhone)(this,t)||u;await this.sendDingMessage({conversationId:s,sessionWebhook:n,content:`\u2705 \u5DF2\u79FB\u9664 ${p}
39
- \u5F53\u524D\u767D\u540D\u5355: ${m}`,msgType:"markdown"});return}}),(0,v.route)("/open",()=>(0,I.parseOpenCommand)(f),async e=>{if(!await this.requireOwner(s,n,a))return;const r=this.getConversationDir(s),t=process.platform,g=(u,m,p)=>new Promise((D,$)=>{const T=(0,_.spawnCommand)(u,m,{cwd:p,detached:!0,stdio:"ignore"});T.once("error",$),T.once("spawn",()=>{T.unref(),D()})});try{if(e==="folder"){if(t==="darwin")await g("open",[r]);else if((0,_.isWindowsPlatform)(t))await g("explorer.exe",[r]);else if((0,_.commandExists)("xdg-open"))await g("xdg-open",[r]);else throw new Error("\u672A\u68C0\u6D4B\u5230\u53EF\u7528\u7684\u6587\u4EF6\u7BA1\u7406\u5668\u6253\u5F00\u547D\u4EE4");await this.sendDingMessage({conversationId:s,sessionWebhook:n,content:`\u{1F4C2} \u5DF2\u5728\u6587\u4EF6\u7BA1\u7406\u5668\u4E2D\u6253\u5F00:
43
+ ${t}`,msgType:"markdown"});return}if(e.type==="adminAdd"){let t=e.staffId;if((0,c.isMobile)(e.staffId)&&(t=await(0,c.resolveUserId)(this,e.staffId),!t)){await this.sendDingMessage({conversationId:s,sessionWebhook:n,content:`\u26A0\uFE0F \u65E0\u6CD5\u89E3\u6790\u624B\u673A\u53F7: ${e.staffId}`,msgType:"markdown"});return}if(this.config.adminUserList?.some(u=>(0,c.resolveToUserId)(this,u)===t)){const u=(0,c.userIdToPhone)(this,t)||t;await this.sendDingMessage({conversationId:s,sessionWebhook:n,content:`\u26A0\uFE0F ${u} \u5DF2\u5728\u7BA1\u7406\u5458\u5217\u8868\u4E2D`,msgType:"markdown"});return}this.config.adminUserList||(this.config.adminUserList=[]),this.config.adminUserList.push(e.staffId),(0,S.saveClientConfig)(this);const p=(0,c.isMobile)(e.staffId)?e.staffId:(0,c.userIdToPhone)(this,e.staffId)||e.staffId;await this.sendDingMessage({conversationId:s,sessionWebhook:n,content:`\u2705 \u5DF2\u6DFB\u52A0 ${p} \u5230\u7BA1\u7406\u5458\u5217\u8868`,msgType:"markdown"});return}if(e.type==="adminRm"){let t=e.staffId;if((0,c.isMobile)(e.staffId)&&(t=await(0,c.resolveUserId)(this,e.staffId),!t)){await this.sendDingMessage({conversationId:s,sessionWebhook:n,content:`\u26A0\uFE0F \u65E0\u6CD5\u89E3\u6790\u624B\u673A\u53F7: ${e.staffId}`,msgType:"markdown"});return}const g=this.config.adminUserList?.findIndex(m=>(0,c.resolveToUserId)(this,m)===t)??-1;if(g<0){const m=(0,c.userIdToPhone)(this,t)||t;await this.sendDingMessage({conversationId:s,sessionWebhook:n,content:`\u26A0\uFE0F ${m} \u4E0D\u5728\u7BA1\u7406\u5458\u5217\u8868\u4E2D`,msgType:"markdown"});return}const p=this.config.adminUserList[g];this.config.adminUserList.splice(g,1),this.config.adminUserList.length===0&&delete this.config.adminUserList,(0,S.saveClientConfig)(this);const u=(0,c.userIdToPhone)(this,t)||p;await this.sendDingMessage({conversationId:s,sessionWebhook:n,content:`\u2705 \u5DF2\u79FB\u9664 ${u}`,msgType:"markdown"});return}if(e.type==="add"){let t=e.staffId;if((0,c.isMobile)(e.staffId)&&(t=await(0,c.resolveUserId)(this,e.staffId),!t)){await this.sendDingMessage({conversationId:s,sessionWebhook:n,content:`\u26A0\uFE0F \u65E0\u6CD5\u89E3\u6790\u624B\u673A\u53F7: ${e.staffId}`,msgType:"markdown"});return}if(a?.some(m=>(0,c.resolveToUserId)(this,m)===t)){const m=(0,c.userIdToPhone)(this,t)||t;await this.sendDingMessage({conversationId:s,sessionWebhook:n,content:`\u26A0\uFE0F ${m} \u5DF2\u5728\u5F53\u524D\u7FA4\u767D\u540D\u5355\u4E2D`,msgType:"markdown"});return}y.whiteUserList||(y.whiteUserList=[]),y.whiteUserList.push(e.staffId),(0,S.saveClientConfig)(this);const p=y.whiteUserList.map(m=>{const T=(0,c.resolveToUserId)(this,m);return(0,c.userIdToPhone)(this,T)||m}),u=(0,c.isMobile)(e.staffId)?e.staffId:(0,c.userIdToPhone)(this,e.staffId)||e.staffId;await this.sendDingMessage({conversationId:s,sessionWebhook:n,content:`\u2705 \u5DF2\u6DFB\u52A0 ${u} \u5230\u5F53\u524D\u7FA4\u767D\u540D\u5355
44
+ \u5F53\u524D\u767D\u540D\u5355: ${p.join(", ")}`,msgType:"markdown"});return}if(e.type==="del"){let t=e.staffId;if((0,c.isMobile)(e.staffId)&&(t=await(0,c.resolveUserId)(this,e.staffId),!t)){await this.sendDingMessage({conversationId:s,sessionWebhook:n,content:`\u26A0\uFE0F \u65E0\u6CD5\u89E3\u6790\u624B\u673A\u53F7: ${e.staffId}`,msgType:"markdown"});return}const g=a?.findIndex(T=>(0,c.resolveToUserId)(this,T)===t)??-1;if(g<0){const T=(0,c.userIdToPhone)(this,t)||t;await this.sendDingMessage({conversationId:s,sessionWebhook:n,content:`\u26A0\uFE0F ${T} \u4E0D\u5728\u5F53\u524D\u7FA4\u767D\u540D\u5355\u4E2D`,msgType:"markdown"});return}const p=y.whiteUserList[g];y.whiteUserList.splice(g,1),y.whiteUserList.length===0&&delete y.whiteUserList,(0,S.saveClientConfig)(this);const u=y.whiteUserList?.length?y.whiteUserList.map(T=>{const v=(0,c.resolveToUserId)(this,T);return(0,c.userIdToPhone)(this,v)||T}).join(", "):"(\u7A7A\uFF0C\u4F7F\u7528\u5168\u5C40\u767D\u540D\u5355)",m=(0,c.userIdToPhone)(this,t)||p;await this.sendDingMessage({conversationId:s,sessionWebhook:n,content:`\u2705 \u5DF2\u79FB\u9664 ${m}
45
+ \u5F53\u524D\u767D\u540D\u5355: ${u}`,msgType:"markdown"});return}}),(0,I.route)("/open",()=>(0,$.parseOpenCommand)(h),async e=>{if(!await this.requireOwner(s,n,r))return;const a=this.getConversationDir(s),t=process.platform,g=(p,u,m)=>new Promise((T,v)=>{const w=(0,U.spawnCommand)(p,u,{cwd:m,detached:!0,stdio:"ignore"});w.once("error",v),w.once("spawn",()=>{w.unref(),T()})});try{if(e==="folder"){if(t==="darwin")await g("open",[a]);else if((0,U.isWindowsPlatform)(t))await g("explorer.exe",[a]);else if((0,U.commandExists)("xdg-open"))await g("xdg-open",[a]);else throw new Error("\u672A\u68C0\u6D4B\u5230\u53EF\u7528\u7684\u6587\u4EF6\u7BA1\u7406\u5668\u6253\u5F00\u547D\u4EE4");await this.sendDingMessage({conversationId:s,sessionWebhook:n,content:`\u{1F4C2} \u5DF2\u5728\u6587\u4EF6\u7BA1\u7406\u5668\u4E2D\u6253\u5F00:
40
46
  \`\`\`
41
- ${r}
42
- \`\`\``,msgType:"markdown"})}else if(e==="code"){if(!(0,_.commandExists)("code")){await this.sendDingMessage({conversationId:s,sessionWebhook:n,content:"\u274C \u672A\u68C0\u6D4B\u5230 VS Code `code` \u547D\u4EE4\n\u8BF7\u5B89\u88C5 VS Code \u5E76\u786E\u8BA4 `code` \u5DF2\u52A0\u5165 PATH",msgType:"markdown"});return}await g("code",[r]),await this.sendDingMessage({conversationId:s,sessionWebhook:n,content:`\u{1F4BB} \u5DF2\u5728 VS Code \u4E2D\u6253\u5F00:
47
+ ${a}
48
+ \`\`\``,msgType:"markdown"})}else if(e==="code"){if(!(0,U.commandExists)("code")){await this.sendDingMessage({conversationId:s,sessionWebhook:n,content:"\u274C \u672A\u68C0\u6D4B\u5230 VS Code `code` \u547D\u4EE4\n\u8BF7\u5B89\u88C5 VS Code \u5E76\u786E\u8BA4 `code` \u5DF2\u52A0\u5165 PATH",msgType:"markdown"});return}await g("code",[a]),await this.sendDingMessage({conversationId:s,sessionWebhook:n,content:`\u{1F4BB} \u5DF2\u5728 VS Code \u4E2D\u6253\u5F00:
43
49
  \`\`\`
44
- ${r}
45
- \`\`\``,msgType:"markdown"})}else{if(t==="darwin")await g("open",["-a","Terminal",r]);else if((0,_.isWindowsPlatform)(t))await g("cmd.exe",["/K","cd","/d",r]);else if((0,_.commandExists)("x-terminal-emulator"))await g("x-terminal-emulator",[],r);else throw new Error("\u672A\u68C0\u6D4B\u5230\u53EF\u7528\u7684\u7EC8\u7AEF\u6253\u5F00\u547D\u4EE4");await this.sendDingMessage({conversationId:s,sessionWebhook:n,content:`\u{1F4BB} \u5DF2\u5728\u7EC8\u7AEF\u4E2D\u6253\u5F00:
50
+ ${a}
51
+ \`\`\``,msgType:"markdown"})}else{if(t==="darwin")await g("open",["-a","Terminal",a]);else if((0,U.isWindowsPlatform)(t))await g("cmd.exe",["/K","cd","/d",a]);else if((0,U.commandExists)("x-terminal-emulator"))await g("x-terminal-emulator",[],a);else throw new Error("\u672A\u68C0\u6D4B\u5230\u53EF\u7528\u7684\u7EC8\u7AEF\u6253\u5F00\u547D\u4EE4");await this.sendDingMessage({conversationId:s,sessionWebhook:n,content:`\u{1F4BB} \u5DF2\u5728\u7EC8\u7AEF\u4E2D\u6253\u5F00:
46
52
  \`\`\`
47
- ${r}
48
- \`\`\``,msgType:"markdown"})}}catch(u){await this.sendDingMessage({conversationId:s,sessionWebhook:n,content:`\u274C \u6253\u5F00\u5931\u8D25: ${u instanceof Error?u.message:String(u)}`,msgType:"markdown"})}}),(0,v.route)("/cron",()=>(0,I.parseCronCommand)(f),async e=>{await this.handleCronCommand(e,{conversationId:s,sessionWebhook:n,senderStaffId:a,senderNick:o,conversationConfig:y})}),(0,v.route)("/todo",()=>(0,X.parseTodoCommand)(f,i.atUsers),async e=>{await this.handleTodoCommand(e,{conversationId:s,sessionWebhook:n,senderStaffId:a,senderNick:o})}),(0,v.route)("/menu",()=>(0,I.parseMenuCommand)(f),async e=>{await this.handleMenuCommand(e,{conversationId:s,sessionWebhook:n,senderStaffId:a})}),(0,v.route)("/bash",()=>(0,I.parseBashCommand)(f),async e=>{if(!await this.requireOwnerOrAdmin(s,n,a))return;this.appendBashAudit(s,a,e);const r=this.getConversationDir(s),t=[];this.config.preBash&&t.push(this.config.preBash),y?.preBash&&t.push(y.preBash);const g=(0,_.isWindowsPlatform)()?" && ":" ; ",u=t.length>0?[...t,e].join(g):e,m=this;(0,B.exec)(u,{cwd:r,timeout:3e4,maxBuffer:1024*1024},async(p,D,$)=>{try{let T;if(p)T=`\u274C \u547D\u4EE4\u6267\u884C\u5931\u8D25
53
+ ${a}
54
+ \`\`\``,msgType:"markdown"})}}catch(p){await this.sendDingMessage({conversationId:s,sessionWebhook:n,content:`\u274C \u6253\u5F00\u5931\u8D25: ${p instanceof Error?p.message:String(p)}`,msgType:"markdown"})}}),(0,I.route)("/cron",()=>(0,$.parseCronCommand)(h),async e=>{await this.handleCronCommand(e,{conversationId:s,sessionWebhook:n,senderStaffId:r,senderNick:o,conversationConfig:y})}),(0,I.route)("/todo",()=>(0,Z.parseTodoCommand)(h,i.atUsers),async e=>{await this.handleTodoCommand(e,{conversationId:s,sessionWebhook:n,senderStaffId:r,senderNick:o})}),(0,I.route)("/menu",()=>(0,$.parseMenuCommand)(h),async e=>{await this.handleMenuCommand(e,{conversationId:s,sessionWebhook:n,senderStaffId:r})}),(0,I.route)("/bash",()=>(0,$.parseBashCommand)(h),async e=>{if(!await this.requireOwnerOrAdmin(s,n,r))return;this.appendBashAudit(s,r,e);const a=this.getConversationDir(s),t=[];this.config.preBash&&t.push(this.config.preBash),y?.preBash&&t.push(y.preBash);const g=(0,U.isWindowsPlatform)()?" && ":" ; ",p=t.length>0?[...t,e].join(g):e,u=this;(0,B.exec)(p,{cwd:a,timeout:3e4,maxBuffer:1024*1024},async(m,T,v)=>{try{let w;if(m)w=`\u274C \u547D\u4EE4\u6267\u884C\u5931\u8D25
49
55
  \`\`\`
50
- ${p.message}
51
- \`\`\``,$&&(T+=`
56
+ ${m.message}
57
+ \`\`\``,v&&(w+=`
52
58
 
53
59
  **stderr:**
54
60
  \`\`\`
55
- ${m.sanitizeOutput($)}
56
- \`\`\``);else{const O=D||"(\u65E0\u8F93\u51FA)";T=`\u2705 \u6267\u884C\u6210\u529F
61
+ ${u.sanitizeOutput(v)}
62
+ \`\`\``);else{const A=T||"(\u65E0\u8F93\u51FA)";w=`\u2705 \u6267\u884C\u6210\u529F
57
63
  \`\`\`
58
- ${m.sanitizeOutput(O)}
59
- \`\`\``,$&&(T+=`
64
+ ${u.sanitizeOutput(A)}
65
+ \`\`\``,v&&(w+=`
60
66
 
61
67
  **stderr:**
62
68
  \`\`\`
63
- ${m.sanitizeOutput($)}
64
- \`\`\``)}await m.sendDingMessage({conversationId:s,sessionWebhook:n,content:T,msgType:"markdown"})}catch(T){console.error("[bash] \u53D1\u9001\u6D88\u606F\u5931\u8D25:",T)}})}),(0,v.route)("/new",()=>/^\/new(?:\s|$)/i.test(f),async()=>{const e=this.findActiveSession(s);e&&(console.log(`\u6536\u5230\u65B0\u4F1A\u8BDD\u547D\u4EE4\uFF0C\u7ED3\u675F\u65E7\u4F1A\u8BDD: \u7FA4=${e.session.session.conversationId}, \u4F1A\u8BDDID=${this.getSessionId(e.session.session)}`),this.interruptClaudeProcess(e.session,"\u65B0\u4F1A\u8BDD\u547D\u4EE4\u4E2D\u65AD\u6B63\u5728\u6267\u884C\u7684 Claude \u8FDB\u7A0B"),this.activeSessions.delete(e.key),this.saveActiveSession(e.key));const r=f.replace(/^\/new\s*/i,"").trim();r?await this.startNewSession({conversationId:s,sessionWebhook:n,senderStaffId:a,senderNick:o,message:r,conversationConfig:y}):await this.sendDingMessage({conversationId:s,sessionWebhook:n,atUserId:a,content:"\u{1F680} \u8BF7\u8F93\u5165\u60A8\u7684\u95EE\u9898\u5F00\u59CB\u65B0\u4F1A\u8BDD"})}),(0,v.route)("/resume",()=>(0,I.parseContinueSessionCommand)(f),async e=>{let r=e;if(!r){const t=(0,c.findLatestSession)(this,s);if(!t){await this.sendDingMessage({conversationId:s,sessionWebhook:n,atUserId:a,content:"\u26A0\uFE0F \u672A\u627E\u5230\u5DF2\u7ED3\u675F\u7684\u4F1A\u8BDD",msgType:"markdown"});return}r=(0,c.getSessionId)(t)}await this.switchToSession(s,n,r,a,y)}),(0,v.route)("/log",()=>(0,I.parseLogCommand)(f),async e=>{const r=this.readSessionLogTail(s,e);r?await this.sendDingMessage({conversationId:s,sessionWebhook:n,content:`\u{1F4CB} \u6700\u8FD1 ${e} \u884C\u65E5\u5FD7:
69
+ ${u.sanitizeOutput(v)}
70
+ \`\`\``)}await u.sendDingMessage({conversationId:s,sessionWebhook:n,content:w,msgType:"markdown"})}catch(w){console.error("[bash] \u53D1\u9001\u6D88\u606F\u5931\u8D25:",w)}})}),(0,I.route)("/new",()=>/^\/new(?:\s|$)/i.test(h),async()=>{const e=this.findActiveSession(s);e&&(console.log(`\u6536\u5230\u65B0\u4F1A\u8BDD\u547D\u4EE4\uFF0C\u7ED3\u675F\u65E7\u4F1A\u8BDD: \u7FA4=${e.session.session.conversationId}, \u4F1A\u8BDDID=${this.getSessionId(e.session.session)}`),this.interruptClaudeProcess(e.session,"\u65B0\u4F1A\u8BDD\u547D\u4EE4\u4E2D\u65AD\u6B63\u5728\u6267\u884C\u7684 Claude \u8FDB\u7A0B"),this.activeSessions.delete(e.key),this.saveActiveSession(e.key));const a=h.replace(/^\/new\s*/i,"").trim();a?await this.startNewSession({conversationId:s,sessionWebhook:n,senderStaffId:r,senderNick:o,message:a,conversationConfig:y}):await this.sendDingMessage({conversationId:s,sessionWebhook:n,content:"\u{1F680} \u8BF7\u8F93\u5165\u60A8\u7684\u95EE\u9898\u5F00\u59CB\u65B0\u4F1A\u8BDD"})}),(0,I.route)("/resume",()=>(0,$.parseContinueSessionCommand)(h),async e=>{let a=e;if(!a){const t=(0,c.findLatestSession)(this,s);if(!t){await this.sendDingMessage({conversationId:s,sessionWebhook:n,content:"\u26A0\uFE0F \u672A\u627E\u5230\u5DF2\u7ED3\u675F\u7684\u4F1A\u8BDD",msgType:"markdown"});return}a=(0,c.getSessionId)(t)}await this.switchToSession(s,n,a,r,y)}),(0,I.route)("/log",()=>(0,$.parseLogCommand)(h),async e=>{const a=this.readSessionLogTail(s,e);a?await this.sendDingMessage({conversationId:s,sessionWebhook:n,content:`\u{1F4CB} \u6700\u8FD1 ${e} \u884C\u65E5\u5FD7:
65
71
  \`\`\`
66
- ${r}
67
- \`\`\``,msgType:"markdown"}):await this.sendDingMessage({conversationId:s,sessionWebhook:n,content:"\u26A0\uFE0F \u5F53\u524D\u65E0\u6D3B\u8DC3\u4F1A\u8BDD\u6216\u6682\u65E0\u65E5\u5FD7"})}),(0,v.route)("/info",()=>(0,I.parseInfoCommand)(f),async e=>{const r=[],t=this.getConversationDir(s);if((e==="all"||e==="robot")&&(r.push(`### \u{1F310} \u5168\u5C40\u6838\u5FC3\u914D\u7F6E
68
- `+(0,I.formatGlobalConfig)(this.config)),r.push(`### \u{1F916} \u7FA4\u914D\u7F6E\u4FE1\u606F
69
- `+(0,I.formatConversationInfo)(y,s,g=>(0,c.userIdToPhone)(this,g),t))),e==="all"||e==="session"){const g=this.formatSessionInfo(s);g?r.push(`### \u{1F4AC} \u5F53\u524D\u4F1A\u8BDD\u4FE1\u606F
70
- `+g):r.push(`### \u{1F4AC} \u5F53\u524D\u4F1A\u8BDD\u4FE1\u606F
71
- \u65E0\u6D3B\u8DC3\u4F1A\u8BDD`)}(e==="all"||e==="task")&&r.push(`### \u{1F4DD} \u4EFB\u52A1\u961F\u5217\u4FE1\u606F
72
- `+this.formatTaskInfo()),await this.sendDingMessage({conversationId:s,sessionWebhook:n,content:r.join(`
72
+ ${a}
73
+ \`\`\``,msgType:"markdown"}):await this.sendDingMessage({conversationId:s,sessionWebhook:n,content:"\u26A0\uFE0F \u5F53\u524D\u65E0\u6D3B\u8DC3\u4F1A\u8BDD\u6216\u6682\u65E0\u65E5\u5FD7"})}),(0,I.route)("/info",()=>(0,$.parseInfoCommand)(h),async e=>{const a=[],t=this.getConversationDir(s);if((e==="all"||e==="robot")&&(a.push(`### \u{1F310} \u5168\u5C40\u6838\u5FC3\u914D\u7F6E
74
+ `+(0,$.formatGlobalConfig)(this.config)),a.push(`### \u{1F916} \u7FA4\u914D\u7F6E\u4FE1\u606F
75
+ `+(0,$.formatConversationInfo)(y,s,g=>(0,c.userIdToPhone)(this,g),t))),e==="all"||e==="session"){const g=this.formatSessionInfo(s);g?a.push(`### \u{1F4AC} \u5F53\u524D\u4F1A\u8BDD\u4FE1\u606F
76
+ `+g):a.push(`### \u{1F4AC} \u5F53\u524D\u4F1A\u8BDD\u4FE1\u606F
77
+ \u65E0\u6D3B\u8DC3\u4F1A\u8BDD`)}(e==="all"||e==="task")&&a.push(`### \u{1F4DD} \u4EFB\u52A1\u961F\u5217\u4FE1\u606F
78
+ `+this.formatTaskInfo()),await this.sendDingMessage({conversationId:s,sessionWebhook:n,content:a.join(`
73
79
 
74
- `),msgType:"markdown"})}),(0,v.route)("/ls",()=>(0,I.parseLsCommand)(f),async e=>{const{target:r,depth:t}=e,g=this.getConversationDir(s);let u=g,m="\u5F53\u524D\u5DE5\u4F5C\u76EE\u5F55";if(r&&r!=="root")if(r.startsWith("./")||r.startsWith("../")||r.startsWith("/")){const D=N.default.resolve(g,r);if(S.default.existsSync(D)&&S.default.statSync(D).isDirectory()){if(!D.startsWith(g)){await this.sendDingMessage({conversationId:s,sessionWebhook:n,content:"\u274C \u8DEF\u5F84\u8D85\u51FA\u5DE5\u4F5C\u76EE\u5F55\u8303\u56F4",msgType:"markdown"});return}u=D,m=r}else{await this.sendDingMessage({conversationId:s,sessionWebhook:n,content:`\u274C \u8DEF\u5F84\u4E0D\u5B58\u5728\u6216\u4E0D\u662F\u76EE\u5F55: **${r}**`,msgType:"markdown"});return}}else{const D=(0,I.findSubdirByName)(g,r);if(D)u=D,m=r;else{await this.sendDingMessage({conversationId:s,sessionWebhook:n,content:`\u274C \u672A\u627E\u5230\u540D\u4E3A **${r}** \u7684\u76EE\u5F55`,msgType:"markdown"});return}}const p=(0,I.getDirectoryStructure)(u,0,t);await this.sendDingMessage({conversationId:s,sessionWebhook:n,content:`\u{1F4C2} ${m} (\u5C55\u5F00${t}\u5C42):
80
+ `),msgType:"markdown"})}),(0,I.route)("/ls",()=>(0,$.parseLsCommand)(h),async e=>{const{target:a,depth:t}=e,g=this.getConversationDir(s);let p=g,u="\u5F53\u524D\u5DE5\u4F5C\u76EE\u5F55";if(a&&a!=="root")if(a.startsWith("./")||a.startsWith("../")||a.startsWith("/")){const T=R.default.resolve(g,a);if(C.default.existsSync(T)&&C.default.statSync(T).isDirectory()){if(!T.startsWith(g)){await this.sendDingMessage({conversationId:s,sessionWebhook:n,content:"\u274C \u8DEF\u5F84\u8D85\u51FA\u5DE5\u4F5C\u76EE\u5F55\u8303\u56F4",msgType:"markdown"});return}p=T,u=a}else{await this.sendDingMessage({conversationId:s,sessionWebhook:n,content:`\u274C \u8DEF\u5F84\u4E0D\u5B58\u5728\u6216\u4E0D\u662F\u76EE\u5F55: **${a}**`,msgType:"markdown"});return}}else{const T=(0,$.findSubdirByName)(g,a);if(T)p=T,u=a;else{await this.sendDingMessage({conversationId:s,sessionWebhook:n,content:`\u274C \u672A\u627E\u5230\u540D\u4E3A **${a}** \u7684\u76EE\u5F55`,msgType:"markdown"});return}}const m=(0,$.getDirectoryStructure)(p,0,t);await this.sendDingMessage({conversationId:s,sessionWebhook:n,content:`\u{1F4C2} ${u} (\u5C55\u5F00${t}\u5C42):
75
81
  \`\`\`
76
- ${p}
77
- \`\`\``,msgType:"markdown"})}),(0,v.route)("/task cancel",()=>(0,b.parseTaskCancelCommand)(f)||null,async e=>{const r=this.cancelTask(e,s);await this.sendDingMessage({conversationId:s,sessionWebhook:n,content:r,msgType:"markdown"})}),(0,v.route)("/task",()=>f.startsWith("/task ")||null,async()=>{const e=f.substring(6).trim();e&&(await this.sendDingMessage({conversationId:s,sessionWebhook:n,atUserId:a,content:"\u{1F4CB} \u4EFB\u52A1\u5DF2\u6536\u5230,\u5B8C\u6210\u540E\u6211\u4F1A\u56DE\u590D"}),await this.saveTask({conversationId:s,prompt:e,senderStaffId:a,senderNickName:o,sessionWebhook:n}))}),(0,v.route)("/mq",()=>(0,I.parseMqCommand)(f),async e=>{const t=this.findActiveSession(s)?.session.messageQueue??[];switch(e.type){case"list":{if(t.length===0)await this.sendDingMessage({conversationId:s,sessionWebhook:n,content:"\u{1F4ED} \u5F53\u524D\u65E0\u6392\u961F\u6D88\u606F",msgType:"markdown"});else{const g=t.map((u,m)=>`${m+1}. **${u.senderNick||u.senderStaffId}:** ${this.truncateMsg(u.message)}`);await this.sendDingMessage({conversationId:s,sessionWebhook:n,content:`\u{1F4E8} \u6D88\u606F\u961F\u5217 (${t.length} \u6761)
82
+ ${m}
83
+ \`\`\``,msgType:"markdown"})}),(0,I.route)("/task cancel",()=>(0,b.parseTaskCancelCommand)(h)||null,async e=>{const a=this.cancelTask(e,s);await this.sendDingMessage({conversationId:s,sessionWebhook:n,content:a,msgType:"markdown"})}),(0,I.route)("/task",()=>h.startsWith("/task ")||null,async()=>{const e=h.substring(6).trim();e&&(await this.sendDingMessage({conversationId:s,sessionWebhook:n,content:"\u{1F4CB} \u4EFB\u52A1\u5DF2\u6536\u5230,\u5B8C\u6210\u540E\u6211\u4F1A\u56DE\u590D"}),await this.saveTask({conversationId:s,prompt:e,senderStaffId:r,senderNickName:o,sessionWebhook:n}))}),(0,I.route)("/mq",()=>(0,$.parseMqCommand)(h),async e=>{const t=this.findActiveSession(s)?.session.messageQueue??[];switch(e.type){case"list":{if(t.length===0)await this.sendDingMessage({conversationId:s,sessionWebhook:n,content:"\u{1F4ED} \u5F53\u524D\u65E0\u6392\u961F\u6D88\u606F",msgType:"markdown"});else{const g=t.map((p,u)=>`${u+1}. **${p.senderNick||p.senderStaffId}:** ${this.truncateMsg(p.message)}`);await this.sendDingMessage({conversationId:s,sessionWebhook:n,content:`\u{1F4E8} \u6D88\u606F\u961F\u5217 (${t.length} \u6761)
78
84
  ${g.join(`
79
- `)}`,msgType:"markdown"})}return}case"front":{if(t.length===0){await this.sendDingMessage({conversationId:s,sessionWebhook:n,content:"\u{1F4ED} \u5F53\u524D\u65E0\u6392\u961F\u6D88\u606F",msgType:"markdown"});return}let g=t.length-1;for(let m=t.length-1;m>=0;m--)if(t[m].senderStaffId===a){g=m;break}if(g===0){await this.sendDingMessage({conversationId:s,sessionWebhook:n,content:"\u2139\uFE0F \u8BE5\u6D88\u606F\u5DF2\u5728\u961F\u9996\uFF0C\u65E0\u9700\u63D2\u961F",msgType:"markdown"});return}const[u]=t.splice(g,1);t.unshift(u),await this.sendDingMessage({conversationId:s,sessionWebhook:n,content:`\u2705 \u5DF2\u63D2\u961F\u5230\u961F\u9996
80
- 1. **${u.senderNick||u.senderStaffId}:** ${this.truncateMsg(u.message)}`,msgType:"markdown"});return}case"rm":{if(t.length===0){await this.sendDingMessage({conversationId:s,sessionWebhook:n,content:"\u{1F4ED} \u5F53\u524D\u65E0\u6392\u961F\u6D88\u606F",msgType:"markdown"});return}if(e.all){const T=t.length;t.length=0,await this.sendDingMessage({conversationId:s,sessionWebhook:n,content:`\u2705 \u5DF2\u6E05\u7A7A\u6D88\u606F\u961F\u5217\uFF0C\u5171\u79FB\u9664 ${T} \u6761\u6D88\u606F`,msgType:"markdown"});return}const g=[...new Set(e.indices)],u=g.filter(T=>T>=1&&T<=t.length).sort((T,O)=>O-T),m=g.filter(T=>T<1||T>t.length);if(u.length===0){await this.sendDingMessage({conversationId:s,sessionWebhook:n,content:`\u26A0\uFE0F \u5E8F\u53F7\u65E0\u6548\uFF0C\u5F53\u524D\u961F\u5217\u5171 ${t.length} \u6761`,msgType:"markdown"});return}const p=[];for(const T of u)p.unshift(t.splice(T-1,1)[0]);const D=p.map(T=>`- **${T.senderNick||T.senderStaffId}:** ${this.truncateMsg(T.message)}`);let $=`\u2705 \u5DF2\u5220\u9664 ${p.length} \u6761\u6D88\u606F
81
- ${D.join(`
82
- `)}`;m.length>0&&($+=`
83
- \u26A0\uFE0F \u5DF2\u5FFD\u7565\u65E0\u6548\u5E8F\u53F7: ${m.join(", ")}`),await this.sendDingMessage({conversationId:s,sessionWebhook:n,content:$,msgType:"markdown"});return}}}),(0,v.route)("/!",()=>(0,I.parseInterruptCommand)(f),async()=>{const e=this.findActiveSession(s);if(!e){await this.sendDingMessage({conversationId:s,sessionWebhook:n,content:"\u26A0\uFE0F \u5F53\u524D\u6CA1\u6709\u6D3B\u8DC3\u4F1A\u8BDD"});return}const r=e.session;if(!r.currentProcess){await this.sendDingMessage({conversationId:s,sessionWebhook:n,content:"\u2139\uFE0F \u5F53\u524D\u6CA1\u6709\u6B63\u5728\u6267\u884C\u7684\u4EFB\u52A1"});return}(0,x.interruptClaudeProcess)(r,`/!: ${o} \u4E2D\u65AD\u5F53\u524D\u4EFB\u52A1`);const t=r.messageQueue.length;await this.sendDingMessage({conversationId:s,sessionWebhook:n,content:t>0?`\u23F9 \u5DF2\u4E2D\u65AD\u5F53\u524D\u4EFB\u52A1\uFF0C\u5F00\u59CB\u5904\u7406\u961F\u5217\u4E2D\u7684 ${t} \u6761\u6D88\u606F`:"\u23F9 \u5DF2\u4E2D\u65AD\u5F53\u524D\u4EFB\u52A1"})}),(0,v.route)("/goon",()=>(0,I.parseGoonCommand)(f),async()=>{const e=this.activeSessions.get(s);if(!e){await this.sendDingMessage({conversationId:s,sessionWebhook:n,content:"\u26A0\uFE0F \u5F53\u524D\u6CA1\u6709\u6D3B\u8DC3\u4F1A\u8BDD"});return}if(e.currentProcess){console.log(`[${(0,c.timestamp)()}] /goon: \u7EC8\u6B62\u5F53\u524D Claude \u8FDB\u7A0B`),e.interrupted=!0,(0,_.isWindows)()?e.currentProcess.kill():e.currentProcess.kill("SIGINT"),await this.sendDingMessage({conversationId:s,sessionWebhook:n,content:"\u{1F504} \u6B63\u5728\u91CD\u542F Claude \u8FDB\u7A0B..."}),e.goonPending=!1,e.isProcessing=!0;try{await(0,x.executeClaudeQuery)(this,e.session,"\u7EE7\u7EED",{senderNick:e.session.startNickName,senderStaffId:e.lastSenderStaffId,permissionMode:e.conversationConfig.permissionMode})}finally{e.isProcessing=!1}}else{console.log(`[${(0,c.timestamp)()}] /goon: \u65E0\u8FD0\u884C\u4E2D\u8FDB\u7A0B\uFF0C\u76F4\u63A5\u53D1\u9001"\u7EE7\u7EED"`),e.isProcessing=!0;try{await(0,x.executeClaudeQuery)(this,e.session,"\u7EE7\u7EED",{senderNick:o,senderStaffId:a,permissionMode:e.conversationConfig.permissionMode})}finally{e.isProcessing=!1}}}),(0,v.route)("/cc",()=>(0,I.parseCcCommand)(f),async e=>{const r=this.activeSessions.get(s);if(!r){await this.sendDingMessage({conversationId:s,sessionWebhook:n,content:"\u26A0\uFE0F \u5F53\u524D\u6CA1\u6709\u6D3B\u8DC3\u4F1A\u8BDD\uFF0C\u8BF7\u5148\u53D1\u9001\u6D88\u606F\u5F00\u59CB\u4F1A\u8BDD"});return}if(r.isProcessing){await this.sendDingMessage({conversationId:s,sessionWebhook:n,content:"\u23F3 \u6B63\u5728\u5904\u7406\u4E2D\uFF0C\u8BF7\u7A0D\u7B49..."});return}r.isProcessing=!0;try{r.conversationConfig.receiveReply!==!1&&await this.sendDingMessage({conversationId:s,sessionWebhook:n,atUserId:a,content:"\u{1F4E5} \u5DF2\u6536\u5230\uFF0C\u6B63\u5728\u5904\u7406..."}).catch(()=>{}),await(0,x.executeClaudeQuery)(this,r.session,e,{senderNick:o,senderStaffId:a,permissionMode:r.conversationConfig.permissionMode})}finally{r.isProcessing=!1}}),(0,v.route)("/claude.md",()=>(0,I.parseClaudeMdCommand)(f),async()=>{const e=this.getConversationDir(s),r=N.default.join(e,".claude","CLAUDE.md");if(S.default.existsSync(r)){const t=S.default.readFileSync(r,"utf-8"),g=t.length>8e3?t.substring(0,8e3)+`
85
+ `)}`,msgType:"markdown"})}return}case"front":{if(t.length===0){await this.sendDingMessage({conversationId:s,sessionWebhook:n,content:"\u{1F4ED} \u5F53\u524D\u65E0\u6392\u961F\u6D88\u606F",msgType:"markdown"});return}let g=t.length-1;for(let u=t.length-1;u>=0;u--)if(t[u].senderStaffId===r){g=u;break}if(g===0){await this.sendDingMessage({conversationId:s,sessionWebhook:n,content:"\u2139\uFE0F \u8BE5\u6D88\u606F\u5DF2\u5728\u961F\u9996\uFF0C\u65E0\u9700\u63D2\u961F",msgType:"markdown"});return}const[p]=t.splice(g,1);t.unshift(p),await this.sendDingMessage({conversationId:s,sessionWebhook:n,content:`\u2705 \u5DF2\u63D2\u961F\u5230\u961F\u9996
86
+ 1. **${p.senderNick||p.senderStaffId}:** ${this.truncateMsg(p.message)}`,msgType:"markdown"});return}case"rm":{if(t.length===0){await this.sendDingMessage({conversationId:s,sessionWebhook:n,content:"\u{1F4ED} \u5F53\u524D\u65E0\u6392\u961F\u6D88\u606F",msgType:"markdown"});return}if(e.all){const w=t.length;t.length=0,await this.sendDingMessage({conversationId:s,sessionWebhook:n,content:`\u2705 \u5DF2\u6E05\u7A7A\u6D88\u606F\u961F\u5217\uFF0C\u5171\u79FB\u9664 ${w} \u6761\u6D88\u606F`,msgType:"markdown"});return}const g=[...new Set(e.indices)],p=g.filter(w=>w>=1&&w<=t.length).sort((w,A)=>A-w),u=g.filter(w=>w<1||w>t.length);if(p.length===0){await this.sendDingMessage({conversationId:s,sessionWebhook:n,content:`\u26A0\uFE0F \u5E8F\u53F7\u65E0\u6548\uFF0C\u5F53\u524D\u961F\u5217\u5171 ${t.length} \u6761`,msgType:"markdown"});return}const m=[];for(const w of p)m.unshift(t.splice(w-1,1)[0]);const T=m.map(w=>`- **${w.senderNick||w.senderStaffId}:** ${this.truncateMsg(w.message)}`);let v=`\u2705 \u5DF2\u5220\u9664 ${m.length} \u6761\u6D88\u606F
87
+ ${T.join(`
88
+ `)}`;u.length>0&&(v+=`
89
+ \u26A0\uFE0F \u5DF2\u5FFD\u7565\u65E0\u6548\u5E8F\u53F7: ${u.join(", ")}`),await this.sendDingMessage({conversationId:s,sessionWebhook:n,content:v,msgType:"markdown"});return}}}),(0,I.route)("/!",()=>(0,$.parseInterruptCommand)(h),async()=>{const e=this.findActiveSession(s);if(!e){await this.sendDingMessage({conversationId:s,sessionWebhook:n,content:"\u26A0\uFE0F \u5F53\u524D\u6CA1\u6709\u6D3B\u8DC3\u4F1A\u8BDD"});return}const a=e.session;if(!a.currentProcess){await this.sendDingMessage({conversationId:s,sessionWebhook:n,content:"\u2139\uFE0F \u5F53\u524D\u6CA1\u6709\u6B63\u5728\u6267\u884C\u7684\u4EFB\u52A1"});return}(0,x.interruptClaudeProcess)(a,`/!: ${o} \u4E2D\u65AD\u5F53\u524D\u4EFB\u52A1`);const t=a.messageQueue.length;await this.sendDingMessage({conversationId:s,sessionWebhook:n,content:t>0?`\u23F9 \u5DF2\u4E2D\u65AD\u5F53\u524D\u4EFB\u52A1\uFF0C\u5F00\u59CB\u5904\u7406\u961F\u5217\u4E2D\u7684 ${t} \u6761\u6D88\u606F`:"\u23F9 \u5DF2\u4E2D\u65AD\u5F53\u524D\u4EFB\u52A1"})}),(0,I.route)("/goon",()=>(0,$.parseGoonCommand)(h),async()=>{const e=this.activeSessions.get(s);if(!e){await this.sendDingMessage({conversationId:s,sessionWebhook:n,content:"\u26A0\uFE0F \u5F53\u524D\u6CA1\u6709\u6D3B\u8DC3\u4F1A\u8BDD"});return}if(e.currentProcess){console.log(`[${(0,c.timestamp)()}] /goon: \u7EC8\u6B62\u5F53\u524D Claude \u8FDB\u7A0B`),e.interrupted=!0,(0,U.isWindows)()?e.currentProcess.kill():e.currentProcess.kill("SIGINT"),await this.sendDingMessage({conversationId:s,sessionWebhook:n,content:"\u{1F504} \u6B63\u5728\u91CD\u542F Claude \u8FDB\u7A0B..."}),e.goonPending=!1,e.isProcessing=!0;try{await(0,x.executeClaudeQuery)(this,e.session,"\u7EE7\u7EED",{senderNick:e.session.startNickName,senderStaffId:e.lastSenderStaffId,permissionMode:e.conversationConfig.permissionMode})}finally{e.isProcessing=!1}}else{console.log(`[${(0,c.timestamp)()}] /goon: \u65E0\u8FD0\u884C\u4E2D\u8FDB\u7A0B\uFF0C\u76F4\u63A5\u53D1\u9001"\u7EE7\u7EED"`),e.isProcessing=!0;try{await(0,x.executeClaudeQuery)(this,e.session,"\u7EE7\u7EED",{senderNick:o,senderStaffId:r,permissionMode:e.conversationConfig.permissionMode})}finally{e.isProcessing=!1}}}),(0,I.route)("/cc",()=>(0,$.parseCcCommand)(h),async e=>{const a=this.activeSessions.get(s);if(!a){await this.sendDingMessage({conversationId:s,sessionWebhook:n,content:"\u26A0\uFE0F \u5F53\u524D\u6CA1\u6709\u6D3B\u8DC3\u4F1A\u8BDD\uFF0C\u8BF7\u5148\u53D1\u9001\u6D88\u606F\u5F00\u59CB\u4F1A\u8BDD"});return}if(a.isProcessing){await this.sendDingMessage({conversationId:s,sessionWebhook:n,content:"\u23F3 \u6B63\u5728\u5904\u7406\u4E2D\uFF0C\u8BF7\u7A0D\u7B49..."});return}a.isProcessing=!0;try{a.conversationConfig.receiveReply!==!1&&await this.sendDingMessage({conversationId:s,sessionWebhook:n,content:"\u{1F4E5} \u5DF2\u6536\u5230\uFF0C\u6B63\u5728\u5904\u7406..."}).catch(()=>{}),await(0,x.executeClaudeQuery)(this,a.session,e,{senderNick:o,senderStaffId:r,permissionMode:a.conversationConfig.permissionMode})}finally{a.isProcessing=!1}}),(0,I.route)("/claude.md",()=>(0,$.parseClaudeMdCommand)(h),async()=>{const e=this.getConversationDir(s),a=R.default.join(e,".claude","CLAUDE.md");if(C.default.existsSync(a)){const t=C.default.readFileSync(a,"utf-8"),g=t.length>8e3?t.substring(0,8e3)+`
84
90
  ...(\u5185\u5BB9\u8FC7\u957F\u5DF2\u622A\u65AD)`:t;await this.sendDingMessage({conversationId:s,sessionWebhook:n,content:`\u{1F4C4} **CLAUDE.md**
85
91
  \`\`\`
86
92
  ${g}
87
93
  \`\`\``,msgType:"markdown"})}else await this.sendDingMessage({conversationId:s,sessionWebhook:n,content:`\u26A0\uFE0F \u672A\u627E\u5230 CLAUDE.md
88
- \u8DEF\u5F84: \`${r}\``,msgType:"markdown"})})];for(const e of R)if(await e.tryHandle())return;let q=f;const H=[];if(i.atUsers&&i.atUsers.length>0){const e=i.chatbotUserId;for(const r of i.atUsers){const t=r.staffId||r.dingtalkId;!t||t===a||t===e||t.startsWith("$:LWCP_v1:")||H.push(t)}}if(H.length>0)for(const e of H){const r=await(0,c.resolveUserIdName)(this,e),t=r?`${r}(${e})`:e;q=q.replace(/\u200b/g,t)}q.startsWith("/")&&!q.startsWith("/cc ")&&(q=` ${q}`),await this.handleSessionMessage({conversationId:s,sessionWebhook:n,senderStaffId:a,senderNick:o,message:q,conversationConfig:y})}async notifyPendingReboot(){const d=N.default.join(this.getClientDir(),".reboot_pending");if(S.default.existsSync(d))try{const i=JSON.parse(S.default.readFileSync(d,"utf-8"));S.default.unlinkSync(d);let o="\u2705 cc-ding \u5DF2\u91CD\u542F\u5B8C\u6210";i.update&&(o+=`
89
- **\u7248\u672C:** ${J}`);let a;const s=this.activeSessions.get(i.conversationId);if(s)a=s.session.sessionWebhook;else if(i.sessionWebhook)a=i.sessionWebhook,console.log(`[${(0,c.timestamp)()}] \u91CD\u542F\u540E\u672A\u627E\u5230\u6D3B\u8DC3\u4F1A\u8BDD\uFF0C\u4F7F\u7528\u4FDD\u5B58\u7684 sessionWebhook \u53D1\u9001\u901A\u77E5`);else{console.log(`[${(0,c.timestamp)()}] \u91CD\u542F\u540E\u672A\u627E\u5230\u6D3B\u8DC3\u4F1A\u8BDD\u4E14\u65E0\u4FDD\u5B58\u7684 webhook\uFF0C\u8DF3\u8FC7\u901A\u77E5`);return}await this.sendDingMessage({conversationId:i.conversationId,sessionWebhook:a,content:o,msgType:"markdown",atUserId:i.senderStaffId}),console.log(`[${(0,c.timestamp)()}] \u91CD\u542F\u5B8C\u6210\u901A\u77E5\u5DF2\u53D1\u9001`)}catch(i){try{const o=S.default.readFileSync(d,"utf-8");console.error(`[${(0,c.timestamp)()}] .reboot_pending \u5185\u5BB9:`,o)}catch{}console.error(`[${(0,c.timestamp)()}] \u5904\u7406\u91CD\u542F\u901A\u77E5\u5931\u8D25:`,i);try{S.default.unlinkSync(d)}catch{}}}startConnectionWatchdog(){let o=Date.now();setInterval(()=>{const a=this.dingStreamClient;if(a.connected){o=Date.now();return}const s=Date.now()-o;if(s>=6e4){console.log(`[${(0,c.timestamp)()}] \u8FDE\u63A5\u76D1\u63A7: \u5DF2\u65AD\u5F00 ${s/1e3}s\uFF0C\u5F3A\u5236\u91CD\u65B0\u8FDE\u63A5`),o=Date.now();try{a.disconnect()}catch{}a.connect().catch(h=>{console.error(`[${(0,c.timestamp)()}] \u5F3A\u5236\u91CD\u8FDE\u5931\u8D25:`,h)})}else this.debugLog(`\u8FDE\u63A5\u76D1\u63A7: \u5DF2\u65AD\u5F00 ${s/1e3}s\uFF0C\u7B49\u5F85\u81EA\u52A8\u91CD\u8FDE...`)},3e4)}async run(){const d=Array.isArray(this.config.conversations)?this.config.conversations:[],i=this.config.taskHandlerCount??this.DEFAULT_TASK_HANDLER_COUNT,o=d.length>0;console.log(`[${(0,c.timestamp)()}] \u9489\u9489\u673A\u5668\u4EBA\u670D\u52A1\u542F\u52A8\uFF0CclientId: ${this.clientId}`),console.log(`[${(0,c.timestamp)()}] \u7FA4\u914D\u7F6E: ${d.map(h=>h.conversationTitle||h.conversationId).join(", ")}`),(0,L.startupCheck)(this),await(0,c.resolveAllPhonesInConfig)(this),this.config.apiKeyCfg&&((0,L.resetApiKeyCfg)(this),(0,L.scheduleApiKeyCfgDailyReset)(this)),this.loadActiveSessions(),(0,x.injectStartupContexts)(this),await this.notifyPendingReboot(),this.cronEngine.start(),(0,M.startSelectionCleanupTimer)(),this.startConnectionWatchdog(),o&&console.log(`[${(0,c.timestamp)()}] \u4EFB\u52A1\u5904\u7406\u5668\u6570\u91CF: ${i}`),this.dingStreamClient.registerCallbackListener("/v1.0/im/bot/messages/get",async h=>{await this.botMsgGetCallback(h)});const a=[];if(o)for(let h=0;h<i;h++)console.log(`[${(0,c.timestamp)()}] \u542F\u52A8\u4EFB\u52A1\u5904\u7406\u5668 #${h+1}`),a.push(this.runTaskHandlerLoop().catch(n=>console.error(`\u4EFB\u52A1\u5904\u7406\u5668 #${h+1} \u9519\u8BEF:`,n)));const s=this.dingStreamClient.connect().catch(h=>{console.error("Fatal error",h),process.exit(1)});await Promise.all([s,...a])}}exports.DingClaude=ee;
94
+ \u8DEF\u5F84: \`${a}\``,msgType:"markdown"})})];for(const e of Y)if(await e.tryHandle())return;let q=h;const W=[];if(i.atUsers&&i.atUsers.length>0){const e=i.chatbotUserId;for(const a of i.atUsers){const t=a.staffId||a.dingtalkId;!t||t===r||t===e||t.startsWith("$:LWCP_v1:")||W.push(t)}}if(W.length>0)for(const e of W){const a=await(0,c.resolveUserIdName)(this,e),t=a?`${a}(${e})`:e;q=q.replace(/\u200b/g,t)}q.startsWith("/")&&!q.startsWith("/cc ")&&(q=` ${q}`),await this.handleSessionMessage({conversationId:s,sessionWebhook:n,senderStaffId:r,senderNick:o,message:q,conversationConfig:y})}async notifyPendingReboot(){const d=R.default.join(this.getClientDir(),".reboot_pending");if(C.default.existsSync(d))try{const i=JSON.parse(C.default.readFileSync(d,"utf-8"));C.default.unlinkSync(d);let o="\u2705 cc-ding \u5DF2\u91CD\u542F\u5B8C\u6210";i.update&&(o+=`
95
+ **\u7248\u672C:** ${J}`);let r;const s=this.activeSessions.get(i.conversationId);if(s)r=s.session.sessionWebhook;else if(i.sessionWebhook)r=i.sessionWebhook,console.log(`[${(0,c.timestamp)()}] \u91CD\u542F\u540E\u672A\u627E\u5230\u6D3B\u8DC3\u4F1A\u8BDD\uFF0C\u4F7F\u7528\u4FDD\u5B58\u7684 sessionWebhook \u53D1\u9001\u901A\u77E5`);else{console.log(`[${(0,c.timestamp)()}] \u91CD\u542F\u540E\u672A\u627E\u5230\u6D3B\u8DC3\u4F1A\u8BDD\u4E14\u65E0\u4FDD\u5B58\u7684 webhook\uFF0C\u8DF3\u8FC7\u901A\u77E5`);return}await this.sendDingMessage({conversationId:i.conversationId,sessionWebhook:r,content:o,msgType:"markdown",atUserId:i.senderStaffId}),console.log(`[${(0,c.timestamp)()}] \u91CD\u542F\u5B8C\u6210\u901A\u77E5\u5DF2\u53D1\u9001`)}catch(i){try{const o=C.default.readFileSync(d,"utf-8");console.error(`[${(0,c.timestamp)()}] .reboot_pending \u5185\u5BB9:`,o)}catch{}console.error(`[${(0,c.timestamp)()}] \u5904\u7406\u91CD\u542F\u901A\u77E5\u5931\u8D25:`,i);try{C.default.unlinkSync(d)}catch{}}}startConnectionWatchdog(){let o=Date.now();setInterval(()=>{const r=this.dingStreamClient;if(r.connected){o=Date.now();return}const s=Date.now()-o;if(s>=6e4){console.log(`[${(0,c.timestamp)()}] \u8FDE\u63A5\u76D1\u63A7: \u5DF2\u65AD\u5F00 ${s/1e3}s\uFF0C\u5F3A\u5236\u91CD\u65B0\u8FDE\u63A5`),o=Date.now();try{r.disconnect()}catch{}r.connect().catch(l=>{console.error(`[${(0,c.timestamp)()}] \u5F3A\u5236\u91CD\u8FDE\u5931\u8D25:`,l)})}else this.debugLog(`\u8FDE\u63A5\u76D1\u63A7: \u5DF2\u65AD\u5F00 ${s/1e3}s\uFF0C\u7B49\u5F85\u81EA\u52A8\u91CD\u8FDE...`)},3e4)}async run(){const d=Array.isArray(this.config.conversations)?this.config.conversations:[],i=this.config.taskHandlerCount??this.DEFAULT_TASK_HANDLER_COUNT,o=d.length>0;console.log(`[${(0,c.timestamp)()}] \u9489\u9489\u673A\u5668\u4EBA\u670D\u52A1\u542F\u52A8\uFF0CclientId: ${this.clientId}`),console.log(`[${(0,c.timestamp)()}] \u7FA4\u914D\u7F6E: ${d.map(l=>l.conversationTitle||l.conversationId).join(", ")}`),(0,S.startupCheck)(this),await(0,c.resolveAllPhonesInConfig)(this),this.config.apiKeyCfg&&((0,S.resetApiKeyCfg)(this),(0,S.scheduleApiKeyCfgDailyReset)(this)),this.loadActiveSessions(),(0,x.injectStartupContexts)(this),await this.notifyPendingReboot(),this.cronEngine.start(),(0,L.startSelectionCleanupTimer)(),this.startConnectionWatchdog(),o&&console.log(`[${(0,c.timestamp)()}] \u4EFB\u52A1\u5904\u7406\u5668\u6570\u91CF: ${i}`),this.dingStreamClient.registerCallbackListener("/v1.0/im/bot/messages/get",async l=>{await this.botMsgGetCallback(l)});const r=[];if(o)for(let l=0;l<i;l++)console.log(`[${(0,c.timestamp)()}] \u542F\u52A8\u4EFB\u52A1\u5904\u7406\u5668 #${l+1}`),r.push(this.runTaskHandlerLoop().catch(n=>console.error(`\u4EFB\u52A1\u5904\u7406\u5668 #${l+1} \u9519\u8BEF:`,n)));const s=this.dingStreamClient.connect().catch(l=>{console.error("Fatal error",l),process.exit(1)});await Promise.all([s,...r])}}exports.DingClaude=se;
@@ -13,7 +13,7 @@ ${f.thinking}
13
13
  `).trim(),v=c&&d||s;if(v&&!A?.interrupted){try{e.appendSessionLog(m,"assistant",v)}catch{}const w=e.activeSessions.get(t.conversationId)?.lastSenderStaffId||t.startStaffId;D=!0,(0,E.sendClaudeResponseToDing)(e,(0,n.getReplyConversationId)(t),(0,n.getReplyWebhook)(t),w,v).catch(b=>console.error("\u53D1\u9001\u9489\u9489\u6D88\u606F\u5931\u8D25:",b))}else console.warn(`[${(0,n.timestamp)()}] Claude \u8FD4\u56DE\u4E86\u7A7A\u7684 result \u4E14 responseBuffer \u4E5F\u4E3A\u7A7A\uFF0C\u65E0\u5185\u5BB9\u53EF\u53D1\u9001`);M=[]}}}),S.stderr?.on("data",p=>{const r=p.toString();if(x+=r,R(),(0,$.isQuotaExhaustedError)(r)){console.log(`[${(0,n.timestamp)()}] [Claude stderr] \u914D\u989D\u8017\u5C3D\u9519\u8BEF(429): ${r.trim()}`);try{a.default.appendFileSync(I,`[${(0,n.timestamp)()}] [WARN]: ${r}`,"utf-8")}catch{}}else if(J(r)){console.log(`[${(0,n.timestamp)()}] [Claude stderr] \u53EF\u91CD\u8BD5API\u9519\u8BEF(422 TPM\u9650\u6D41): ${r.trim()}`);try{a.default.appendFileSync(I,`[${(0,n.timestamp)()}] [WARN]: ${r}`,"utf-8")}catch{}}else{console.error(`[Claude stderr]: ${r}`);try{a.default.appendFileSync(I,`[${(0,n.timestamp)()}] [ERROR]: ${r}`,"utf-8")}catch{}}}),S.on("close",p=>{W=!0,l&&(clearInterval(l),l=null),console.log(`[${(0,n.timestamp)()}] Claude \u8FDB\u7A0B\u9000\u51FA\uFF0C\u4EE3\u7801: ${p}`);try{a.default.appendFileSync(I,`[${(0,n.timestamp)()}] [SYSTEM]: Claude \u67E5\u8BE2\u7ED3\u675F\uFF0C\u9000\u51FA\u7801: ${p}
14
14
  `,"utf-8")}catch{}const r=e.activeSessions.get(t.conversationId);if(r&&(r.currentProcess=void 0),r?.interrupted){console.log(`[${(0,n.timestamp)()}] \u7528\u6237\u4E3B\u52A8\u4E2D\u65AD\uFF0C\u4E22\u5F03 responseBuffer (${M.length} \u6BB5)`),r.interrupted=!1,M=[],g(0);return}if(M.length>0){const d=M.join(`
15
15
  `).trim();if(d){try{e.appendSessionLog(m,"assistant",d)}catch{}const s=r?.lastSenderStaffId||t.startStaffId;D=!0,(0,E.sendClaudeResponseToDing)(e,(0,n.getReplyConversationId)(t),(0,n.getReplyWebhook)(t),s,d).catch(v=>console.error("\u53D1\u9001\u9489\u9489\u6D88\u606F\u5931\u8D25:",v))}}if(p===0&&!D&&!r?.interrupted){console.warn(`[${(0,n.timestamp)()}] Claude \u8FDB\u7A0B\u6B63\u5E38\u9000\u51FA\u4F46\u672A\u4EA7\u751F\u4EFB\u4F55\u56DE\u590D\u5185\u5BB9`);try{a.default.appendFileSync(I,`[${(0,n.timestamp)()}] [WARN]: Claude \u8FDB\u7A0B\u6B63\u5E38\u9000\u51FA\u4F46\u672A\u4EA7\u751F\u4EFB\u4F55\u56DE\u590D\u5185\u5BB9
16
- `,"utf-8")}catch{}const d=r?.lastSenderStaffId||t.startStaffId;(0,E.sendDingMessage)(e,{conversationId:(0,n.getReplyConversationId)(t),sessionWebhook:(0,n.getReplyWebhook)(t),atUserId:d,content:"\u26A0\uFE0F Claude \u5904\u7406\u5B8C\u6210\u4F46\u672A\u8FD4\u56DE\u4EFB\u4F55\u5185\u5BB9\uFF0C\u8BF7\u91CD\u8BD5\u6216\u6362\u79CD\u65B9\u5F0F\u63D0\u95EE"}).catch(s=>console.error("\u53D1\u9001\u9489\u9489\u6D88\u606F\u5931\u8D25:",s))}if(p===0){g(0);return}const c=x+`
16
+ `,"utf-8")}catch{}const d=r?.lastSenderStaffId||t.startStaffId;(0,E.sendDingMessage)(e,{conversationId:(0,n.getReplyConversationId)(t),sessionWebhook:(0,n.getReplyWebhook)(t),atUserId:d,content:"\u26A0\uFE0F Claude \u5904\u7406\u5B8C\u6210\u4F46\u672A\u8FD4\u56DE\u4EFB\u4F55\u5185\u5BB9"}).catch(s=>console.error("\u53D1\u9001\u9489\u9489\u6D88\u606F\u5931\u8D25:",s))}if(p===0){g(0);return}const c=x+`
17
17
  `+O;if((0,$.isQuotaExhaustedError)(c)){const s=Date.now()-T<G;console.log(`[${(0,n.timestamp)()}] \u68C0\u6D4B\u5230\u914D\u989D\u8017\u5C3D\u9519\u8BEF(429)\uFF0Cstdout\u5339\u914D=${(0,$.isQuotaExhaustedError)(O)}, stderr\u5339\u914D=${(0,$.isQuotaExhaustedError)(x)}`),C(new V(s,c));return}if((0,$.isAuthenticationError)(c)){console.log(`[${(0,n.timestamp)()}] \u68C0\u6D4B\u5230\u8BA4\u8BC1\u9519\u8BEF(401)\uFF0C\u901A\u77E5\u7528\u6237`);const d=r?.lastSenderStaffId||t.startStaffId;(0,E.sendDingMessage)(e,{conversationId:(0,n.getReplyConversationId)(t),sessionWebhook:(0,n.getReplyWebhook)(t),atUserId:d,content:"\u26A0\uFE0F \u8BA4\u8BC1\u5931\u8D25(401)\uFF0CAPI Key \u65E0\u6548\u6216\u670D\u52A1\u672A\u6388\u6743\uFF0C\u8BF7\u68C0\u67E5\u914D\u7F6E"}).catch(s=>console.error("\u53D1\u9001\u9489\u9489\u6D88\u606F\u5931\u8D25:",s)),g(p??1);return}if(J(c)){const s=Date.now()-T<G;C(new V(s,c));return}if(me(c)){console.log(`[${(0,n.timestamp)()}] \u68C0\u6D4B\u5230\u9700\u8981\u6388\u6743\uFF0C\u901A\u77E5\u7528\u6237`);const d=r?.lastSenderStaffId||t.startStaffId;(0,E.sendDingMessage)(e,{conversationId:(0,n.getReplyConversationId)(t),sessionWebhook:(0,n.getReplyWebhook)(t),atUserId:d,content:"\u26A0\uFE0F Claude \u9700\u8981\u6388\u6743\uFF0C\u8BF7\u4EBA\u5DE5\u4ECB\u5165"}).catch(s=>console.error("\u53D1\u9001\u9489\u9489\u6D88\u606F\u5931\u8D25:",s)),g(p??1);return}if(t.claudeSessionId&&ge(c)){console.log(`[${(0,n.timestamp)()}] Claude \u4F1A\u8BDD\u5DF2\u5931\u6548: ${t.claudeSessionId}\uFF0C\u901A\u77E5\u5916\u5C42\u91CD\u65B0\u53D1\u8D77\u65B0\u4F1A\u8BDD`),C(new ee);return}if(fe(c)){console.log(`[${(0,n.timestamp)()}] \u68C0\u6D4B\u5230\u4E0A\u4E0B\u6587\u7A97\u53E3\u8D85\u957F\u9519\u8BEF(400)\uFF0C\u5C06\u81EA\u52A8\u53D1\u9001 /compact \u538B\u7F29\u4E0A\u4E0B\u6587`);try{a.default.appendFileSync(I,`[${(0,n.timestamp)()}] [SYSTEM]: \u4E0A\u4E0B\u6587\u7A97\u53E3\u8D85\u957F\uFF0C\u5C06\u81EA\u52A8 /compact
18
18
  `,"utf-8")}catch{}C(new te);return}C(new Error(`Claude \u8FDB\u7A0B\u9000\u51FA\uFF0C\u4EE3\u7801: ${p}`))}),S.on("error",p=>{W=!0,l&&(clearInterval(l),l=null),console.error("Claude \u8FDB\u7A0B\u9519\u8BEF:",p),a.default.appendFileSync(I,`[${(0,n.timestamp)()}] [ERROR]: \u8FDB\u7A0B\u9519\u8BEF: ${p.message}
19
19
  `,"utf-8"),C(p)})})}const ie="<!-- cc-ding:session-context-start (DO NOT EDIT) -->",z="<!-- cc-ding:session-context-end (DO NOT EDIT) -->";function se(e,t){const o=e.getConversationConfig(t),i=e.config;return[ie,"# cc-ding Session Context","","## Client",`- clientId: \`${e.clientId}\``,i.clientName?`- clientName: ${i.clientName}`:"",`- owner: ${i.owner}`,"","## Conversation",`- conversationId: \`${t}\``,o?.conversationType?`- conversationType: ${o.conversationType==="1"?"\u5355\u804A":"\u7FA4\u804A"}`:"",o?.conversationTitle?`- conversationTitle: ${o.conversationTitle}`:"",o?.linkConversationId?`- linkConversationId: \`${o.linkConversationId}\` (\u5173\u8054\u7FA4\uFF0C\u5171\u4EAB\u5DE5\u4F5C\u76EE\u5F55)`:"","","## Settings",o?.permissionMode?`- permissionMode: ${o.permissionMode}`:"",o?.agent?`- agent: ${o.agent}`:"",o?.taskCfg?.skill?`- taskCfg.skill: ${o.taskCfg.skill}`:"",i.resultOnly!==void 0?`- resultOnly: ${i.resultOnly}`:"",i.includeThinking!==void 0?`- includeThinking: ${i.includeThinking}`:"",i.preBash?`- preBash(\u5168\u5C40): \`${i.preBash}\``:"",o?.preBash?`- preBash(\u7FA4): \`${o.preBash}\``:"","","## DingTalk Context",'\u5F53 prompt \u4E2D\u5305\u542B "\u6D88\u606F\u6765\u81EA: xxx(\u7528\u6237ID)" \u65F6\uFF0C\u8BF4\u660E\u6D88\u606F\u6765\u81EA\u9489\u9489\u7528\u6237\u3002',"- \u56DE\u7B54\u65F6\u8981\u8003\u8651\u7528\u6237\u7684\u4F7F\u7528\u573A\u666F\uFF08\u9489\u9489\u804A\u5929\u754C\u9762\uFF0C\u975E\u7EC8\u7AEF\u73AF\u5883\uFF09","- \u7528\u6237\u4E00\u822C\u60C5\u51B5\u4E0B\u53EA\u80FD\u901A\u8FC7 cc-ding \u8FDB\u884C\u64CD\u4F5C","- cc-ding \u6587\u6863: https://github.com/yihuineng/cc-ding",z].filter(Boolean).join(`
@@ -1,6 +1,6 @@
1
- "use strict";var g=exports&&exports.__importDefault||function(e){return e&&e.__esModule?e:{default:e}};Object.defineProperty(exports,"__esModule",{value:!0}),exports.parseHelpCommand=w,exports.parseCommandHelp=k,exports.getCommandByName=I,exports.formatHelpOverview=b,exports.formatCommandHelp=M,exports.parseEndCommand=S,exports.parseInfoCommand=L,exports.formatConversationInfo=T,exports.formatGlobalConfig=v,exports.parseLogCommand=q,exports.parseLsCommand=D,exports.findSubdirByName=O,exports.getDirectoryStructure=$,exports.parseContinueSessionCommand=R,exports.parseCronCommand=_,exports.parseVersionCommand=B,exports.parseOpenCommand=A,exports.parseCleanCommand=N,exports.parseResetApiKeyCfgCommand=H,exports.parseCfgCommand=U,exports.parseBashCommand=E,exports.parseMqCommand=G,exports.parseAuthCommand=K,exports.parseGoonCommand=W,exports.parseCcCommand=P,exports.parseClaudeMdCommand=V,exports.parseInterruptCommand=Y,exports.parseTodoCommand=z,exports.parseMenuCommand=F,exports.parseRebootCommand=Q,exports.parseRecorderCommandEnhanced=J;const y=g(require("fs")),l=g(require("path")),C=[{name:"/help",description:"\u67E5\u770B\u6240\u6709\u53EF\u7528\u547D\u4EE4",usage:"/help",examples:["/help"],category:"\u7CFB\u7EDF"},{name:"/info",description:"\u67E5\u770B\u7FA4\u914D\u7F6E\u3001\u4F1A\u8BDD\u548C\u4EFB\u52A1\u4FE1\u606F",usage:"/info [robot|session|task]",examples:["/info","/info robot","/info session","/info task"],category:"\u7CFB\u7EDF"},{name:"/log",description:"\u67E5\u770B\u6700\u8FD1\u4F1A\u8BDD\u65E5\u5FD7",usage:"/log [\u884C\u6570]",examples:["/log","/log 20"],category:"\u4F1A\u8BDD"},{name:"/new",description:"\u5F00\u59CB\u65B0\u7684\u5BF9\u8BDD\u4F1A\u8BDD(\u7ED3\u675F\u5F53\u524D\u4F1A\u8BDD)",usage:"/new [\u521D\u59CB\u6D88\u606F]",examples:["/new","/new \u5E2E\u6211\u5206\u6790\u4E00\u4E0B\u8FD9\u4E2A\u9879\u76EE"],category:"\u4F1A\u8BDD"},{name:"/resume",description:"\u7EE7\u7EED\u6307\u5B9A\u7684\u5386\u53F2\u4F1A\u8BDD(\u53EF\u6307\u5B9A\u4F1A\u8BDDID,\u4E0D\u6307\u5B9A\u5219\u6062\u590D\u6700\u8FD1\u4E00\u4E2A)",usage:"/resume [\u4F1A\u8BDDID]",examples:["/resume","/resume abc123"],category:"\u4F1A\u8BDD"},{name:"/end",description:"\u7ED3\u675F\u5F53\u524D\u4F1A\u8BDD",usage:"/end",examples:["/end"],category:"\u4F1A\u8BDD"},{name:"/goon",description:'\u5F3A\u5236\u91CD\u542F Claude \u8FDB\u7A0B\u5E76\u53D1\u9001"\u7EE7\u7EED"\u6062\u590D\u6267\u884C',usage:"/goon",examples:["/goon"],category:"\u4F1A\u8BDD"},{name:"/cc",description:"\u76F4\u63A5\u900F\u4F20\u6D88\u606F\u7ED9 Claude\uFF08\u4E0D\u9644\u52A0\u53D1\u9001\u4EBA\u4FE1\u606F\uFF09",usage:"/cc <\u6D88\u606F>",examples:["/cc \u7EE7\u7EED","/cc /compact"],category:"\u4F1A\u8BDD"},{name:"/task",description:"\u63D0\u4EA4\u4EFB\u52A1\u5230\u961F\u5217",usage:"/task <\u4EFB\u52A1\u63CF\u8FF0>",examples:["/task \u5E2E\u6211\u91CD\u6784\u767B\u5F55\u6A21\u5757"],category:"\u4EFB\u52A1"},{name:"/mq",description:"\u67E5\u770B\u548C\u7BA1\u7406\u5F53\u524D\u4F1A\u8BDD\u6D88\u606F\u961F\u5217",usage:"/mq | /mq front | /mq rm <\u5E8F\u53F7> | /mq rm <1-3> | /mq -n <\u6570\u91CF> | /mq -all",examples:["/mq","/mq front","/mq rm 1","/mq rm 1-3","/mq rm 1 3 5","/mq -n 1","/mq -all"],category:"\u4EFB\u52A1"},{name:"/cron",description:"\u521B\u5EFA\u548C\u7BA1\u7406\u5B9A\u65F6\u4EFB\u52A1(Claude\u81EA\u52A8\u5206\u6790\u81EA\u7136\u8BED\u8A00)",usage:"/cron <\u81EA\u7136\u8BED\u8A00\u63CF\u8FF0> | /cron <cron\u8868\u8FBE\u5F0F> <\u4EFB\u52A1\u63CF\u8FF0> | /cron list|pause|resume|delete <id>",examples:["/cron \u6BCF\u5929\u65E9\u4E0A9\u70B9\u67E5\u770Bdima\u4EFB\u52A1","/cron 0 9 * * * \u67E5\u770Bdima\u4EFB\u52A1","/cron list","/cron pause cron_123","/cron delete cron_123"],category:"\u4EFB\u52A1"},{name:"/ls",description:"\u67E5\u770B\u5DE5\u4F5C\u76EE\u5F55\u7ED3\u6784",usage:"/ls [\u76EE\u6807\u76EE\u5F55] [\u5C55\u5F00\u5C42\u6570]",examples:["/ls","/ls root 2","/ls product 1"],category:"\u6587\u4EF6"},{name:"/claude.md",description:"\u67E5\u770B\u5F53\u524D\u5DE5\u4F5C\u76EE\u5F55\u7684 CLAUDE.md \u6587\u4EF6\u5185\u5BB9",usage:"/claude.md",examples:["/claude.md"],category:"\u6587\u4EF6"},{name:"/version",description:"\u67E5\u770B\u5DE5\u5177\u7248\u672C\u4FE1\u606F",usage:"/version",examples:["/version"],category:"\u7CFB\u7EDF"},{name:"/open",description:"\u5728\u6587\u4EF6\u7BA1\u7406\u5668\u3001\u7EC8\u7AEF\u6216VS Code\u4E2D\u6253\u5F00\u5DE5\u4F5C\u76EE\u5F55",usage:"/open [shell|code]",examples:["/open","/open shell","/open code"],category:"\u7BA1\u7406",ownerOnly:!0},{name:"/clean",description:"\u6E05\u9664\u5386\u53F2\u4F1A\u8BDD\u548C\u7F13\u5B58(.sessions/.tasks/.images/.playwright-cli)",usage:"/clean",examples:["/clean"],category:"\u7BA1\u7406",ownerOnly:!0},{name:"/reset-apikeycfg",description:"\u91CD\u7F6EAPI Key\u914D\u7F6E(\u5C06\u6240\u6709Key\u6807\u8BB0\u4E3A\u6709\u6548)",usage:"/reset-apikeycfg",examples:["/reset-apikeycfg"],category:"\u7BA1\u7406",ownerOnly:!0},{name:"/cfg",description:"\u6CE8\u518C\u5F53\u524D\u7FA4\u5230\u914D\u7F6E\uFF0C\u6216\u5237\u65B0\u6307\u5B9A\u5B57\u6BB5(\u5DF2\u6CE8\u518C\u7FA4)",usage:'/cfg [--conversationId xxx] [--dingToken xxx] [--linkConversationId yyy] [--whiteUserList 138xxxx,139xxxx] [--conversationTitle \u540D\u79F0] [--atSender true|false] [--receiveReply true|false] [--preBash "\u547D\u4EE4"] [--permissionMode mode]',examples:["/cfg","/cfg --dingToken myToken --whiteUserList 13800138000,13900139000","/cfg --conversationTitle \u5DE5\u4F5C\u7FA4","/cfg --whiteUserList 13800138000","/cfg --atSender false","/cfg --receiveReply false",'/cfg --preBash "source .env"',"/cfg --permissionMode auto","/cfg --conversationId targetConvId --dingToken xxx --conversationTitle \u76EE\u6807\u7FA4"],category:"\u7BA1\u7406",ownerOnly:!0},{name:"/bash",description:"\u5728\u5DE5\u4F5C\u76EE\u5F55\u6267\u884C bash \u547D\u4EE4\uFF08\u4EC5 owner/\u7BA1\u7406\u5458\uFF0C\u6267\u884C\u5C06\u8BB0\u5F55\u5BA1\u8BA1\u65E5\u5FD7\uFF1B\u5982\u914D\u7F6E\u4E86 preBash \u5168\u5C40/\u7FA4\u7EA7\u522B\uFF0C\u5C06\u53E0\u52A0\u524D\u7F6E\u6267\u884C\uFF09",usage:"/bash <\u547D\u4EE4>",examples:["/bash ls -la","/bash pwd","/bash git status"],category:"\u6587\u4EF6",ownerOnly:!0},{name:"/auth",description:"\u7BA1\u7406\u767D\u540D\u5355\u548C\u7BA1\u7406\u5458(add/del/rm/admin,\u9ED8\u8BA4list)",usage:"/auth [add|del|rm <\u624B\u673A\u53F7\u6216userId>] | /auth admin [add|rm <\u624B\u673A\u53F7\u6216userId>] | /auth [approve|reject <requestId>]",examples:["/auth","/auth add 13800138000","/auth rm 13800138000","/auth admin add 13800138000","/auth admin rm 13800138000","/auth admin","/auth approve r1234"],category:"\u7BA1\u7406",ownerOnly:!0},{name:"/recorder",aliases:["/r"],description:"Recorder \u6A21\u5F0F\uFF1A\u8BB0\u5F55\u6240\u6709\u6D88\u606F\u5230\u672C\u5730\uFF08\u4EC5 owner \u5355\u804A\uFF0C\u5F55\u5236\u4E2D\u53EF\u53D1\u9001 /exit \u6216 /e \u5FEB\u6377\u9000\u51FA\uFF09",usage:"/recorder [on|exit]",examples:["/recorder on","/recorder exit","/r on","/r exit"],category:"\u7BA1\u7406",ownerOnly:!0},{name:"/todo",description:"\u5F85\u529E\u7BA1\u7406\uFF1A\u6DFB\u52A0/\u5B8C\u6210/\u5220\u9664/\u5217\u8868/\u63D0\u9192/\u6A21\u5F0F\u5207\u6362",usage:"/todo <\u5185\u5BB9> [@\u4EBA] [ddl \u622A\u6B62\u65F6\u95F4] | /todo done <\u5E8F\u53F7> | /todo rm <\u5E8F\u53F7|all> | /todo list | /todo remind <0-23> | /todo mode <staffId|dingtalkId>",examples:["/todo \u5B8C\u6210\u62A5\u544A ddl \u660E\u5929","/todo \u4FEE\u590Dbug @\u5F20\u4E09 ddl \u4E0B\u5468\u4E94","/todo done 1","/todo rm 2","/todo rm all","/todo list","/todo remind 9","/todo remind -1","/todo mode dingtalkId"],category:"\u4EFB\u52A1"},{name:"/menu",description:"\u5FEB\u6377\u6307\u4EE4\u83DC\u5355\uFF1A\u81EA\u5B9A\u4E49\u5E38\u7528\u6307\u4EE4\uFF0C\u56DE\u590D\u5E8F\u53F7\u6267\u884C",usage:"/menu add <\u6307\u4EE4> | /menu del <\u5E8F\u53F7> | /menu list | /menu trigger <\u8BCD> | /menu -g add/del/list",examples:["/menu add /help","/menu add /cron \u6BCF\u5929\u65E9\u4E0A9\u70B9\u67E5\u770Bdima","/menu del 1","/menu list","/menu trigger go","/menu -g add /info robot","/menu -g del 1"],category:"\u7CFB\u7EDF"},{name:"/!",description:"\u4E2D\u65AD\u5F53\u524D\u4EFB\u52A1\u5E76\u7ACB\u5373\u5904\u7406\u65B0\u6D88\u606F",usage:"/!",examples:["/!"],category:"\u4F1A\u8BDD"},{name:"/reboot",description:"\u91CD\u542F cc-ding \u5E94\u7528\uFF08\u9700 pm2 \u90E8\u7F72\uFF09",usage:"/reboot [--update [tag]]",examples:["/reboot","/reboot --update","/reboot --update beta"],category:"\u7BA1\u7406",ownerOnly:!0}],x=[{category:"\u4F1A\u8BDD",icon:"\u{1F4AC}"},{category:"\u4EFB\u52A1",icon:"\u{1F4CB}"},{category:"\u6587\u4EF6",icon:"\u{1F4C2}"},{category:"\u7CFB\u7EDF",icon:"\u2699\uFE0F"},{category:"\u7BA1\u7406",icon:"\u{1F527}"}];function w(e){return e.trim().toLowerCase()==="/help"}function k(e){const s=e.trim().match(/^(\/\w+)\s+--help$/i);return s?s[1].toLowerCase():null}function I(e){const t=e.toLowerCase();return C.find(s=>s.name.toLowerCase()===t||s.aliases?.some(n=>n.toLowerCase()===t))}function b(e,t){const s=C.filter(r=>t||!r.ownerOnly),n=["### \u{1F917}","----",`- **\u7248\u672C:** ${e}`,"- **\u4F5C\u8005:** yihuineng","- **Github:** https://github.com/yihuineng/cc-ding","----"];for(const{category:r,icon:i}of x){const o=s.filter(a=>a.category===r);if(o.length!==0){n.push(`${i} **${r}**`);for(const a of o)n.push(`- \`${a.name}\` ${a.description}`);n.push("")}}return n.push("\u{1F4A1} \u8F93\u5165 `/{\u547D\u4EE4} --help` \u67E5\u770B\u547D\u4EE4\u8BE6\u7EC6\u7528\u6CD5"),n.join(`
1
+ "use strict";var g=exports&&exports.__importDefault||function(e){return e&&e.__esModule?e:{default:e}};Object.defineProperty(exports,"__esModule",{value:!0}),exports.parseHelpCommand=w,exports.parseCommandHelp=I,exports.getCommandByName=k,exports.formatHelpOverview=b,exports.formatCommandHelp=M,exports.parseEndCommand=S,exports.parseInfoCommand=L,exports.formatConversationInfo=v,exports.formatGlobalConfig=T,exports.parseLogCommand=q,exports.parseLsCommand=D,exports.findSubdirByName=O,exports.getDirectoryStructure=$,exports.parseContinueSessionCommand=R,exports.parseCronCommand=_,exports.parseVersionCommand=B,exports.parseOpenCommand=A,exports.parseCleanCommand=N,exports.parseResetApiKeyCfgCommand=H,exports.parseCfgCommand=U,exports.parseBashCommand=E,exports.parseMqCommand=G,exports.parseAuthCommand=K,exports.parseGoonCommand=W,exports.parseCcCommand=P,exports.parseClaudeMdCommand=F,exports.parseInterruptCommand=V,exports.parseDestroyCommand=Y,exports.parseFreedomCommand=z,exports.parseTodoCommand=Q,exports.parseMenuCommand=J,exports.parseRebootCommand=X,exports.parseRecorderCommandEnhanced=Z;const y=g(require("fs")),l=g(require("path")),C=[{name:"/help",description:"\u67E5\u770B\u6240\u6709\u53EF\u7528\u547D\u4EE4",usage:"/help",examples:["/help"],category:"\u7CFB\u7EDF"},{name:"/info",description:"\u67E5\u770B\u7FA4\u914D\u7F6E\u3001\u4F1A\u8BDD\u548C\u4EFB\u52A1\u4FE1\u606F",usage:"/info [robot|session|task]",examples:["/info","/info robot","/info session","/info task"],category:"\u7CFB\u7EDF"},{name:"/log",description:"\u67E5\u770B\u6700\u8FD1\u4F1A\u8BDD\u65E5\u5FD7",usage:"/log [\u884C\u6570]",examples:["/log","/log 20"],category:"\u4F1A\u8BDD"},{name:"/new",description:"\u5F00\u59CB\u65B0\u7684\u5BF9\u8BDD\u4F1A\u8BDD(\u7ED3\u675F\u5F53\u524D\u4F1A\u8BDD)",usage:"/new [\u521D\u59CB\u6D88\u606F]",examples:["/new","/new \u5E2E\u6211\u5206\u6790\u4E00\u4E0B\u8FD9\u4E2A\u9879\u76EE"],category:"\u4F1A\u8BDD"},{name:"/resume",description:"\u7EE7\u7EED\u6307\u5B9A\u7684\u5386\u53F2\u4F1A\u8BDD(\u53EF\u6307\u5B9A\u4F1A\u8BDDID,\u4E0D\u6307\u5B9A\u5219\u6062\u590D\u6700\u8FD1\u4E00\u4E2A)",usage:"/resume [\u4F1A\u8BDDID]",examples:["/resume","/resume abc123"],category:"\u4F1A\u8BDD"},{name:"/end",description:"\u7ED3\u675F\u5F53\u524D\u4F1A\u8BDD",usage:"/end",examples:["/end"],category:"\u4F1A\u8BDD"},{name:"/goon",description:'\u5F3A\u5236\u91CD\u542F Claude \u8FDB\u7A0B\u5E76\u53D1\u9001"\u7EE7\u7EED"\u6062\u590D\u6267\u884C',usage:"/goon",examples:["/goon"],category:"\u4F1A\u8BDD"},{name:"/cc",description:"\u76F4\u63A5\u900F\u4F20\u6D88\u606F\u7ED9 Claude\uFF08\u4E0D\u9644\u52A0\u53D1\u9001\u4EBA\u4FE1\u606F\uFF09",usage:"/cc <\u6D88\u606F>",examples:["/cc \u7EE7\u7EED","/cc /compact"],category:"\u4F1A\u8BDD"},{name:"/task",description:"\u63D0\u4EA4\u4EFB\u52A1\u5230\u961F\u5217",usage:"/task <\u4EFB\u52A1\u63CF\u8FF0>",examples:["/task \u5E2E\u6211\u91CD\u6784\u767B\u5F55\u6A21\u5757"],category:"\u4EFB\u52A1"},{name:"/mq",description:"\u67E5\u770B\u548C\u7BA1\u7406\u5F53\u524D\u4F1A\u8BDD\u6D88\u606F\u961F\u5217",usage:"/mq | /mq front | /mq rm <\u5E8F\u53F7> | /mq rm <1-3> | /mq -n <\u6570\u91CF> | /mq -all",examples:["/mq","/mq front","/mq rm 1","/mq rm 1-3","/mq rm 1 3 5","/mq -n 1","/mq -all"],category:"\u4EFB\u52A1"},{name:"/cron",description:"\u521B\u5EFA\u548C\u7BA1\u7406\u5B9A\u65F6\u4EFB\u52A1(Claude\u81EA\u52A8\u5206\u6790\u81EA\u7136\u8BED\u8A00)",usage:"/cron <\u81EA\u7136\u8BED\u8A00\u63CF\u8FF0> | /cron <cron\u8868\u8FBE\u5F0F> <\u4EFB\u52A1\u63CF\u8FF0> | /cron list|pause|resume|delete <id>",examples:["/cron \u6BCF\u5929\u65E9\u4E0A9\u70B9\u67E5\u770Bdima\u4EFB\u52A1","/cron 0 9 * * * \u67E5\u770Bdima\u4EFB\u52A1","/cron list","/cron pause cron_123","/cron delete cron_123"],category:"\u4EFB\u52A1"},{name:"/ls",description:"\u67E5\u770B\u5DE5\u4F5C\u76EE\u5F55\u7ED3\u6784",usage:"/ls [\u76EE\u6807\u76EE\u5F55] [\u5C55\u5F00\u5C42\u6570]",examples:["/ls","/ls root 2","/ls product 1"],category:"\u6587\u4EF6"},{name:"/claude.md",description:"\u67E5\u770B\u5F53\u524D\u5DE5\u4F5C\u76EE\u5F55\u7684 CLAUDE.md \u6587\u4EF6\u5185\u5BB9",usage:"/claude.md",examples:["/claude.md"],category:"\u6587\u4EF6"},{name:"/version",description:"\u67E5\u770B\u5DE5\u5177\u7248\u672C\u4FE1\u606F",usage:"/version",examples:["/version"],category:"\u7CFB\u7EDF"},{name:"/open",description:"\u5728\u6587\u4EF6\u7BA1\u7406\u5668\u3001\u7EC8\u7AEF\u6216VS Code\u4E2D\u6253\u5F00\u5DE5\u4F5C\u76EE\u5F55",usage:"/open [shell|code]",examples:["/open","/open shell","/open code"],category:"\u7BA1\u7406",ownerOnly:!0},{name:"/clean",description:"\u6E05\u9664\u5386\u53F2\u4F1A\u8BDD\u548C\u7F13\u5B58(.sessions/.tasks/.images/.playwright-cli)",usage:"/clean",examples:["/clean"],category:"\u7BA1\u7406",ownerOnly:!0},{name:"/reset-apikeycfg",description:"\u91CD\u7F6EAPI Key\u914D\u7F6E(\u5C06\u6240\u6709Key\u6807\u8BB0\u4E3A\u6709\u6548)",usage:"/reset-apikeycfg",examples:["/reset-apikeycfg"],category:"\u7BA1\u7406",ownerOnly:!0},{name:"/cfg",description:"\u6CE8\u518C\u5F53\u524D\u7FA4\u5230\u914D\u7F6E\uFF0C\u6216\u5237\u65B0\u6307\u5B9A\u5B57\u6BB5(\u5DF2\u6CE8\u518C\u7FA4)",usage:'/cfg [--conversationId xxx] [--dingToken xxx] [--linkConversationId yyy] [--whiteUserList 138xxxx,139xxxx] [--conversationTitle \u540D\u79F0] [--atSender true|false] [--receiveReply true|false] [--preBash "\u547D\u4EE4"] [--permissionMode mode]',examples:["/cfg","/cfg --dingToken myToken --whiteUserList 13800138000,13900139000","/cfg --conversationTitle \u5DE5\u4F5C\u7FA4","/cfg --whiteUserList 13800138000","/cfg --atSender false","/cfg --receiveReply false",'/cfg --preBash "source .env"',"/cfg --permissionMode auto","/cfg --conversationId targetConvId --dingToken xxx --conversationTitle \u76EE\u6807\u7FA4"],category:"\u7BA1\u7406",ownerOnly:!0},{name:"/bash",description:"\u5728\u5DE5\u4F5C\u76EE\u5F55\u6267\u884C bash \u547D\u4EE4\uFF08\u4EC5 owner/\u7BA1\u7406\u5458\uFF0C\u6267\u884C\u5C06\u8BB0\u5F55\u5BA1\u8BA1\u65E5\u5FD7\uFF1B\u5982\u914D\u7F6E\u4E86 preBash \u5168\u5C40/\u7FA4\u7EA7\u522B\uFF0C\u5C06\u53E0\u52A0\u524D\u7F6E\u6267\u884C\uFF09",usage:"/bash <\u547D\u4EE4>",examples:["/bash ls -la","/bash pwd","/bash git status"],category:"\u6587\u4EF6",ownerOnly:!0},{name:"/auth",description:"\u7BA1\u7406\u767D\u540D\u5355\u548C\u7BA1\u7406\u5458(add/del/rm/admin,\u9ED8\u8BA4list)",usage:"/auth [add|del|rm <\u624B\u673A\u53F7\u6216userId>] | /auth admin [add|rm <\u624B\u673A\u53F7\u6216userId>] | /auth [approve|reject <requestId>]",examples:["/auth","/auth add 13800138000","/auth rm 13800138000","/auth admin add 13800138000","/auth admin rm 13800138000","/auth admin","/auth approve r1234"],category:"\u7BA1\u7406",ownerOnly:!0},{name:"/recorder",description:"Recorder \u6A21\u5F0F\uFF1A\u8BB0\u5F55\u6240\u6709\u6D88\u606F\u5230\u672C\u5730\uFF08\u4EC5 owner \u5355\u804A\uFF0C\u53D1\u9001 /recorder exit \u9000\u51FA\uFF09",usage:"/recorder [on|exit]",examples:["/recorder on","/recorder exit"],category:"\u7BA1\u7406",ownerOnly:!0},{name:"/todo",description:"\u5F85\u529E\u7BA1\u7406\uFF1A\u6DFB\u52A0/\u5B8C\u6210/\u5220\u9664/\u5217\u8868/\u63D0\u9192/\u6A21\u5F0F\u5207\u6362",usage:"/todo <\u5185\u5BB9> [@\u4EBA] [ddl \u622A\u6B62\u65F6\u95F4] | /todo done <\u5E8F\u53F7> | /todo rm <\u5E8F\u53F7|all> | /todo list | /todo remind <0-23> | /todo mode <staffId|dingtalkId>",examples:["/todo \u5B8C\u6210\u62A5\u544A ddl \u660E\u5929","/todo \u4FEE\u590Dbug @\u5F20\u4E09 ddl \u4E0B\u5468\u4E94","/todo done 1","/todo rm 2","/todo rm all","/todo list","/todo remind 9","/todo remind -1","/todo mode dingtalkId"],category:"\u4EFB\u52A1"},{name:"/menu",description:"\u5FEB\u6377\u6307\u4EE4\u83DC\u5355\uFF1A\u81EA\u5B9A\u4E49\u5E38\u7528\u6307\u4EE4\uFF0C\u56DE\u590D\u5E8F\u53F7\u6267\u884C",usage:"/menu add <\u6307\u4EE4> | /menu del <\u5E8F\u53F7> | /menu list | /menu trigger <\u8BCD> | /menu -g add/del/list",examples:["/menu add /help","/menu add /cron \u6BCF\u5929\u65E9\u4E0A9\u70B9\u67E5\u770Bdima","/menu del 1","/menu list","/menu trigger go","/menu -g add /info robot","/menu -g del 1"],category:"\u7CFB\u7EDF"},{name:"/!",description:"\u4E2D\u65AD\u5F53\u524D\u4EFB\u52A1\u5E76\u7ACB\u5373\u5904\u7406\u65B0\u6D88\u606F\uFF08\u652F\u6301 /! /\uFF01 ! \uFF01\uFF09",usage:"/! | /\uFF01 | ! | \uFF01",examples:["/!","!"],category:"\u4F1A\u8BDD"},{name:"/reboot",description:"\u91CD\u542F cc-ding \u5E94\u7528\uFF08\u9700 pm2 \u90E8\u7F72\uFF09",usage:"/reboot [--update [tag]]",examples:["/reboot","/reboot --update","/reboot --update beta"],category:"\u7BA1\u7406",ownerOnly:!0},{name:"/destroy",description:"\u6CE8\u9500\u5F53\u524D\u7FA4\u673A\u5668\u4EBA\uFF0C\u5220\u9664\u5DE5\u4F5C\u76EE\u5F55\u548C\u914D\u7F6E",usage:"/destroy [--conversationId xxx]",examples:["/destroy","/destroy --conversationId targetConvId"],category:"\u7BA1\u7406",ownerOnly:!0},{name:"/freedom",description:"\u81EA\u7531\u6A21\u5F0F\uFF1A\u5F00\u542F\u540E\u6240\u6709\u7FA4\u6210\u5458\u5747\u53EF\u4F7F\u7528\u673A\u5668\u4EBA\uFF08\u8DF3\u8FC7\u767D\u540D\u5355\u9650\u5236\uFF09",usage:"/freedom | /freedom exit",examples:["/freedom","/freedom exit"],category:"\u7BA1\u7406",ownerOnly:!0}],x=[{category:"\u4F1A\u8BDD",icon:"\u{1F4AC}"},{category:"\u4EFB\u52A1",icon:"\u{1F4CB}"},{category:"\u6587\u4EF6",icon:"\u{1F4C2}"},{category:"\u7CFB\u7EDF",icon:"\u2699\uFE0F"},{category:"\u7BA1\u7406",icon:"\u{1F527}"}];function w(e){return e.trim().toLowerCase()==="/help"}function I(e){const s=e.trim().match(/^(\/\w+)\s+--help$/i);return s?s[1].toLowerCase():null}function k(e){const t=e.toLowerCase();return C.find(s=>s.name.toLowerCase()===t||s.aliases?.some(r=>r.toLowerCase()===t))}function b(e,t){const s=C.filter(n=>t||!n.ownerOnly),r=["### \u{1F917}","----",`- **\u7248\u672C:** ${e}`,"- **\u4F5C\u8005:** yihuineng","- **Github:** https://github.com/yihuineng/cc-ding","----"];for(const{category:n,icon:i}of x){const o=s.filter(a=>a.category===n);if(o.length!==0){r.push(`${i} **${n}**`);for(const a of o)r.push(`- \`${a.name}\` ${a.description}`);r.push("")}}return r.push("\u{1F4A1} \u8F93\u5165 `/{\u547D\u4EE4} --help` \u67E5\u770B\u547D\u4EE4\u8BE6\u7EC6\u7528\u6CD5"),r.join(`
2
2
  `)}function M(e){const t=[`### \u{1F4D6} ${e.name}`,"",`**\u63CF\u8FF0:** ${e.description}`,"",`**\u7528\u6CD5:** \`${e.usage}\``];e.aliases?.length&&t.push("",`**\u522B\u540D:** ${e.aliases.join(", ")}`),t.push("","**\u793A\u4F8B:**");for(const s of e.examples)t.push(`- \`${s}\``);return t.join(`
3
- `)}function S(e){return e.trim().toLowerCase()==="/end"}function L(e){const t=e.trim().toLowerCase();return t==="/info"?"all":t==="/info robot"?"robot":t==="/info session"?"session":t==="/info task"?"task":null}function T(e,t,s,n){const r=[`- **\u7FA4ID:** ${t}`];if(e.conversationTitle&&r.push(`- **\u7FA4\u540D\u79F0:** ${e.conversationTitle}`),e.conversationType&&r.push(`- **\u4F1A\u8BDD\u7C7B\u578B:** ${e.conversationType==="1"?"\u5355\u804A":e.conversationType==="2"?"\u7FA4\u804A":e.conversationType}`),n&&r.push(`- **\u5DE5\u4F5C\u76EE\u5F55:** \`${n}\``),e.linkConversationId&&r.push(`- **\u5173\u8054\u4F1A\u8BDDID:** ${e.linkConversationId}`),e.agent&&r.push(`- **agent:** ${e.agent}`),e.dingToken&&r.push(`- **dingToken:** ${e.dingToken.substring(0,8)}...`),e.whiteUserList?.length){const i=e.whiteUserList.map(o=>s?.(o)||o).join(", ");r.push(`- **\u7FA4\u767D\u540D\u5355:** ${i}`)}return e.atSender===!1&&r.push("- **atSender:** false"),e.receiveReply===!1&&r.push("- **receiveReply:** false (\u4E0D\u56DE\u590D\u786E\u8BA4\u6D88\u606F)"),e.useLocalOcr===!1&&r.push("- **\u672C\u5730OCR:** \u5173\u95ED"),e.permissionMode&&r.push(`- **permissionMode:** ${e.permissionMode}`),e.taskCfg?.skill&&r.push(`- **taskSkill:** ${e.taskCfg.skill}`),e.preBash&&r.push(`- **preBash:** \`${e.preBash}\``),r.join(`
4
- `)}function v(e){const t=[`- **clientName:** ${e.clientName||"-"}`,`- **sessionMaxConcurrency:** ${e.sessionMaxConcurrency??5}`,`- **taskHandlerCount:** ${e.taskHandlerCount??1}`,`- **taskQueueSize:** ${e.taskQueueSize??50}`,`- **includeThinking:** ${e.includeThinking??!1}`,`- **resultOnly:** ${e.resultOnly??!0}`];if(e.defaultDingToken&&t.push(`- **defaultDingToken:** ${e.defaultDingToken.substring(0,8)}...`),e.owner&&t.push(`- **owner:** ${e.owner}`),e.whiteUserList?.length&&t.push(`- **\u5168\u5C40\u767D\u540D\u5355:** ${e.whiteUserList.join(", ")}`),e.apiKeyCfg){const s=e.apiKeyCfg.claudeSettings.filter(n=>n.isValid).length;t.push(`- **apiKeyCfg:** ${s}/${e.apiKeyCfg.claudeSettings.length} \u6709\u6548`),t.push(` - **\u6700\u8FD1\u91CD\u7F6E:** ${e.apiKeyCfg.resetTime||"-"}`)}return t.join(`
5
- `)}function q(e){const s=e.trim().match(/^\/log(?:\s+(\d+))?$/i);if(!s)return null;const n=parseInt(s[1],10);return isNaN(n)||n<=0?10:n}function D(e){const s=e.trim().match(/^\/ls(?:\s+(.+))?$/i);if(!s)return null;if(s[1]===void 0)return{target:"",depth:1};const n=s[1].trim().split(/\s+/),r=n[0]||"",i=n[1]?parseInt(n[1],10):1;return{target:r,depth:isNaN(i)||i<0?1:Math.min(i,5)}}function O(e,t,s=3){const n=[{dir:e,depth:0}];for(;n.length>0;){const{dir:r,depth:i}=n.shift();if(!(i>s))try{const o=y.default.readdirSync(r,{withFileTypes:!0});for(const a of o)if(!(!a.isDirectory()||a.name.startsWith("."))){if(a.name===t)return l.default.join(r,a.name);n.push({dir:l.default.join(r,a.name),depth:i+1})}}catch{continue}}return null}function $(e,t=0,s=1){try{const n=y.default.readdirSync(e,{withFileTypes:!0}).filter(o=>!o.name.startsWith("."));if(n.length===0)return t===0?"\u{1F4C2} \u76EE\u5F55\u4E3A\u7A7A":"";n.sort((o,a)=>o.isDirectory()!==a.isDirectory()?o.isDirectory()?-1:1:o.name.localeCompare(a.name));const r=[],i=". ".repeat(t);for(const o of n){const a=o.isDirectory()?"\u{1F4C1} ":"\u{1F4C4} ",m=o.isDirectory()?"/":"";if(r.push(`${i}${a}${o.name}${m}`),o.isDirectory()&&t<s){const u=l.default.join(e,o.name),d=$(u,t+1,s);d&&r.push(d)}}return r.join(`
6
- `)}catch{return t===0?"\u274C \u65E0\u6CD5\u8BFB\u53D6\u76EE\u5F55":""}}function R(e){const t=e.trim().match(/^\/resume(?:\s+(\S+))?$/i);return t?t[1]!==void 0?t[1]:"":null}function j(e){const t=e.trim().split(/\s+/);return t.length!==5?!1:t.every(s=>/^[\d*/\-]+$/.test(s))}function _(e){const t=e.trim();if(!t.toLowerCase().startsWith("/cron"))return null;const s=t.substring(5).trim();if(!s)return null;if(/^(list|ls)$/i.test(s))return{type:"list"};const n=s.match(/^(?:delete|rm)\s+(\S+)$/i);if(n)return{type:"delete",id:n[1]};const r=s.match(/^pause\s+(\S+)$/i);if(r)return{type:"pause",id:r[1]};const i=s.match(/^resume\s+(\S+)$/i);if(i)return{type:"resume",id:i[1]};const o=s.match(/^(\S+\s+\S+\s+\S+\s+\S+\s+\S+)\s+(.+)$/);return o&&j(o[1])?{type:"create_cron",cronExpression:o[1],prompt:o[2]}:{type:"create_nl",input:s}}function B(e){return e.trim()==="/version"}function A(e){const t=e.trim().toLowerCase();return t==="/open"?"folder":t==="/open shell"?"shell":t==="/open code"?"code":null}function N(e){const t=e.trim().toLowerCase();return t==="/clean"?"current":t==="/clean all"?"all":null}function H(e){return e.trim().toLowerCase()==="/reset-apikeycfg"}function U(e){const t=e.trim();if(!/^\/cfg(?:\s|$)/i.test(t))return null;const s=t.substring(4).trim();if(!s)return{};if(/^--help$/i.test(s))return null;const n={},r=s.split(/\s+/);for(let i=0;i<r.length;i++){const o=r[i];if(o==="--dingToken"&&r[i+1])n.dingToken=r[++i];else if(o==="--linkConversationId"&&r[i+1])n.linkConversationId=r[++i];else if(o==="--conversationId"&&r[i+1])n.conversationId=r[++i];else if(o==="--whiteUserList"&&r[i+1])n.whiteUserList=r[++i].split(",").map(a=>a.trim()).filter(Boolean);else if(o==="--conversationTitle"&&r[i+1]){const a=[];for(;i+1<r.length&&!r[i+1].startsWith("--");)a.push(r[++i]);a.length>0&&(n.conversationTitle=a.join(" "))}else if(o==="--atSender"&&r[i+1]){const a=r[++i].toLowerCase();n.atSender=a==="true"||a==="1"||a==="yes"}else if(o==="--receiveReply"&&r[i+1]){const a=r[++i].toLowerCase();n.receiveReply=a==="true"||a==="1"||a==="yes"}else if(o==="--preBash"&&r[i+1]){const a=[];for(;i+1<r.length&&!r[i+1].startsWith("--");)a.push(r[++i]);a.length>0&&(n.preBash=a.join(" ").replace(/^["']|["']$/g,""))}else o==="--permissionMode"&&r[i+1]&&(n.permissionMode=r[++i])}return n}function E(e){const s=e.trim().match(/^\/bash\s+(.+)$/i);return s&&s[1].trim()||null}function G(e){const t=e.trim();if(!/^\/mq(?:\s|$)/i.test(t)&&t.toLowerCase()!=="/mq")return null;const s=t.substring(3).trim();if(!s)return{type:"list"};if(/^front$/i.test(s))return{type:"front"};if(/^rm$/i.test(s))return{type:"rm",all:!0};const n=s.match(/^rm\s+(.+)$/i);if(n){const r=n[1].trim(),i=[],o=r.match(/^(\d+)\s*-\s*(\d+)$/);if(o){const m=parseInt(o[1],10),u=parseInt(o[2],10);if(m>0&&u>=m){for(let d=m;d<=u;d++)i.push(d);return{type:"rm",indices:i}}}const a=r.split(/\s+/);for(const m of a){const u=parseInt(m,10);u>0&&i.push(u)}if(i.length>0)return{type:"rm",indices:i}}return null}function K(e){const t=e.trim(),s=t.match(/^\/auth\s+admin\s+add\s+(\S+)$/i);if(s)return{type:"adminAdd",staffId:s[1]};const n=t.match(/^\/auth\s+admin\s+(?:rm|del)\s+(\S+)$/i);if(n)return{type:"adminRm",staffId:n[1]};if(/^\/auth\s+admin(?:\s+list)?$/i.test(t))return{type:"adminList"};const r=t.match(/^\/auth\s+add\s+(\S+)$/i);if(r)return{type:"add",staffId:r[1]};const i=t.match(/^\/auth\s+(?:del(?:ete)?|rm)\s+(\S+)$/i);if(i)return{type:"del",staffId:i[1]};const o=t.match(/^\/auth\s+approve\s+(\S+)$/i);if(o)return{type:"approve",requestId:o[1]};const a=t.match(/^\/auth\s+reject\s+(\S+)$/i);return a?{type:"reject",requestId:a[1]}:/^\/auth(?:\s+list)?$/i.test(t)?{type:"list"}:null}function W(e){return/^\/goon$/i.test(e.trim())}function P(e){const s=e.trim().match(/^\/cc\s+(.+)$/i);if(!s)return null;const n=s[1].trim();return n.startsWith("/")?n:`/${n}`}function V(e){return/^\/claude\.md$/i.test(e.trim())}function Y(e){return e.trim()==="/!"}function z(e,t){const s=e.trim();if(!/^\/todo(?:\s|$)/i.test(s)&&s.toLowerCase()!=="/todo")return null;const n=s.substring(5).trim();if(/^list$/i.test(n))return{type:"list"};if(!n)return{type:"list"};const r=n.match(/^mode\s+(staffId|dingtalkId)$/i);if(r)return{type:"mode",mode:r[1]};const i=n.match(/^done\s+(\d+)$/i);if(i)return{type:"done",index:parseInt(i[1],10)};if(/^rm\s+all$/i.test(n))return{type:"remove",index:"all"};const o=n.match(/^rm\s+(\d+)$/i);if(o)return{type:"remove",index:parseInt(o[1],10)};if(/^remind\s+-1$/i.test(n))return{type:"remind",hour:null};const a=n.match(/^remind\s+(\d+)$/i);if(a){const c=parseInt(a[1],10);return c>=0&&c<=23?{type:"remind",hour:c}:null}let m=n,u,d,p;const f=m.match(/@(\S+)/);if(f){const c=f[1];m=m.replace(/@\S+/,"").trim(),u=c,d=c}const h=m.match(/\bddl\s+(.+)$/i);return h&&(p=h[1].trim(),m=m.replace(/\bddl\s+.+$/i,"").trim()),m?{type:"add",content:m,assigneeId:u,assigneeNick:d,deadline:p}:null}function F(e){const t=e.trim();if(!/^\/menu(?:\s|$)/i.test(t)&&t.toLowerCase()!=="/menu")return null;const s=t.substring(5).trim(),n=s.startsWith("-g "),r=n?s.substring(3).trim():s;if(!s)return{type:"show"};if(n&&!r)return{type:"list",isGlobal:!0};const i=r.match(/^trigger\s+(\S+)$/i);if(i&&!n)return{type:"trigger",word:i[1]};const o=r.match(/^add\s+(.+)$/i);if(o)return{type:"add",command:o[1].trim(),isGlobal:n};const a=r.match(/^del(?:ete)?\s+(\d+)$/i);return a?{type:"del",index:parseInt(a[1],10),isGlobal:n}:/^list$/i.test(r)?{type:"list",isGlobal:n}:n?null:{type:"show"}}function Q(e){const t=e.trim();if(!/^\/reboot(?:\s|$)/i.test(t))return null;const s=t.substring(7).trim();if(!s)return{update:!1};const n=s.match(/^--update(?:\s+(\S+))?$/i);return n?{update:!0,tag:n[1]}:null}function J(e){const t=e.trim().toLowerCase();return/^\/(?:recorder|r)\s+on$/i.test(t)?"on":/^\/(?:recorder|r)\s+(?:exit|e)$/i.test(t)||/^\/(?:exit|e)$/i.test(t)?"exit":null}
3
+ `)}function S(e){return e.trim().toLowerCase()==="/end"}function L(e){const t=e.trim().toLowerCase();return t==="/info"?"all":t==="/info robot"?"robot":t==="/info session"?"session":t==="/info task"?"task":null}function v(e,t,s,r){const n=[`- **\u7FA4ID:** ${t}`];if(e.conversationTitle&&n.push(`- **\u7FA4\u540D\u79F0:** ${e.conversationTitle}`),e.conversationType&&n.push(`- **\u4F1A\u8BDD\u7C7B\u578B:** ${e.conversationType==="1"?"\u5355\u804A":e.conversationType==="2"?"\u7FA4\u804A":e.conversationType}`),r&&n.push(`- **\u5DE5\u4F5C\u76EE\u5F55:** \`${r}\``),e.linkConversationId&&n.push(`- **\u5173\u8054\u4F1A\u8BDDID:** ${e.linkConversationId}`),e.agent&&n.push(`- **agent:** ${e.agent}`),e.dingToken&&n.push(`- **dingToken:** ${e.dingToken.substring(0,8)}...`),e.whiteUserList?.length){const i=e.whiteUserList.map(o=>s?.(o)||o).join(", ");n.push(`- **\u7FA4\u767D\u540D\u5355:** ${i}`)}return e.atSender===!1&&n.push("- **atSender:** false"),e.receiveReply===!1&&n.push("- **receiveReply:** false (\u4E0D\u56DE\u590D\u786E\u8BA4\u6D88\u606F)"),e.freedomMode&&n.push("- **freedomMode:** \u5DF2\u5F00\u542F\uFF08\u8DF3\u8FC7\u767D\u540D\u5355\u9650\u5236\uFF09"),e.useLocalOcr===!1&&n.push("- **\u672C\u5730OCR:** \u5173\u95ED"),e.permissionMode&&n.push(`- **permissionMode:** ${e.permissionMode}`),e.taskCfg?.skill&&n.push(`- **taskSkill:** ${e.taskCfg.skill}`),e.preBash&&n.push(`- **preBash:** \`${e.preBash}\``),n.join(`
4
+ `)}function T(e){const t=[`- **clientName:** ${e.clientName||"-"}`,`- **sessionMaxConcurrency:** ${e.sessionMaxConcurrency??5}`,`- **taskHandlerCount:** ${e.taskHandlerCount??1}`,`- **taskQueueSize:** ${e.taskQueueSize??50}`,`- **includeThinking:** ${e.includeThinking??!1}`,`- **resultOnly:** ${e.resultOnly??!0}`];if(e.defaultDingToken&&t.push(`- **defaultDingToken:** ${e.defaultDingToken.substring(0,8)}...`),e.owner&&t.push(`- **owner:** ${e.owner}`),e.whiteUserList?.length&&t.push(`- **\u5168\u5C40\u767D\u540D\u5355:** ${e.whiteUserList.join(", ")}`),e.apiKeyCfg){const s=e.apiKeyCfg.claudeSettings.filter(r=>r.isValid).length;t.push(`- **apiKeyCfg:** ${s}/${e.apiKeyCfg.claudeSettings.length} \u6709\u6548`),t.push(` - **\u6700\u8FD1\u91CD\u7F6E:** ${e.apiKeyCfg.resetTime||"-"}`)}return t.join(`
5
+ `)}function q(e){const s=e.trim().match(/^\/log(?:\s+(\d+))?$/i);if(!s)return null;const r=parseInt(s[1],10);return isNaN(r)||r<=0?10:r}function D(e){const s=e.trim().match(/^\/ls(?:\s+(.+))?$/i);if(!s)return null;if(s[1]===void 0)return{target:"",depth:1};const r=s[1].trim().split(/\s+/),n=r[0]||"",i=r[1]?parseInt(r[1],10):1;return{target:n,depth:isNaN(i)||i<0?1:Math.min(i,5)}}function O(e,t,s=3){const r=[{dir:e,depth:0}];for(;r.length>0;){const{dir:n,depth:i}=r.shift();if(!(i>s))try{const o=y.default.readdirSync(n,{withFileTypes:!0});for(const a of o)if(!(!a.isDirectory()||a.name.startsWith("."))){if(a.name===t)return l.default.join(n,a.name);r.push({dir:l.default.join(n,a.name),depth:i+1})}}catch{continue}}return null}function $(e,t=0,s=1){try{const r=y.default.readdirSync(e,{withFileTypes:!0}).filter(o=>!o.name.startsWith("."));if(r.length===0)return t===0?"\u{1F4C2} \u76EE\u5F55\u4E3A\u7A7A":"";r.sort((o,a)=>o.isDirectory()!==a.isDirectory()?o.isDirectory()?-1:1:o.name.localeCompare(a.name));const n=[],i=". ".repeat(t);for(const o of r){const a=o.isDirectory()?"\u{1F4C1} ":"\u{1F4C4} ",m=o.isDirectory()?"/":"";if(n.push(`${i}${a}${o.name}${m}`),o.isDirectory()&&t<s){const d=l.default.join(e,o.name),u=$(d,t+1,s);u&&n.push(u)}}return n.join(`
6
+ `)}catch{return t===0?"\u274C \u65E0\u6CD5\u8BFB\u53D6\u76EE\u5F55":""}}function R(e){const t=e.trim().match(/^\/resume(?:\s+(\S+))?$/i);return t?t[1]!==void 0?t[1]:"":null}function j(e){const t=e.trim().split(/\s+/);return t.length!==5?!1:t.every(s=>/^[\d*/\-]+$/.test(s))}function _(e){const t=e.trim();if(!t.toLowerCase().startsWith("/cron"))return null;const s=t.substring(5).trim();if(!s)return null;if(/^(list|ls)$/i.test(s))return{type:"list"};const r=s.match(/^(?:delete|rm)\s+(\S+)$/i);if(r)return{type:"delete",id:r[1]};const n=s.match(/^pause\s+(\S+)$/i);if(n)return{type:"pause",id:n[1]};const i=s.match(/^resume\s+(\S+)$/i);if(i)return{type:"resume",id:i[1]};const o=s.match(/^(\S+\s+\S+\s+\S+\s+\S+\s+\S+)\s+(.+)$/);return o&&j(o[1])?{type:"create_cron",cronExpression:o[1],prompt:o[2]}:{type:"create_nl",input:s}}function B(e){return e.trim()==="/version"}function A(e){const t=e.trim().toLowerCase();return t==="/open"?"folder":t==="/open shell"?"shell":t==="/open code"?"code":null}function N(e){const t=e.trim().toLowerCase();return t==="/clean"?"current":t==="/clean all"?"all":null}function H(e){return e.trim().toLowerCase()==="/reset-apikeycfg"}function U(e){const t=e.trim();if(!/^\/cfg(?:\s|$)/i.test(t))return null;const s=t.substring(4).trim();if(!s)return{};if(/^--help$/i.test(s))return null;const r={},n=s.split(/\s+/);for(let i=0;i<n.length;i++){const o=n[i];if(o==="--dingToken"&&n[i+1])r.dingToken=n[++i];else if(o==="--linkConversationId"&&n[i+1])r.linkConversationId=n[++i];else if(o==="--conversationId"&&n[i+1])r.conversationId=n[++i];else if(o==="--whiteUserList"&&n[i+1])r.whiteUserList=n[++i].split(",").map(a=>a.trim()).filter(Boolean);else if(o==="--conversationTitle"&&n[i+1]){const a=[];for(;i+1<n.length&&!n[i+1].startsWith("--");)a.push(n[++i]);a.length>0&&(r.conversationTitle=a.join(" "))}else if(o==="--atSender"&&n[i+1]){const a=n[++i].toLowerCase();r.atSender=a==="true"||a==="1"||a==="yes"}else if(o==="--receiveReply"&&n[i+1]){const a=n[++i].toLowerCase();r.receiveReply=a==="true"||a==="1"||a==="yes"}else if(o==="--preBash"&&n[i+1]){const a=[];for(;i+1<n.length&&!n[i+1].startsWith("--");)a.push(n[++i]);a.length>0&&(r.preBash=a.join(" ").replace(/^["']|["']$/g,""))}else o==="--permissionMode"&&n[i+1]&&(r.permissionMode=n[++i])}return r}function E(e){const s=e.trim().match(/^\/bash\s+(.+)$/i);return s&&s[1].trim()||null}function G(e){const t=e.trim();if(!/^\/mq(?:\s|$)/i.test(t)&&t.toLowerCase()!=="/mq")return null;const s=t.substring(3).trim();if(!s)return{type:"list"};if(/^front$/i.test(s))return{type:"front"};if(/^rm$/i.test(s))return{type:"rm",all:!0};const r=s.match(/^rm\s+(.+)$/i);if(r){const n=r[1].trim(),i=[],o=n.match(/^(\d+)\s*-\s*(\d+)$/);if(o){const m=parseInt(o[1],10),d=parseInt(o[2],10);if(m>0&&d>=m){for(let u=m;u<=d;u++)i.push(u);return{type:"rm",indices:i}}}const a=n.split(/\s+/);for(const m of a){const d=parseInt(m,10);d>0&&i.push(d)}if(i.length>0)return{type:"rm",indices:i}}return null}function K(e){const t=e.trim(),s=t.match(/^\/auth\s+admin\s+add\s+(\S+)$/i);if(s)return{type:"adminAdd",staffId:s[1]};const r=t.match(/^\/auth\s+admin\s+(?:rm|del)\s+(\S+)$/i);if(r)return{type:"adminRm",staffId:r[1]};if(/^\/auth\s+admin(?:\s+list)?$/i.test(t))return{type:"adminList"};const n=t.match(/^\/auth\s+add\s+(\S+)$/i);if(n)return{type:"add",staffId:n[1]};const i=t.match(/^\/auth\s+(?:del(?:ete)?|rm)\s+(\S+)$/i);if(i)return{type:"del",staffId:i[1]};const o=t.match(/^\/auth\s+approve\s+(\S+)$/i);if(o)return{type:"approve",requestId:o[1]};const a=t.match(/^\/auth\s+reject\s+(\S+)$/i);return a?{type:"reject",requestId:a[1]}:/^\/auth(?:\s+list)?$/i.test(t)?{type:"list"}:null}function W(e){return/^\/goon$/i.test(e.trim())}function P(e){const s=e.trim().match(/^\/cc\s+(.+)$/i);if(!s)return null;const r=s[1].trim();return r.startsWith("/")?r:`/${r}`}function F(e){return/^\/claude\.md$/i.test(e.trim())}function V(e){const t=e.trim();return t==="/!"||t==="/\uFF01"||t==="!"||t==="\uFF01"}function Y(e){const t=e.trim();if(!/^\/destroy(\b|$)/.test(t))return null;const s=t.substring(8).trim();if(!s)return{};if(/^--help$/i.test(s))return null;const r={},n=s.split(/\s+/);for(let i=0;i<n.length;i++)n[i]==="--conversationId"&&n[i+1]&&(r.conversationId=n[++i]);return r}function z(e){const t=e.trim();if(!/^\/freedom(\b|$)/i.test(t))return null;const s=t.substring(8).trim().toLowerCase();return s?s==="exit"?{action:"exit"}:null:{action:"enter"}}function Q(e,t){const s=e.trim();if(!/^\/todo(?:\s|$)/i.test(s)&&s.toLowerCase()!=="/todo")return null;const r=s.substring(5).trim();if(/^list$/i.test(r))return{type:"list"};if(!r)return{type:"list"};const n=r.match(/^mode\s+(staffId|dingtalkId)$/i);if(n)return{type:"mode",mode:n[1]};const i=r.match(/^done\s+(\d+)$/i);if(i)return{type:"done",index:parseInt(i[1],10)};if(/^rm\s+all$/i.test(r))return{type:"remove",index:"all"};const o=r.match(/^rm\s+(\d+)$/i);if(o)return{type:"remove",index:parseInt(o[1],10)};if(/^remind\s+-1$/i.test(r))return{type:"remind",hour:null};const a=r.match(/^remind\s+(\d+)$/i);if(a){const c=parseInt(a[1],10);return c>=0&&c<=23?{type:"remind",hour:c}:null}let m=r,d,u,p;const f=m.match(/@(\S+)/);if(f){const c=f[1];m=m.replace(/@\S+/,"").trim(),d=c,u=c}const h=m.match(/\bddl\s+(.+)$/i);return h&&(p=h[1].trim(),m=m.replace(/\bddl\s+.+$/i,"").trim()),m?{type:"add",content:m,assigneeId:d,assigneeNick:u,deadline:p}:null}function J(e){const t=e.trim();if(!/^\/menu(?:\s|$)/i.test(t)&&t.toLowerCase()!=="/menu")return null;const s=t.substring(5).trim(),r=s.startsWith("-g "),n=r?s.substring(3).trim():s;if(!s)return{type:"show"};if(r&&!n)return{type:"list",isGlobal:!0};const i=n.match(/^trigger\s+(\S+)$/i);if(i&&!r)return{type:"trigger",word:i[1]};const o=n.match(/^add\s+(.+)$/i);if(o)return{type:"add",command:o[1].trim(),isGlobal:r};const a=n.match(/^del(?:ete)?\s+(\d+)$/i);return a?{type:"del",index:parseInt(a[1],10),isGlobal:r}:/^list$/i.test(n)?{type:"list",isGlobal:r}:r?null:{type:"show"}}function X(e){const t=e.trim();if(!/^\/reboot(?:\s|$)/i.test(t))return null;const s=t.substring(7).trim();if(!s)return{update:!1};const r=s.match(/^--update(?:\s+(\S+))?$/i);return r?{update:!0,tag:r[1]}:null}function Z(e){const t=e.trim();return/^\/recorder\s+on$/i.test(t)?"on":/^\/recorder\s+exit$/i.test(t)?"exit":null}
@@ -1,6 +1,6 @@
1
- "use strict";var $=exports&&exports.__importDefault||function(e){return e&&e.__esModule?e:{default:e}};Object.defineProperty(exports,"__esModule",{value:!0}),exports.fetchQuotedMessage=U,exports.queryDingUser=A,exports.queryUserIdByMobile=w,exports.filterToolUseContent=M,exports.splitMessage=_,exports.sendDingMessage=k,exports.sendClaudeResponseToDing=q,exports.sendMessageToUser=O,exports.sendOwnerMessage=x;const I=require("utils-ok"),u=$(require("urllib")),m=require("./secrets"),h="https://api.dingtalk.com",b="https://oapi.dingtalk.com";async function U(e,t){try{const o=await e.dingStreamClient.getAccessToken(),s=`${h}/v1.0/im/api/messages/${encodeURIComponent(t)}`,r=await u.default.request(s,{method:"GET",headers:{"x-acs-dingtalk-access-token":o},dataType:"json",timeout:5e3});if(r.status!==200||!r.data)return e.debugLog(`fetchQuotedMessage API \u8FD4\u56DE\u975E200: status=${r.status}, data=${JSON.stringify(r.data)}`),null;const n=r.data;if(n.text&&typeof n.text=="object"){const a=n.text.content;if(typeof a=="string"&&a)return a.trim()}if(typeof n.content=="string"&&n.content)try{const a=JSON.parse(n.content);if(typeof a=="string")return a.trim();if(a.text)return String(a.text).trim();if(a.content)return String(a.content).trim()}catch{return n.content.trim()}if(n.body&&typeof n.body=="object"){const a=n.body;if(typeof a.content=="string"&&a.content)return a.content.trim()}return e.debugLog(`fetchQuotedMessage \u65E0\u6CD5\u4ECE\u54CD\u5E94\u4E2D\u63D0\u53D6\u6587\u672C: keys=${Object.keys(n).join(",")}`),null}catch(o){return console.warn("fetchQuotedMessage \u8BF7\u6C42\u5931\u8D25:",o),null}}async function A(e,t){try{const o=await e.dingStreamClient.getAccessToken(),s=`${b}/topapi/v2/user/get?access_token=${o}`,r=await u.default.request(s,{method:"POST",data:{userid:t},contentType:"json",dataType:"json",timeout:5e3});if(r.status!==200||!r.data)return e.debugLog(`queryDingUser API \u8FD4\u56DE\u975E200: status=${r.status}, data=${JSON.stringify(r.data)}`),null;const n=r.data;return n.errcode!==0?(console.warn(`queryDingUser \u63A5\u53E3\u8FD4\u56DE\u9519\u8BEF: errcode=${n.errcode}, errmsg=${n.errmsg}`),null):n.result||null}catch(o){return console.warn("queryDingUser \u8BF7\u6C42\u5931\u8D25:",o),null}}async function w(e,t){try{const o=await e.dingStreamClient.getAccessToken(),s=`${b}/topapi/v2/user/getbymobile?access_token=${o}`,r=await u.default.request(s,{method:"POST",data:{mobile:t},contentType:"json",dataType:"json",timeout:5e3});if(r.status!==200||!r.data)return e.debugLog(`queryUserIdByMobile API \u8FD4\u56DE\u975E200: status=${r.status}, data=${JSON.stringify(r.data)}`),null;const n=r.data;return n.errcode!==0?(console.warn(`queryUserIdByMobile \u63A5\u53E3\u8FD4\u56DE\u9519\u8BEF: errcode=${n.errcode}, errmsg=${n.errmsg}`),null):n.result?.userid||null}catch(o){return console.warn("queryUserIdByMobile \u8BF7\u6C42\u5931\u8D25:",o),null}}const S=["Write","Read","Edit","Bash","Grep","Glob","Agent","Skill","WebFetch","WebSearch","TaskOutput","AskUserQuestion","EnterPlanMode","ExitPlanMode","TaskCreate","TaskGet","TaskUpdate","TaskList","EnterWorktree","ExitWorktree","CronCreate","CronDelete","CronList","LSP","NotebookEdit"].join("|"),E=new RegExp(`<(${S})[^>]*\\/>`,"g"),C=new RegExp(`<(${S})[^>]*>[\\s\\S]*?<\\/\\1>`,"g"),j=/\n{3,}/g;function M(e){let t=e.replace(E,"");return t=t.replace(C,""),t=t.replace(j,`
1
+ "use strict";var $=exports&&exports.__importDefault||function(e){return e&&e.__esModule?e:{default:e}};Object.defineProperty(exports,"__esModule",{value:!0}),exports.fetchQuotedMessage=U,exports.queryDingUser=A,exports.queryUserIdByMobile=w,exports.queryUserIdByJobNumber=j,exports.filterToolUseContent=_,exports.splitMessage=M,exports.sendDingMessage=p,exports.sendClaudeResponseToDing=N,exports.sendMessageToUser=O,exports.sendOwnerMessage=P;const I=require("utils-ok"),u=$(require("urllib")),m=require("./secrets"),h="https://api.dingtalk.com",k="https://oapi.dingtalk.com";async function U(e,n){try{const o=await e.dingStreamClient.getAccessToken(),r=`${h}/v1.0/im/api/messages/${encodeURIComponent(n)}`,s=await u.default.request(r,{method:"GET",headers:{"x-acs-dingtalk-access-token":o},dataType:"json",timeout:5e3});if(s.status!==200||!s.data)return e.debugLog(`fetchQuotedMessage API \u8FD4\u56DE\u975E200: status=${s.status}, data=${JSON.stringify(s.data)}`),null;const t=s.data;if(t.text&&typeof t.text=="object"){const a=t.text.content;if(typeof a=="string"&&a)return a.trim()}if(typeof t.content=="string"&&t.content)try{const a=JSON.parse(t.content);if(typeof a=="string")return a.trim();if(a.text)return String(a.text).trim();if(a.content)return String(a.content).trim()}catch{return t.content.trim()}if(t.body&&typeof t.body=="object"){const a=t.body;if(typeof a.content=="string"&&a.content)return a.content.trim()}return e.debugLog(`fetchQuotedMessage \u65E0\u6CD5\u4ECE\u54CD\u5E94\u4E2D\u63D0\u53D6\u6587\u672C: keys=${Object.keys(t).join(",")}`),null}catch(o){return console.warn("fetchQuotedMessage \u8BF7\u6C42\u5931\u8D25:",o),null}}async function A(e,n){try{const o=await e.dingStreamClient.getAccessToken(),r=`${k}/topapi/v2/user/get?access_token=${o}`,s=await u.default.request(r,{method:"POST",data:{userid:n},contentType:"json",dataType:"json",timeout:5e3});if(s.status!==200||!s.data)return e.debugLog(`queryDingUser API \u8FD4\u56DE\u975E200: status=${s.status}, data=${JSON.stringify(s.data)}`),null;const t=s.data;return t.errcode!==0?(console.warn(`queryDingUser \u63A5\u53E3\u8FD4\u56DE\u9519\u8BEF: errcode=${t.errcode}, errmsg=${t.errmsg}`),null):t.result||null}catch(o){return console.warn("queryDingUser \u8BF7\u6C42\u5931\u8D25:",o),null}}async function w(e,n){try{const o=await e.dingStreamClient.getAccessToken(),r=`${k}/topapi/v2/user/getbymobile?access_token=${o}`,s=await u.default.request(r,{method:"POST",data:{mobile:n},contentType:"json",dataType:"json",timeout:5e3});if(s.status!==200||!s.data)return e.debugLog(`queryUserIdByMobile API \u8FD4\u56DE\u975E200: status=${s.status}, data=${JSON.stringify(s.data)}`),null;const t=s.data;return t.errcode!==0?(console.warn(`queryUserIdByMobile \u63A5\u53E3\u8FD4\u56DE\u9519\u8BEF: errcode=${t.errcode}, errmsg=${t.errmsg}`),null):t.result?.userid||null}catch(o){return console.warn("queryUserIdByMobile \u8BF7\u6C42\u5931\u8D25:",o),null}}async function j(e,n){try{const o=await e.dingStreamClient.getAccessToken(),r=`${k}/topapi/v2/user/getbyjobnumber?access_token=${o}`,s=await u.default.request(r,{method:"POST",data:{job_number:n},contentType:"json",dataType:"json",timeout:5e3});if(s.status!==200||!s.data)return e.debugLog(`queryUserIdByJobNumber API \u8FD4\u56DE\u975E200: status=${s.status}, data=${JSON.stringify(s.data)}`),null;const t=s.data;return t.errcode!==0?(console.warn(`queryUserIdByJobNumber \u63A5\u53E3\u8FD4\u56DE\u9519\u8BEF: errcode=${t.errcode}, errmsg=${t.errmsg}`),null):t.result?.userid||null}catch(o){return console.warn("queryUserIdByJobNumber \u8BF7\u6C42\u5931\u8D25:",o),null}}const S=["Write","Read","Edit","Bash","Grep","Glob","Agent","Skill","WebFetch","WebSearch","TaskOutput","AskUserQuestion","EnterPlanMode","ExitPlanMode","TaskCreate","TaskGet","TaskUpdate","TaskList","EnterWorktree","ExitWorktree","CronCreate","CronDelete","CronList","LSP","NotebookEdit"].join("|"),q=new RegExp(`<(${S})[^>]*\\/>`,"g"),E=new RegExp(`<(${S})[^>]*>[\\s\\S]*?<\\/\\1>`,"g"),C=/\n{3,}/g;function _(e){let n=e.replace(q,"");return n=n.replace(E,""),n=n.replace(C,`
2
2
 
3
- `),t.trim()}function _(e,t){const o=[];for(;e.length>t;){let s=e.lastIndexOf(`
4
- `,t);(s===-1||s<t*.5)&&(s=e.lastIndexOf("\u3002",t)),(s===-1||s<t*.5)&&(s=e.lastIndexOf(" ",t)),s===-1||s<t*.5?s=t:s+=1,o.push(e.substring(0,s).trim()),e=e.substring(s).trim()}return e.length>0&&o.push(e),o}async function k(e,t){const{conversationId:o,sessionWebhook:s,atUserId:r,content:n,msgType:a="text"}=t,c=e.config.conversations.find(d=>d.conversationId===o);let i=r;(c?.atSender===!1||c?.conversationType==="1")&&(i=void 0);const g=i?[i]:[],p=(0,m.resolveSecret)(c?.dingToken);let f=n;i&&a==="markdown"&&(f=`${n}
5
- @${i}`);const y=a==="markdown"?{msgtype:"markdown",markdown:{title:f,text:f},at:{atUserIds:g,isAtAll:!1}}:{msgtype:"text",text:{content:n},at:{atUserIds:g,isAtAll:!1}};if(p){const d=await e.dingStreamClient.getAccessToken(),l=`https://oapi.dingtalk.com/robot/send?access_token=${p}`;try{await u.default.request(l,{method:"POST",data:y,contentType:"json",headers:{"x-acs-dingtalk-access-token":d},dataType:"json"})}catch(T){console.error("\u901A\u8FC7 dingToken \u53D1\u9001\u9489\u9489\u6D88\u606F\u5931\u8D25:",T)}}else if(s){const d=await e.dingStreamClient.getAccessToken();try{await u.default.request(s,{method:"POST",data:y,contentType:"json",headers:{"x-acs-dingtalk-access-token":d},dataType:"json"})}catch(l){console.error("\u901A\u8FC7 sessionWebhook \u53D1\u9001\u9489\u9489\u6D88\u606F\u5931\u8D25:",l)}}else if(e.config.defaultDingToken){const d=await e.dingStreamClient.getAccessToken(),l=`https://oapi.dingtalk.com/robot/send?access_token=${(0,m.resolveSecret)(e.config.defaultDingToken)}`;try{await u.default.request(l,{method:"POST",data:y,contentType:"json",headers:{"x-acs-dingtalk-access-token":d},dataType:"json"})}catch(T){console.error("\u901A\u8FC7 defaultDingToken \u53D1\u9001\u9489\u9489\u6D88\u606F\u5931\u8D25:",T)}}else console.error("\u672A\u80FD\u83B7\u53D6\u673A\u5668\u4EBA\u4FE1\u606F\u53D1\u9001\u9014\u5F84")}async function q(e,t,o,s,r){const a=M(r);if(!a){e.debugLog("\u8FC7\u6EE4\u540E\u5185\u5BB9\u4E3A\u7A7A\uFF0C\u8DF3\u8FC7\u53D1\u9001");return}if(a.length<=18e3)await k(e,{conversationId:t,sessionWebhook:o,atUserId:s,content:a,msgType:"markdown"});else{const c=_(a,18e3);for(let i=0;i<c.length;i++){const g=c.length>1?`**[${i+1}/${c.length}]**
6
- `:"";await k(e,{conversationId:t,sessionWebhook:o,atUserId:i===c.length-1?s:"",content:g+c[i],msgType:"markdown"}),i<c.length-1&&await I.asyncUtil.sleep(500)}}}async function O(e,t,o,s="text"){if(!e.config.enableMsgToUser)return console.log(`[sendMessageToUser] enableMsgToUser \u672A\u5F00\u542F\uFF0C\u8DF3\u8FC7\u53D1\u9001 (userId=${t})`),!1;try{const r=await e.dingStreamClient.getAccessToken(),n=s==="markdown"?"sampleMarkdown":"sampleText",a=JSON.stringify(s==="markdown"?{title:"notification",text:o}:{content:o}),c=await u.default.request(`${h}/v1.0/robot/oToMessages/batchSend`,{method:"POST",data:{robotCode:e.clientId,userIds:[t],msgKey:n,msgParam:a},contentType:"json",headers:{"x-acs-dingtalk-access-token":r},dataType:"json"});return c.status===200?!0:(console.error(`sendMessageToUser API \u8FD4\u56DE\u975E200: status=${c.status}, userId=${t}`),!1)}catch(r){return console.error(`sendMessageToUser \u5931\u8D25 (userId=${t}):`,r),!1}}async function x(e,t,o="text"){const{ownerConversationId:s,owner:r}=e.config;if(!s||!r)return!1;const n=await w(e,r);return n?O(e,n,t,o):(console.error(`sendOwnerMessage: \u65E0\u6CD5\u5C06\u624B\u673A\u53F7 ${r} \u89E3\u6790\u4E3A Ding userId`),!1)}
3
+ `),n.trim()}function M(e,n){const o=[];for(;e.length>n;){let r=e.lastIndexOf(`
4
+ `,n);(r===-1||r<n*.5)&&(r=e.lastIndexOf("\u3002",n)),(r===-1||r<n*.5)&&(r=e.lastIndexOf(" ",n)),r===-1||r<n*.5?r=n:r+=1,o.push(e.substring(0,r).trim()),e=e.substring(r).trim()}return e.length>0&&o.push(e),o}async function p(e,n){const{conversationId:o,sessionWebhook:r,atUserId:s,content:t,msgType:a="text"}=n,c=e.config.conversations.find(d=>d.conversationId===o);let i=s;(c?.atSender===!1||c?.conversationType==="1")&&(i=void 0);const g=i?[i]:[],b=(0,m.resolveSecret)(c?.dingToken);let y=t;i&&a==="markdown"&&(y=`${t}
5
+ @${i}`);const f=a==="markdown"?{msgtype:"markdown",markdown:{title:y,text:y},at:{atUserIds:g,isAtAll:!1}}:{msgtype:"text",text:{content:t},at:{atUserIds:g,isAtAll:!1}};if(b){const d=await e.dingStreamClient.getAccessToken(),l=`https://oapi.dingtalk.com/robot/send?access_token=${b}`;try{await u.default.request(l,{method:"POST",data:f,contentType:"json",headers:{"x-acs-dingtalk-access-token":d},dataType:"json"})}catch(T){console.error("\u901A\u8FC7 dingToken \u53D1\u9001\u9489\u9489\u6D88\u606F\u5931\u8D25:",T)}}else if(r){const d=await e.dingStreamClient.getAccessToken();try{await u.default.request(r,{method:"POST",data:f,contentType:"json",headers:{"x-acs-dingtalk-access-token":d},dataType:"json"})}catch(l){console.error("\u901A\u8FC7 sessionWebhook \u53D1\u9001\u9489\u9489\u6D88\u606F\u5931\u8D25:",l)}}else if(e.config.defaultDingToken){const d=await e.dingStreamClient.getAccessToken(),l=`https://oapi.dingtalk.com/robot/send?access_token=${(0,m.resolveSecret)(e.config.defaultDingToken)}`;try{await u.default.request(l,{method:"POST",data:f,contentType:"json",headers:{"x-acs-dingtalk-access-token":d},dataType:"json"})}catch(T){console.error("\u901A\u8FC7 defaultDingToken \u53D1\u9001\u9489\u9489\u6D88\u606F\u5931\u8D25:",T)}}else console.error("\u672A\u80FD\u83B7\u53D6\u673A\u5668\u4EBA\u4FE1\u606F\u53D1\u9001\u9014\u5F84")}async function N(e,n,o,r,s){const a=_(s);if(!a){e.debugLog("\u8FC7\u6EE4\u540E\u5185\u5BB9\u4E3A\u7A7A\uFF0C\u8DF3\u8FC7\u53D1\u9001");return}if(a.length<=18e3)await p(e,{conversationId:n,sessionWebhook:o,atUserId:r,content:a,msgType:"markdown"});else{const c=M(a,18e3);for(let i=0;i<c.length;i++){const g=c.length>1?`**[${i+1}/${c.length}]**
6
+ `:"";await p(e,{conversationId:n,sessionWebhook:o,atUserId:i===c.length-1?r:"",content:g+c[i],msgType:"markdown"}),i<c.length-1&&await I.asyncUtil.sleep(500)}}}async function O(e,n,o,r="text"){if(!e.config.enableMsgToUser)return console.log(`[sendMessageToUser] enableMsgToUser \u672A\u5F00\u542F\uFF0C\u8DF3\u8FC7\u53D1\u9001 (userId=${n})`),!1;try{const s=await e.dingStreamClient.getAccessToken(),t=r==="markdown"?"sampleMarkdown":"sampleText",a=JSON.stringify(r==="markdown"?{title:"notification",text:o}:{content:o}),c=await u.default.request(`${h}/v1.0/robot/oToMessages/batchSend`,{method:"POST",data:{robotCode:e.clientId,userIds:[n],msgKey:t,msgParam:a},contentType:"json",headers:{"x-acs-dingtalk-access-token":s},dataType:"json"});return c.status===200?!0:(console.error(`sendMessageToUser API \u8FD4\u56DE\u975E200: status=${c.status}, userId=${n}`),!1)}catch(s){return console.error(`sendMessageToUser \u5931\u8D25 (userId=${n}):`,s),!1}}async function P(e,n,o="text"){const{ownerConversationId:r,owner:s}=e.config;if(!r||!s)return!1;const t=await w(e,s);return t?O(e,t,n,o):(console.error(`sendOwnerMessage: \u65E0\u6CD5\u5C06\u624B\u673A\u53F7 ${s} \u89E3\u6790\u4E3A Ding userId`),!1)}
@@ -1 +1 @@
1
- "use strict";var g=exports&&exports.__importDefault||function(e){return e&&e.__esModule?e:{default:e}};Object.defineProperty(exports,"__esModule",{value:!0}),exports.sendNotify=F;const u=g(require("fs")),S=g(require("path")),N=g(require("os")),m=g(require("urllib")),O=require("./secrets"),I="https://api.dingtalk.com",q="https://oapi.dingtalk.com";function w(e){return S.default.join(N.default.homedir(),".cc-ding",e)}function P(e){return S.default.join(w(e),"phone-map.json")}function M(e){const n=P(e);if(!u.default.existsSync(n))return{};try{const t=JSON.parse(u.default.readFileSync(n,"utf-8"));if(typeof t=="object"&&t!==null)return t}catch{}return{}}function x(e,n){const t=P(e);try{u.default.writeFileSync(t,JSON.stringify(n,null,2),"utf-8")}catch{}}async function D(e,n){const t=await m.default.request(`${I}/v1.0/oauth2/accessToken`,{method:"POST",data:{appKey:e,appSecret:n},contentType:"json",dataType:"json",timeout:1e4});if(t.status!==200||!t.data?.accessToken)throw new Error(`\u83B7\u53D6 accessToken \u5931\u8D25: ${JSON.stringify(t.data)}`);return t.data.accessToken}async function E(e,n){const t=await m.default.request(`${q}/topapi/v2/user/getbymobile?access_token=${e}`,{method:"POST",data:{mobile:n},contentType:"json",dataType:"json",timeout:5e3});if(t.status!==200||!t.data)return null;const r=t.data;return r.errcode!==0?null:r.result?.userid||null}async function J(e,n,t,r,c){const h=c?"sampleMarkdown":"sampleText",f=JSON.stringify(c?{title:"notification",text:r}:{content:r});return(await m.default.request(`${I}/v1.0/robot/oToMessages/batchSend`,{method:"POST",data:{robotCode:n,userIds:[t],msgKey:h,msgParam:f},contentType:"json",headers:{"x-acs-dingtalk-access-token":e},dataType:"json"})).status===200}async function F(e){const{clientId:n,message:t,conversationIds:r,atUserIds:c=[],mobiles:h=[],markdown:f=!1}=e,b=w(n),T=S.default.join(b,"config.json");if(!u.default.existsSync(T))return console.error(`\u274C \u914D\u7F6E\u6587\u4EF6\u4E0D\u5B58\u5728: ${T}`),{success:0,fail:r.length};let d;try{d=JSON.parse(u.default.readFileSync(T,"utf-8"))}catch(a){return console.error(`\u274C \u914D\u7F6E\u6587\u4EF6\u89E3\u6790\u5931\u8D25: ${a instanceof Error?a.message:a}`),{success:0,fail:r.length}}let $=0,i=0,y=null;const k=M(n);for(const a of r){const p=d.conversations.find(o=>o.conversationId===a),l=p?.conversationTitle||a;if(p?.conversationType==="1"){const o=h[r.indexOf(a)]||p.mobile;if(!o){console.error(` \u2717 ${l}: \u5355\u804A\u7F3A\u5C11\u624B\u673A\u53F7\uFF08\u8BF7\u914D\u7F6E conversations[].mobile \u6216\u4F20 --mobile\uFF09`),i++;continue}try{y||(y=await D(n,(0,O.resolveSecret)(d.clientSecret)));let s=k[o];if(s||(s=await E(y,o),s&&(k[o]=s,x(n,k))),!s){console.error(` \u2717 ${l}: \u65E0\u6CD5\u89E3\u6790\u624B\u673A\u53F7 ${o} \u4E3A userId`),i++;continue}await J(y,n,s,t,f)?(console.log(` \u2713 ${l}`),$++):(console.error(` \u2717 ${l}: API \u8FD4\u56DE\u5931\u8D25`),i++)}catch(s){console.error(` \u2717 ${l}: ${s instanceof Error?s.message:s}`),i++}continue}const _=(0,O.resolveSecret)(p?.dingToken||d.defaultDingToken);if(!_){console.error(` \u2717 ${l}: \u65E0 dingToken \u53EF\u7528`),i++;continue}try{const o=c.length>0?`${t} ${c.map(A=>`@${A}`).join(" ")}`:t,s=f?{msgtype:"markdown",markdown:{title:o,text:o},at:{atUserIds:c,isAtAll:!1}}:{msgtype:"text",text:{content:o},at:{atUserIds:c,isAtAll:!1}},j=`https://oapi.dingtalk.com/robot/send?access_token=${_}`,v=await m.default.request(j,{method:"POST",data:s,contentType:"json",dataType:"json"});v.status===200?(console.log(` \u2713 ${l}`),$++):(console.error(` \u2717 ${a}: HTTP ${v.status}`),i++)}catch(o){console.error(` \u2717 ${a}: ${o instanceof Error?o.message:o}`),i++}}return{success:$,fail:i}}
1
+ "use strict";var p=exports&&exports.__importDefault||function(e){return e&&e.__esModule?e:{default:e}};Object.defineProperty(exports,"__esModule",{value:!0}),exports.sendNotify=F;const u=p(require("fs")),S=p(require("path")),N=p(require("os")),m=p(require("urllib")),O=require("./secrets"),I="https://api.dingtalk.com",q="https://oapi.dingtalk.com";function w(e){return S.default.join(N.default.homedir(),".cc-ding",e)}function P(e){return S.default.join(w(e),"user-map.json")}function M(e){const n=P(e);if(!u.default.existsSync(n))return{};try{const t=JSON.parse(u.default.readFileSync(n,"utf-8"));if(typeof t=="object"&&t!==null)return t}catch{}return{}}function x(e,n){const t=P(e);try{u.default.writeFileSync(t,JSON.stringify(n,null,2),"utf-8")}catch{}}async function D(e,n){const t=await m.default.request(`${I}/v1.0/oauth2/accessToken`,{method:"POST",data:{appKey:e,appSecret:n},contentType:"json",dataType:"json",timeout:1e4});if(t.status!==200||!t.data?.accessToken)throw new Error(`\u83B7\u53D6 accessToken \u5931\u8D25: ${JSON.stringify(t.data)}`);return t.data.accessToken}async function E(e,n){const t=await m.default.request(`${q}/topapi/v2/user/getbymobile?access_token=${e}`,{method:"POST",data:{mobile:n},contentType:"json",dataType:"json",timeout:5e3});if(t.status!==200||!t.data)return null;const r=t.data;return r.errcode!==0?null:r.result?.userid||null}async function J(e,n,t,r,c){const T=c?"sampleMarkdown":"sampleText",f=JSON.stringify(c?{title:"notification",text:r}:{content:r});return(await m.default.request(`${I}/v1.0/robot/oToMessages/batchSend`,{method:"POST",data:{robotCode:n,userIds:[t],msgKey:T,msgParam:f},contentType:"json",headers:{"x-acs-dingtalk-access-token":e},dataType:"json"})).status===200}async function F(e){const{clientId:n,message:t,conversationIds:r,atUserIds:c=[],mobiles:T=[],markdown:f=!1}=e,b=w(n),h=S.default.join(b,"config.json");if(!u.default.existsSync(h))return console.error(`\u274C \u914D\u7F6E\u6587\u4EF6\u4E0D\u5B58\u5728: ${h}`),{success:0,fail:r.length};let d;try{d=JSON.parse(u.default.readFileSync(h,"utf-8"))}catch(a){return console.error(`\u274C \u914D\u7F6E\u6587\u4EF6\u89E3\u6790\u5931\u8D25: ${a instanceof Error?a.message:a}`),{success:0,fail:r.length}}let $=0,i=0,y=null;const k=M(n);for(const a of r){const g=d.conversations.find(o=>o.conversationId===a),l=g?.conversationTitle||a;if(g?.conversationType==="1"){const o=T[r.indexOf(a)]||g.mobile;if(!o){console.error(` \u2717 ${l}: \u5355\u804A\u7F3A\u5C11\u624B\u673A\u53F7\uFF08\u8BF7\u914D\u7F6E conversations[].mobile \u6216\u4F20 --mobile\uFF09`),i++;continue}try{y||(y=await D(n,(0,O.resolveSecret)(d.clientSecret)));let s=k[o];if(s||(s=await E(y,o),s&&(k[o]=s,x(n,k))),!s){console.error(` \u2717 ${l}: \u65E0\u6CD5\u89E3\u6790\u624B\u673A\u53F7 ${o} \u4E3A userId`),i++;continue}await J(y,n,s,t,f)?(console.log(` \u2713 ${l}`),$++):(console.error(` \u2717 ${l}: API \u8FD4\u56DE\u5931\u8D25`),i++)}catch(s){console.error(` \u2717 ${l}: ${s instanceof Error?s.message:s}`),i++}continue}const _=(0,O.resolveSecret)(g?.dingToken||d.defaultDingToken);if(!_){console.error(` \u2717 ${l}: \u65E0 dingToken \u53EF\u7528`),i++;continue}try{const o=c.length>0?`${t} ${c.map(A=>`@${A}`).join(" ")}`:t,s=f?{msgtype:"markdown",markdown:{title:o,text:o},at:{atUserIds:c,isAtAll:!1}}:{msgtype:"text",text:{content:o},at:{atUserIds:c,isAtAll:!1}},j=`https://oapi.dingtalk.com/robot/send?access_token=${_}`,v=await m.default.request(j,{method:"POST",data:s,contentType:"json",dataType:"json"});v.status===200?(console.log(` \u2713 ${l}`),$++):(console.error(` \u2717 ${a}: HTTP ${v.status}`),i++)}catch(o){console.error(` \u2717 ${a}: ${o instanceof Error?o.message:o}`),i++}}return{success:$,fail:i}}
@@ -1,14 +1,14 @@
1
- "use strict";var U=exports&&exports.__importDefault||function(e){return e&&e.__esModule?e:{default:e}};Object.defineProperty(exports,"__esModule",{value:!0}),exports.timestamp=$,exports.getHomeDir=F,exports.getClientDir=P,exports.initClientDir=E,exports.ensureClientDir=ie,exports.getClientConfig=oe,exports.resolveToUserId=b,exports.authCheck=re,exports.isOwner=Y,exports.isAdmin=R,exports.isOwnerOrAdmin=J,exports.debugLog=H,exports.isMobile=k,exports.getPhoneMapFile=W,exports.loadPhoneMap=B,exports.savePhoneMap=_,exports.userIdToPhone=ae,exports.getUserIdNameMapFile=L,exports.loadUserIdNameMap=z,exports.saveUserIdNameMap=G,exports.resolveUserIdName=ue,exports.resolveUserId=de,exports.resolveAllPhonesInConfig=le,exports.hashConversationId=K,exports.getReplyWebhook=fe,exports.getReplyConversationId=ge,exports.findActiveSession=C,exports.getConversationConfig=T,exports.getConversationDir=N,exports.getSessionsDir=M,exports.getTasksDir=X,exports.getImagesDir=V,exports.getSessionDir=v,exports.getSessionId=w,exports.formatSessionInfo=Se,exports.readSessionLogTail=ye,exports.findHistorySession=Z,exports.findLatestSession=he,exports.updateSessionFile=A,exports.appendSessionLog=me,exports.getActiveSessionsFile=O,exports.saveActiveSession=D,exports.loadActiveSessions=$e,exports.endSession=ee,exports.switchToSession=ve,exports.startNewSession=ne,exports.processMessageQueue=j,exports.handleSessionMessage=we,exports.cleanCache=pe;const p=require("utils-ok"),o=U(require("fs")),se=U(require("os")),x=U(require("assert")),Q=U(require("crypto")),g=U(require("path")),te=require("./commands"),h=require("./messaging"),I=require("./claude-process"),q=require("./platform");function $(){return p.dateUtil.mm(Date.now()).format("YYYY-MM-DD HH:mm:ss")}function F(){return se.default.homedir()}function P(e){return g.default.join(F(),".cc-ding",e.clientId)}function E(e,s){const n=g.default.join(F(),".cc-ding",e),t=g.default.join(n,"config.json");return o.default.mkdirSync(n,{recursive:!0}),o.default.writeFileSync(t,JSON.stringify(s,null,2),{encoding:"utf-8",mode:(0,q.isWindows)()?void 0:384}),(0,q.isWindows)()||o.default.chmodSync(t,384),t}function ie(e){const s=g.default.join(F(),".cc-ding",e),n=g.default.join(s,"config.json");if(o.default.existsSync(n))return;console.log(`[${$()}] \u5BA2\u6237\u7AEF\u76EE\u5F55\u672A\u521D\u59CB\u5316: ${s}`),console.log(`[${$()}] \u6B63\u5728\u81EA\u52A8\u521D\u59CB\u5316...`),E(e,{clientName:"cc\u52A9\u624B",owner:"<owner\u624B\u673A\u53F7>",whiteUserList:[],clientSecret:"<clientSecret-\u9489\u9489Stream\u8FDE\u63A5\u5BC6\u94A5>",defaultDingToken:"<\u515C\u5E95\u9489\u9489\u673A\u5668\u4EBAToken>",conversations:[]}),console.log(`[${$()}] \u5DF2\u751F\u6210\u9ED8\u8BA4\u914D\u7F6E\u6587\u4EF6: ${n}`),console.log(`[${$()}] \u8BF7\u7F16\u8F91 config.json \u586B\u5199\u5FC5\u8981\u7684\u914D\u7F6E\u9879\u540E\u91CD\u65B0\u542F\u52A8`),process.exit(1)}function oe(e){const s=g.default.join(P(e),"config.json");(0,x.default)(o.default.existsSync(s),`Could not find client config file: ${s}`);const n=p.fileUtil.getJSON(s);return(0,x.default)(n.clientSecret,"config.json missing required field: clientSecret"),(0,x.default)(n.whiteUserList,"config.json missing required field: whiteUserList"),n}function b(e,s){return k(s)&&e.resolvedPhones[s]||s}function re(e,s,n){if(J(e,s))return!0;if(n){const t=e.config.conversations.find(i=>i.conversationId===n);if(t?.whiteUserList&&t.whiteUserList.length>0)return t.whiteUserList.some(i=>b(e,i)===s)}return e.config.whiteUserList.some(t=>b(e,t)===s)}function Y(e,s){const n=e.config.owner;if(!n||!k(n))return!1;const t=e.resolvedPhones[n];return!!t&&t===s}function R(e,s){return e.config.adminUserList?.length?e.config.adminUserList.some(n=>b(e,n)===s):!1}function J(e,s){return Y(e,s)||R(e,s)}function H(e,s,...n){e.config.debug&&console.log(`[DEBUG] ${s}`,...n)}const ce=/^1\d{10}$/;function k(e){return ce.test(e)}function W(e){return g.default.join(P(e),"phone-map.json")}function B(e){const s=W(e);if(!o.default.existsSync(s))return{};try{const n=JSON.parse(o.default.readFileSync(s,"utf-8"));if(typeof n=="object"&&n!==null)return n}catch{}return{}}function _(e,s){const n=W(e);try{o.default.writeFileSync(n,JSON.stringify(s,null,2),"utf-8")}catch(t){console.error("\u4FDD\u5B58 phone-map.json \u5931\u8D25:",t)}}function ae(e,s){for(const[n,t]of Object.entries(e.resolvedPhones))if(t===s)return n;return null}function L(e){return g.default.join(P(e),"user-id-name-map.json")}function z(e){const s=L(e);if(!o.default.existsSync(s))return{};try{const n=JSON.parse(o.default.readFileSync(s,"utf-8"));if(typeof n=="object"&&n!==null)return n}catch{}return{}}function G(e,s){const n=L(e);try{o.default.writeFileSync(n,JSON.stringify(s,null,2),"utf-8")}catch(t){console.error("\u4FDD\u5B58 user-id-name-map.json \u5931\u8D25:",t)}}async function ue(e,s){if(!s)return null;const n=z(e);if(n[s])return n[s];const t=await(0,h.queryDingUser)(e,s);return t&&t.name?(n[s]=t.name,G(e,n),t.name):null}async function de(e,s){if(!s)return null;if(!k(s))return s;if(e.resolvedPhones[s])return e.resolvedPhones[s];const n=await(0,h.queryUserIdByMobile)(e,s);return n&&(e.resolvedPhones[s]=n,_(e,e.resolvedPhones)),n}async function le(e){e.resolvedPhones=B(e);const s=[],n=async t=>{if(e.resolvedPhones[t])return;const i=await(0,h.queryUserIdByMobile)(e,t);i&&(e.resolvedPhones[t]=i,s.push(t))};e.config.owner&&(k(e.config.owner)?(await n(e.config.owner),e.resolvedPhones[e.config.owner]||console.warn(`[WARN] \u65E0\u6CD5\u89E3\u6790 owner \u624B\u673A\u53F7: ${e.config.owner}`)):console.warn(`[WARN] owner \u5FC5\u987B\u4E3A\u624B\u673A\u53F7\uFF0C\u5F53\u524D\u503C\u65E0\u6548: ${e.config.owner}`));for(const t of e.config.whiteUserList)k(t)&&(await n(t),e.resolvedPhones[t]||console.warn(`[WARN] \u65E0\u6CD5\u89E3\u6790 whiteUserList \u624B\u673A\u53F7: ${t}`));for(const t of e.config.conversations)if(t.whiteUserList)for(const i of t.whiteUserList)k(i)&&(await n(i),e.resolvedPhones[i]||console.warn(`[WARN] \u65E0\u6CD5\u89E3\u6790\u7FA4\u767D\u540D\u5355\u624B\u673A\u53F7: ${i}`));s.length>0&&_(e,e.resolvedPhones),console.log(`[\u624B\u673A\u89E3\u6790] \u5DF2\u52A0\u8F7D ${Object.keys(e.resolvedPhones).length} \u6761\u8BB0\u5F55 (${s.length} \u6761\u65B0\u89E3\u6790)`)}function K(e,s){const t=T(e,s)?.linkConversationId||s;return Q.default.createHash("md5").update(t).digest("hex")}function fe(e){return e.currentWebhook||e.sessionWebhook}function ge(e){return e.currentConversationId||e.conversationId}function C(e,s){const n=e.activeSessions.get(s);if(n)return{key:s,session:n};const t=T(e,s);if(t?.linkConversationId){for(const i of e.activeSessions)if(T(e,i[0])?.linkConversationId===t.linkConversationId)return{key:i[0],session:i[1]}}}function T(e,s){return e.config.conversations.find(n=>n.conversationId===s)}function N(e,s){const n=K(e,s);return g.default.join(P(e),n)}function M(e,s){return g.default.join(N(e,s),".sessions")}function X(e,s){return g.default.join(N(e,s),".tasks")}function V(e,s){return g.default.join(N(e,s),".images")}function v(e,s){const n=s.claudeSessionId||s.startTimeStr;return g.default.join(M(e,s.conversationId),n)}function w(e){return e.claudeSessionId||e.startTimeStr}function Se(e,s){const n=C(e,s);if(!n)return null;const{session:t,isProcessing:i,messageQueue:r}=n.session;return[`- **\u4F1A\u8BDDID:** ${w(t)}`,`- **\u53D1\u8D77\u8005:** ${t.startNickName}(${t.startStaffId})`,`- **\u5F00\u59CB\u65F6\u95F4:** ${t.startTimeStr}`,`- **\u6700\u540E\u53D1\u9001\u8005:** ${n.session.lastSenderStaffId}`,`- **\u5904\u7406\u4E2D:** ${i}`,`- **\u6392\u961F\u6D88\u606F:** ${r?.length||0} \u6761`].join(`
2
- `)}function ye(e,s,n){const t=C(e,s);if(!t)return null;const i=t.session,r=`${v(e,i.session)}/session.log`;if(!o.default.existsSync(r))return null;try{return o.default.readFileSync(r,"utf-8").split(`
3
- `).filter(u=>u.length>0).slice(-n).join(`
4
- `)}catch{return null}}function Z(e,s,n){const t=M(e,s),i=`${t}/${n}/session.json`;try{return p.fileUtil.getJSON(i)}catch{}const r=parseInt(n,10);if(!isNaN(r)&&r>0){const d=p.dateUtil.mm(r).format("YYYY-MM-DD-HH-mm-ss"),a=`${t}/${d}/session.json`;try{return p.fileUtil.getJSON(a)}catch{}}return null}function he(e,s){const n=M(e,s);if(!o.default.existsSync(n))return null;const t=C(e,s),i=t?w(t.session.session):null;let r=null,d=0;try{const a=o.default.readdirSync(n,{withFileTypes:!0});for(const u of a){if(!u.isDirectory())continue;const f=g.default.join(n,u.name,"session.json");if(o.default.existsSync(f))try{const c=p.fileUtil.getJSON(f);if(i&&w(c)===i)continue;c.startTime>d&&(d=c.startTime,r=c)}catch{continue}}}catch{}return r}function A(e,s,n){if(n.claudeSessionId&&!s.claudeSessionId){const i=v(e,s);s.claudeSessionId=n.claudeSessionId;const r=v(e,s);i!==r&&o.default.existsSync(i)&&(o.default.renameSync(i,r),console.log(`[${$()}] \u4F1A\u8BDD\u76EE\u5F55\u91CD\u547D\u540D: ${g.default.basename(i)} -> ${g.default.basename(r)}`))}const t=`${v(e,s)}/session.json`;try{n.sessionWebhook&&(s.sessionWebhook=n.sessionWebhook),n.currentWebhook!==void 0&&(s.currentWebhook=n.currentWebhook||void 0),n.currentConversationId!==void 0&&(s.currentConversationId=n.currentConversationId||void 0),o.default.writeFileSync(t,JSON.stringify(s,null,2),"utf-8");const i=n.claudeSessionId?"claudeSessionId":n.currentWebhook!==void 0?"currentWebhook":"sessionWebhook";console.log(`[${$()}] \u4F1A\u8BDD\u6587\u4EF6\u5DF2\u4FDD\u5B58: ${i}`),D(e,s.conversationId)}catch(i){console.error("\u66F4\u65B0 session.json \u5931\u8D25:",i)}}function me(e,s,n){const t=`${e}/session.log`,r=`[${$()}] [${s.toUpperCase()}]: ${n}
5
- `;try{o.default.appendFileSync(t,r,"utf-8")}catch{}}function O(e,s){return`${M(e,s)}/active.json`}function D(e,s){const n=e.activeSessions.get(s),t=O(e,s);try{if(!n){o.default.existsSync(t)&&o.default.unlinkSync(t);return}const i={session:n.session,lastSenderStaffId:n.lastSenderStaffId,conversationConfig:n.conversationConfig};o.default.mkdirSync(g.default.dirname(t),{recursive:!0}),o.default.writeFileSync(t,JSON.stringify(i,null,2),"utf-8"),H(e,`\u6D3B\u8DC3\u4F1A\u8BDD\u5DF2\u6301\u4E45\u5316: \u7FA4=${s}`)}catch(i){console.error(`\u6301\u4E45\u5316\u6D3B\u8DC3\u4F1A\u8BDD\u5931\u8D25: \u7FA4=${s}`,i)}}function $e(e){for(const s of e.config.conversations){const n=O(e,s.conversationId);if(o.default.existsSync(n))try{const t=p.fileUtil.getJSON(n);if(!t?.session){console.log(`\u6D3B\u8DC3\u4F1A\u8BDD\u6587\u4EF6\u65E0\u6548\uFF0C\u8DF3\u8FC7: ${n}`);continue}const i=v(e,t.session);if(!o.default.existsSync(i)){console.log(`\u6D3B\u8DC3\u4F1A\u8BDD\u76EE\u5F55\u5DF2\u4E0D\u5B58\u5728\uFF0C\u6E05\u7406\u6301\u4E45\u5316\u6587\u4EF6: ${n}`),o.default.unlinkSync(n);continue}e.activeSessions.set(s.conversationId,{session:t.session,lastSenderStaffId:t.lastSenderStaffId||t.session.startStaffId,isProcessing:!1,messageQueue:[],conversationConfig:t.conversationConfig}),console.log(`\u6062\u590D\u6D3B\u8DC3\u4F1A\u8BDD: \u7FA4=${s.conversationId}, \u4F1A\u8BDDID=${w(t.session)}`)}catch(t){console.error(`\u52A0\u8F7D\u6D3B\u8DC3\u4F1A\u8BDD\u5931\u8D25: ${n}`,t)}}}async function ee(e,s,n){const t=C(e,s);if(!t){console.log(`\u7FA4 ${s} \u65E0\u6D3B\u8DC3\u4F1A\u8BDD`),await(0,h.sendDingMessage)(e,{conversationId:s,sessionWebhook:n,content:`\u26A0\uFE0F \u5F53\u524D\u6CA1\u6709\u6D3B\u8DC3\u7684\u4F1A\u8BDD\uFF0C\u65E0\u9700\u7ED3\u675F\u3002
6
- \u53EF\u4EE5\u901A\u8FC7 /new \u5F00\u59CB\u65B0\u4F1A\u8BDD\u3002`});return}const{key:i,session:r}=t,{session:d}=r,a=v(e,d),u=w(d);console.log(`\u7ED3\u675F\u4F1A\u8BDD: \u7FA4=${s}, \u4F1A\u8BDDID=${u}`),(0,I.interruptClaudeProcess)(r,"\u7ED3\u675F\u4F1A\u8BDD\u65F6\u4E2D\u65AD\u6B63\u5728\u6267\u884C\u7684 Claude \u8FDB\u7A0B")&&o.default.appendFileSync(`${a}/session.log`,`[${$()}] [SYSTEM]: \u7ED3\u675F\u4F1A\u8BDD\u65F6\u4E2D\u65AD Claude \u8FDB\u7A0B
7
- `,"utf-8");const f=r.messageQueue?.length??0;f>0&&(r.messageQueue=[],console.log(`[${$()}] \u7ED3\u675F\u4F1A\u8BDD\u65F6\u6E05\u7A7A\u6D88\u606F\u961F\u5217: \u7FA4=${s}, \u6E05\u7A7A${f}\u6761\u6D88\u606F`)),await(0,h.sendDingMessage)(e,{conversationId:s,sessionWebhook:n,atUserId:d.startStaffId,content:`\u{1F4AC} \u4F1A\u8BDD\u5DF2\u7ED3\u675F
8
- \u{1F194} ${u}${f>0?`
9
- \u{1F5D1}\uFE0F \u5DF2\u6E05\u7A7A\u6D88\u606F\u961F\u5217\uFF0C\u4E22\u5F03${f}\u6761\u5F85\u5904\u7406\u6D88\u606F`:""}`}),e.activeSessions.delete(i),D(e,i),o.default.appendFileSync(`${a}/session.log`,`[${$()}] [SYSTEM]: \u7528\u6237\u8BF7\u6C42\u7ED3\u675F\u4F1A\u8BDD
10
- `,"utf-8")}async function ve(e,s,n,t,i,r){const d=Z(e,s,t);if(!d)return await(0,h.sendDingMessage)(e,{conversationId:s,sessionWebhook:n,atUserId:i,content:`\u274C \u672A\u627E\u5230\u4F1A\u8BDD ${t}\uFF0C\u8BE5\u4F1A\u8BDD\u53EF\u80FD\u5DF2\u88AB\u6E05\u7406\uFF0C\u8BF7\u53D1\u9001\u65B0\u6D88\u606F\u5F00\u59CB\u65B0\u4F1A\u8BDD`}),!1;const a=v(e,d);if(!o.default.existsSync(a))return await(0,h.sendDingMessage)(e,{conversationId:s,sessionWebhook:n,atUserId:i,content:`\u274C \u4F1A\u8BDD ${t} \u7684\u6570\u636E\u5DF2\u88AB\u6E05\u7406\uFF0C\u65E0\u6CD5\u6062\u590D\uFF0C\u8BF7\u53D1\u9001\u65B0\u6D88\u606F\u5F00\u59CB\u65B0\u4F1A\u8BDD`}),!1;const u=C(e,s);u&&(console.log(`\u5207\u6362\u4F1A\u8BDD\uFF0C\u5148\u7ED3\u675F\u5F53\u524D\u4F1A\u8BDD: ${w(u.session.session)}`),(0,I.interruptClaudeProcess)(u.session,"\u5207\u6362\u4F1A\u8BDD\u65F6\u4E2D\u65AD\u6B63\u5728\u6267\u884C\u7684 Claude \u8FDB\u7A0B"),e.activeSessions.delete(u.key),D(e,u.key),o.default.appendFileSync(`${v(e,u.session.session)}/session.log`,`[${$()}] [SYSTEM]: \u4F1A\u8BDD\u88AB\u5207\u6362\u5230 ${t}\uFF0C\u7ED3\u675F\u5F53\u524D\u4F1A\u8BDD
11
- `,"utf-8")),e.activeSessions.set(s,{session:d,lastSenderStaffId:i,isProcessing:!1,messageQueue:[],conversationConfig:r}),D(e,s);const f=!!d.claudeSessionId,c=w(d);return await(0,h.sendDingMessage)(e,{conversationId:s,sessionWebhook:n,atUserId:i,content:`\u2705 \u5DF2\u5207\u6362\u5230\u5386\u53F2\u4F1A\u8BDD (\u{1F194} ${c})
1
+ "use strict";var N=exports&&exports.__importDefault||function(e){return e&&e.__esModule?e:{default:e}};Object.defineProperty(exports,"__esModule",{value:!0}),exports.timestamp=$,exports.getHomeDir=F,exports.getClientDir=U,exports.initClientDir=J,exports.ensureClientDir=oe,exports.getClientConfig=re,exports.resolveToUserId=T,exports.authCheck=ce,exports.isOwner=Y,exports.isAdmin=R,exports.isOwnerOrAdmin=H,exports.debugLog=B,exports.isMobile=p,exports.isJobNumber=M,exports.getPhoneMapFile=W,exports.loadPhoneMap=z,exports.savePhoneMap=L,exports.userIdToPhone=ue,exports.getUserIdNameMapFile=A,exports.loadUserIdNameMap=G,exports.saveUserIdNameMap=K,exports.resolveUserIdName=de,exports.resolveUserId=le,exports.resolveAllPhonesInConfig=fe,exports.hashConversationId=X,exports.getReplyWebhook=ge,exports.getReplyConversationId=Se,exports.findActiveSession=D,exports.getConversationConfig=O,exports.getConversationDir=j,exports.getSessionsDir=P,exports.getTasksDir=Z,exports.getImagesDir=V,exports.getSessionDir=w,exports.getSessionId=v,exports.formatSessionInfo=ye,exports.readSessionLogTail=he,exports.findHistorySession=ee,exports.findLatestSession=me,exports.updateSessionFile=q,exports.appendSessionLog=$e,exports.getActiveSessionsFile=x,exports.saveActiveSession=I,exports.loadActiveSessions=we,exports.endSession=ne,exports.switchToSession=ve,exports.startNewSession=se,exports.processMessageQueue=b,exports.handleSessionMessage=pe,exports.cleanCache=Ce;const C=require("utils-ok"),r=N(require("fs")),te=N(require("os")),_=N(require("assert")),Q=N(require("crypto")),g=N(require("path")),ie=require("./commands"),S=require("./messaging"),k=require("./claude-process"),E=require("./platform");function $(){return C.dateUtil.mm(Date.now()).format("YYYY-MM-DD HH:mm:ss")}function F(){return te.default.homedir()}function U(e){return g.default.join(F(),".cc-ding",e.clientId)}function J(e,s){const n=g.default.join(F(),".cc-ding",e),t=g.default.join(n,"config.json");return r.default.mkdirSync(n,{recursive:!0}),r.default.writeFileSync(t,JSON.stringify(s,null,2),{encoding:"utf-8",mode:(0,E.isWindows)()?void 0:384}),(0,E.isWindows)()||r.default.chmodSync(t,384),t}function oe(e){const s=g.default.join(F(),".cc-ding",e),n=g.default.join(s,"config.json");if(r.default.existsSync(n))return;console.log(`[${$()}] \u5BA2\u6237\u7AEF\u76EE\u5F55\u672A\u521D\u59CB\u5316: ${s}`),console.log(`[${$()}] \u6B63\u5728\u81EA\u52A8\u521D\u59CB\u5316...`),J(e,{clientName:"cc\u52A9\u624B",owner:"<owner\u624B\u673A\u53F7>",whiteUserList:[],clientSecret:"<clientSecret-\u9489\u9489Stream\u8FDE\u63A5\u5BC6\u94A5>",defaultDingToken:"<\u515C\u5E95\u9489\u9489\u673A\u5668\u4EBAToken>",conversations:[]}),console.log(`[${$()}] \u5DF2\u751F\u6210\u9ED8\u8BA4\u914D\u7F6E\u6587\u4EF6: ${n}`),console.log(`[${$()}] \u8BF7\u7F16\u8F91 config.json \u586B\u5199\u5FC5\u8981\u7684\u914D\u7F6E\u9879\u540E\u91CD\u65B0\u542F\u52A8`),process.exit(1)}function re(e){const s=g.default.join(U(e),"config.json");(0,_.default)(r.default.existsSync(s),`Could not find client config file: ${s}`);const n=C.fileUtil.getJSON(s);return(0,_.default)(n.clientSecret,"config.json missing required field: clientSecret"),(0,_.default)(n.whiteUserList,"config.json missing required field: whiteUserList"),n}function T(e,s){return p(s)&&e.resolvedPhones[s]||s}function ce(e,s,n){if(H(e,s))return!0;if(n){const t=e.config.conversations.find(i=>i.conversationId===n);if(t?.freedomMode)return!0;if(t?.whiteUserList&&t.whiteUserList.length>0)return t.whiteUserList.some(i=>T(e,i)===s)}return e.config.whiteUserList.some(t=>T(e,t)===s)}function Y(e,s){const n=e.config.owner;if(!n)return!1;const t=e.resolvedPhones[n];return!!t&&t===s}function R(e,s){return e.config.adminUserList?.length?e.config.adminUserList.some(n=>T(e,n)===s):!1}function H(e,s){return Y(e,s)||R(e,s)}function B(e,s,...n){e.config.debug&&console.log(`[DEBUG] ${s}`,...n)}const ae=/^1\d{10}$/;function p(e){return ae.test(e)}function M(e){return!p(e)&&!e.includes("_")&&/^[A-Za-z0-9]+$/.test(e)}function W(e){return g.default.join(U(e),"user-map.json")}function z(e){const s=W(e);if(!r.default.existsSync(s))return{};try{const n=JSON.parse(r.default.readFileSync(s,"utf-8"));if(typeof n=="object"&&n!==null)return n}catch{}return{}}function L(e,s){const n=W(e);try{r.default.writeFileSync(n,JSON.stringify(s,null,2),"utf-8")}catch(t){console.error("\u4FDD\u5B58 user-map.json \u5931\u8D25:",t)}}function ue(e,s){for(const[n,t]of Object.entries(e.resolvedPhones))if(t===s)return n;return null}function A(e){return g.default.join(U(e),"user-id-name-map.json")}function G(e){const s=A(e);if(!r.default.existsSync(s))return{};try{const n=JSON.parse(r.default.readFileSync(s,"utf-8"));if(typeof n=="object"&&n!==null)return n}catch{}return{}}function K(e,s){const n=A(e);try{r.default.writeFileSync(n,JSON.stringify(s,null,2),"utf-8")}catch(t){console.error("\u4FDD\u5B58 user-id-name-map.json \u5931\u8D25:",t)}}async function de(e,s){if(!s)return null;const n=G(e);if(n[s])return n[s];const t=await(0,S.queryDingUser)(e,s);return t&&t.name?(n[s]=t.name,K(e,n),t.name):null}async function le(e,s){if(!s)return null;if(!p(s)&&!M(s))return s;if(e.resolvedPhones[s])return e.resolvedPhones[s];let n=null;return p(s)?n=await(0,S.queryUserIdByMobile)(e,s):M(s)&&(n=await(0,S.queryUserIdByJobNumber)(e,s)),n&&(e.resolvedPhones[s]=n,L(e,e.resolvedPhones)),n}async function fe(e){e.resolvedPhones=z(e);const s=[],n=async t=>{if(e.resolvedPhones[t])return;let i=null;p(t)?i=await(0,S.queryUserIdByMobile)(e,t):M(t)&&(i=await(0,S.queryUserIdByJobNumber)(e,t)),i&&(e.resolvedPhones[t]=i,s.push(t))};e.config.owner&&(p(e.config.owner)||M(e.config.owner)?(await n(e.config.owner),e.resolvedPhones[e.config.owner]||console.warn(`[WARN] \u65E0\u6CD5\u89E3\u6790 owner: ${e.config.owner}`)):console.warn(`[WARN] owner \u683C\u5F0F\u65E0\u6548(\u9700\u4E3A\u624B\u673A\u53F7\u6216\u5DE5\u53F7): ${e.config.owner}`));for(const t of e.config.whiteUserList)(p(t)||M(t))&&(await n(t),e.resolvedPhones[t]||console.warn(`[WARN] \u65E0\u6CD5\u89E3\u6790 whiteUserList: ${t}`));for(const t of e.config.conversations)if(t.whiteUserList)for(const i of t.whiteUserList)(p(i)||M(i))&&(await n(i),e.resolvedPhones[i]||console.warn(`[WARN] \u65E0\u6CD5\u89E3\u6790\u7FA4\u767D\u540D\u5355: ${i}`));s.length>0&&L(e,e.resolvedPhones),console.log(`[\u7528\u6237\u89E3\u6790] \u5DF2\u52A0\u8F7D ${Object.keys(e.resolvedPhones).length} \u6761\u8BB0\u5F55 (${s.length} \u6761\u65B0\u89E3\u6790)`)}function X(e,s){const t=O(e,s)?.linkConversationId||s;return Q.default.createHash("md5").update(t).digest("hex")}function ge(e){return e.currentWebhook||e.sessionWebhook}function Se(e){return e.currentConversationId||e.conversationId}function D(e,s){const n=e.activeSessions.get(s);if(n)return{key:s,session:n};const t=O(e,s);if(t?.linkConversationId){for(const i of e.activeSessions)if(O(e,i[0])?.linkConversationId===t.linkConversationId)return{key:i[0],session:i[1]}}}function O(e,s){return e.config.conversations.find(n=>n.conversationId===s)}function j(e,s){const n=X(e,s);return g.default.join(U(e),n)}function P(e,s){return g.default.join(j(e,s),".sessions")}function Z(e,s){return g.default.join(j(e,s),".tasks")}function V(e,s){return g.default.join(j(e,s),".images")}function w(e,s){const n=s.claudeSessionId||s.startTimeStr;return g.default.join(P(e,s.conversationId),n)}function v(e){return e.claudeSessionId||e.startTimeStr}function ye(e,s){const n=D(e,s);if(!n)return null;const{session:t,isProcessing:i,messageQueue:o}=n.session;return[`- **\u4F1A\u8BDDID:** ${v(t)}`,`- **\u53D1\u8D77\u8005:** ${t.startNickName}(${t.startStaffId})`,`- **\u5F00\u59CB\u65F6\u95F4:** ${t.startTimeStr}`,`- **\u6700\u540E\u53D1\u9001\u8005:** ${n.session.lastSenderStaffId}`,`- **\u5904\u7406\u4E2D:** ${i}`,`- **\u6392\u961F\u6D88\u606F:** ${o?.length||0} \u6761`].join(`
2
+ `)}function he(e,s,n){const t=D(e,s);if(!t)return null;const i=t.session,o=`${w(e,i.session)}/session.log`;if(!r.default.existsSync(o))return null;try{return r.default.readFileSync(o,"utf-8").split(`
3
+ `).filter(a=>a.length>0).slice(-n).join(`
4
+ `)}catch{return null}}function ee(e,s,n){const t=P(e,s),i=`${t}/${n}/session.json`;try{return C.fileUtil.getJSON(i)}catch{}const o=parseInt(n,10);if(!isNaN(o)&&o>0){const d=C.dateUtil.mm(o).format("YYYY-MM-DD-HH-mm-ss"),u=`${t}/${d}/session.json`;try{return C.fileUtil.getJSON(u)}catch{}}return null}function me(e,s){const n=P(e,s);if(!r.default.existsSync(n))return null;const t=D(e,s),i=t?v(t.session.session):null;let o=null,d=0;try{const u=r.default.readdirSync(n,{withFileTypes:!0});for(const a of u){if(!a.isDirectory())continue;const f=g.default.join(n,a.name,"session.json");if(r.default.existsSync(f))try{const c=C.fileUtil.getJSON(f);if(i&&v(c)===i)continue;c.startTime>d&&(d=c.startTime,o=c)}catch{continue}}}catch{}return o}function q(e,s,n){if(n.claudeSessionId&&!s.claudeSessionId){const i=w(e,s);s.claudeSessionId=n.claudeSessionId;const o=w(e,s);i!==o&&r.default.existsSync(i)&&(r.default.renameSync(i,o),console.log(`[${$()}] \u4F1A\u8BDD\u76EE\u5F55\u91CD\u547D\u540D: ${g.default.basename(i)} -> ${g.default.basename(o)}`))}const t=`${w(e,s)}/session.json`;try{n.sessionWebhook&&(s.sessionWebhook=n.sessionWebhook),n.currentWebhook!==void 0&&(s.currentWebhook=n.currentWebhook||void 0),n.currentConversationId!==void 0&&(s.currentConversationId=n.currentConversationId||void 0),r.default.writeFileSync(t,JSON.stringify(s,null,2),"utf-8");const i=n.claudeSessionId?"claudeSessionId":n.currentWebhook!==void 0?"currentWebhook":"sessionWebhook";console.log(`[${$()}] \u4F1A\u8BDD\u6587\u4EF6\u5DF2\u4FDD\u5B58: ${i}`),I(e,s.conversationId)}catch(i){console.error("\u66F4\u65B0 session.json \u5931\u8D25:",i)}}function $e(e,s,n){const t=`${e}/session.log`,o=`[${$()}] [${s.toUpperCase()}]: ${n}
5
+ `;try{r.default.appendFileSync(t,o,"utf-8")}catch{}}function x(e,s){return`${P(e,s)}/active.json`}function I(e,s){const n=e.activeSessions.get(s),t=x(e,s);try{if(!n){r.default.existsSync(t)&&r.default.unlinkSync(t);return}const i={session:n.session,lastSenderStaffId:n.lastSenderStaffId,conversationConfig:n.conversationConfig};r.default.mkdirSync(g.default.dirname(t),{recursive:!0}),r.default.writeFileSync(t,JSON.stringify(i,null,2),"utf-8"),B(e,`\u6D3B\u8DC3\u4F1A\u8BDD\u5DF2\u6301\u4E45\u5316: \u7FA4=${s}`)}catch(i){console.error(`\u6301\u4E45\u5316\u6D3B\u8DC3\u4F1A\u8BDD\u5931\u8D25: \u7FA4=${s}`,i)}}function we(e){for(const s of e.config.conversations){const n=x(e,s.conversationId);if(r.default.existsSync(n))try{const t=C.fileUtil.getJSON(n);if(!t?.session){console.log(`\u6D3B\u8DC3\u4F1A\u8BDD\u6587\u4EF6\u65E0\u6548\uFF0C\u8DF3\u8FC7: ${n}`);continue}const i=w(e,t.session);if(!r.default.existsSync(i)){console.log(`\u6D3B\u8DC3\u4F1A\u8BDD\u76EE\u5F55\u5DF2\u4E0D\u5B58\u5728\uFF0C\u6E05\u7406\u6301\u4E45\u5316\u6587\u4EF6: ${n}`),r.default.unlinkSync(n);continue}e.activeSessions.set(s.conversationId,{session:t.session,lastSenderStaffId:t.lastSenderStaffId||t.session.startStaffId,isProcessing:!1,messageQueue:[],conversationConfig:t.conversationConfig}),console.log(`\u6062\u590D\u6D3B\u8DC3\u4F1A\u8BDD: \u7FA4=${s.conversationId}, \u4F1A\u8BDDID=${v(t.session)}`)}catch(t){console.error(`\u52A0\u8F7D\u6D3B\u8DC3\u4F1A\u8BDD\u5931\u8D25: ${n}`,t)}}}async function ne(e,s,n){const t=D(e,s);if(!t){console.log(`\u7FA4 ${s} \u65E0\u6D3B\u8DC3\u4F1A\u8BDD`),await(0,S.sendDingMessage)(e,{conversationId:s,sessionWebhook:n,content:`\u26A0\uFE0F \u5F53\u524D\u6CA1\u6709\u6D3B\u8DC3\u7684\u4F1A\u8BDD\uFF0C\u65E0\u9700\u7ED3\u675F\u3002
6
+ \u53EF\u4EE5\u901A\u8FC7 /new \u5F00\u59CB\u65B0\u4F1A\u8BDD\u3002`});return}const{key:i,session:o}=t,{session:d}=o,u=w(e,d),a=v(d);console.log(`\u7ED3\u675F\u4F1A\u8BDD: \u7FA4=${s}, \u4F1A\u8BDDID=${a}`),(0,k.interruptClaudeProcess)(o,"\u7ED3\u675F\u4F1A\u8BDD\u65F6\u4E2D\u65AD\u6B63\u5728\u6267\u884C\u7684 Claude \u8FDB\u7A0B")&&r.default.appendFileSync(`${u}/session.log`,`[${$()}] [SYSTEM]: \u7ED3\u675F\u4F1A\u8BDD\u65F6\u4E2D\u65AD Claude \u8FDB\u7A0B
7
+ `,"utf-8");const f=o.messageQueue?.length??0;f>0&&(o.messageQueue=[],console.log(`[${$()}] \u7ED3\u675F\u4F1A\u8BDD\u65F6\u6E05\u7A7A\u6D88\u606F\u961F\u5217: \u7FA4=${s}, \u6E05\u7A7A${f}\u6761\u6D88\u606F`)),await(0,S.sendDingMessage)(e,{conversationId:s,sessionWebhook:n,content:`\u{1F4AC} \u4F1A\u8BDD\u5DF2\u7ED3\u675F
8
+ \u{1F194} ${a}${f>0?`
9
+ \u{1F5D1}\uFE0F \u5DF2\u6E05\u7A7A\u6D88\u606F\u961F\u5217\uFF0C\u4E22\u5F03${f}\u6761\u5F85\u5904\u7406\u6D88\u606F`:""}`}),e.activeSessions.delete(i),I(e,i),r.default.appendFileSync(`${u}/session.log`,`[${$()}] [SYSTEM]: \u7528\u6237\u8BF7\u6C42\u7ED3\u675F\u4F1A\u8BDD
10
+ `,"utf-8")}async function ve(e,s,n,t,i,o){const d=ee(e,s,t);if(!d)return await(0,S.sendDingMessage)(e,{conversationId:s,sessionWebhook:n,content:`\u274C \u672A\u627E\u5230\u4F1A\u8BDD ${t}\uFF0C\u8BE5\u4F1A\u8BDD\u53EF\u80FD\u5DF2\u88AB\u6E05\u7406\uFF0C\u8BF7\u53D1\u9001\u65B0\u6D88\u606F\u5F00\u59CB\u65B0\u4F1A\u8BDD`}),!1;const u=w(e,d);if(!r.default.existsSync(u))return await(0,S.sendDingMessage)(e,{conversationId:s,sessionWebhook:n,content:`\u274C \u4F1A\u8BDD ${t} \u7684\u6570\u636E\u5DF2\u88AB\u6E05\u7406\uFF0C\u65E0\u6CD5\u6062\u590D\uFF0C\u8BF7\u53D1\u9001\u65B0\u6D88\u606F\u5F00\u59CB\u65B0\u4F1A\u8BDD`}),!1;const a=D(e,s);a&&(console.log(`\u5207\u6362\u4F1A\u8BDD\uFF0C\u5148\u7ED3\u675F\u5F53\u524D\u4F1A\u8BDD: ${v(a.session.session)}`),(0,k.interruptClaudeProcess)(a.session,"\u5207\u6362\u4F1A\u8BDD\u65F6\u4E2D\u65AD\u6B63\u5728\u6267\u884C\u7684 Claude \u8FDB\u7A0B"),e.activeSessions.delete(a.key),I(e,a.key),r.default.appendFileSync(`${w(e,a.session.session)}/session.log`,`[${$()}] [SYSTEM]: \u4F1A\u8BDD\u88AB\u5207\u6362\u5230 ${t}\uFF0C\u7ED3\u675F\u5F53\u524D\u4F1A\u8BDD
11
+ `,"utf-8")),e.activeSessions.set(s,{session:d,lastSenderStaffId:i,isProcessing:!1,messageQueue:[],conversationConfig:o}),I(e,s);const f=!!d.claudeSessionId,c=v(d);return await(0,S.sendDingMessage)(e,{conversationId:s,sessionWebhook:n,content:`\u2705 \u5DF2\u5207\u6362\u5230\u5386\u53F2\u4F1A\u8BDD (\u{1F194} ${c})
12
12
  ${f?"\u{1F504} \u5DF2\u6062\u590D\u5BF9\u8BDD\u4E0A\u4E0B\u6587":"\u26A0\uFE0F \u8BE5\u4F1A\u8BDD\u65E0\u5386\u53F2\u4E0A\u4E0B\u6587\uFF0C\u5C06\u4ECE\u5934\u5F00\u59CB"}
13
- \u{1F4A1} \u56DE\u590D /end \u53EF\u7ED3\u675F\u672C\u8F6E\u5BF9\u8BDD`}),console.log(`\u5DF2\u5207\u6362\u5230\u5386\u53F2\u4F1A\u8BDD: \u7FA4=${s}, \u4F1A\u8BDDID=${c}, \u6709Claude\u4E0A\u4E0B\u6587=${f}`),!0}async function ne(e,s){const{conversationId:n,sessionWebhook:t,senderStaffId:i,senderNick:r,message:d,conversationConfig:a}=s,u=e.config.sessionMaxConcurrency??e.DEFAULT_SESSION_MAX_CONCURRENCY;if(e.activeSessions.size>=u){console.log(`\u8FBE\u5230\u6700\u5927\u5E76\u53D1\u6570 (${u})\uFF0C\u62D2\u7EDD\u65B0\u4F1A\u8BDD: \u7FA4=${n}`),await(0,h.sendDingMessage)(e,{conversationId:n,sessionWebhook:t,atUserId:i,content:"\u{1F92F} \u5F53\u524D\u7E41\u5FD9\uFF0C\u8BF7\u7A0D\u540E\u518D\u8BD5..."});return}const f=Date.now(),c=Q.default.randomUUID(),l={conversationId:n,sessionWebhook:t,startTime:f,startTimeStr:p.dateUtil.mm(f).format("YYYY-MM-DD-HH-mm-ss"),startStaffId:i,startNickName:r};console.log(`\u521B\u5EFA\u65B0\u4F1A\u8BDD: \u7FA4=${n}, \u4F1A\u8BDDID=${c}, \u53D1\u8D77\u8005=${i}, \u5F53\u524D\u5E76\u53D1=${e.activeSessions.size+1}/${u}`);const m=v(e,l);o.default.mkdirSync(m,{recursive:!0}),o.default.writeFileSync(`${m}/session.json`,JSON.stringify(l,null,2),"utf-8"),e.activeSessions.set(n,{session:l,lastSenderStaffId:i,isProcessing:!0,messageQueue:[],conversationConfig:a}),D(e,n),a.receiveReply!==!1&&await(0,h.sendDingMessage)(e,{conversationId:n,sessionWebhook:t,content:`\u2705 \u6536\u5230\uFF0C\u6211\u6765\u5904\u7406...
14
- \u{1F194} ${c}`});try{await(0,I.executeClaudeQuery)(e,l,d,{skill:a.taskCfg?.skill,agent:a.agent,senderNick:r,senderStaffId:i,permissionMode:a.permissionMode,newSessionId:c})}catch(y){console.error("\u6267\u884C Claude \u67E5\u8BE2\u5931\u8D25:",y),await(0,h.sendDingMessage)(e,{conversationId:n,sessionWebhook:t,atUserId:i,content:`\u274C \u5904\u7406\u6D88\u606F\u65F6\u53D1\u751F\u9519\u8BEF: ${y instanceof Error?y.message:String(y)}`})}finally{const y=e.activeSessions.get(n);y&&(y.isProcessing=!1)}const S=e.activeSessions.get(n);S&&S.messageQueue.length>0&&await j(e,n)}async function j(e,s){const n=e.activeSessions.get(s);if(!n||n.messageQueue.length===0)return;const t=n.messageQueue.shift(),{message:i,senderStaffId:r,senderNick:d}=t,a=n.session.sessionWebhook;console.log(`\u5904\u7406\u961F\u5217\u6D88\u606F: \u7FA4=${s}, \u5269\u4F59 ${n.messageQueue.length} \u6761`),n.isProcessing=!0,n.lastSenderStaffId=r,D(e,s),n.conversationConfig.receiveReply!==!1&&await(0,h.sendDingMessage)(e,{conversationId:s,sessionWebhook:a,content:"\u2705 \u6536\u5230\uFF0C\u6211\u6765\u5904\u7406..."}).catch(()=>{});try{await(0,I.executeClaudeQuery)(e,n.session,i,{skill:n.conversationConfig.taskCfg?.skill,agent:n.conversationConfig.agent,senderNick:d,senderStaffId:r,permissionMode:n.conversationConfig.permissionMode})}catch(u){console.error("\u6267\u884C\u961F\u5217 Claude \u67E5\u8BE2\u5931\u8D25:",u),await(0,h.sendDingMessage)(e,{conversationId:s,sessionWebhook:a,atUserId:r,content:`\u274C \u5904\u7406\u6D88\u606F\u65F6\u53D1\u751F\u9519\u8BEF: ${u instanceof Error?u.message:String(u)}`})}finally{n.isProcessing=!1}if(n.goonPending){n.goonPending=!1,n.interrupted=!1,n.isProcessing=!0;try{await(0,I.executeClaudeQuery)(e,n.session,"\u7EE7\u7EED",{senderNick:n.session.startNickName,senderStaffId:n.lastSenderStaffId,permissionMode:n.conversationConfig.permissionMode})}catch(u){console.error("goonPending \u6062\u590D\u6267\u884C\u5931\u8D25:",u)}finally{n.isProcessing=!1}}n.messageQueue.length>0&&await j(e,s)}async function we(e,s){const{conversationId:n,sessionWebhook:t,senderStaffId:i,senderNick:r,message:d,conversationConfig:a}=s,u=d.replace(/^\[提及用户: .+\]\n/,"");if((0,te.parseEndCommand)(u)){await ee(e,n,t);return}const f=C(e,n),c=f?.session;if(c){const l=v(e,c.session);if(o.default.existsSync(l)||(o.default.mkdirSync(l,{recursive:!0}),o.default.writeFileSync(`${l}/session.json`,JSON.stringify(c.session,null,2),"utf-8"),console.log(`\u4F1A\u8BDD\u76EE\u5F55\u5DF2\u91CD\u5EFA: \u7FA4=${n}, \u8DEF\u5F84=${l}`)),c.isProcessing){const S={message:d,senderStaffId:i,senderNick:r};c.messageQueue.push(S);const y=c.messageQueue.length;console.log(`\u4F1A\u8BDD ${n} \u6D88\u606F\u5DF2\u5165\u961F\uFF0C\u6392\u961F\u7B2C ${y} \u6761`),await(0,h.sendDingMessage)(e,{conversationId:n,sessionWebhook:t,atUserId:i,content:`\u23F3 \u6B63\u5728\u5904\u7406\u4E2D\uFF0C\u5DF2\u52A0\u5165\u961F\u5217\uFF08\u6392\u961F\u7B2C ${y} \u6761\uFF09`});return}const m=c.session.conversationId===n;console.log(`\u8FFD\u52A0\u6D88\u606F\u5230\u6D3B\u8DC3\u4F1A\u8BDD: \u7FA4=${n}, \u4F1A\u8BDDID=${w(c.session)}${m?"":`(\u5173\u8054\u7FA4,\u4F1A\u8BDD\u5F52\u5C5E=${c.session.conversationId})`}`),c.lastSenderStaffId=i,c.isProcessing=!0,D(e,f.key),m&&t!==c.session.sessionWebhook&&(c.session.sessionWebhook=t,A(e,c.session,{sessionWebhook:t})),c.session.currentWebhook=t,c.session.currentConversationId=n,A(e,c.session,{currentWebhook:t,currentConversationId:n}),a.receiveReply!==!1&&await(0,h.sendDingMessage)(e,{conversationId:n,sessionWebhook:t,content:"\u2705 \u6536\u5230\uFF0C\u6211\u6765\u5904\u7406..."});try{await(0,I.executeClaudeQuery)(e,c.session,d,{skill:a.taskCfg?.skill,agent:a.agent,senderNick:r,senderStaffId:i,permissionMode:a.permissionMode})}catch(S){if(c.session.claudeSessionId){console.log(`[\u4F1A\u8BDD\u6062\u590D\u5931\u8D25] \u6E05\u9664 claudeSessionId \u5E76\u91CD\u65B0\u53D1\u8D77: ${c.session.claudeSessionId}`),c.session.claudeSessionId=void 0,e.updateSessionFile(c.session,{});try{await(0,I.executeClaudeQuery)(e,c.session,d,{skill:a.taskCfg?.skill,agent:a.agent,senderNick:r,senderStaffId:i,permissionMode:a.permissionMode});return}catch(y){console.error("\u91CD\u8BD5\u6267\u884C Claude \u67E5\u8BE2\u5931\u8D25:",y),await(0,h.sendDingMessage)(e,{conversationId:n,sessionWebhook:t,atUserId:i,content:`\u274C \u5904\u7406\u6D88\u606F\u65F6\u53D1\u751F\u9519\u8BEF: ${y instanceof Error?y.message:String(y)}`}),c.isProcessing=!1,await j(e,n);return}}console.error("\u6267\u884C Claude \u67E5\u8BE2\u5931\u8D25:",S),await(0,h.sendDingMessage)(e,{conversationId:n,sessionWebhook:t,atUserId:i,content:`\u274C \u5904\u7406\u6D88\u606F\u65F6\u53D1\u751F\u9519\u8BEF: ${S instanceof Error?S.message:String(S)}`})}finally{c.isProcessing=!1}await j(e,n)}else await ne(e,{conversationId:n,sessionWebhook:t,senderStaffId:i,senderNick:r,message:d,conversationConfig:a})}function pe(e,s,n=!0){const t={sessionsDeleted:0,tasksDeleted:0,imagesDeleted:0,errors:[]},i=s?[s]:e.config.conversations.map(r=>r.conversationId);for(const r of i){let d=null;if(n){const l=C(e,r);l&&(d=w(l.session.session))}const a=M(e,r);if(o.default.existsSync(a))try{const l=o.default.readdirSync(a,{withFileTypes:!0});for(const m of l){if(!m.isDirectory()||d&&m.name===d)continue;const S=g.default.join(a,m.name);try{o.default.rmSync(S,{recursive:!0,force:!0}),t.sessionsDeleted++}catch{t.errors.push(`\u5220\u9664\u4F1A\u8BDD\u76EE\u5F55\u5931\u8D25: ${S}`)}}}catch{t.errors.push(`\u8BFB\u53D6sessions\u76EE\u5F55\u5931\u8D25: ${a}`)}const u=X(e,r);if(o.default.existsSync(u))try{const l=o.default.readdirSync(u,{withFileTypes:!0});for(const m of l){if(!m.isDirectory())continue;const S=g.default.join(u,m.name);try{o.default.rmSync(S,{recursive:!0,force:!0}),t.tasksDeleted++}catch{t.errors.push(`\u5220\u9664\u4EFB\u52A1\u76EE\u5F55\u5931\u8D25: ${S}`)}}}catch{t.errors.push(`\u8BFB\u53D6tasks\u76EE\u5F55\u5931\u8D25: ${u}`)}const f=V(e,r);if(o.default.existsSync(f))try{const l=o.default.readdirSync(f,{withFileTypes:!0});for(const m of l){const S=g.default.join(f,m.name);try{o.default.unlinkSync(S),t.imagesDeleted++}catch{t.errors.push(`\u5220\u9664\u56FE\u7247\u5931\u8D25: ${S}`)}}}catch{t.errors.push(`\u8BFB\u53D6images\u76EE\u5F55\u5931\u8D25: ${f}`)}const c=g.default.join(N(e,r),".playwright-cli");if(o.default.existsSync(c))try{o.default.rmSync(c,{recursive:!0,force:!0})}catch{t.errors.push(`\u5220\u9664 playwright-cli \u7F13\u5B58\u5931\u8D25: ${c}`)}if(!n){const l=O(e,r);if(o.default.existsSync(l))try{o.default.unlinkSync(l)}catch{t.errors.push(`\u5220\u9664\u6D3B\u8DC3\u4F1A\u8BDD\u6587\u4EF6\u5931\u8D25: ${l}`)}e.activeSessions.has(r)&&e.activeSessions.delete(r)}}return t}
13
+ \u{1F4A1} \u56DE\u590D /end \u53EF\u7ED3\u675F\u672C\u8F6E\u5BF9\u8BDD`}),console.log(`\u5DF2\u5207\u6362\u5230\u5386\u53F2\u4F1A\u8BDD: \u7FA4=${s}, \u4F1A\u8BDDID=${c}, \u6709Claude\u4E0A\u4E0B\u6587=${f}`),!0}async function se(e,s){const{conversationId:n,sessionWebhook:t,senderStaffId:i,senderNick:o,message:d,conversationConfig:u}=s,a=e.config.sessionMaxConcurrency??e.DEFAULT_SESSION_MAX_CONCURRENCY;if(e.activeSessions.size>=a){console.log(`\u8FBE\u5230\u6700\u5927\u5E76\u53D1\u6570 (${a})\uFF0C\u62D2\u7EDD\u65B0\u4F1A\u8BDD: \u7FA4=${n}`),await(0,S.sendDingMessage)(e,{conversationId:n,sessionWebhook:t,content:"\u{1F92F} \u5F53\u524D\u7E41\u5FD9\uFF0C\u8BF7\u7A0D\u540E\u518D\u8BD5..."});return}const f=Date.now(),c=Q.default.randomUUID(),l={conversationId:n,sessionWebhook:t,startTime:f,startTimeStr:C.dateUtil.mm(f).format("YYYY-MM-DD-HH-mm-ss"),startStaffId:i,startNickName:o};console.log(`\u521B\u5EFA\u65B0\u4F1A\u8BDD: \u7FA4=${n}, \u4F1A\u8BDDID=${c}, \u53D1\u8D77\u8005=${i}, \u5F53\u524D\u5E76\u53D1=${e.activeSessions.size+1}/${a}`);const m=w(e,l);r.default.mkdirSync(m,{recursive:!0}),r.default.writeFileSync(`${m}/session.json`,JSON.stringify(l,null,2),"utf-8"),e.activeSessions.set(n,{session:l,lastSenderStaffId:i,isProcessing:!0,messageQueue:[],conversationConfig:u}),I(e,n),u.receiveReply!==!1&&await(0,S.sendDingMessage)(e,{conversationId:n,sessionWebhook:t,content:`\u2705 \u6536\u5230\uFF0C\u6211\u6765\u5904\u7406...
14
+ \u{1F194} ${c}`});try{await(0,k.executeClaudeQuery)(e,l,d,{skill:u.taskCfg?.skill,agent:u.agent,senderNick:o,senderStaffId:i,permissionMode:u.permissionMode,newSessionId:c})}catch(h){console.error("\u6267\u884C Claude \u67E5\u8BE2\u5931\u8D25:",h),await(0,S.sendDingMessage)(e,{conversationId:n,sessionWebhook:t,atUserId:i,content:`\u274C \u5904\u7406\u6D88\u606F\u65F6\u53D1\u751F\u9519\u8BEF: ${h instanceof Error?h.message:String(h)}`})}finally{const h=e.activeSessions.get(n);h&&(h.isProcessing=!1)}const y=e.activeSessions.get(n);y&&y.messageQueue.length>0&&await b(e,n)}async function b(e,s){const n=e.activeSessions.get(s);if(!n||n.messageQueue.length===0)return;const t=n.messageQueue.shift(),{message:i,senderStaffId:o,senderNick:d}=t,u=n.session.sessionWebhook;if(console.log(`\u5904\u7406\u961F\u5217\u6D88\u606F: \u7FA4=${s}, \u5269\u4F59 ${n.messageQueue.length} \u6761`),n.isProcessing=!0,n.lastSenderStaffId=o,I(e,s),n.conversationConfig.receiveReply!==!1){const a=i.length>50?i.substring(0,50)+"\u2026":i;await(0,S.sendDingMessage)(e,{conversationId:s,sessionWebhook:u,atUserId:o,content:`\u{1F680} \u5F00\u59CB\u5904\u7406\u6D88\u606F\u300C${a}\u300D`}).catch(()=>{})}try{await(0,k.executeClaudeQuery)(e,n.session,i,{skill:n.conversationConfig.taskCfg?.skill,agent:n.conversationConfig.agent,senderNick:d,senderStaffId:o,permissionMode:n.conversationConfig.permissionMode})}catch(a){console.error("\u6267\u884C\u961F\u5217 Claude \u67E5\u8BE2\u5931\u8D25:",a),await(0,S.sendDingMessage)(e,{conversationId:s,sessionWebhook:u,atUserId:o,content:`\u274C \u5904\u7406\u6D88\u606F\u65F6\u53D1\u751F\u9519\u8BEF: ${a instanceof Error?a.message:String(a)}`})}finally{n.isProcessing=!1}if(n.goonPending){n.goonPending=!1,n.interrupted=!1,n.isProcessing=!0;try{await(0,k.executeClaudeQuery)(e,n.session,"\u7EE7\u7EED",{senderNick:n.session.startNickName,senderStaffId:n.lastSenderStaffId,permissionMode:n.conversationConfig.permissionMode})}catch(a){console.error("goonPending \u6062\u590D\u6267\u884C\u5931\u8D25:",a)}finally{n.isProcessing=!1}}n.messageQueue.length>0&&await b(e,s)}async function pe(e,s){const{conversationId:n,sessionWebhook:t,senderStaffId:i,senderNick:o,message:d,conversationConfig:u}=s,a=d.replace(/^\[提及用户: .+\]\n/,"");if((0,ie.parseEndCommand)(a)){await ne(e,n,t);return}const f=D(e,n),c=f?.session;if(c){const l=w(e,c.session);if(r.default.existsSync(l)||(r.default.mkdirSync(l,{recursive:!0}),r.default.writeFileSync(`${l}/session.json`,JSON.stringify(c.session,null,2),"utf-8"),console.log(`\u4F1A\u8BDD\u76EE\u5F55\u5DF2\u91CD\u5EFA: \u7FA4=${n}, \u8DEF\u5F84=${l}`)),c.isProcessing){const y={message:d,senderStaffId:i,senderNick:o};c.messageQueue.push(y);const h=c.messageQueue.length;console.log(`\u4F1A\u8BDD ${n} \u6D88\u606F\u5DF2\u5165\u961F\uFF0C\u6392\u961F\u7B2C ${h} \u6761`),await(0,S.sendDingMessage)(e,{conversationId:n,sessionWebhook:t,content:`\u23F3 \u6B63\u5728\u5904\u7406\u4E2D\uFF0C\u5DF2\u52A0\u5165\u961F\u5217\uFF08\u6392\u961F\u7B2C ${h} \u6761\uFF09`});return}const m=c.session.conversationId===n;console.log(`\u8FFD\u52A0\u6D88\u606F\u5230\u6D3B\u8DC3\u4F1A\u8BDD: \u7FA4=${n}, \u4F1A\u8BDDID=${v(c.session)}${m?"":`(\u5173\u8054\u7FA4,\u4F1A\u8BDD\u5F52\u5C5E=${c.session.conversationId})`}`),c.lastSenderStaffId=i,c.isProcessing=!0,I(e,f.key),m&&t!==c.session.sessionWebhook&&(c.session.sessionWebhook=t,q(e,c.session,{sessionWebhook:t})),c.session.currentWebhook=t,c.session.currentConversationId=n,q(e,c.session,{currentWebhook:t,currentConversationId:n}),u.receiveReply!==!1&&await(0,S.sendDingMessage)(e,{conversationId:n,sessionWebhook:t,content:"\u2705 \u6536\u5230\uFF0C\u6211\u6765\u5904\u7406..."});try{await(0,k.executeClaudeQuery)(e,c.session,d,{skill:u.taskCfg?.skill,agent:u.agent,senderNick:o,senderStaffId:i,permissionMode:u.permissionMode})}catch(y){if(c.session.claudeSessionId){console.log(`[\u4F1A\u8BDD\u6062\u590D\u5931\u8D25] \u6E05\u9664 claudeSessionId \u5E76\u91CD\u65B0\u53D1\u8D77: ${c.session.claudeSessionId}`),c.session.claudeSessionId=void 0,e.updateSessionFile(c.session,{});try{await(0,k.executeClaudeQuery)(e,c.session,d,{skill:u.taskCfg?.skill,agent:u.agent,senderNick:o,senderStaffId:i,permissionMode:u.permissionMode});return}catch(h){console.error("\u91CD\u8BD5\u6267\u884C Claude \u67E5\u8BE2\u5931\u8D25:",h),await(0,S.sendDingMessage)(e,{conversationId:n,sessionWebhook:t,atUserId:i,content:`\u274C \u5904\u7406\u6D88\u606F\u65F6\u53D1\u751F\u9519\u8BEF: ${h instanceof Error?h.message:String(h)}`}),c.isProcessing=!1,await b(e,n);return}}console.error("\u6267\u884C Claude \u67E5\u8BE2\u5931\u8D25:",y),await(0,S.sendDingMessage)(e,{conversationId:n,sessionWebhook:t,atUserId:i,content:`\u274C \u5904\u7406\u6D88\u606F\u65F6\u53D1\u751F\u9519\u8BEF: ${y instanceof Error?y.message:String(y)}`})}finally{c.isProcessing=!1}await b(e,n)}else await se(e,{conversationId:n,sessionWebhook:t,senderStaffId:i,senderNick:o,message:d,conversationConfig:u})}function Ce(e,s,n=!0){const t={sessionsDeleted:0,tasksDeleted:0,imagesDeleted:0,errors:[]},i=s?[s]:e.config.conversations.map(o=>o.conversationId);for(const o of i){let d=null;if(n){const l=D(e,o);l&&(d=v(l.session.session))}const u=P(e,o);if(r.default.existsSync(u))try{const l=r.default.readdirSync(u,{withFileTypes:!0});for(const m of l){if(!m.isDirectory()||d&&m.name===d)continue;const y=g.default.join(u,m.name);try{r.default.rmSync(y,{recursive:!0,force:!0}),t.sessionsDeleted++}catch{t.errors.push(`\u5220\u9664\u4F1A\u8BDD\u76EE\u5F55\u5931\u8D25: ${y}`)}}}catch{t.errors.push(`\u8BFB\u53D6sessions\u76EE\u5F55\u5931\u8D25: ${u}`)}const a=Z(e,o);if(r.default.existsSync(a))try{const l=r.default.readdirSync(a,{withFileTypes:!0});for(const m of l){if(!m.isDirectory())continue;const y=g.default.join(a,m.name);try{r.default.rmSync(y,{recursive:!0,force:!0}),t.tasksDeleted++}catch{t.errors.push(`\u5220\u9664\u4EFB\u52A1\u76EE\u5F55\u5931\u8D25: ${y}`)}}}catch{t.errors.push(`\u8BFB\u53D6tasks\u76EE\u5F55\u5931\u8D25: ${a}`)}const f=V(e,o);if(r.default.existsSync(f))try{const l=r.default.readdirSync(f,{withFileTypes:!0});for(const m of l){const y=g.default.join(f,m.name);try{r.default.unlinkSync(y),t.imagesDeleted++}catch{t.errors.push(`\u5220\u9664\u56FE\u7247\u5931\u8D25: ${y}`)}}}catch{t.errors.push(`\u8BFB\u53D6images\u76EE\u5F55\u5931\u8D25: ${f}`)}const c=g.default.join(j(e,o),".playwright-cli");if(r.default.existsSync(c))try{r.default.rmSync(c,{recursive:!0,force:!0})}catch{t.errors.push(`\u5220\u9664 playwright-cli \u7F13\u5B58\u5931\u8D25: ${c}`)}if(!n){const l=x(e,o);if(r.default.existsSync(l))try{r.default.unlinkSync(l)}catch{t.errors.push(`\u5220\u9664\u6D3B\u8DC3\u4F1A\u8BDD\u6587\u4EF6\u5931\u8D25: ${l}`)}e.activeSessions.has(o)&&e.activeSessions.delete(o)}}return t}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "cc-ding",
3
- "version": "1.0.0",
3
+ "version": "1.0.2",
4
4
  "description": "本地Claude对接钉钉机器人工具套件",
5
5
  "keywords": [
6
6
  "cli",
@@ -34,7 +34,7 @@
34
34
  "license": "MIT",
35
35
  "author": "yhn",
36
36
  "engines": {
37
- "node": ">=24"
37
+ "node": ">=22"
38
38
  },
39
39
  "bin": {
40
40
  "cc-ding": "./dist/bin/cc-ding.js"