cc-ding 1.0.3 → 1.0.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/src/biz/doctor.js +1 -1
- package/package.json +1 -1
package/dist/src/biz/doctor.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
"use strict";var v=exports&&exports.__importDefault||function(i){return i&&i.__esModule?i:{default:i}};Object.defineProperty(exports,"__esModule",{value:!0}),exports.printDoctorResults=I,exports.runDoctor=R;const N=require("./session"),F=require("./api-key-manager"),u=v(require("fs")),A=v(require("path")),T=require("./platform");function I(i){console.log(""),console.log("========== cc-ding doctor ==========");const e=i.some(r=>r.level==="FATAL");for(const r of i){const l=r.level==="PASS"?"\u2713":r.level==="FATAL"?"\u2717":"\u26A0",h=r.level==="PASS"?"":`[${r.level}] `;console.log(` ${l} ${h}${r.message}`)}const f=i.filter(r=>r.level==="PASS").length,S=i.filter(r=>r.level==="WARN").length,p=i.filter(r=>r.level==="FATAL").length;console.log("------------------------------------"),console.log(` \u5408\u8BA1: ${f} \u901A\u8FC7, ${S} \u8B66\u544A, ${p} \u81F4\u547D`),console.log(e?" \u274C \u5B58\u5728\u81F4\u547D\u95EE\u9898\uFF0C\u8BF7\u4FEE\u590D\u540E\u91CD\u65B0\u8FD0\u884C":" \u2705 \u6240\u6709\u68C0\u67E5\u901A\u8FC7"),console.log(`====================================
|
|
2
|
-
`),e&&process.exit(1)}function R(i){const e=[],f=process.version.slice(1);if(parseInt(f.split(".")[0],10)<
|
|
2
|
+
`),e&&process.exit(1)}function R(i){const e=[],f=process.version.slice(1);if(parseInt(f.split(".")[0],10)<22?e.push(s("FATAL",`Node \u7248\u672C\u8FC7\u4F4E\uFF1A${f}\uFF0C\u8981\u6C42 Node >= 22`)):e.push(s("PASS",`Node \u7248\u672C\uFF1A${f}`)),!u.default.existsSync(i))return e.push(s("FATAL",`\u5BA2\u6237\u7AEF\u76EE\u5F55\u4E0D\u5B58\u5728: ${i}`)),e;e.push(s("PASS",`\u5BA2\u6237\u7AEF\u76EE\u5F55\u5B58\u5728: ${i}`));const p=A.default.join(i,".pid.lock");if(u.default.existsSync(p))try{const n=parseInt(u.default.readFileSync(p,"utf-8").trim(),10);if(!isNaN(n))try{process.kill(n,0),e.push(s("PASS",`\u8FDB\u7A0B\u8FD0\u884C\u4E2D (PID: ${n})`))}catch{e.push(s("WARN",`\u9501\u6587\u4EF6\u5B58\u5728\u4F46\u8FDB\u7A0B ${n} \u5DF2\u9000\u51FA\uFF08\u8FC7\u671F\u9501\u6587\u4EF6\uFF09`))}}catch{e.push(s("WARN",`PID \u9501\u6587\u4EF6\u8BFB\u53D6\u5F02\u5E38: ${p}`))}else e.push(s("PASS","\u65E0\u8FD0\u884C\u4E2D\u7684\u8FDB\u7A0B"));const r=A.default.join(i,"config.json");if(!u.default.existsSync(r))return e.push(s("FATAL","config.json \u4E0D\u5B58\u5728")),e;let l;try{l=JSON.parse(u.default.readFileSync(r,"utf-8"))}catch(n){return e.push(s("FATAL",`config.json \u89E3\u6790\u5931\u8D25: ${n instanceof Error?n.message:n}`)),e}e.push(s("PASS","config.json \u89E3\u6790\u6210\u529F"));const h=[{key:"clientSecret",label:"clientSecret"},{key:"defaultDingToken",label:"defaultDingToken"},{key:"whiteUserList",label:"whiteUserList",isArr:!0},{key:"owner",label:"owner"}];for(const{key:n,label:o,isArr:a}of h){const t=l[n];t==null||t===""?e.push(s("FATAL",`\u7F3A\u5C11\u5FC5\u586B\u5B57\u6BB5: ${o}`)):a&&!Array.isArray(t)?e.push(s("FATAL",`${o} \u5E94\u4E3A\u6570\u7EC4`)):n!=="conversations"&&a&&t.length===0?e.push(s("WARN",`${o} \u4E3A\u7A7A\u6570\u7EC4`)):!a&&typeof t=="string"&&t.startsWith("<")?e.push(s("FATAL",`${o} \u4ECD\u4E3A\u5360\u4F4D\u7B26: ${t}`)):e.push(s("PASS",`${o} \u2713`))}l.owner?e.push(s("PASS",`owner: ${l.owner}`)):e.push(s("FATAL","owner \u672A\u914D\u7F6E\uFF0C\u7BA1\u7406\u547D\u4EE4\uFF08/clean, /open, /reset-apikeycfg, /reg, /auth\uFF09\u4E0D\u53EF\u7528"));const j=["clientSecret","defaultDingToken"];for(const n of j){const o=l[n];typeof o=="string"&&/^<.*>$/.test(o.trim())&&e.push(s("FATAL",`${n} \u4ECD\u4E3A\u5360\u4F4D\u7B26: ${o}`))}const g=new Set;if(!Array.isArray(l.conversations))e.push(s("FATAL","conversations \u5E94\u4E3A\u6570\u7EC4"));else if(l.conversations.length===0)e.push(s("PASS","conversations \u4E3A\u7A7A\u6570\u7EC4\uFF0C\u53EF\u901A\u8FC7 /reg \u547D\u4EE4\u52A8\u6001\u6CE8\u518C"));else{for(let n=0;n<l.conversations.length;n++){const o=l.conversations[n],a=`conversations[${n}]`;o.conversationId?typeof o.conversationId=="string"&&/^<.*>$/.test(o.conversationId.trim())?e.push(s("FATAL",`${a} conversationId \u4ECD\u4E3A\u5360\u4F4D\u7B26: ${o.conversationId}`)):g.has(o.conversationId)?e.push(s("WARN",`${a} conversationId \u91CD\u590D: ${o.conversationId}`)):g.add(o.conversationId):e.push(s("FATAL",`${a} \u7F3A\u5C11 conversationId`)),o.linkConversationId&&!l.conversations.some(t=>t.conversationId===o.linkConversationId)&&e.push(s("WARN",`${a} linkConversationId "${o.linkConversationId}" \u672A\u5728 conversations \u4E2D\u627E\u5230`)),o.dingToken&&typeof o.dingToken=="string"&&/^<.*>$/.test(o.dingToken.trim())&&e.push(s("WARN",`${a} dingToken \u4ECD\u4E3A\u5360\u4F4D\u7B26`))}e.push(s("PASS",`conversations \u5171 ${l.conversations.length} \u4E2A\u7FA4\u914D\u7F6E`))}if(l.apiKeyCfg){const n=l.apiKeyCfg;if(n.resetTime&&e.push(s("PASS",`apiKeyCfg.resetTime: ${n.resetTime}`)),!Array.isArray(n.claudeSettings))e.push(s("WARN","apiKeyCfg.claudeSettings \u4E0D\u662F\u6570\u7EC4"));else if(n.claudeSettings.length===0)e.push(s("WARN","apiKeyCfg.claudeSettings \u4E3A\u7A7A\uFF0C\u65E0\u5907\u7528 Key"));else{const o=new Set;for(let t=0;t<n.claudeSettings.length;t++){const c=n.claudeSettings[t],d=`apiKeyCfg.claudeSettings[${t}]`;c.apiKey?o.has(c.apiKey)?e.push(s("WARN",`${d} apiKey \u91CD\u590D: ${(0,F.settingLabel)(c)}`)):o.add(c.apiKey):e.push(s("FATAL",`${d} \u7F3A\u5C11 apiKey`)),c.baseUrl||e.push(s("WARN",`${d} \u7F3A\u5C11 baseUrl`)),c.model||e.push(s("WARN",`${d} \u7F3A\u5C11 model`)),typeof c.isValid!="boolean"&&e.push(s("WARN",`${d} isValid \u7C7B\u578B\u5F02\u5E38: ${typeof c.isValid}`))}const a=n.claudeSettings.filter(t=>t.isValid).length;e.push(s("PASS",`apiKeyCfg.claudeSettings \u5171 ${n.claudeSettings.length} \u9879\uFF0C\u6709\u6548 ${a}`))}}else e.push(s("WARN","apiKeyCfg \u672A\u914D\u7F6E\uFF0C\u65E0\u6CD5\u4F7F\u7528 API Key \u6C60\u5316\u8F6E\u6362"));const y=A.default.join(i,"cron.json");if(u.default.existsSync(y))try{const n=JSON.parse(u.default.readFileSync(y,"utf-8")),o=Array.isArray(n)?n:n.jobs;if(Array.isArray(o)){const a=o.filter(t=>t.enabled!==!1).length;e.push(s("PASS",`cron.json \u5171 ${o.length} \u4E2A\u5B9A\u65F6\u4EFB\u52A1 (${a} \u542F\u7528)`));for(let t=0;t<o.length;t++){const c=o[t];c.id||e.push(s("WARN",`cron.json[${t}] \u7F3A\u5C11 id`)),c.cronExpression||e.push(s("WARN",`cron.json[${t}] \u7F3A\u5C11 cronExpression`)),c.prompt||e.push(s("WARN",`cron.json[${t}] \u7F3A\u5C11 prompt`)),c.conversationId?g.has(c.conversationId)||e.push(s("WARN",`cron.json[${t}] conversationId "${c.conversationId}" \u672A\u5728 config.json conversations \u4E2D\u627E\u5230`)):e.push(s("WARN",`cron.json[${t}] \u7F3A\u5C11 conversationId`))}}else e.push(s("WARN","cron.json \u683C\u5F0F\u5F02\u5E38\uFF0C\u65E0\u6CD5\u89E3\u6790\u4E3A\u4EFB\u52A1\u6570\u7EC4"))}catch(n){e.push(s("WARN",`cron.json \u89E3\u6790\u5931\u8D25: ${n instanceof Error?n.message:n}`))}else e.push(s("PASS","cron.json \u4E0D\u5B58\u5728 (\u65E0\u5B9A\u65F6\u4EFB\u52A1)"));const $=A.default.join((0,N.getHomeDir)(),".cc-ding","settings-tpl.json");if(u.default.existsSync($))try{const n=JSON.parse(u.default.readFileSync($,"utf-8"));if(typeof n!="object"||n===null)e.push(s("WARN","settings-tpl.json \u6839\u5143\u7D20\u4E0D\u662F\u5BF9\u8C61"));else if(!n.env||typeof n.env!="object")e.push(s("WARN","settings-tpl.json \u7F3A\u5C11 env \u5B57\u6BB5"));else{const o=Object.keys(n.env);e.push(s("PASS",`settings-tpl.json \u6709\u6548\uFF0Cenv \u5305\u542B: ${o.join(", ")||"(\u7A7A)"}`))}}catch(n){e.push(s("WARN",`settings-tpl.json \u89E3\u6790\u5931\u8D25: ${n instanceof Error?n.message:n}`))}else e.push(s("WARN","settings-tpl.json \u4E0D\u5B58\u5728\uFF0C\u521B\u5EFA settings-ding.json \u65F6\u5C06\u4F7F\u7528\u7A7A\u6A21\u677F"));(0,T.commandExists)("claude")?e.push(s("PASS","claude \u547D\u4EE4\u53EF\u7528")):e.push(s("FATAL","claude \u547D\u4EE4\u4E0D\u53EF\u7528\uFF0C\u8BF7\u786E\u8BA4 Claude Code CLI \u5DF2\u5B89\u88C5"));try{const n=A.default.join(i,".doctor-check");u.default.writeFileSync(n,"ok","utf-8"),u.default.unlinkSync(n),e.push(s("PASS","\u5BA2\u6237\u7AEF\u76EE\u5F55\u53EF\u5199"))}catch(n){e.push(s("FATAL",`\u5BA2\u6237\u7AEF\u76EE\u5F55\u4E0D\u53EF\u5199: ${n instanceof Error?n.message:n}`))}return e}function s(i,e){return{level:i,message:e}}
|