cc-ding 0.4.1 → 1.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
|
@@ -1,90 +1,89 @@
|
|
|
1
|
-
"use strict";var
|
|
2
|
-
`;
|
|
3
|
-
`),msgType:"markdown"});return}for(const U of this.pendingAuthRequests.values())if(U.senderStaffId===i&&U.conversationId===a){await this.sendDingMessage({conversationId:a,sessionWebhook:
|
|
4
|
-
`);await(0,
|
|
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}\`
|
|
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,
|
|
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}
|
|
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,
|
|
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}**
|
|
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
|
|
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}**
|
|
11
11
|
|
|
12
|
-
${
|
|
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,`
|
|
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
|
|
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:
|
|
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
|
|
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:
|
|
19
|
-
\u{1F4A1} \u53EF\u7F16\u8F91 config.json \u8865\u5145\u66F4\u591A\u914D\u7F6E`),await this.sendDingMessage({conversationId:s,sessionWebhook:
|
|
20
|
-
`),msgType:"markdown"})}),(0,v.route)("/help",()=>(0,I.parseHelpCommand)(f),async()=>{await this.sendDingMessage({conversationId:s,sessionWebhook:
|
|
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}**
|
|
21
22
|
|
|
22
|
-
\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,
|
|
23
|
-
\u{1F4A1} \u6D3B\u8DC3\u4F1A\u8BDD\u5DF2\u4FDD\u7559`),
|
|
24
|
-
\u26A0\uFE0F \u9519\u8BEF: ${
|
|
25
|
-
`),msgType:"markdown"})}),(0,v.route)("/reset-apikeycfg",()=>(0,I.parseResetApiKeyCfgCommand)(f),async()=>{if(!await this.requireOwner(s,
|
|
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} \u6D3B\u8DC3\u4F1A\u8BDD\u5DF2\u4FDD\u7559`),t.errors.length>0&&g.push(`
|
|
25
|
+
\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
|
|
26
27
|
- \u6709\u6548 Key \u6570: ${e}/${this.config.apiKeyCfg.claudeSettings.length}
|
|
27
|
-
- \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,
|
|
28
|
-
- **\u7528\u6237ID:** ${
|
|
29
|
-
- **\u6635\u79F0:** ${
|
|
30
|
-
- **\u4F1A\u8BDDID:** ${
|
|
31
|
-
- **\u7528\u6237ID:** ${
|
|
32
|
-
- **\u6635\u79F0:** ${
|
|
33
|
-
`):"(\u672A\u914D\u7F6E\u7FA4\u7EA7\u767D\u540D\u5355\uFF0C\u4F7F\u7528\u5168\u5C40\u767D\u540D\u5355)";await this.sendDingMessage({conversationId:s,sessionWebhook:
|
|
34
|
-
${
|
|
35
|
-
`):"(\u672A\u914D\u7F6E\u7BA1\u7406\u5458)";await this.sendDingMessage({conversationId:s,sessionWebhook:
|
|
36
|
-
${
|
|
37
|
-
\u5F53\u524D\u767D\u540D\u5355: ${
|
|
38
|
-
\u5F53\u524D\u767D\u540D\u5355: ${
|
|
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
|
|
29
|
+
- **\u7528\u6237ID:** ${t.senderStaffId}
|
|
30
|
+
- **\u6635\u79F0:** ${t.senderNick}
|
|
31
|
+
- **\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
|
+
- **\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(`
|
|
34
|
+
`):"(\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
|
+
${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
|
+
`):"(\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:
|
|
39
40
|
\`\`\`
|
|
40
41
|
${r}
|
|
41
|
-
\`\`\``,msgType:"markdown"})}else if(e==="code"){if(!(0,
|
|
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:
|
|
42
43
|
\`\`\`
|
|
43
44
|
${r}
|
|
44
|
-
\`\`\``,msgType:"markdown"})}else{if(
|
|
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:
|
|
45
46
|
\`\`\`
|
|
46
47
|
${r}
|
|
47
|
-
\`\`\``,msgType:"markdown"})}}catch(
|
|
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
|
|
48
49
|
\`\`\`
|
|
49
|
-
${
|
|
50
|
+
${p.message}
|
|
50
51
|
\`\`\``,$&&(T+=`
|
|
51
52
|
|
|
52
53
|
**stderr:**
|
|
53
54
|
\`\`\`
|
|
54
|
-
${
|
|
55
|
-
\`\`\``);else{const O=
|
|
55
|
+
${m.sanitizeOutput($)}
|
|
56
|
+
\`\`\``);else{const O=D||"(\u65E0\u8F93\u51FA)";T=`\u2705 \u6267\u884C\u6210\u529F
|
|
56
57
|
\`\`\`
|
|
57
|
-
${
|
|
58
|
+
${m.sanitizeOutput(O)}
|
|
58
59
|
\`\`\``,$&&(T+=`
|
|
59
60
|
|
|
60
61
|
**stderr:**
|
|
61
62
|
\`\`\`
|
|
62
|
-
${
|
|
63
|
-
\`\`\``)}await
|
|
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:
|
|
64
65
|
\`\`\`
|
|
65
66
|
${r}
|
|
66
|
-
\`\`\``,msgType:"markdown"}):await this.sendDingMessage({conversationId:s,sessionWebhook:
|
|
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
|
|
67
68
|
`+(0,I.formatGlobalConfig)(this.config)),r.push(`### \u{1F916} \u7FA4\u914D\u7F6E\u4FE1\u606F
|
|
68
|
-
`+(0,I.formatConversationInfo)(
|
|
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
|
|
69
70
|
`+g):r.push(`### \u{1F4AC} \u5F53\u524D\u4F1A\u8BDD\u4FE1\u606F
|
|
70
71
|
\u65E0\u6D3B\u8DC3\u4F1A\u8BDD`)}(e==="all"||e==="task")&&r.push(`### \u{1F4DD} \u4EFB\u52A1\u961F\u5217\u4FE1\u606F
|
|
71
|
-
`+this.formatTaskInfo()),await this.sendDingMessage({conversationId:s,sessionWebhook:
|
|
72
|
+
`+this.formatTaskInfo()),await this.sendDingMessage({conversationId:s,sessionWebhook:n,content:r.join(`
|
|
72
73
|
|
|
73
|
-
`),msgType:"markdown"})}),(0,v.route)("/ls",()=>(0,I.parseLsCommand)(f),async e=>{const{target:r,depth:
|
|
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):
|
|
74
75
|
\`\`\`
|
|
75
|
-
${
|
|
76
|
-
\`\`\``,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:
|
|
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)
|
|
77
78
|
${g.join(`
|
|
78
|
-
`)}`,msgType:"markdown"})}return}case"front":{if(
|
|
79
|
-
1. **${
|
|
80
|
-
${
|
|
81
|
-
`)}`;
|
|
82
|
-
\u26A0\uFE0F \u5DF2\u5FFD\u7565\u65E0\u6548\u5E8F\u53F7: ${
|
|
83
|
-
|
|
84
|
-
`)}`,msgType:"markdown"});return}case"cancelAll":{if(n.length===0){await this.sendDingMessage({conversationId:s,sessionWebhook:t,content:"\u{1F4ED} \u5F53\u524D\u65E0\u6392\u961F\u6D88\u606F",msgType:"markdown"});return}const g=n.length;n.length=0,await this.sendDingMessage({conversationId:s,sessionWebhook:t,content:`\u2705 \u5DF2\u6E05\u7A7A\u6D88\u606F\u961F\u5217\uFF0C\u5171\u79FB\u9664 ${g} \u6761\u6D88\u606F`,msgType:"markdown"});return}}}),(0,v.route)("/!",()=>(0,I.parseInterruptCommand)(f),async()=>{const e=this.findActiveSession(s);if(!e){await this.sendDingMessage({conversationId:s,sessionWebhook:t,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:t,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 n=r.messageQueue.length;await this.sendDingMessage({conversationId:s,sessionWebhook:t,content:n>0?`\u23F9 \u5DF2\u4E2D\u65AD\u5F53\u524D\u4EFB\u52A1\uFF0C\u5F00\u59CB\u5904\u7406\u961F\u5217\u4E2D\u7684 ${n} \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:t,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,q.isWindows)()?e.currentProcess.kill():e.currentProcess.kill("SIGINT"),await this.sendDingMessage({conversationId:s,sessionWebhook:t,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:t,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:t,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:t,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=A.default.join(e,".claude","CLAUDE.md");if(M.default.existsSync(r)){const n=M.default.readFileSync(r,"utf-8"),g=n.length>8e3?n.substring(0,8e3)+`
|
|
85
|
-
...(\u5185\u5BB9\u8FC7\u957F\u5DF2\u622A\u65AD)`:n;await this.sendDingMessage({conversationId:s,sessionWebhook:t,content:`\u{1F4C4} **CLAUDE.md**
|
|
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)+`
|
|
84
|
+
...(\u5185\u5BB9\u8FC7\u957F\u5DF2\u622A\u65AD)`:t;await this.sendDingMessage({conversationId:s,sessionWebhook:n,content:`\u{1F4C4} **CLAUDE.md**
|
|
86
85
|
\`\`\`
|
|
87
86
|
${g}
|
|
88
|
-
\`\`\``,msgType:"markdown"})}else await this.sendDingMessage({conversationId:s,sessionWebhook:
|
|
89
|
-
\u8DEF\u5F84: \`${r}\``,msgType:"markdown"})})];for(const e of
|
|
90
|
-
**\u7248\u672C:** ${
|
|
87
|
+
\`\`\``,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;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
"use strict";var q=exports&&exports.__importDefault||function(e){return e&&e.__esModule?e:{default:e}};Object.defineProperty(exports,"__esModule",{value:!0}),exports.resolveClaudeSettingsPath=H,exports.isRetryableApiError=J,exports.parseClaudeStreamLine=ne,exports.interruptClaudeProcess=ye,exports.injectStartupContexts=Se,exports.injectSessionContextIfChanged=ae,exports.executeClaudeQuery=$e;const a=q(require("fs")),j=q(require("path")),ce=q(require("readline")),de=require("crypto"),E=require("./messaging"),n=require("./session"),$=require("./api-key-manager"),X=require("./secrets"),N=require("./platform"),
|
|
1
|
+
"use strict";var q=exports&&exports.__importDefault||function(e){return e&&e.__esModule?e:{default:e}};Object.defineProperty(exports,"__esModule",{value:!0}),exports.resolveClaudeSettingsPath=H,exports.isRetryableApiError=J,exports.parseClaudeStreamLine=ne,exports.interruptClaudeProcess=ye,exports.injectStartupContexts=Se,exports.injectSessionContextIfChanged=ae,exports.executeClaudeQuery=$e;const a=q(require("fs")),j=q(require("path")),ce=q(require("readline")),de=require("crypto"),E=require("./messaging"),n=require("./session"),$=require("./api-key-manager"),X=require("./secrets"),N=require("./platform"),P=20,K=1e4,G=1e4,B=10,Z=300*1e3,U=300*1e3,ue=30*1e3,Q=new Map;function H(e,t,o){const i=(0,$.getForceEnabledSettingsPath)(t);if(i)return i;if(e.config.apiKeyCfg){const f=(0,$.readApiKeyFromSettings)(t);let h=null;if(f&&(h=e.config.apiKeyCfg.claudeSettings.find(m=>(0,X.resolveSecret)(m.apiKey)===f&&m.isValid)||null),h||(h=(0,$.pickValidApiKey)(e)),h)return(0,$.ensureSettingsWithApiKey)(t,h)}if(e.config.apiKeyCfg)return;if(o)return o;const y=j.default.join(t,".claude","settings.json");if(a.default.existsSync(y))return console.log(`[${(0,n.timestamp)()}] \u81EA\u52A8\u68C0\u6D4B\u5230 settings.json: ${y}`),y}function J(e){if(/\b429\b/.test(e)&&!(0,$.isQuotaExhaustedError)(e)||/API\s*Error.*422/i.test(e)||/\b422\b.*(?:TPM|额度超限|rate\s*limit|tokens?\s*per\s*minute)/i.test(e)||/(?:TPM|额度超限).*\b422\b/i.test(e))return!0;const t=e.toLowerCase();return["rate limit","rate_limit","ratelimit","too many requests","tokens per minute","requests per minute","rpm limit","overloaded","capacity","temporarily unavailable"].some(i=>t.includes(i))}function le(e){return new Promise(t=>setTimeout(t,e))}class V extends Error{constructor(t,o=""){super(`Retryable API error (TPM limit etc.)${t?" [fast fail]":""}`),this.name="RetryableApiError",this.isFastFail=t,this.output=o}}class ee extends Error{constructor(){super("Claude conversation not found"),this.name="ConversationNotFoundError"}}class te extends Error{constructor(){super("Context window exceeded: prompt tokens exceed maximum context window"),this.name="ContextWindowExceededError"}}function pe(e,t){try{return a.default.readFileSync(e,"utf-8").split(`
|
|
2
2
|
`).filter(Boolean).slice(-t).join(`
|
|
3
3
|
`)}catch{return""}}function fe(e){return/prompt tokens?\s*\(\s*\d+\s*\)\s*exceeds/i.test(e)||/exceeds?.*maximum context window/i.test(e)}function me(e){const t=e.toLowerCase();return["permission denied","permission_required","needs permission","requires permission","authorization required","authorize","not authorized","access denied","\u9700\u8981\u6388\u6743","\u6743\u9650\u4E0D\u8DB3","\u6CA1\u6709\u6743\u9650"].some(i=>t.includes(i))}function ge(e){return/no conversation found with session id/i.test(e)}function ne(e,t=!1){if(!e.trim())return null;try{const o=JSON.parse(e);if(o.type==="system"&&o.subtype==="init"&&o.session_id)return{type:"system",sessionId:o.session_id};if(o.type==="assistant"){const i=o.message?.content;if(Array.isArray(i)){const y=[];for(const f of i)f.type==="text"&&f.text?y.push(f.text):f.type==="thinking"&&f.thinking&&t&&y.push(`\u{1F4AD} **\u601D\u8003\u8FC7\u7A0B**
|
|
4
4
|
\`\`\`
|
|
@@ -6,13 +6,13 @@ ${f.thinking}
|
|
|
6
6
|
\`\`\``);if(y.length>0)return{type:"assistant",content:y.join(`
|
|
7
7
|
`)}}else if(o.content)return{type:"assistant",content:typeof o.content=="string"?o.content:JSON.stringify(o.content)};return{type:"assistant"}}if(o.type==="result"){const i=o.result||"";return{type:"result",content:typeof i=="string"?i:JSON.stringify(i)}}return{type:o.type||"unknown"}}catch{return{type:"text",content:e}}}function ye(e,t){return e.currentProcess?(console.log(`[${(0,n.timestamp)()}] ${t}`),e.interrupted=!0,(0,N.isWindows)()?e.currentProcess.kill():e.currentProcess.kill("SIGINT"),!0):!1}function oe(e,t,o,i,y,f,h){let m=e.getSessionDir(t),I=`${m}/session.log`;a.default.existsSync(m)||a.default.mkdirSync(m,{recursive:!0});const T=Date.now();return new Promise((g,C)=>{const S=(0,N.spawnCommand)(i,o,{cwd:y,stdio:["pipe","pipe","pipe"]}),A=e.activeSessions.get(t.conversationId);A&&(A.currentProcess=S,A.lastActivityTime=Date.now()),a.default.appendFileSync(I,`[${(0,n.timestamp)()}] [SYSTEM]: Claude \u67E5\u8BE2\u542F\u52A8${h?" (\u91CD\u8BD5)":""}
|
|
8
8
|
`,"utf-8"),S.stdin?.write(`${f}
|
|
9
|
-
`),S.stdin?.end();let Y=!h&&!!t.claudeSessionId,M=[],x="",O="",
|
|
9
|
+
`),S.stdin?.end();let Y=!h&&!!t.claudeSessionId,M=[],x="",O="",D=!1,W=!1,l=null;const k=new Set,R=()=>{A&&(A.lastActivityTime=Date.now())};l=setInterval(()=>{if(W){l&&clearInterval(l);return}const p=A?.lastActivityTime??T;if(Date.now()-p>=U){console.warn(`[${(0,n.timestamp)()}] Watchdog: Claude \u8FDB\u7A0B ${U/1e3}s \u65E0\u6D3B\u52A8\uFF0C\u901A\u77E5\u7528\u6237`);try{a.default.appendFileSync(I,`[${(0,n.timestamp)()}] [SYSTEM]: Watchdog \u8D85\u65F6\uFF0C${U/1e3}s \u65E0\u6D3B\u52A8\uFF0C\u5DF2\u901A\u77E5\u7528\u6237
|
|
10
10
|
`,"utf-8")}catch{}l&&clearInterval(l),l=null;const c=A?.lastSenderStaffId||t.startStaffId;(0,E.sendDingMessage)(e,{conversationId:(0,n.getReplyConversationId)(t),sessionWebhook:(0,n.getReplyWebhook)(t),atUserId:c,content:`\u23F0 Claude \u8FDB\u7A0B\u8D85\u8FC7 ${U/1e3}s \u65E0\u54CD\u5E94\uFF0C\u53EF\u53D1\u9001 /goon \u5F3A\u5236\u91CD\u542F\u6062\u590D\uFF0C\u6216 /end \u7ED3\u675F\u4F1A\u8BDD`}).catch(d=>console.error("\u53D1\u9001 Watchdog \u901A\u77E5\u5931\u8D25:",d))}},ue),ce.default.createInterface({input:S.stdout}).on("line",p=>{if(O+=p+`
|
|
11
11
|
`,R(),e.debugLog(`Claude stdout: ${p.substring(0,200)}${p.length>200?"...":""}`),e.config.debug)try{a.default.appendFileSync(I,`[${(0,n.timestamp)()}] [RAW]: ${p}
|
|
12
12
|
`,"utf-8")}catch{}const r=ne(p,e.config.includeThinking??!1);if(r){if(r.type==="system"&&r.sessionId&&!Y&&(e.updateSessionFile(t,{claudeSessionId:r.sessionId}),Y=!0,m=e.getSessionDir(t),I=`${m}/session.log`),r.type==="assistant"){try{const d=JSON.parse(p)?.message?.content;if(Array.isArray(d)){for(const s of d)if(s.type==="tool_use"&&s.id&&!k.has(s.id)){k.add(s.id);const v=s.name||"unknown";let u="";s.input&&(s.input.command?u=s.input.command.substring(0,200):s.input.file_path?u=s.input.file_path:s.input.pattern?u=s.input.pattern:s.input.query?u=s.input.query:s.input.description?u=s.input.description:s.input.prompt?u=s.input.prompt.substring(0,200):u=JSON.stringify(s.input).substring(0,200)),e.appendSessionLog(m,"tool",`${v}${u?": "+u:""}`)}}}catch{}r.content&&M.push(r.content)}if(r.type==="result"){const c=e.config.resultOnly??!0,d=(r.content||"").trim(),s=M.join(`
|
|
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;
|
|
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
|
-
`).trim();if(d){try{e.appendSessionLog(m,"assistant",d)}catch{}const s=r?.lastSenderStaffId||t.startStaffId;
|
|
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
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+`
|
|
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}
|
|
@@ -20,7 +20,7 @@ ${f.thinking}
|
|
|
20
20
|
`)+`
|
|
21
21
|
`}function re(e,t,o){const i=e.getConversationDir(t),y=j.default.join(i,".claude");a.default.existsSync(y)||a.default.mkdirSync(y,{recursive:!0});const f=j.default.join(y,"CLAUDE.md");if(!a.default.existsSync(f)){a.default.writeFileSync(f,o,"utf-8"),console.log(`[${(0,n.timestamp)()}] cc-ding \u4E0A\u4E0B\u6587\u5DF2\u6CE8\u5165 CLAUDE.md: ${f}`);return}const h=a.default.readFileSync(f,"utf-8"),m=h.indexOf(ie),I=h.indexOf(z);if(m!==-1&&I!==-1&&I>m){const T=h.substring(0,m),g=h.substring(I+z.length),C=T+o+g;a.default.writeFileSync(f,C,"utf-8"),console.log(`[${(0,n.timestamp)()}] cc-ding \u4E0A\u4E0B\u6587\u5DF2\u66F4\u65B0: ${f}`)}else a.default.writeFileSync(f,o+`
|
|
22
22
|
`+h,"utf-8"),console.log(`[${(0,n.timestamp)()}] cc-ding \u4E0A\u4E0B\u6587\u5DF2\u8FFD\u52A0\u5230\u73B0\u6709 CLAUDE.md: ${f}`)}function Se(e){const t=Array.isArray(e.config.conversations)?e.config.conversations:[];for(const o of t){const i=se(e,o.conversationId);Q.set(o.conversationId,i),re(e,o.conversationId,i)}}function ae(e,t){const o=t.conversationId,i=se(e,o);Q.get(o)!==i&&(Q.set(o,i),re(e,o,i))}async function $e(e,t,o,i){const{skill:y,agent:f,senderNick:h,senderStaffId:m,newSessionId:I}=i||{};let T=e.getSessionDir(t),g=`${T}/session.log`;const C=e.getConversationDir(t.conversationId);ae(e,t),a.default.mkdirSync(T,{recursive:!0});let S=null;const A=(0,$.readApiKeyFromSettings)(C);if(A&&e.config.apiKeyCfg&&(S=e.config.apiKeyCfg.claudeSettings.find(c=>(0,X.resolveSecret)(c.apiKey)===A&&c.isValid)||null,S&&console.log(`[${(0,n.timestamp)()}] \u4ECE settings-ding.json \u6062\u590D Claude Setting: ${(0,$.settingLabel)(S)}`)),!(0,$.getForceEnabledSettingsPath)(C)&&e.config.apiKeyCfg&&(S=(0,$.pickValidApiKey)(e),!S)){const c=m||t.startStaffId;await(0,E.sendDingMessage)(e,{conversationId:(0,n.getReplyConversationId)(t),sessionWebhook:(0,n.getReplyWebhook)(t),atUserId:c,content:"\u26A0\uFE0F \u5F53\u524D\u65E0\u53EF\u7528\u914D\u989D\uFF08\u65E0\u53EF\u7528 API Key\uFF09\uFF0C\u8BF7\u660E\u5929\u518D\u8BD5\u6216\u8054\u7CFB\u7BA1\u7406\u5458"});return}const M=h&&m?`${o} \u2500\u2500 \u6D88\u606F\u6765\u81EA: ${h}(${m})`:o;e.appendSessionLog(T,"user",M);const x="claude";if(!(0,N.commandExists)(x)){const c=(0,N.formatClaudeCommandMissingMessage)(x);console.error(`[${(0,n.timestamp)()}] ${c.replace(/\n/g," ")}`),a.default.appendFileSync(g,`[${(0,n.timestamp)()}] [ERROR]: ${c}
|
|
23
|
-
`,"utf-8"),await(0,E.sendDingMessage)(e,{conversationId:(0,n.getReplyConversationId)(t),sessionWebhook:(0,n.getReplyWebhook)(t),atUserId:m||t.startStaffId,content:`\u274C ${c}`});return}const
|
|
23
|
+
`,"utf-8"),await(0,E.sendDingMessage)(e,{conversationId:(0,n.getReplyConversationId)(t),sessionWebhook:(0,n.getReplyWebhook)(t),atUserId:m||t.startStaffId,content:`\u274C ${c}`});return}const D=["--permission-mode",i?.permissionMode??"bypassPermissions","--print","--output-format","stream-json","--verbose"];f&&D.push("--agent",f);const W=y?`/${y} ${M}`:M;let l=0,k=0,R=0;const _=[],p=e.activeSessions.get(t.conversationId),r=c=>{const d=e.activeSessions.get(t.conversationId);return!d||d!==p?(console.log(`[${(0,n.timestamp)()}] \u4F1A\u8BDD\u5DF2\u88AB\u7EC8\u6B62\uFF0C${c}`),!1):d.goonPending?(console.log(`[${(0,n.timestamp)()}] \u6536\u5230 /goon \u8BF7\u6C42\uFF0C${c}`),!1):!0};for(;;){if(!r("\u505C\u6B62\u91CD\u8BD5"))return;const c=l>0;if(k>=B||k>=3&&R>0&&Date.now()-R>Z){const u=k>=B?`\u603B\u91CD\u8BD5\u6B21\u6570\u5DF2\u8FBE ${B} \u6B21`:`\u91CD\u8BD5\u6301\u7EED\u65F6\u95F4\u8D85\u8FC7 ${Z/1e3}s\uFF08\u5DF2\u91CD\u8BD5 ${k} \u6B21\uFF09`;console.error(`[${(0,n.timestamp)()}] \u68C0\u6D4B\u5230\u65E0\u9650\u91CD\u8BD5\u5FAA\u73AF: ${u}`),a.default.appendFileSync(g,`[${(0,n.timestamp)()}] [SYSTEM]: \u68C0\u6D4B\u5230\u65E0\u9650\u91CD\u8BD5\u5FAA\u73AF\uFF0C${u}\uFF0C\u7EC8\u6B62\u91CD\u8BD5
|
|
24
24
|
`,"utf-8");const w=pe(g,1),b=_.slice(-1)[0]||"",L=m||t.startStaffId;await(0,E.sendDingMessage)(e,{conversationId:(0,n.getReplyConversationId)(t),sessionWebhook:(0,n.getReplyWebhook)(t),atUserId:L,content:`\u{1F504} \u68C0\u6D4B\u5230 Claude \u9677\u5165\u65E0\u9650\u91CD\u8BD5\uFF0C\u5DF2\u7EC8\u6B62\uFF08${u}\uFF09
|
|
25
25
|
|
|
26
26
|
\u{1F4CB} \u6700\u8FD1\u91CD\u8BD5\u8BB0\u5F55\uFF1A
|
|
@@ -31,13 +31,13 @@ ${b}
|
|
|
31
31
|
${w}
|
|
32
32
|
\`\`\`
|
|
33
33
|
|
|
34
|
-
\u{1F4A1} \u53EF\u5C1D\u8BD5\u53D1\u9001 /new \u5F00\u59CB\u65B0\u4F1A\u8BDD\uFF0C\u6216 /end \u7ED3\u675F\u5F53\u524D\u4F1A\u8BDD`});return}const d=[...
|
|
34
|
+
\u{1F4A1} \u53EF\u5C1D\u8BD5\u53D1\u9001 /new \u5F00\u59CB\u65B0\u4F1A\u8BDD\uFF0C\u6216 /end \u7ED3\u675F\u5F53\u524D\u4F1A\u8BDD`});return}const d=[...D];if(t.claudeSessionId)d.push("--resume",t.claudeSessionId),c||console.log(`[${(0,n.timestamp)()}] \u6062\u590D Claude \u4F1A\u8BDD: ${t.claudeSessionId}`);else if(!c){const u=I||(0,de.randomUUID)();d.push("--session-id",u),d.push("--name",`cc-ding-${u.substring(0,8)}`),console.log(`[${(0,n.timestamp)()}] \u521B\u5EFA Claude \u4F1A\u8BDD(\u663E\u5F0F session-id): ${u}`)}const s=H(e,C,i?.settings);s&&d.push("--settings",s);let v;c?(v="\u7EE7\u7EED",console.log(`[${(0,n.timestamp)()}] \u53D1\u9001"\u7EE7\u7EED"\u91CD\u8BD5 (\u5FEB\u901F\u5931\u8D25\u8FDE\u7EED${l}/${P}\u6B21)`),a.default.appendFileSync(g,`[${(0,n.timestamp)()}] [SYSTEM]: TPM \u9650\u6D41\uFF0C\u53D1\u9001"\u7EE7\u7EED"\u91CD\u8BD5 (\u5FEB\u901F\u5931\u8D25\u8FDE\u7EED${l}/${P})
|
|
35
35
|
`,"utf-8")):v=W,console.log(`[${(0,n.timestamp)()}] \u6267\u884C Claude \u67E5\u8BE2[\u539F\u751Fclaude \u6A21\u5F0F]: ${x} ${d.join(" ")}`),e.debugLog(`\u53D1\u9001\u6D88\u606F: ${v.substring(0,100)}...`);try{await oe(e,t,d,x,C,v,c);return}catch(u){if(T=e.getSessionDir(t),g=`${T}/session.log`,u instanceof V){if(k++,R=R||Date.now(),(0,$.isQuotaExhaustedError)(u.output)&&e.config.apiKeyCfg){if(_.push(`[${(0,n.timestamp)()}] 429 \u914D\u989D\u8017\u5C3D\uFF0C\u5C1D\u8BD5\u8F6E\u6362 Key`),S){const b=(0,$.rotateApiKey)(e,S.apiKey);if(b){S=b,l=0,console.log(`[${(0,n.timestamp)()}] API Key \u914D\u989D\u8017\u5C3D(429)\uFF0C\u5207\u6362\u5230\u65B0 Key: ${(0,$.settingLabel)(b)}`),a.default.appendFileSync(g,`[${(0,n.timestamp)()}] [SYSTEM]: API Key \u914D\u989D\u8017\u5C3D(429)\uFF0C\u5207\u6362\u5230\u65B0 Key
|
|
36
|
-
`,"utf-8");continue}}const w=m||t.startStaffId;await(0,E.sendDingMessage)(e,{conversationId:(0,n.getReplyConversationId)(t),sessionWebhook:(0,n.getReplyWebhook)(t),atUserId:w,content:"\u26A0\uFE0F \u5F53\u524D\u65E0\u53EF\u7528\u914D\u989D/API Key\uFF0C\u8BF7\u660E\u5929\u518D\u8BD5\u6216\u8054\u7CFB\u7BA1\u7406\u5458"});return}if(u.isFastFail){if(l++,l>=
|
|
37
|
-
`,"utf-8");continue}}throw console.log(`[${(0,n.timestamp)()}] TPM \u9650\u6D41\u5FEB\u901F\u5931\u8D25\u8FDE\u7EED${
|
|
38
|
-
`,"utf-8"),new Error(`TPM \u9650\u6D41\uFF0C\u5FEB\u901F\u5931\u8D25\u8FDE\u7EED ${
|
|
36
|
+
`,"utf-8");continue}}const w=m||t.startStaffId;await(0,E.sendDingMessage)(e,{conversationId:(0,n.getReplyConversationId)(t),sessionWebhook:(0,n.getReplyWebhook)(t),atUserId:w,content:"\u26A0\uFE0F \u5F53\u524D\u65E0\u53EF\u7528\u914D\u989D/API Key\uFF0C\u8BF7\u660E\u5929\u518D\u8BD5\u6216\u8054\u7CFB\u7BA1\u7406\u5458"});return}if(u.isFastFail){if(l++,l>=P){if(S&&e.config.apiKeyCfg){const w=(0,$.rotateApiKey)(e,S.apiKey);if(w){S=w,l=0,console.log(`[${(0,n.timestamp)()}] TPM \u9650\u6D41\u8FDE\u7EED\u5FEB\u901F\u5931\u8D25 ${P} \u6B21\uFF0C\u5207\u6362\u5230\u65B0 Key: ${(0,$.settingLabel)(w)}`),a.default.appendFileSync(g,`[${(0,n.timestamp)()}] [SYSTEM]: TPM \u9650\u6D41\u8FDE\u7EED\u5FEB\u901F\u5931\u8D25\uFF0C\u5207\u6362\u5230\u65B0 Key
|
|
37
|
+
`,"utf-8");continue}}throw console.log(`[${(0,n.timestamp)()}] TPM \u9650\u6D41\u5FEB\u901F\u5931\u8D25\u8FDE\u7EED${P}\u6B21\uFF0C\u653E\u5F03`),a.default.appendFileSync(g,`[${(0,n.timestamp)()}] [SYSTEM]: TPM \u9650\u6D41\u5FEB\u901F\u5931\u8D25\u8FDE\u7EED${P}\u6B21\uFF0C\u653E\u5F03
|
|
38
|
+
`,"utf-8"),new Error(`TPM \u9650\u6D41\uFF0C\u5FEB\u901F\u5931\u8D25\u8FDE\u7EED ${P} \u6B21`)}console.log(`[${(0,n.timestamp)()}] \u68C0\u6D4B\u5230 TPM \u9650\u6D41(\u5FEB\u901F\u5931\u8D25)\uFF0C${K/1e3}s \u540E\u91CD\u8BD5 (${l}/${P})`)}else l=0,console.log(`[${(0,n.timestamp)()}] \u68C0\u6D4B\u5230 TPM \u9650\u6D41(\u8FDB\u7A0B\u5DF2\u8FD0\u884C\u4E00\u6BB5\u65F6\u95F4)\uFF0C\u91CD\u7F6E\u5FEB\u901F\u5931\u8D25\u8BA1\u6570\uFF0C${K/1e3}s \u540E\u91CD\u8BD5`);if(a.default.appendFileSync(g,`[${(0,n.timestamp)()}] [SYSTEM]: TPM \u9650\u6D41\uFF0C${K/1e3}s \u540E\u91CD\u8BD5
|
|
39
39
|
`,"utf-8"),_.push(`[${(0,n.timestamp)()}] TPM \u9650\u6D41\uFF0C${K/1e3}s \u540E\u91CD\u8BD5`),await le(K),!r("\u505C\u6B62\u5F53\u524D\u91CD\u8BD5"))return;continue}if(u instanceof ee){k++,R=R||Date.now(),_.push(`[${(0,n.timestamp)()}] \u4F1A\u8BDD\u5931\u6548\uFF0C\u6E05\u9664\u65E7\u4F1A\u8BDD`),console.log(`[${(0,n.timestamp)()}] Claude \u4F1A\u8BDD\u5931\u6548\uFF0C\u6E05\u9664 claudeSessionId \u5E76\u91CD\u65B0\u53D1\u8D77`),a.default.appendFileSync(g,`[${(0,n.timestamp)()}] [SYSTEM]: Claude \u4F1A\u8BDD\u5DF2\u5931\u6548\uFF0C\u6E05\u9664\u65E7\u4F1A\u8BDD\u5E76\u91CD\u65B0\u53D1\u8D77
|
|
40
40
|
`,"utf-8"),t.claudeSessionId&&(t.claudeSessionId=void 0,e.updateSessionFile(t,{})),l=0;continue}if(u instanceof te){k++,R=R||Date.now(),_.push(`[${(0,n.timestamp)()}] \u4E0A\u4E0B\u6587\u7A97\u53E3\u8D85\u957F\uFF0C\u81EA\u52A8 /compact`),console.log(`[${(0,n.timestamp)()}] \u4E0A\u4E0B\u6587\u7A97\u53E3\u8D85\u957F\uFF0C\u81EA\u52A8\u53D1\u9001 /compact \u538B\u7F29\u4E0A\u4E0B\u6587`),a.default.appendFileSync(g,`[${(0,n.timestamp)()}] [SYSTEM]: \u4E0A\u4E0B\u6587\u7A97\u53E3\u8D85\u957F\uFF0C\u81EA\u52A8\u53D1\u9001 /compact \u538B\u7F29\u4E0A\u4E0B\u6587
|
|
41
|
-
`,"utf-8");const w=m||t.startStaffId;await(0,E.sendDingMessage)(e,{conversationId:(0,n.getReplyConversationId)(t),sessionWebhook:(0,n.getReplyWebhook)(t),atUserId:w,content:"\u{1F4E6} \u4E0A\u4E0B\u6587\u8D85\u957F\uFF0C\u6B63\u5728\u81EA\u52A8\u538B\u7F29\u4E0A\u4E0B\u6587(/compact)\u540E\u7EE7\u7EED..."});const b=[...
|
|
41
|
+
`,"utf-8");const w=m||t.startStaffId;await(0,E.sendDingMessage)(e,{conversationId:(0,n.getReplyConversationId)(t),sessionWebhook:(0,n.getReplyWebhook)(t),atUserId:w,content:"\u{1F4E6} \u4E0A\u4E0B\u6587\u8D85\u957F\uFF0C\u6B63\u5728\u81EA\u52A8\u538B\u7F29\u4E0A\u4E0B\u6587(/compact)\u540E\u7EE7\u7EED..."});const b=[...D];t.claudeSessionId&&b.push("--resume",t.claudeSessionId);const L=H(e,C,i?.settings);L&&b.push("--settings",L);try{await oe(e,t,b,x,C,"/compact",!1),console.log(`[${(0,n.timestamp)()}] /compact \u6267\u884C\u6210\u529F\uFF0C\u53D1\u9001"\u7EE7\u7EED"\u6062\u590D\u6267\u884C`),a.default.appendFileSync(g,`[${(0,n.timestamp)()}] [SYSTEM]: /compact \u6267\u884C\u6210\u529F\uFF0C\u53D1\u9001"\u7EE7\u7EED"\u6062\u590D\u6267\u884C
|
|
42
42
|
`,"utf-8")}catch(F){throw console.error(`[${(0,n.timestamp)()}] /compact \u6267\u884C\u5931\u8D25:`,F),a.default.appendFileSync(g,`[${(0,n.timestamp)()}] [SYSTEM]: /compact \u6267\u884C\u5931\u8D25: ${F instanceof Error?F.message:String(F)}
|
|
43
43
|
`,"utf-8"),await(0,E.sendDingMessage)(e,{conversationId:(0,n.getReplyConversationId)(t),sessionWebhook:(0,n.getReplyWebhook)(t),atUserId:w,content:"\u274C \u81EA\u52A8\u538B\u7F29\u4E0A\u4E0B\u6587(/compact)\u5931\u8D25\uFF0C\u8BF7\u624B\u52A8\u53D1\u9001 /compact \u6216 /new \u5F00\u59CB\u65B0\u4F1A\u8BDD"}),new Error(`\u4E0A\u4E0B\u6587\u8D85\u957F\u4E14 /compact \u5931\u8D25: ${F instanceof Error?F.message:String(F)}`)}l=0;continue}throw u}}}
|
|
@@ -1,2 +1,3 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.runOneShotPrompt=
|
|
2
|
-
`),
|
|
1
|
+
"use strict";var h=exports&&exports.__importDefault||function(e){return e&&e.__esModule?e:{default:e}};Object.defineProperty(exports,"__esModule",{value:!0}),exports.runOneShotPrompt=S;const M=h(require("readline")),a=require("./platform"),w=require("./claude-process");async function S(e,p){const{cwd:_,settingsPath:l,timeoutMs:O=6e4}=p;if(!(0,a.commandExists)("claude"))return{ok:!1,text:"",errorOutput:(0,a.formatClaudeCommandMissingMessage)("claude"),timedOut:!1};const c=["--output-format","stream-json","--max-turns","1","--permission-mode","default"];l&&c.push("--settings",l);let o="",d="",i=!1,s="",u=!1;try{const t=(0,a.spawnCommand)("claude",c,{cwd:_,stdio:["pipe","pipe","pipe"]});t.stdin.write(`${e}
|
|
2
|
+
`),t.stdin.end();const f=setTimeout(()=>{u=!0,t.kill("SIGTERM")},O);f.unref?.(),t.stderr.on("data",r=>{o+=r.toString()});const g=M.default.createInterface({input:t.stdout});for await(const r of g){const n=(0,w.parseClaudeStreamLine)(r);n?.type==="result"&&(d=n.content||"",i=!0)}const m=await new Promise(r=>{t.on("close",n=>{r(n)}),t.on("error",()=>{r(1)})});clearTimeout(f),u?s="One-shot prompt \u8D85\u65F6":!i&&m!==0&&(s=o.trim()||`\u5B50\u8FDB\u7A0B\u9000\u51FA\u7801: ${m}`)}catch(t){s=t instanceof Error?t.message:String(t)}return{ok:i,text:d,errorOutput:[o,s].filter(Boolean).join(`
|
|
3
|
+
`),timedOut:u}}
|
package/dist/src/biz/commands.js
CHANGED
|
@@ -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")),
|
|
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(`
|
|
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
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
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
|
|
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"};const n=s.match(/^rm\s+(.+)$/i);if(n){const
|
|
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}
|
package/dist/src/biz/session.js
CHANGED
|
@@ -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=
|
|
2
|
-
`)}function ye(e,s,n){const t=C(e,s);if(!t)return null;const i=t.session,
|
|
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
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
|
|
5
|
-
`;try{
|
|
6
|
-
\u53EF\u4EE5\u901A\u8FC7 /new \u5F00\u59CB\u65B0\u4F1A\u8BDD\u3002`});return}const{key:i,session:
|
|
7
|
-
`,"utf-8");const f=
|
|
8
|
-
\u{1F194}
|
|
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),
|
|
10
|
-
`,"utf-8")}async function ve(e,s,n,t,i,
|
|
11
|
-
`,"utf-8")),e.activeSessions.set(s,{session:d,lastSenderStaffId:i,isProcessing:!1,messageQueue:[],conversationConfig:
|
|
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})
|
|
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:
|
|
14
|
-
\u{1F194}
|
|
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}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "cc-ding",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "1.0.0",
|
|
4
4
|
"description": "本地Claude对接钉钉机器人工具套件",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"cli",
|
|
@@ -9,7 +9,6 @@
|
|
|
9
9
|
],
|
|
10
10
|
"main": "dist/index",
|
|
11
11
|
"dependencies": {
|
|
12
|
-
"@anthropic-ai/claude-agent-sdk": "^0.3.173",
|
|
13
12
|
"commander": "^7.2.0",
|
|
14
13
|
"dotenv": "^16.6.1",
|
|
15
14
|
"shelljs": "^0.10.0",
|