makecoder 4.0.54 → 4.0.56
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/cc.mjs +3 -41
- package/dist/coder.js +96 -96
- package/dist/darwin-arm64/cc.js +3 -38
- package/dist/darwin-x64/cc.js +3 -38
- package/dist/linux-x64/cc.js +3 -38
- package/dist/win32-x64/cc.js +3 -38
- package/package.json +4 -4
package/dist/coder.js
CHANGED
|
@@ -1,99 +1,99 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
-
var
|
|
2
|
+
var gt=Object.create;var we=Object.defineProperty;var yt=Object.getOwnPropertyDescriptor;var bt=Object.getOwnPropertyNames;var It=Object.getPrototypeOf,wt=Object.prototype.hasOwnProperty;var $=(c,e)=>()=>(e||c((e={exports:{}}).exports,e),e.exports);var xt=(c,e,t,o)=>{if(e&&typeof e=="object"||typeof e=="function")for(let n of bt(e))!wt.call(c,n)&&n!==t&&we(c,n,{get:()=>e[n],enumerable:!(o=yt(e,n))||o.enumerable});return c};var $t=(c,e,t)=>(t=c!=null?gt(It(c)):{},xt(e||!c||!c.__esModule?we(t,"default",{value:c,enumerable:!0}):t,c));var N=$((wo,kt)=>{kt.exports={name:"makecoder",version:"4.0.56",description:"MakeCoder: Unified AI agent CLI tool integrating Claude Code, Codex and Gemini CLI",main:"./dist/coder.js",bin:{coder:"./dist/coder.js"},scripts:{test:'echo "Error: no test specified" && exit 1',start:"node ./src/coder.js",build:"node scripts/build.js","build:clean":"node scripts/build.js --clean","build:dev":"node scripts/build.js --no-minify --sourcemap",postinstall:"node scripts/postinstall.js"},keywords:["cli","ai","claude","gemini","codex","agent"],author:"makecoder",license:"MIT",repository:{type:"git",url:"https://github.com/makecoderai/coder.git"},homepage:"https://github.com/makecoderai/coder",dependencies:{"node-fetch":"^3.3.2",open:"^10.1.0",zod:"^3.25.76"},optionalDependencies:{bun:">=1.3.12"},engines:{node:">=20.0.0"},devDependencies:{chokidar:"^4.0.3"},files:["dist","claude","scripts/postinstall.js"]}});var Se=$((xo,ke)=>{var E=require("fs"),xe=require("path"),St=require("os"),Ct=new Set(["auth","skills","wiki","channel","team"]),$e=new Set(["claude","gemini","codex"]),vt=new Set(["pub","auth","update","skills","wiki","channel","team"]),Q=class{constructor(){let e=process.env.CODER_PROFILE,t=e?`.coder.${e}`:".coder";this.configPath=xe.join(St.homedir(),t,"config.json"),this.defaultConfig={agent:"claude",auth:{apikey:null}}}loadConfig(){let e=xe.dirname(this.configPath);try{return E.existsSync(e)||E.mkdirSync(e,{recursive:!0}),E.existsSync(this.configPath)||E.writeFileSync(this.configPath,JSON.stringify(this.defaultConfig,null,2)),JSON.parse(E.readFileSync(this.configPath,"utf8"))}catch{return{...this.defaultConfig}}}getApiKeyFromConfig(e){return e.auth?.apikey?e.auth.apikey:e.auth?.ak&&e.auth?.sk?`${e.auth.ak}.${e.auth.sk}`:null}saveAuthToConfig(e){let t=this.loadConfig();t.auth={apikey:e};try{return E.writeFileSync(this.configPath,JSON.stringify(t,null,2)),!0}catch{return!1}}clearAuthFromConfig(){let e=this.loadConfig();e.auth={apikey:null};try{return E.writeFileSync(this.configPath,JSON.stringify(e,null,2)),!0}catch{return!1}}getTeam(){return this.loadConfig().team||null}setTeam(e,t){let o=this.loadConfig();e==null?delete o.team:o.team={id:e,name:t||""};try{return E.writeFileSync(this.configPath,JSON.stringify(o,null,2)),!0}catch{return!1}}getTeamManual(){return!!this.loadConfig().team_manual}setTeamManual(e){let t=this.loadConfig();e?t.team_manual=!0:delete t.team_manual;try{return E.writeFileSync(this.configPath,JSON.stringify(t,null,2)),!0}catch{return!1}}async parse(e=process.argv.slice(2)){let t=this.loadConfig(),o={agent:t.agent||"claude",remainingArgs:[]},n=0;if(e.length>0){if($e.has(e[0]))o.agent=e[0],o.agentSetBySubcommand=!0,n=1;else if(vt.has(e[0])){if(o.command=e[0],n=1,e[0]==="auth"){let r=e[1];r==="--help"||r==="-h"?o.authSubcommand="--help":(o.authSubcommand=r,o.authRemainingArgs=e.slice(2)),n=e.length}else if(e[0]==="skills"){let r=e[1];o.skillsSubcommand=r==="--help"||r==="-h"?void 0:r,o.skillsArg=e[2],o.skillsRemainingArgs=e.slice(2),n=e.length}else if(e[0]==="wiki"){let r=e[1];o.wikiSubcommand=r==="--help"||r==="-h"?void 0:r,o.wikiArg=e[2],o.wikiRemainingArgs=e.slice(2),n=e.length}else if(e[0]==="team"){let r=e[1];o.teamSubcommand=r==="--help"||r==="-h"?void 0:r,o.teamArg=e[2],o.teamRemainingArgs=e.slice(2),n=e.length}else if(e[0]==="channel"){let r=e[1];r==="--help"||r==="-h"?o.channelSubcommand="--help":r==="list"||r==="show"||r==="add"||r==="remove"||r==="update"?(o.channelSubcommand=r,o.channelArg=e[2],o.channelRemainingArgs=e.slice(2)):o.channelRemainingArgs=e.slice(1),n=e.length}}}for(;n<e.length;){let r=e[n];if(r==="--agent"){if(o.agentSetBySubcommand)throw new Error(`\u4E0D\u80FD\u540C\u65F6\u4F7F\u7528\u5B50\u547D\u4EE4 '${o.agent}' \u548C --agent\uFF0C\u8BF7\u9009\u62E9\u5176\u4E00`);let i=e[n+1];if(!i||!$e.has(i))throw new Error("--agent \u9700\u8981\u6307\u5B9A\u4EE3\u7406\u7C7B\u578B\uFF08claude|gemini|codex\uFF09");o.agent=i,n+=2}else if(r==="--apikey"){let i=e[n+1];if(!i||i.startsWith("--"))throw new Error("--apikey \u9700\u8981\u63D0\u4F9B API Key \u503C");if(i.indexOf(".")===-1)throw new Error("API Key \u683C\u5F0F\u9519\u8BEF\uFF0C\u5E94\u4E3A <ak>.<sk>");o.apikey=i,n+=2}else if(r==="--name"){let i=e[n+1];i&&!i.startsWith("--")?(o.pubName=i,n+=2):n+=1}else if(r==="--allow-clone")o.allowClone=!0,n+=1;else if(r==="--meta-data"){let i=e[n+1];if(!i||i.startsWith("--"))throw new Error("--meta-data \u9700\u8981\u4E00\u4E2A JSON \u5B57\u7B26\u4E32\u503C");try{JSON.parse(i)}catch(a){throw new Error(`--meta-data \u4E0D\u662F\u5408\u6CD5\u7684 JSON\uFF1A${a.message}`)}o.pubMetaData=i,n+=2}else{o.remainingArgs=e.slice(n);break}}if(o.command!=="auth"&&!o.apikey){let r=this.getApiKeyFromConfig(t);o.apikey=r||process.env.CODER_APIKEY||null}o.codevServer=process.env.CODEV_SERVER||t.codevServer||"https://makecoder.com/bigapis/codev/v1";let s=o.remainingArgs.includes("--version")||o.remainingArgs.includes("-v")||o.remainingArgs.includes("--help")||o.remainingArgs.includes("-h");return!Ct.has(o.command)&&!s&&!o.apikey&&await this._oauthLogin(o),o}async _oauthLogin(e){console.log(`\u274C \u5C1A\u672A\u767B\u5F55
|
|
3
3
|
`),console.log("\u8BF7\u5148\u767B\u5F55:"),console.log(` coder auth login
|
|
4
4
|
`),console.log("\u6216\u76F4\u63A5\u63D0\u4F9B API Key:"),console.log(` coder auth login --apikey <your-api-key>
|
|
5
5
|
`),console.log(`\u83B7\u53D6 API Key: https://makecoder.com/my/apikeys
|
|
6
|
-
`),process.exit(1)}showHelp(){let{version:e}=
|
|
7
|
-
`))}};
|
|
6
|
+
`),process.exit(1)}showHelp(){let{version:e}=N(),t=[`Coder v${e} - \u7EDF\u4E00 AI \u4EE3\u7406 CLI`,"","Usage: coder [options] [command] [arguments]","","Arguments:"," prompt \u60A8\u7684\u63D0\u793A\u8BCD","","Commands:"," claude \u542F\u52A8 Claude Code \u4EE3\u7406\uFF08\u9ED8\u8BA4\uFF09"," gemini \u542F\u52A8 Gemini \u4EE3\u7406"," codex \u542F\u52A8 OpenAI Codex \u4EE3\u7406"," auth \u7BA1\u7406\u8EAB\u4EFD\u9A8C\u8BC1\u51ED\u8BC1"," update \u5347\u7EA7 Coder \u5230\u6700\u65B0\u7248\u672C"," pub \u53D1\u5E03\u5F53\u524D\u76EE\u5F55\u4E3A MakeCoder \u7F51\u9875\u5E94\u7528"," skills \u7BA1\u7406 Claude Code skills"," wiki \u7BA1\u7406 MakeCoder \u77E5\u8BC6\u5E93"," channel \u7BA1\u7406\u6E20\u9053\u7ED1\u5B9A\uFF08\u4F01\u4E1A\u5FAE\u4FE1\u7B49\uFF09"," team \u7BA1\u7406\u56E2\u961F\u4E0E\u6210\u5458\uFF08\u9762\u5411 AI\uFF09","","Options:"," --agent <agent> \u6307\u5B9A\u4F7F\u7528\u7684 AI \u4EE3\u7406\uFF08claude|gemini|codex\uFF09"," --apikey <key> \u4E34\u65F6\u63D0\u4F9B API Key\uFF08\u683C\u5F0F: <ak>.<sk>\uFF09"," --version, -v \u663E\u793A\u7248\u672C\u53F7"," --help, -h \u663E\u793A\u6B64\u5E2E\u52A9\u4FE1\u606F","","Examples:"," coder claude \u542F\u52A8 Claude Code \u4EE3\u7406"," coder gemini \u542F\u52A8 Gemini \u4EE3\u7406"," coder auth login \u767B\u5F55\uFF08\u6D4F\u89C8\u5668\u6216\u7EC8\u7AEF\u8F93\u5165 API Key\uFF09"," coder auth login --apikey <key> \u76F4\u63A5\u4FDD\u5B58 API Key"," coder auth logout \u9000\u51FA\u767B\u5F55"," coder auth status \u67E5\u770B\u767B\u5F55\u72B6\u6001"," coder pub --name myproject \u53D1\u5E03\u5F53\u524D\u76EE\u5F55\u4E3A MakeCoder \u7F51\u9875\u5E94\u7528"," coder skills --help \u67E5\u770B skills \u5B50\u547D\u4EE4\u5E2E\u52A9"," coder wiki --help \u67E5\u770B wiki \u5B50\u547D\u4EE4\u5E2E\u52A9"," coder channel --help \u67E5\u770B channel \u5B50\u547D\u4EE4\u5E2E\u52A9"," coder team --help \u67E5\u770B team \u5B50\u547D\u4EE4\u5E2E\u52A9","",`\u914D\u7F6E\u6587\u4EF6: ${this.configPath}`];console.log(t.join(`
|
|
7
|
+
`))}};ke.exports=Q});var U=$(($o,Ce)=>{function Et(c=process.argv.slice(2)){return c.includes("--print")||c.includes("-p")}Ce.exports={isPrintMode:Et}});var F=$((ko,ve)=>{var{spawn:_t}=require("child_process"),H=require("path"),R=require("fs"),Ot=require("os"),{isPrintMode:Dt}=U(),ee=class{constructor(e){this.config=e}async ensureConfig(e=0){let t=H.join(Ot.homedir(),this.config.configDir,this.config.configFile),o=H.dirname(t);if(!R.existsSync(t)){let n=this.config.defaultConfig||{};try{R.existsSync(o)||R.mkdirSync(o,{recursive:!0}),R.writeFileSync(t,JSON.stringify(n,null,2)),e>0&&await new Promise(s=>setTimeout(s,e))}catch(s){console.warn(`Failed to create ${this.config.configFile}: ${s.message}`)}}}findExecutablePath(){let e=H.dirname(require.main.filename);for(let t of this.config.executablePaths){let o=H.resolve(e,t);if(R.existsSync(o))return o}throw new Error(`Could not find executable in any of the configured paths: ${this.config.executablePaths.join(", ")}`)}handleChildMessages(e){process.env.CODEV_DEBUG&&console.log("Child process message handler initialized"),e.connected&&(e.on("message",t=>{this.onChildMessage(t)}),e.on("exit",async(t,o)=>{try{await this.handleChildProcessExit(t,o)}catch(n){console.error("Error in handleChildProcessExit:",n.message)}}),e.on("error",t=>{this.handleChildProcessError(t)}))}onChildMessage(e){process.env.CODEV_DEBUG&&console.log("Received IPC message from child:",e)}handleChildProcessExit(e,t){}handleChildProcessError(e){}async launch(e={}){let{remainingArgs:t=[],codevServer:o,apikey:n=null,extraEnv:s={}}=e;try{await this.ensureConfig(1e3);let r=this.findExecutablePath();return process.env.CODEV_DEBUG&&console.log(`executablePath: ${r}`),new Promise((i,a)=>{let l={...process.env,...this.config.environmentVariables(o),...s};n&&(l.CODER_APIKEY=n);let d=["--no-warnings"];process.env.CODEV_INSPECT_BRK==="True"&&d.push("--inspect-brk"),d.push(r,...t);let u=_t("node",d,{env:l,stdio:["inherit","inherit","inherit","ipc"]});this.handleChildMessages(u),u.on("error",m=>{console.error(`Failed to start: ${m.message}`),a(m)}),u.on("exit",async(m,p)=>{Dt(t)||p&&console.log(`terminated by signal: ${p}`)}),process.on("SIGINT",async()=>{console.log(`
|
|
8
8
|
Terminating ...`),u.kill("SIGTERM"),setTimeout(()=>{u.killed||u.kill("SIGKILL")},8e3)}),process.on("SIGTERM",async()=>{console.log(`
|
|
9
|
-
Terminating ...`),u.kill("SIGTERM"),setTimeout(()=>{u.killed||u.kill("SIGKILL")},8e3)})})}catch(r){throw r}}};Re.exports=re});var ae=$((rs,We)=>{var I=process.env.CODEV_DEBUG==="True",ie=class{constructor(e={}){this.queue=[],this.processing=!1,this.shuttingDown=!1,this.shutdownTimeout=e.shutdownTimeout||5e3,this.maxRetries=e.maxRetries||3,this.retryDelay=e.retryDelay||1e3,this.onProcessMessage=e.onProcessMessage||null,this.shutdownPromise=null,this.currentlyProcessing=null}enqueue(e){if(this.shuttingDown)return I&&console.log("Queue is shutting down, skipping new messages"),null;let t={id:Date.now()+Math.random(),data:e,timestamp:Date.now(),retryCount:0,processing:!1};return this.queue.push(t),I&&console.log(`Message enqueued, queue length: ${this.queue.length}`),this.processQueue(),t.id}dequeue(){let e=this.queue.shift();return I&&e&&console.log(`Message dequeued, remaining queue length: ${this.queue.length}`),e}removeById(e){let t=this.queue.findIndex(o=>o.id===e);return t>-1?(this.queue.splice(t,1),I&&console.log(`Message ${e} removed from queue`),!0):!1}async processQueue(){if(!(this.processing||this.queue.length===0)){this.processing=!0;try{for(;this.queue.length>0&&!this.shuttingDown;){let e=this.queue[0];e.processing=!0;try{this.onProcessMessage&&await this.onProcessMessage(e),this.dequeue()}catch(t){if(I&&console.error(`Failed to process message: ${t.message}`),e.retryCount++,I&&console.log("Start Retry:",e.retryCount,"times..."),e.retryCount>=this.maxRetries)I&&console.error("Message exceeded max retries, removing from queue"),this.dequeue();else{e.processing=!1;let o=this.shuttingDown?100:this.retryDelay*e.retryCount;await new Promise(s=>setTimeout(s,o))}}}}finally{this.processing=!1}}}getQueueSize(){return this.queue.length}clear(){this.queue=[],I&&console.log("Message queue cleared")}setMessageProcessor(e){this.onProcessMessage=e}async waitForProcessingMessages(e=5e3){let t=this.queue.filter(s=>s.processing);if(t.length===0)return;I&&console.log(`Waiting for ${t.length} processing messages to complete (timeout: ${e}ms)`);let o=Date.now();for(;Date.now()-o<e;){if(this.queue.filter(n=>n.processing).length===0){I&&console.log(`All processing messages completed in ${Date.now()-o}ms`);return}await new Promise(n=>setTimeout(n,50))}if(I){let s=this.queue.filter(n=>n.processing);console.log(`Timeout waiting for processing messages. ${s.length} messages still processing`)}}async gracefulShutdown(e={}){if(this.shutdownPromise)return this.shutdownPromise;let{timeoutMs:t=this.shutdownTimeout,batchSize:o=10,fastMode:s=!1}=e;return this.shutdownPromise=new Promise(async n=>{this.shuttingDown=!0,await this.waitForProcessingMessages(Math.min(t*.3,3e3));let r=this.queue.filter(h=>!h.processing),i=r.length;I&&(console.log(`Starting graceful shutdown with ${i} pending messages (${this.queue.length-i} already processing)`),console.log(`Mode: ${s?"fast (parallel)":"sequential"}, timeout: ${t}ms`));let a=Date.now(),l=0,d=0;try{if(s){let h=await this.processAllParallel(t-(Date.now()-a),r);l=h.processed,d=h.failed}else{let h=await this.processInBatches(o,t-(Date.now()-a),r);l=h.processed,d=h.failed}}catch(h){I&&console.error("Error during shutdown processing:",h.message)}let u=Date.now()-a,p=this.queue.length;I&&(console.log(`Shutdown completed in ${u}ms:`),console.log(` - Total: ${i} messages`),console.log(` - Processed: ${l}`),console.log(` - Failed: ${d}`),console.log(` - Remaining: ${p}`)),n({totalMessages:i,processedMessages:l,failedMessages:d,remainingMessages:p,duration:u,allMessagesSent:p===0&&d===0})}),this.shutdownPromise}async processAllParallel(e){if(this.queue.length===0)return{processed:0,failed:0};I&&console.log(`Processing ${this.queue.length} messages in parallel...`);let t=[...this.queue];this.queue=[];let o=t.map(async a=>{try{return this.onProcessMessage&&await this.onProcessMessage(a),{success:!0,messageId:a.id}}catch(l){return I&&console.warn(`Message ${a.id} processing failed: ${l.message}`),{success:!1,messageId:a.id,error:l}}}),s=new Promise(a=>{setTimeout(()=>a({timedOut:!0}),e)}),n=await Promise.race([Promise.allSettled(o).then(a=>({results:a})),s]);if(n.timedOut)return I&&console.log(`Parallel processing timed out after ${e}ms`),{processed:0,failed:t.length};let r=n.results.filter(a=>a.status==="fulfilled"&&a.value?.success).length,i=t.length-r;return{processed:r,failed:i}}async processInBatches(e,t){if(this.queue.length===0)return{processed:0,failed:0};I&&console.log(`Processing ${this.queue.length} messages in batches of ${e}...`);let o=Date.now(),s=0,n=0;for(;this.queue.length>0&&Date.now()-o<t;){let r=this.queue.splice(0,e),i=r.map(async u=>{try{return this.onProcessMessage&&await this.onProcessMessage(u),{success:!0}}catch(p){return I&&console.warn(`Batch message processing failed: ${p.message}`),{success:!1,error:p}}}),l=(await Promise.allSettled(i)).filter(u=>u.status==="fulfilled"&&u.value?.success).length,d=r.length-l;s+=l,n+=d,I&&r.length>0&&console.log(`Batch completed: ${l}/${r.length} successful`),this.queue.length>0&&await new Promise(u=>setTimeout(u,10))}return this.queue.length>0&&(n+=this.queue.length,I&&console.log(`${this.queue.length} messages not processed due to timeout`),this.queue=[]),{processed:s,failed:n}}async forceFlushAndShutdown(e=2e3){this.shuttingDown=!0,await this.waitForProcessingMessages(Math.min(e*.4,1e3));let t=this.queue.filter(a=>!a.processing);I&&console.log(`Force flush: attempting to send ${t.length} pending messages within ${e}ms (${this.queue.length-t.length} already processing)`);let o=Date.now(),s=t.map(async a=>{try{return this.onProcessMessage&&Date.now()-o<e?(await this.onProcessMessage(a),{success:!0,messageId:a.id}):{success:!1,messageId:a.id,reason:"timeout"}}catch(l){return{success:!1,messageId:a.id,error:l.message}}}),n=e-(Date.now()-o),r=new Promise(a=>{setTimeout(()=>a({timedOut:!0}),Math.max(100,n))}),i=await Promise.race([Promise.allSettled(s).then(a=>({results:a})),r]);if(t.forEach(a=>{let l=this.queue.findIndex(d=>d.id===a.id);l>-1&&this.queue.splice(l,1)}),this.processing=!1,i.timedOut)return I&&console.log(`Force flush timed out after ${e}ms`),{success:!1,reason:"timeout",attemptedCount:t.length};{let a=i.results.filter(l=>l.status==="fulfilled"&&l.value.success).length;return I&&console.log(`Force flush completed: ${a}/${t.length} messages sent`),{success:a===t.length,successCount:a,totalCount:t.length,results:i.results}}}forceShutdown(){this.shuttingDown=!0,this.queue=[],this.processing=!1,I&&console.log("Force shutdown: Queue cleared")}};We.exports=ie});var le=$((is,Ge)=>{var Xt=require("http"),Zt=require("https"),{URL:He}=require("url"),{version:eo}=L(),Je=process.env.CODEV_DEBUG==="True",ce=class{constructor(e={}){this.baseUrl=e.baseUrl||"",this.timeout=e.timeout||3e4,this.defaultHeaders={"Content-Type":"application/json","User-Agent":`codev-cli/${eo}`,...e.headers}}setBaseUrl(e){this.baseUrl=e}setDefaultHeaders(e){this.defaultHeaders={...this.defaultHeaders,...e}}async post(e,t,o={}){let s=this.resolveUrl(e),n={...this.defaultHeaders,...o.headers};return new Promise((r,i)=>{this.validateRequest(s,t,i);let a=this.serializeData(t,i);if(!a)return;n["Content-Length"]=Buffer.byteLength(a);let l=this.buildRequestOptions(s,"POST",n),d=this.getHttpModule(s);Je&&console.debug(`HTTP POST to ${s} with data length: ${a.length}`);let u=d.request(l,p=>{this.handleResponse(p,r,i)});this.attachErrorHandlers(u,s,i),u.setTimeout(this.timeout),u.write(a),u.end()})}resolveUrl(e){return e.startsWith("http")?e:`${this.baseUrl}${e.startsWith("/")?"":"/"}${e}`}validateRequest(e,t,o){return!e||typeof e!="string"?(o(new Error(`Invalid URL: ${e}`)),!1):t?!0:(o(new Error("No data provided for HTTP POST")),!1)}serializeData(e,t){try{return typeof e=="string"?e:JSON.stringify(e)}catch(o){return t(new Error(`Failed to serialize data: ${o.message}`)),null}}buildRequestOptions(e,t,o){let s=new He(e),n=s.protocol==="https:";return{hostname:s.hostname,port:s.port||(n?443:80),path:s.pathname+s.search,method:t,headers:o}}getHttpModule(e){return new He(e).protocol==="https:"?Zt:Xt}handleResponse(e,t,o){Je&&console.debug(`HTTP response status: ${e.statusCode}`);let s="";e.on("data",n=>{s+=n}),e.on("end",()=>{e.statusCode>=200&&e.statusCode<300?t({statusCode:e.statusCode,data:s,headers:e.headers}):o(new Error(`HTTP request returned status ${e.statusCode}: ${s}`))})}attachErrorHandlers(e,t,o){e.on("error",s=>{o(new Error(`HTTP POST request failed: ${s.message}`))}),e.on("timeout",()=>{o(new Error(`HTTP POST request timed out for URL: ${t}`)),e.destroy()})}};Ge.exports=ce});var ue=$((as,ze)=>{var de=class{constructor(){this.apikey=null}setCredentials(e){this.apikey=e||null}hasCredentials(){return!!this.apikey}generateAuthHeaders(){return this.apikey?{AUTHORIZATION:`Bearer ${this.apikey}`}:{}}clearCredentials(){this.apikey=null}};ze.exports=de});var pe=$((cs,Ve)=>{var z=process.env.CODEV_DEBUG==="True",he=class{constructor(e={}){this.currentSessionId=null,this.previousSessionId=null,this.onSessionSwitch=e.onSessionSwitch||null,this.terminateSignal=e.terminateSignal||"CODEV_TERMINATE_SIGNAL"}handleSessionSwitch(e){if(!e)return z&&console.warn("Received empty session ID"),!1;let t=this.previousSessionId!==null&&this.previousSessionId!==e;return t&&(z&&console.log(`Session switch detected: ${this.previousSessionId} -> ${e}`),this.onSessionSwitch&&this.onSessionSwitch({type:this.terminateSignal,reason:"User switch session",agent:"claude",previousSessionId:this.previousSessionId,newSessionId:e})),this.previousSessionId=this.currentSessionId,this.currentSessionId=e,t}getCurrentSessionId(){return this.currentSessionId}getPreviousSessionId(){return this.previousSessionId}hasActiveSession(){return!!this.currentSessionId}terminateCurrentSession(e="Session terminated",t=null,o=null){if(!this.hasActiveSession())return z&&console.log("No active session to terminate"),null;let s={type:this.terminateSignal,reason:o?`terminated by signal: ${o}`:e,code:t,signal:o,timestamp:Date.now(),agent:"claude",sessionId:this.currentSessionId};return z&&console.log("Terminating session:",s),this.previousSessionId=null,this.currentSessionId=null,s}createErrorTermination(e){return this.hasActiveSession()?{type:this.terminateSignal,error:e.message,stack:e.stack,timestamp:Date.now(),agent:"claude",sessionId:this.currentSessionId}:null}reset(){z&&console.log("Resetting session manager"),this.currentSessionId=null,this.previousSessionId=null}setSessionSwitchCallback(e){this.onSessionSwitch=e}getSessionInfo(){return{currentSessionId:this.currentSessionId,previousSessionId:this.previousSessionId,hasActiveSession:this.hasActiveSession()}}};Ve.exports=he});var fe=$((ls,Ke)=>{var M=require("fs"),U=require("path"),to=require("events"),oo=require("crypto"),v=process.env.CODEV_DEBUG==="True",me=class extends to{constructor(e={}){super(),this.watchPaths=e.watchPaths||[],this.excludePatterns=e.excludePatterns||[/node_modules/,/\.git/,/\.DS_Store/,/\.tmp/,/\.log$/,/\.swp$/,/codev\.log/],this.includePatterns=e.includePatterns||[/\.(js|jsx|ts|tsx|py|java|c|cpp|h|hpp|go|rs|rb|php|html|css|scss|sass|less|json|xml|yaml|yml|md|txt)$/],this.watchers=new Map,this.isWatching=!1,this.debounceTimeout=e.debounceTimeout||300,this.pendingChanges=new Map,this.fileContentHashes=new Map,this.enableContentComparison=e.enableContentComparison!==!1,this.onFileChange=e.onFileChange||null}calculateFileHash(e){try{let t=M.readFileSync(e,"utf8");return oo.createHash("sha256").update(t).digest("hex")}catch{return null}}hasContentChanged(e){if(!this.enableContentComparison)return!0;let t=this.calculateFileHash(e),o=this.fileContentHashes.get(e);return t===null?o!==void 0?(this.fileContentHashes.delete(e),!0):!1:o===void 0||t!==o?(this.fileContentHashes.set(e,t),!0):!1}preloadFileHashes(e){if(!(!this.enableContentComparison||!M.existsSync(e)))try{let t=M.readdirSync(e,{withFileTypes:!0});for(let o of t){let s=U.join(e,o.name);o.isFile()&&this.shouldWatchFile(s)?(this.calculateFileHash(s),this.fileContentHashes.set(s,this.calculateFileHash(s))):o.isDirectory()&&!this.shouldExcludeDirectory(s)&&this.preloadFileHashes(s)}}catch(t){v&&console.warn(`Failed to preload hashes for ${e}:`,t.message)}}shouldExcludeDirectory(e){let t=e.replace(/\\/g,"/");for(let o of this.excludePatterns)if(o.test(t)||o.test(U.basename(e)))return!0;return!1}startWatching(e=null){if(this.isWatching){v&&console.log("FileWatchService is already watching");return}let t=e||this.watchPaths;if(t.length===0){v&&console.log("No watch paths specified");return}this.isWatching=!0;for(let o of t)this.enableContentComparison&&this.preloadFileHashes(o),this.watchDirectory(o);v&&(console.log(`FileWatchService started watching ${t.length} paths`),this.enableContentComparison&&console.log(`Preloaded hashes for ${this.fileContentHashes.size} files`))}stopWatching(){if(this.isWatching){this.isWatching=!1;for(let[e,t]of this.watchers)try{t.close(),v&&console.log(`Stopped watching: ${e}`)}catch(o){v&&console.error(`Error stopping watcher for ${e}:`,o.message)}this.watchers.clear(),this.pendingChanges.clear(),this.fileContentHashes.clear(),v&&console.log("FileWatchService stopped watching all paths")}}watchDirectory(e){if(!M.existsSync(e)){v&&console.warn(`Watch path does not exist: ${e}`);return}if(!M.statSync(e).isDirectory()){v&&console.warn(`Watch path is not a directory: ${e}`);return}try{let o=M.watch(e,{recursive:!0,persistent:!1},(s,n)=>{if(!n)return;let r=U.join(e,n);this.handleFileChange(s,r,e)});this.watchers.set(e,o),v&&console.log(`Started watching directory: ${e}`),o.on("error",s=>{v&&console.error(`Watcher error for ${e}:`,s.message),this.watchers.delete(e)})}catch(o){v&&console.error(`Failed to start watching ${e}:`,o.message)}}handleFileChange(e,t,o){if(!this.shouldWatchFile(t))return;let s=`${e}:${t}`;this.pendingChanges.has(s)&&clearTimeout(this.pendingChanges.get(s)),this.pendingChanges.set(s,setTimeout(()=>{this.pendingChanges.delete(s),this.processFileChange(e,t,o)},this.debounceTimeout))}processFileChange(e,t,o){if(!this.isWatching)return;let s="modified",n=!1;try{M.statSync(t),n=!0,e==="rename"?s="created":e==="change"&&(s="modified")}catch{e==="rename"&&(s="deleted")}if(n&&(s==="modified"||s==="created")&&!this.hasContentChanged(t)){v&&console.log(`Ignoring false change for: ${U.relative(o,t)}`);return}!n&&s==="deleted"&&this.fileContentHashes.delete(t);let r={type:"CODEV_FILE_CHANGE_DETECTTED",data:{eventType:e,changeType:s,filePath:t,relativePath:U.relative(o,t),watchPath:o,fileExists:n,timestamp:Date.now(),sessionId:process.env.SESSION_ID||"default"}};if(v&&console.log(`File ${s}: ${r.data.relativePath}`),this.emit("fileChange",r),this.onFileChange&&typeof this.onFileChange=="function")try{this.onFileChange(r)}catch(i){v&&console.error("Error in file change callback:",i.message)}}shouldWatchFile(e){let t=U.basename(e),o=e.replace(/\\/g,"/");for(let s of this.excludePatterns)if(s.test(o)||s.test(t))return!1;if(this.includePatterns.length===0)return!0;for(let s of this.includePatterns)if(s.test(o)||s.test(t))return!0;return!1}addWatchPath(e){this.watchPaths.includes(e)||(this.watchPaths.push(e),this.isWatching&&this.watchDirectory(e))}removeWatchPath(e){let t=this.watchPaths.indexOf(e);if(t>-1&&(this.watchPaths.splice(t,1),this.watchers.has(e)))try{this.watchers.get(e).close(),this.watchers.delete(e),v&&console.log(`Removed watch path: ${e}`)}catch(o){v&&console.error(`Error removing watch path ${e}:`,o.message)}}getStatus(){return{isWatching:this.isWatching,watchPaths:[...this.watchPaths],activeWatchers:this.watchers.size,pendingChanges:this.pendingChanges.size}}setFileChangeCallback(e){this.onFileChange=e}};Ke.exports=me});var Ye=$((hs,Qe)=>{var so=G(),no=require("path"),ds=require("fs"),us=require("os"),ro=ae(),io=le(),ao=ue(),co=pe(),lo=fe(),C=process.env.CODEV_DEBUG==="True",ge=class extends so{constructor(){super({configDir:".",configFile:".claude.json",defaultModel:"Claude Sonnet 4.6",executablePaths:["cc.mjs","../dist/cc.mjs","/tmp/claude-code/package/cc.mjs"],environmentVariables:e=>({ANTHROPIC_BASE_URL:`${e}/claude`,ANTHROPIC_API_KEY:"codev",DISABLE_TELEMETRY:!0,CLAUDE_CODE_DISABLE_NONESSENTIAL_TRAFFIC:!0,DISABLE_COST_WARNINGS:!0,DISABLE_NON_ESSENTIAL_MODEL_CALLS:!0,CODEV_SERVER:e,CLAUDE_CODE_ATTRIBUTION_HEADER:"0"}),defaultConfig:{numStartups:1,installMethod:"unknown",autoUpdates:!1,theme:"Coder Dark",customApiKeyResponses:{approved:["codev"]},shiftEnterKeyBindingInstalled:!0,hasCompletedOnboarding:!0,subscriptionNoticeCount:0,hasAvailableSubscription:!0,projects:{}}}),this.fileWatchService=null,this.shutdownInProgress=!1,this.initializeServices()}initializeServices(){this.httpClient=new io({timeout:1e4}),this.authService=new ao({validateCredentials:!1}),this.sessionManager=new co({onSessionSwitch:e=>{this.sendTerminationMessage(e)}}),this.messageQueue=new ro({maxRetries:2,retryDelay:500,shutdownTimeout:3e3,onProcessMessage:e=>this.processMessage(e)}),this.initializeFileWatchService()}resloveSettingFilePath(e){return no.join(e,this.config.configDir,".claude","settings.json")}initializeFileWatchService(){if(!process.env.SESSION_ID){C&&console.log("FileWatchService disabled: SESSION_ID environment variable not found");return}try{this.fileWatchService=new lo({watchPaths:this.getFileWatchPaths(),onFileChange:e=>this.handleFileChange(e),debounceTimeout:300}),C&&console.log("FileWatchService initialized with SESSION_ID:",process.env.SESSION_ID)}catch(e){C&&console.error("Failed to initialize FileWatchService:",e.message)}}getFileWatchPaths(){let e=[],t=process.cwd();e.push(t);let o=process.env.CODEV_WATCH_PATHS;if(o){let s=o.split(",").map(n=>n.trim());e.push(...s)}return e}handleFileChange(e){if(C&&console.log("File change detected:",e.data.relativePath),this.shutdownInProgress)return;let t={message:e,sessionId:e.data.sessionId||process.env.SESSION_ID};this.messageQueue.enqueue(t)}startFileWatching(){this.fileWatchService&&!this.fileWatchService.isWatching&&(this.fileWatchService.startWatching(),C&&console.log("File watching started"))}stopFileWatching(){this.fileWatchService&&this.fileWatchService.isWatching&&(this.fileWatchService.stopWatching(),C&&console.log("File watching stopped"))}onChildMessage(e){e&&e.type==="claude:send-msg"&&this.handleClaudeSendMessage(e.data),super.onChildMessage(e)}handleClaudeSendMessage(e){if(C&&console.log("Handling claude:send-msg message:",e),!e||typeof e!="object"){console.error(`handleClaudeSendMessage: Invalid message data. Expected object, got: ${typeof e}`);return}if(this.shutdownInProgress){C&&console.log("Shutdown in progress, ignoring new message");return}let t=e.sessionId||process.env.SESSION_ID;this.sessionManager.handleSessionSwitch(t),this.messageQueue.enqueue(e)}async processMessage(e){let t=e.data.message,o=e.data.sessionId||process.env.SESSION_ID;if(!o)throw new Error("No session ID available");let s;try{s=typeof t=="string"?JSON.parse(t):t}catch(i){throw new Error(`Failed to parse message data: ${i.message}`)}let n=`/conversations/${o}/@append?task_type=codev`,r=this.authService.hasCredentials()?this.authService.generateAuthHeaders():{};C&&(console.debug("Sending message to:",n),console.debug("Send Message: ",JSON.stringify(s))),e.type!=="CODEV_TERMINATE_SIGNAL"&&(this.sessionManager.currentSessionId=o)}sendTerminationMessage(e){let t={message:e,sessionId:e.sessionId||this.sessionManager.getCurrentSessionId()};this.messageQueue.enqueue(t)}async handleChildProcessExit(e,t){C&&console.log(`Child process exited with code: ${e}, signal: ${t}`),this.stopFileWatching();let o=this.messageQueue.getQueueSize(),s=this.sessionManager.terminateCurrentSession("process exited normally",e,t);if(s&&this.sendTerminationMessage(s),o>0||s){C&&console.log("Starting graceful shutdown of message queue...");try{let n=!t||t==="SIGTERM",r=this.messageQueue.getQueueSize(),i={timeoutMs:n?8e3:3e3,batchSize:Math.min(r,15),fastMode:!n||r>30};C&&console.log("Shutdown options:",i);let a=await this.messageQueue.gracefulShutdown(i);C&&console.log("Message queue shutdown completed:",a),a.failedMessages>0&&C&&console.warn(`Shutdown summary: ${a.processedMessages} sent, ${a.failedMessages} failed, ${a.remainingMessages} remaining`)}catch(n){C&&console.error("Error during message queue shutdown:",n.message)}}}handleChildProcessError(e){C&&console.error(`Child process error: ${e.message}`);let t=this.sessionManager.createErrorTermination(e);t&&this.sendTerminationMessage(t)}async forceFlushMessages(e=3e3){if(this.messageQueue.getQueueSize()===0)return{success:!0,message:"No messages to flush"};C&&console.log(`Force flushing ${this.messageQueue.getQueueSize()} messages...`);try{return await this.messageQueue.forceFlushAndShutdown(e)}catch(t){return C&&console.error("Force flush failed:",t.message),{success:!1,error:t.message}}}async launch(e={}){let{codevServer:t,apikey:o=null}=e;return this.httpClient.setBaseUrl(t),o&&this.authService.setCredentials(o),this.startFileWatching(),super.launch(e)}};Qe.exports=ge});var Ze=$((ps,Xe)=>{var uo=G(),{spawn:ho,execFileSync:po}=require("child_process"),V=require("path"),K=require("fs"),mo=ae(),fo=le(),go=ue(),yo=pe(),wo=fe(),{isPrintMode:bo}=H(),E=process.env.CODEV_DEBUG==="True",ye=class extends uo{constructor(){let e=`${process.platform}-${process.arch}`;super({configDir:".",configFile:".claude.json",defaultModel:"Claude Sonnet 4.6",executablePaths:[`${e}/cc.js`,`../dist/${e}/cc.js`,`/tmp/claude-code-${e}/package/extracted/src/entrypoints/cc.js`],environmentVariables:t=>({ANTHROPIC_BASE_URL:`${t}/claude`,ANTHROPIC_API_KEY:"codev",DISABLE_TELEMETRY:!0,CLAUDE_CODE_DISABLE_NONESSENTIAL_TRAFFIC:!0,DISABLE_COST_WARNINGS:!0,DISABLE_NON_ESSENTIAL_MODEL_CALLS:!0,CODEV_SERVER:t,CLAUDE_CODE_ATTRIBUTION_HEADER:"0",DISABLE_INSTALLATION_CHECKS:"1",ANTHROPIC_DEFAULT_HAIKU_MODEL:"claude-haiku-4-5"}),defaultConfig:{numStartups:1,installMethod:"unknown",autoUpdates:!1,theme:"Coder Dark",customApiKeyResponses:{approved:["codev"]},shiftEnterKeyBindingInstalled:!0,hasCompletedOnboarding:!0,subscriptionNoticeCount:0,hasAvailableSubscription:!0,projects:{}}}),this.fileWatchService=null,this.shutdownInProgress=!1,this.initializeServices()}initializeServices(){this.httpClient=new fo({timeout:1e4}),this.authService=new go({validateCredentials:!1}),this.sessionManager=new yo({onSessionSwitch:e=>{this.sendTerminationMessage(e)}}),this.messageQueue=new mo({maxRetries:2,retryDelay:500,shutdownTimeout:3e3,onProcessMessage:e=>this.processMessage(e)}),this.initializeFileWatchService()}resloveSettingFilePath(e){return V.join(e,this.config.configDir,".claude","settings.json")}initializeFileWatchService(){if(!process.env.SESSION_ID){E&&console.log("FileWatchService disabled: SESSION_ID environment variable not found");return}try{this.fileWatchService=new wo({watchPaths:this.getFileWatchPaths(),onFileChange:e=>this.handleFileChange(e),debounceTimeout:300}),E&&console.log("FileWatchService initialized with SESSION_ID:",process.env.SESSION_ID)}catch(e){E&&console.error("Failed to initialize FileWatchService:",e.message)}}getFileWatchPaths(){let e=[],t=process.cwd();e.push(t);let o=process.env.CODEV_WATCH_PATHS;if(o){let s=o.split(",").map(n=>n.trim());e.push(...s)}return e}handleFileChange(e){if(E&&console.log("File change detected:",e.data.relativePath),this.shutdownInProgress)return;let t={message:e,sessionId:e.data.sessionId||process.env.SESSION_ID};this.messageQueue.enqueue(t)}startFileWatching(){this.fileWatchService&&!this.fileWatchService.isWatching&&(this.fileWatchService.startWatching(),E&&console.log("File watching started"))}stopFileWatching(){this.fileWatchService&&this.fileWatchService.isWatching&&(this.fileWatchService.stopWatching(),E&&console.log("File watching stopped"))}onChildMessage(e){e&&e.type==="claude:send-msg"&&this.handleClaudeSendMessage(e.data),super.onChildMessage(e)}handleClaudeSendMessage(e){if(E&&console.log("Handling claude:send-msg message:",e),!e||typeof e!="object"){console.error(`handleClaudeSendMessage: Invalid message data. Expected object, got: ${typeof e}`);return}if(this.shutdownInProgress){E&&console.log("Shutdown in progress, ignoring new message");return}let t=e.sessionId||process.env.SESSION_ID;this.sessionManager.handleSessionSwitch(t),this.messageQueue.enqueue(e)}async processMessage(e){let t=e.data.message,o=e.data.sessionId||process.env.SESSION_ID;if(!o)throw new Error("No session ID available");let s;try{s=typeof t=="string"?JSON.parse(t):t}catch(i){throw new Error(`Failed to parse message data: ${i.message}`)}let n=`/conversations/${o}/@append?task_type=codev`,r=this.authService.hasCredentials()?this.authService.generateAuthHeaders():{};E&&(console.debug("Sending message to:",n),console.debug("Send Message: ",JSON.stringify(s))),e.type!=="CODEV_TERMINATE_SIGNAL"&&(this.sessionManager.currentSessionId=o)}sendTerminationMessage(e){let t={message:e,sessionId:e.sessionId||this.sessionManager.getCurrentSessionId()};this.messageQueue.enqueue(t)}async handleChildProcessExit(e,t){E&&console.log(`Child process exited with code: ${e}, signal: ${t}`),this.stopFileWatching();let o=this.messageQueue.getQueueSize(),s=this.sessionManager.terminateCurrentSession("process exited normally",e,t);if(s&&this.sendTerminationMessage(s),o>0||s){E&&console.log("Starting graceful shutdown of message queue...");try{let n=!t||t==="SIGTERM",r=this.messageQueue.getQueueSize(),i={timeoutMs:n?8e3:3e3,batchSize:Math.min(r,15),fastMode:!n||r>30},a=await this.messageQueue.gracefulShutdown(i);E&&console.log("Message queue shutdown completed:",a)}catch(n){E&&console.error("Error during message queue shutdown:",n.message)}}}handleChildProcessError(e){E&&console.error(`Child process error: ${e.message}`);let t=this.sessionManager.createErrorTermination(e);t&&this.sendTerminationMessage(t)}async launch(e={}){let{codevServer:t,apikey:o=null}=e;return this.httpClient.setBaseUrl(t),o&&this.authService.setCredentials(o),this.startFileWatching(),this._launchWithBun(e)}_resolveBunPath(){let e=process.platform==="win32",t=e?"bun.exe":"bun";try{return po(t,["--version"],{stdio:"ignore"}),t}catch{}let o=V.join(process.env.HOME||process.env.USERPROFILE||"",".local","bin",t);if(K.existsSync(o))return o;let s=V.join(__dirname,"..","..","node_modules",".bin",t);if(K.existsSync(s))return s;let n=this._getBunPlatformPackage();if(n)try{let r=V.dirname(require.resolve(`${n}/package.json`)),i=V.join(r,"bin",t);if(K.existsSync(i))return i}catch{}try{let r=require.resolve(`bun/${e?"bin/bun.exe":"bin/bun"}`);if(K.existsSync(r))return r}catch{}throw new Error("bun is not installed. Install it with: npm install -g bun or curl -fsSL https://bun.sh/install | bash")}_getBunPlatformPackage(){let e=process.platform,t=process.arch;return{"darwin-arm64":"@oven-sh/bun-darwin-aarch64","darwin-x64":"@oven-sh/bun-darwin-x64","linux-arm64":"@oven-sh/bun-linux-aarch64","linux-x64":"@oven-sh/bun-linux-x64","win32-x64":"@oven-sh/bun-windows-x64"}[`${e}-${t}`]||null}async _launchWithBun(e={}){let{remainingArgs:t=[],codevServer:o,apikey:s=null,extraEnv:n={}}=e;try{await this.ensureConfig(1e3);let r=this.findExecutablePath(),i=this._resolveBunPath();return E&&(console.log(`executablePath (bun): ${r}`),console.log(`bunPath: ${i}`)),new Promise((a,l)=>{let d={...process.env,...this.config.environmentVariables(o),CODER_EXECPATH:K.realpathSync(process.argv[1]),...n};s&&(d.CODER_APIKEY=s);let u=[r,...t],p=ho(i,u,{env:d,stdio:["inherit","inherit","inherit","ipc"]});this.handleChildMessages(p),p.on("error",h=>{h.code==="ENOENT"?console.error("bun binary not found. Install it with: npm install -g bun or curl -fsSL https://bun.sh/install | bash"):console.error(`Failed to start bun: ${h.message}`),l(h)}),p.on("exit",async(h,f)=>{bo(t)||f&&console.log(`terminated by signal: ${f}`)}),process.on("SIGINT",async()=>{console.log(`
|
|
10
|
-
Terminating ...`),
|
|
11
|
-
Terminating ...`),
|
|
12
|
-
Terminating ...`),
|
|
13
|
-
Terminating ...`),
|
|
14
|
-
`).map(a=>a.trim());t(i.includes(this.extensionId))}else t(!1)}),
|
|
15
|
-
\u{1F4C2} [allow-clone] \u67E5\u627E JSONL \u6587\u4EF6...`),console.log(` \u9879\u76EE\u76EE\u5F55: ${e}`),console.log(` Claude \u9879\u76EE\u540D: ${o}`),console.log(` Claude \u9879\u76EE\u76EE\u5F55: ${
|
|
16
|
-
\u{1F504} [allow-clone] \u5F00\u59CB\u5904\u7406 AI \u751F\u6210\u8BB0\u5F55...`);let a=this.getClaudeJsonlPath(e,!0);if(a){let l=
|
|
17
|
-
\u{1F4E6} [allow-clone] \u6253\u5305 JSONL \u6587\u4EF6...`),console.log(` \u6E90\u6587\u4EF6: ${a}`),console.log(` \u6587\u4EF6\u5927\u5C0F: ${u} KB`),console.log(` \u4E34\u65F6\u6587\u4EF6: ${l}`),
|
|
9
|
+
Terminating ...`),u.kill("SIGTERM"),setTimeout(()=>{u.killed||u.kill("SIGKILL")},8e3)})})}catch(r){throw r}}};ve.exports=ee});var Oe=$((So,_e)=>{var At=F(),M=require("path"),Ee=require("fs"),te=class extends At{constructor(){super({configDir:".",configFile:".claude.json",executablePaths:["cc.mjs","../dist/cc.mjs","/tmp/claude-code/package/cc.mjs"],environmentVariables:e=>({ANTHROPIC_BASE_URL:`${e}/claude`,ANTHROPIC_API_KEY:"codev",DISABLE_TELEMETRY:!0,CLAUDE_CODE_DISABLE_NONESSENTIAL_TRAFFIC:!0,DISABLE_COST_WARNINGS:!0,DISABLE_NON_ESSENTIAL_MODEL_CALLS:!0,CODEV_SERVER:e,CLAUDE_CODE_ATTRIBUTION_HEADER:"0"}),defaultConfig:{numStartups:1,installMethod:"unknown",autoUpdates:!1,theme:"Coder Dark",customApiKeyResponses:{approved:["codev"]},shiftEnterKeyBindingInstalled:!0,hasCompletedOnboarding:!0,subscriptionNoticeCount:0,hasAvailableSubscription:!0,projects:{}}})}findExecutablePath(){let e=M.dirname(require.main.filename);for(let o of this.config.executablePaths){let n=M.resolve(e,o);if(Ee.existsSync(n))return n}let t=this._findGlobalMakecoderCcMjs();if(t)return t;throw new Error(`Could not find Claude Code (node) executable in any of the configured paths: ${this.config.executablePaths.join(", ")}`)}_findGlobalMakecoderCcMjs(){let e=M.dirname(process.execPath),t=[M.join(e,"..","lib","node_modules","makecoder","dist","cc.mjs"),M.join(e,"node_modules","makecoder","dist","cc.mjs")];for(let o of t)if(Ee.existsSync(o))return o;return null}};_e.exports=te});var Ae=$((Co,De)=>{var Pt=F(),{spawn:Tt,execFileSync:qt}=require("child_process"),_=require("path"),P=require("fs"),{isPrintMode:Bt}=U(),jt=process.env.CODEV_DEBUG==="True",oe=class extends Pt{constructor(){let e=`${process.platform}-${process.arch}`;super({configDir:".",configFile:".claude.json",executablePaths:[`${e}/cc.js`,`../dist/${e}/cc.js`,`/tmp/claude-code-${e}/package/extracted/src/entrypoints/cc.js`],environmentVariables:t=>({ANTHROPIC_BASE_URL:`${t}/claude`,ANTHROPIC_API_KEY:"codev",DISABLE_TELEMETRY:!0,CLAUDE_CODE_DISABLE_NONESSENTIAL_TRAFFIC:!0,DISABLE_COST_WARNINGS:!0,DISABLE_NON_ESSENTIAL_MODEL_CALLS:!0,CODEV_SERVER:t,CLAUDE_CODE_ATTRIBUTION_HEADER:"0",DISABLE_INSTALLATION_CHECKS:"1",ANTHROPIC_DEFAULT_HAIKU_MODEL:"claude-haiku-4-5"}),defaultConfig:{numStartups:1,installMethod:"unknown",autoUpdates:!1,theme:"Coder Dark",customApiKeyResponses:{approved:["codev"]},shiftEnterKeyBindingInstalled:!0,hasCompletedOnboarding:!0,subscriptionNoticeCount:0,hasAvailableSubscription:!0,projects:{}}})}async launch(e={}){return this._launchWithBun(e)}findExecutablePath(){let e=_.dirname(require.main.filename);for(let o of this.config.executablePaths){let n=_.resolve(e,o);if(P.existsSync(n))return n}let t=this._findGlobalMakecoderCc();if(t)return t;throw new Error(`Could not find Claude Code (bun) executable in any of the configured paths: ${this.config.executablePaths.join(", ")}`)}_findGlobalMakecoderCc(){let e=`${process.platform}-${process.arch}`,t=_.dirname(process.execPath),o=[_.join(t,"..","lib","node_modules","makecoder","dist",e,"cc.js"),_.join(t,"node_modules","makecoder","dist",e,"cc.js")];for(let n of o)if(P.existsSync(n))return n;return null}_resolveBunPath(){let e=process.platform==="win32",t=e?"bun.exe":"bun";try{return qt(t,["--version"],{stdio:"ignore"}),t}catch{}let o=_.join(process.env.HOME||process.env.USERPROFILE||"",".local","bin",t);if(P.existsSync(o))return o;let n=_.join(__dirname,"..","..","node_modules",".bin",t);if(P.existsSync(n))return n;let s=this._getBunPlatformPackage();if(s)try{let r=_.dirname(require.resolve(`${s}/package.json`)),i=_.join(r,"bin",t);if(P.existsSync(i))return i}catch{}try{let r=require.resolve(`bun/${e?"bin/bun.exe":"bin/bun"}`);if(P.existsSync(r))return r}catch{}throw new Error("bun is not installed. Install it with: npm install -g bun or curl -fsSL https://bun.sh/install | bash")}_getBunPlatformPackage(){let e=process.platform,t=process.arch;return{"darwin-arm64":"@oven-sh/bun-darwin-aarch64","darwin-x64":"@oven-sh/bun-darwin-x64","linux-arm64":"@oven-sh/bun-linux-aarch64","linux-x64":"@oven-sh/bun-linux-x64","win32-x64":"@oven-sh/bun-windows-x64"}[`${e}-${t}`]||null}async _launchWithBun(e={}){let{remainingArgs:t=[],codevServer:o,apikey:n=null,extraEnv:s={}}=e;await this.ensureConfig(1e3);let r=this.findExecutablePath(),i=this._resolveBunPath();return jt&&(console.log(`executablePath (bun): ${r}`),console.log(`bunPath: ${i}`)),new Promise((a,l)=>{let d={...process.env,...this.config.environmentVariables(o),CODER_EXECPATH:P.realpathSync(process.argv[1]),...s};n&&(d.CODER_APIKEY=n);let u=[r,...t],m=Tt(i,u,{env:d,stdio:["inherit","inherit","inherit","ipc"]});m.on("error",p=>{p.code==="ENOENT"?console.error("bun binary not found. Install it with: npm install -g bun or curl -fsSL https://bun.sh/install | bash"):console.error(`Failed to start bun: ${p.message}`),l(p)}),m.on("exit",async(p,f)=>{Bt(t)||f&&console.log(`terminated by signal: ${f}`)}),process.on("SIGINT",async()=>{console.log(`
|
|
10
|
+
Terminating ...`),m.kill("SIGTERM"),setTimeout(()=>{m.killed||m.kill("SIGKILL")},8e3)}),process.on("SIGTERM",async()=>{console.log(`
|
|
11
|
+
Terminating ...`),m.kill("SIGTERM"),setTimeout(()=>{m.killed||m.kill("SIGKILL")},8e3)})})}};De.exports=oe});var qe=$((vo,Te)=>{var Lt=F(),J=require("path"),Pe=require("fs"),ne=class extends Lt{constructor(){super({configDir:".gemini",configFile:"settings.json",executablePaths:["gemini/gemini.js","../dist/gemini/gemini.js"],environmentVariables:e=>({GOOGLE_GEMINI_BASE_URL:`${e}/gemini`,GEMINI_API_KEY:"coder",GOOGLE_API_KEY:"coder",GOOGLE_CLOUD_PROJECT:"coder",GOOGLE_CLOUD_LOCATION:"coder",DISABLE_TELEMETRY:!0,GEMINI_CODE_DISABLE_NONESSENTIAL_TRAFFIC:!0,DISABLE_COST_WARNINGS:!0,DISABLE_NON_ESSENTIAL_MODEL_CALLS:!0,USE_VERTEX:!0}),defaultConfig:{ide:{hasSeenNudge:!0},telemetry:{enabled:!1,logPrompts:!1},privacy:{usageStatisticsEnabled:!1},general:{disableUpdateNag:!0,preferredEditor:"vscode",previewFeatures:!0},ui:{hideBanner:!0,theme:"Default"},security:{auth:{selectedType:"vertex-ai"}}}})}findExecutablePath(){let e=J.dirname(require.main.filename);for(let o of this.config.executablePaths){let n=J.resolve(e,o);if(Pe.existsSync(n))return n}let t=this._findGlobalMakecoderGemini();if(t)return t;throw new Error(`Could not find Gemini executable in any of the configured paths: ${this.config.executablePaths.join(", ")}`)}_findGlobalMakecoderGemini(){let e=J.dirname(process.execPath),t=[J.join(e,"..","lib","node_modules","makecoder","dist","gemini","gemini.js"),J.join(e,"node_modules","makecoder","dist","gemini","gemini.js")];for(let o of t)if(Pe.existsSync(o))return o;return null}};Te.exports=ne});var je=$((Eo,Be)=>{var Nt=F(),G=require("path"),re=require("fs"),{spawn:Ut}=require("child_process"),Rt=process.env.CODEV_DEBUG==="True",se=class extends Nt{constructor(){super({executablePaths:["codex.mjs","../dist/codex.mjs"],environmentVariables:()=>({CODEX_DISABLE_WEBSOCKET:"1"})})}checkCodexAvailability(){try{let e=this.findExecutablePath();return re.existsSync(e)}catch{return!1}}findExecutablePath(){let e=G.dirname(require.main.filename);for(let o of this.config.executablePaths){let n=G.resolve(e,o);if(re.existsSync(n))return n}let t=this._findGlobalMakecoderCodex();if(t)return t;throw new Error(`Could not find Codex executable in any of the configured paths: ${this.config.executablePaths.join(", ")}`)}_findGlobalMakecoderCodex(){let e=G.dirname(process.execPath),t=[G.join(e,"..","lib","node_modules","makecoder","dist","codex.mjs"),G.join(e,"node_modules","makecoder","dist","codex.mjs")];for(let o of t)if(re.existsSync(o))return o;return null}async launch(e={}){let{remainingArgs:t=[],codevServer:o,apikey:n=null}=e;try{if(!this.checkCodexAvailability())throw new Error("Codex executable not found. Please ensure makecoder is properly installed: npm install -g makecoder@latest");let s=this.findExecutablePath();Rt&&console.log(`executablePath: ${s}`);let i=[...["-c",`openai_base_url="${o}/codex"`,"-c","analytics.enabled=false","-c","feedback.enabled=false","-c","check_for_update_on_startup=false","-c",'otel.exporter="none"',"-c",'otel.trace_exporter="none"',"-c",'otel.metrics_exporter="none"'],...t];return new Promise((a,l)=>{let d={...process.env,...this.config.environmentVariables(o)};n&&(d.CODER_APIKEY=n);let u=["--no-warnings"];process.env.CODEV_INSPECT_BRK==="True"&&u.push("--inspect-brk"),u.push(s,...i);let m=Ut("node",u,{env:d,stdio:["inherit","inherit","inherit","ipc"]});this.handleChildMessages(m),m.on("error",p=>{console.error(`Failed to start Codex: ${p.message}`),l(p)}),m.on("exit",async(p,f)=>{f&&console.log(`terminated by signal: ${f}`)}),process.on("SIGINT",async()=>{console.log(`
|
|
12
|
+
Terminating ...`),m.kill("SIGTERM"),setTimeout(()=>{m.killed||m.kill("SIGKILL")},8e3)}),process.on("SIGTERM",async()=>{console.log(`
|
|
13
|
+
Terminating ...`),m.kill("SIGTERM"),setTimeout(()=>{m.killed||m.kill("SIGKILL")},8e3)})})}catch(s){throw s}}};Be.exports=se});var Re=$((_o,Ue)=>{var V=require("fs"),Le=require("path"),{spawn:Ne}=require("child_process"),ie=class{constructor(){this.extensionId="codev.codev-background";let e=require.main?Le.dirname(require.main.filename):__dirname;this.extensionPath=Le.resolve(e,"vendor/claude-code.vsix"),this._codeCommand=null}async resolveCodeCommand(){if(this._codeCommand)return this._codeCommand;if(process.env.IS_AISTUDIO==="True"){let e="/usr/lib/aistudio/lib/vscode/bin/remote-cli/aistudio";if(V.existsSync(e))try{return V.accessSync(e,V.constants.F_OK|V.constants.X_OK),this._codeCommand=e,process.env.CODEV_DEBUG&&console.log(`Using AI Studio VSCode path: ${e}`),this._codeCommand}catch(t){process.env.CODEV_DEBUG&&console.log(`AI Studio path exists but not executable: ${t.message}`)}else process.env.CODEV_DEBUG&&console.log(`AI Studio path not found: ${e}`)}try{let{spawn:e}=require("child_process");return new Promise(t=>{let o=e("which",["code"],{stdio:["ignore","pipe","ignore"]}),n="";o.stdout.on("data",s=>{n+=s.toString().trim()}),o.on("close",s=>{s===0&&n?(this._codeCommand=n,process.env.CODEV_DEBUG&&console.log(`Resolved code command path: ${n}`),t(this._codeCommand)):(this._codeCommand="code",t(this._codeCommand))}),o.on("error",()=>{this._codeCommand="code",t(this._codeCommand)}),setTimeout(()=>{o.kill(),this._codeCommand="code",t(this._codeCommand)},3e3)})}catch{return this._codeCommand="code",this._codeCommand}}async shouldInstallExtension(){try{return process.env.IS_AISTUDIO!=="True"?(process.env.CODEV_DEBUG&&console.log("Not in AI Studio environment (IS_AISTUDIO!=True), skipping extension installation"),!1):await this.isVSCodeAvailable()?await this.isExtensionInstalled()?(process.env.CODEV_DEBUG&&console.log(`Extension ${this.extensionId} already installed`),!1):!!V.existsSync(this.extensionPath):(process.env.CODEV_DEBUG&&console.log("VSCode not available, skipping extension installation"),!1)}catch(e){return process.env.CODEV_DEBUG&&console.error(`Error checking extension installation status: ${e.message}`),!1}}async installExtension(){try{return console.log("Installing Codev VSCode extension..."),await this.executeVSCodeCommand(["--install-extension",this.extensionPath])?(console.log("\u2705 Codev VSCode extension installed successfully"),!0):(console.warn("\u274C Failed to install Codev VSCode extension"),!1)}catch(e){return console.warn(`Error installing VSCode extension: ${e.message}`),!1}}async isVSCodeAvailable(){try{let e=process.env.IS_AISTUDIO==="True"?["--help"]:["--version"],t=await this.executeVSCodeCommand(e,{timeout:1e4});if(process.env.CODEV_DEBUG&&(console.log(`VSCode availability check (${e.join(" ")}): ${t?"available":"unavailable"}`),process.env.IS_AISTUDIO==="True")){let{spawn:o}=require("child_process");try{o("which",["code"],{stdio:["ignore","pipe","ignore"]}).stdout.on("data",s=>{console.log("which code:",s.toString().trim())})}catch(n){console.log("which command failed:",n.message)}}return t}catch(e){return process.env.CODEV_DEBUG&&console.error("VSCode availability check error:",e.message),!1}}async isExtensionInstalled(){let e=await this.resolveCodeCommand();try{return new Promise(t=>{try{let o={stdio:["ignore","pipe","ignore"],shell:!1,env:{...process.env,PATH:process.env.PATH,HOME:process.env.HOME,USER:process.env.USER}};process.env.CODEV_DEBUG&&console.log(`Spawning: ${e} --list-extensions`);let n=Ne(e,["--list-extensions"],o),s="";n.stdout.on("data",r=>{s+=r.toString()}),n.on("close",r=>{if(r===0){let i=s.split(`
|
|
14
|
+
`).map(a=>a.trim());t(i.includes(this.extensionId))}else t(!1)}),n.on("error",r=>{process.env.CODEV_DEBUG&&(console.error("VSCode list extensions error:",r.message),console.error("Error code:",r.code),console.error("Error errno:",r.errno),console.error("Error syscall:",r.syscall)),t(!1)}),setTimeout(()=>{try{n.kill()}catch{}t(!1)},1e4)}catch(o){process.env.CODEV_DEBUG&&console.error("Failed to spawn VSCode list extensions:",o.message),t(!1)}})}catch{return!1}}async executeVSCodeCommand(e,t={}){let o=await this.resolveCodeCommand();return new Promise(n=>{try{let s={stdio:"ignore",shell:!1,env:{...process.env,PATH:process.env.PATH,HOME:process.env.HOME,USER:process.env.USER}};process.env.CODEV_DEBUG&&console.log(`Spawning: ${o} ${e.join(" ")}`);let r=Ne(o,e,s);r.on("close",a=>{n(a===0)}),r.on("error",a=>{process.env.CODEV_DEBUG&&(console.error("VSCode command error:",a.message),console.error("Error code:",a.code),console.error("Error errno:",a.errno),console.error("Error syscall:",a.syscall)),n(!1)});let i=t.timeout||3e4;setTimeout(()=>{try{r.kill()}catch{}n(!1)},i)}catch(s){process.env.CODEV_DEBUG&&console.error("Failed to spawn VSCode command:",s.message),n(!1)}})}async ensureExtensionInstalled(){try{process.env.CODEV_DEBUG&&console.log("VSCode Extension Service: Checking extension status..."),await this.shouldInstallExtension()&&await this.installExtension()}catch(e){process.env.CODEV_DEBUG&&console.error("VSCode Extension Service Error:",e)}}};Ue.exports=ie});var Je=$((Oo,Me)=>{var C=require("fs"),T=require("path"),Ft=require("readline"),{execSync:z}=require("child_process"),Fe=require("os"),ce=class{constructor(){this.serverUrl="https://makecoder.com/bigapis/codev/v1/coderpub"}getClaudeJsonlPath(e,t=!1){let o=e.replace(/[/_]/g,"-"),n=T.join(Fe.homedir(),".claude","projects",o);if(t&&(console.log(`
|
|
15
|
+
\u{1F4C2} [allow-clone] \u67E5\u627E JSONL \u6587\u4EF6...`),console.log(` \u9879\u76EE\u76EE\u5F55: ${e}`),console.log(` Claude \u9879\u76EE\u540D: ${o}`),console.log(` Claude \u9879\u76EE\u76EE\u5F55: ${n}`)),!C.existsSync(n))return t&&console.log(" \u274C Claude \u9879\u76EE\u76EE\u5F55\u4E0D\u5B58\u5728"),null;t&&console.log(" \u2713 Claude \u9879\u76EE\u76EE\u5F55\u5B58\u5728");try{let s=C.readdirSync(n).filter(r=>r.endsWith(".jsonl")).map(r=>({name:r,path:T.join(n,r),mtime:C.statSync(T.join(n,r)).mtime,size:C.statSync(T.join(n,r)).size})).sort((r,i)=>i.mtime-r.mtime);return t&&(console.log(` \u627E\u5230 ${s.length} \u4E2A JSONL \u6587\u4EF6:`),s.forEach((r,i)=>{let a=(r.size/1024).toFixed(2),l=r.mtime.toLocaleString(),d=i===0?" <- \u6700\u65B0":"";console.log(` ${i+1}. ${r.name} (${a} KB, ${l})${d}`)})),s.length>0?(t&&console.log(` \u2713 \u9009\u62E9\u6700\u65B0\u6587\u4EF6: ${s[0].name}`),s[0].path):(t&&console.log(" \u274C \u76EE\u5F55\u4E2D\u6CA1\u6709 JSONL \u6587\u4EF6"),null)}catch(s){return t&&console.log(` \u274C \u8BFB\u53D6\u76EE\u5F55\u5931\u8D25: ${s.message}`),null}}async promptForName(){let e=Ft.createInterface({input:process.stdin,output:process.stdout});return new Promise((t,o)=>{e.question("\u8BF7\u8F93\u5165\u9879\u76EE\u540D\u79F0 (name): ",n=>{e.close();let s=n.trim();if(!s){o(new Error("\u9879\u76EE\u540D\u79F0\u4E0D\u80FD\u4E3A\u7A7A"));return}if(!/^[a-zA-Z0-9_-]+$/.test(s)){o(new Error("\u9879\u76EE\u540D\u79F0\u53EA\u80FD\u5305\u542B\u5B57\u6BCD\u3001\u6570\u5B57\u3001\u4E0B\u5212\u7EBF\u548C\u8FDE\u5B57\u7B26"));return}t(s)})})}async createZip(e,t={}){let{allowClone:o=!1}=t,n=Fe.tmpdir(),s=`coder-pub-${Date.now()}.zip`,r=T.join(n,s);try{let i=!1;if(C.existsSync(T.join(e,".git")))try{z(`git archive -o "${r}" HEAD`,{cwd:e,stdio:"pipe"}),console.log("\u{1F4E6} \u4F7F\u7528 git archive \u521B\u5EFA\u538B\u7F29\u5305\uFF08\u5DF2\u6392\u9664 .gitignore \u4E2D\u7684\u6587\u4EF6\uFF09"),i=!0}catch{console.log("\u26A0\uFE0F git archive \u5931\u8D25\uFF0C\u4F7F\u7528\u666E\u901A zip \u547D\u4EE4")}if(!i){let l=[".git/*","node_modules/*",".env",".env.*","*.log",".DS_Store"].map(d=>`-x "${d}"`).join(" ");z(`zip -r "${r}" . ${l}`,{cwd:e,stdio:"pipe"}),console.log("\u{1F4E6} \u5DF2\u521B\u5EFA\u538B\u7F29\u5305")}if(o){console.log(`
|
|
16
|
+
\u{1F504} [allow-clone] \u5F00\u59CB\u5904\u7406 AI \u751F\u6210\u8BB0\u5F55...`);let a=this.getClaudeJsonlPath(e,!0);if(a){let l=T.join(n,"coder.pub.jsonl"),u=(C.statSync(a).size/1024).toFixed(2);console.log(`
|
|
17
|
+
\u{1F4E6} [allow-clone] \u6253\u5305 JSONL \u6587\u4EF6...`),console.log(` \u6E90\u6587\u4EF6: ${a}`),console.log(` \u6587\u4EF6\u5927\u5C0F: ${u} KB`),console.log(` \u4E34\u65F6\u6587\u4EF6: ${l}`),C.copyFileSync(a,l),console.log(" \u2713 \u5DF2\u590D\u5236\u5230\u4E34\u65F6\u76EE\u5F55"),console.log(` \u76EE\u6807 ZIP: ${r}`),console.log(" \u76EE\u6807\u6587\u4EF6\u540D: coder.pub.jsonl"),z(`zip -j "${r}" "${l}"`,{stdio:"pipe"}),console.log(" \u2713 \u5DF2\u6DFB\u52A0\u5230 ZIP \u5305"),C.unlinkSync(l),console.log(" \u2713 \u5DF2\u6E05\u7406\u4E34\u65F6\u6587\u4EF6"),console.log(`\u{1F4CB} [allow-clone] AI \u751F\u6210\u8BB0\u5F55\u5904\u7406\u5B8C\u6210 (coder.pub.jsonl)
|
|
18
18
|
`)}else console.log(`\u26A0\uFE0F [allow-clone] \u672A\u627E\u5230 Claude Code \u751F\u6210\u8BB0\u5F55
|
|
19
|
-
`)}return r}catch(i){throw new Error(`\u521B\u5EFA\u538B\u7F29\u5305\u5931\u8D25: ${i.message}`)}}async upload(e,t,o,s
|
|
20
|
-
\u{1F680} \u6B63\u5728\u53D1\u5E03\u9879\u76EE: ${
|
|
21
|
-
\u{1F310} [allow-clone] \u5F00\u59CB\u4E0A\u4F20\u5230\u670D\u52A1\u5668...`);let l=await this.upload(r,
|
|
22
|
-
\u2705 \u53D1\u5E03\u6210\u529F!`),console.log(`\u{1F4CC} \u7248\u672C: ${l.data.version}`),console.log(`\u{1F310} \u8BBF\u95EE\u5730\u5740: https://${
|
|
19
|
+
`)}return r}catch(i){throw new Error(`\u521B\u5EFA\u538B\u7F29\u5305\u5931\u8D25: ${i.message}`)}}async upload(e,t,o,n,s=!1){let r=n?`${n}/coderpub`:this.serverUrl,i=o;console.log("\u{1F4E4} \u6B63\u5728\u4E0A\u4F20\u5230\u670D\u52A1\u5668..."),s&&(console.log(` \u670D\u52A1\u5668\u5730\u5740: ${r}`),console.log(` \u9879\u76EE\u540D\u79F0: ${t}`),console.log(` ZIP \u6587\u4EF6: ${e}`));try{let a=`curl -s -X POST "${r}" -H "Authorization: Bearer ${i}" -F "name=${t}" -F "zip_file=@${e}"`;s&&console.log(" \u6267\u884C\u4E0A\u4F20\u547D\u4EE4...");let l=z(a,{encoding:"utf-8",stdio:["pipe","pipe","pipe"]});return s&&console.log(" \u2713 \u4E0A\u4F20\u5B8C\u6210\uFF0C\u89E3\u6790\u54CD\u5E94..."),JSON.parse(l)}catch(a){if(a.stdout)try{return JSON.parse(a.stdout)}catch{throw new Error(`\u4E0A\u4F20\u5931\u8D25: ${a.message}`)}throw new Error(`\u4E0A\u4F20\u5931\u8D25: ${a.message}`)}}cleanup(e){try{C.existsSync(e)&&C.unlinkSync(e)}catch{}}async publish(e){let{apikey:t,serverBaseUrl:o,allowClone:n}=e,{name:s}=e,r=null;try{s||(s=await this.promptForName()),console.log(`
|
|
20
|
+
\u{1F680} \u6B63\u5728\u53D1\u5E03\u9879\u76EE: ${s}`),console.log(`\u{1F4C1} \u76EE\u5F55: ${process.cwd()}`),n&&console.log("\u{1F513} allow-clone: \u542F\u7528 (\u5C06\u5305\u542B AI \u751F\u6210\u8BB0\u5F55)"),console.log(),r=await this.createZip(process.cwd(),{allowClone:n});let a=(C.statSync(r).size/(1024*1024)).toFixed(2);console.log(`\u{1F4CA} \u538B\u7F29\u5305\u5927\u5C0F: ${a} MB`),n&&console.log(`
|
|
21
|
+
\u{1F310} [allow-clone] \u5F00\u59CB\u4E0A\u4F20\u5230\u670D\u52A1\u5668...`);let l=await this.upload(r,s,t,o,n);return l.code===0?(console.log(`
|
|
22
|
+
\u2705 \u53D1\u5E03\u6210\u529F!`),console.log(`\u{1F4CC} \u7248\u672C: ${l.data.version}`),console.log(`\u{1F310} \u8BBF\u95EE\u5730\u5740: https://${s}.coder.pub/`),0):(console.error(`
|
|
23
23
|
\u274C \u53D1\u5E03\u5931\u8D25: ${l.message||l.reason}`),1)}catch(i){return console.error(`
|
|
24
24
|
\u274C ${i.message}`),1}finally{r&&this.cleanup(r)}}showHelp(){console.log(["Usage: coder pub [options]","","\u53D1\u5E03\u5F53\u524D\u76EE\u5F55\u4E3A MakeCoder \u7F51\u9875\u5E94\u7528","","Options:"," --name <name> \u5E94\u7528\u540D\u79F0\uFF08\u5FC5\u9700\uFF09"," --allow-clone \u5305\u542B Claude Code \u751F\u6210\u8BB0\u5F55\uFF0C\u5141\u8BB8\u4ED6\u4EBA\u514B\u9686"," --help, -h \u663E\u793A\u6B64\u5E2E\u52A9\u4FE1\u606F","","Description:"," \u5C06\u5F53\u524D\u76EE\u5F55\u7684\u4EE3\u7801\u53D1\u5E03\u4E3A MakeCoder \u5E73\u53F0\u4E0A\u7684\u7F51\u9875\u5E94\u7528\u3002"," \u5E94\u7528\u5C06\u5728 https://<name>.coder.pub/ \u4E0A\u53EF\u8BBF\u95EE\u3002","","Examples:"," coder pub --name myapp \u53D1\u5E03\u5E94\u7528\uFF0C\u8BBF\u95EE\u5730\u5740: https://myapp.coder.pub/"," coder pub --name myapp --allow-clone \u53D1\u5E03\u5E94\u7528\u5E76\u5305\u542B\u751F\u6210\u8BB0\u5F55","","Notes:"," - \u5E94\u7528\u540D\u79F0\u53EA\u80FD\u5305\u542B\u5B57\u6BCD\u3001\u6570\u5B57\u3001\u4E0B\u5212\u7EBF\u548C\u8FDE\u5B57\u7B26"," - \u4F7F\u7528 git archive \u521B\u5EFA\u538B\u7F29\u5305\uFF08\u81EA\u52A8\u6392\u9664 .gitignore \u4E2D\u7684\u6587\u4EF6\uFF09"," - \u5982\u679C\u4E0D\u662F git \u4ED3\u5E93\uFF0C\u5C06\u4F7F\u7528\u666E\u901A zip \u547D\u4EE4"].join(`
|
|
25
|
-
`))}};
|
|
25
|
+
`))}};Me.exports=ce});var Ke=$((Do,Ve)=>{var Ge=require("https"),w=require("fs"),k=require("path"),W=require("os"),O="https://makecoder.com/skillhub",ae=class{getSkillDirs(){let e=W.homedir();return[k.join(e,".agents","skills")]}fetchWithAuth(e,t){return new Promise((o,n)=>{let s=new URL(e),r={hostname:s.hostname,port:s.port||443,path:s.pathname+s.search,method:"GET",headers:t?{Authorization:`Bearer ${t}`}:{}};Ge.get(r,i=>{if(i.statusCode>=300&&i.statusCode<400&&i.headers.location)return this.fetchWithAuth(i.headers.location,t).then(o).catch(n);let a="";i.on("data",l=>{a+=l}),i.on("end",()=>o({status:i.statusCode,body:a}))}).on("error",n)})}async handle({skillsSubcommand:e,skillsArg:t,skillsRemainingArgs:o,apikey:n}){if(!e||e==="--help"||e==="-h")return this.showHelp(),0;if(e==="publish")return await this.publish(o||[],n);if(e==="unpublish")return await this.unpublish(t,n);if(e==="list")return await this.listMySkills(n);if(e==="namespaces")return await this.listNamespaces(n);if(e==="check-updates"){let s=this.getInstalledSkills();if(s.length===0)return console.log("\u6CA1\u6709\u5DF2\u5B89\u88C5\u7684 skill"),0;console.log(`\u{1F50D} \u68C0\u67E5 ${s.length} \u4E2A skill \u7684\u66F4\u65B0...`);let r=await this.checkUpdates(n);if(r.length===0)console.log("\u2705 \u6240\u6709 skill \u5747\u4E3A\u6700\u65B0\u7248\u672C");else{console.log(`
|
|
26
26
|
\u53D1\u73B0 ${r.length} \u4E2A\u53EF\u66F4\u65B0\u7684 skill:
|
|
27
|
-
`);for(let i of r)console.log(` ${i.name.padEnd(24)} ${i.localVersion} \u2192 ${i.remoteVersion}`);console.log("\n\u8FD0\u884C `coder skills update` \u66F4\u65B0\u5168\u90E8")}return 0}if(t&&e!=="search"&&!/^[@a-zA-Z0-9_\-/.]+$/.test(t))return console.error("\u274C skill \u540D\u79F0\u5305\u542B\u975E\u6CD5\u5B57\u7B26"),1;if(e==="search")return t?await this.search(t):(console.error("\u274C \u8BF7\u6307\u5B9A\u641C\u7D22\u5173\u952E\u8BCD"),1);if(e==="remove")return t?this.remove(t):(console.error("\u274C \u8BF7\u6307\u5B9A skill \u540D\u79F0"),1);if(e==="add")return t?
|
|
28
|
-
`);let r=0,i=0,a=!1;for(let l of
|
|
29
|
-
\u66F4\u65B0\u5B8C\u6210: ${r} \u6210\u529F, ${i} \u5931\u8D25`);try{let l=k.join(
|
|
27
|
+
`);for(let i of r)console.log(` ${i.name.padEnd(24)} ${i.localVersion} \u2192 ${i.remoteVersion}`);console.log("\n\u8FD0\u884C `coder skills update` \u66F4\u65B0\u5168\u90E8")}return 0}if(t&&e!=="search"&&!/^[@a-zA-Z0-9_\-/.]+$/.test(t))return console.error("\u274C skill \u540D\u79F0\u5305\u542B\u975E\u6CD5\u5B57\u7B26"),1;if(e==="search")return t?await this.search(t):(console.error("\u274C \u8BF7\u6307\u5B9A\u641C\u7D22\u5173\u952E\u8BCD"),1);if(e==="remove")return t?this.remove(t):(console.error("\u274C \u8BF7\u6307\u5B9A skill \u540D\u79F0"),1);if(e==="add")return t?n?await this.install(t,n):(console.error("\u274C \u7F3A\u5C11 API Key\uFF0C\u8BF7\u5148\u767B\u5F55: coder auth login"),1):(console.error("\u274C \u8BF7\u6307\u5B9A skill \u540D\u79F0"),1);if(e==="update"){if(!n)return console.error("\u274C \u7F3A\u5C11 API Key\uFF0C\u8BF7\u5148\u767B\u5F55: coder auth login"),1;if(t)return await this.install(t,n);console.log("\u{1F50D} \u68C0\u67E5\u53EF\u66F4\u65B0\u7684 skill...");let s=await this.checkUpdates(n);if(s.length===0)return console.log("\u2705 \u6240\u6709 skill \u5747\u4E3A\u6700\u65B0\u7248\u672C"),0;console.log(`\u{1F4E6} \u53D1\u73B0 ${s.length} \u4E2A\u53EF\u66F4\u65B0\u7684 skill\uFF0C\u5F00\u59CB\u66F4\u65B0...
|
|
28
|
+
`);let r=0,i=0,a=!1;for(let l of s){let d=await this.install(l.name,n);d==="EACCES"?(a=!0,i++):d!==0?i++:r++}console.log(`
|
|
29
|
+
\u66F4\u65B0\u5B8C\u6210: ${r} \u6210\u529F, ${i} \u5931\u8D25`);try{let l=k.join(W.homedir(),".agents","skills",".update-cache.json");w.existsSync(l)&&w.unlinkSync(l)}catch{}if(a){let l=this.getSkillDirs()[0];console.error(`
|
|
30
30
|
\u26A0\uFE0F \u90E8\u5206 skill \u6743\u9650\u4E0D\u8DB3\uFF0C\u8BF7\u5148\u8FD0\u884C:
|
|
31
|
-
sudo chown -R $(whoami) "${l}"`)}return i>0?1:0}return console.error(`\u274C \u672A\u77E5\u5B50\u547D\u4EE4: ${e}`),1}async install(e,t){let o=
|
|
32
|
-
`);for(let a of i)console.log(` ${a.slug.padEnd(20)} ${a.summary}`);o(0)}catch(r){console.error(`\u274C \u89E3\u6790\u54CD\u5E94\u5931\u8D25: ${r.message}`),o(1)}})}).on("error",
|
|
33
|
-
\u2705 \u53D1\u5E03\u6210\u529F!`),console.log(` ${
|
|
34
|
-
\u274C \u53D1\u5E03\u5931\u8D25: ${
|
|
35
|
-
\u274C \u53D1\u5E03\u5931\u8D25: ${
|
|
36
|
-
`);for(let l of i){let d=`${l.namespace}/${l.slug}`.padEnd(36),u=`\u2B50 ${l.starCount??0}`.padEnd(8),
|
|
37
|
-
`);for(let a of i){let l=a.type==="GLOBAL"?"\u5168\u5C40":"\u56E2\u961F";console.log(` @${a.slug.padEnd(20)} ${a.displayName.padEnd(20)} [${l}] ${a.status}`)}return 0}catch(
|
|
38
|
-
`))}};
|
|
31
|
+
sudo chown -R $(whoami) "${l}"`)}return i>0?1:0}return console.error(`\u274C \u672A\u77E5\u5B50\u547D\u4EE4: ${e}`),1}async install(e,t){let o=O.replace(/\/$/,"");console.log(`\u{1F50D} \u6B63\u5728\u4ECE ${O} \u67E5\u627E skill...`);let n;try{let u=await this.fetchWithAuth(`${o}/.well-known/agent-skills/index.json?skill=${encodeURIComponent(e)}`,t);if(u.status===404)return console.error(`\u274C \u672A\u627E\u5230 skill: ${e}`),1;if(u.status!==200)return console.error(`\u274C \u65E0\u6CD5\u83B7\u53D6 skill \u4FE1\u606F (HTTP ${u.status})`),1;n=JSON.parse(u.body)}catch(u){return console.error(`\u274C \u8BF7\u6C42\u5931\u8D25: ${u.message}`),1}let s=(n.skills||[])[0];if(!s)return console.error(`\u274C \u672A\u627E\u5230 skill: ${e}`),1;let r=Array.from(new Set(["SKILL.md",...s.files||[]])),i=`${o}/.well-known/agent-skills/${s.name}`,a={};for(let u of r)try{let m=await this.fetchWithAuth(`${i}/${u}`,t);if(m.status!==200){console.warn(`\u26A0\uFE0F \u8DF3\u8FC7 ${u} (HTTP ${m.status})`);continue}a[u]=m.body}catch(m){console.warn(`\u26A0\uFE0F \u4E0B\u8F7D ${u} \u5931\u8D25: ${m.message}`)}console.log(`\u{1F4E6} \u6B63\u5728\u5B89\u88C5 ${s.name}...`);let l={name:s.name,version:s.version||null,installedAt:new Date().toISOString()};for(let u of this.getSkillDirs()){let m=k.join(u,s.name);w.mkdirSync(m,{recursive:!0});try{for(let[p,f]of Object.entries(a)){let g=k.join(m,p);w.mkdirSync(k.dirname(g),{recursive:!0}),w.writeFileSync(g,f,"utf8")}w.writeFileSync(k.join(m,".skill-meta.json"),JSON.stringify(l,null,2),"utf8")}catch(p){if(p.code==="EACCES")return"EACCES";throw p}}let d=s.version?` (v${s.version})`:"";return console.log(`\u2705 ${s.name}${d} \u5B89\u88C5\u5B8C\u6210`),this.cleanLegacySkill(s.name),0}cleanLegacySkill(e){let t=W.homedir(),o=[".claude",".codex",".gemini"].map(n=>k.join(t,n,"skills",e));for(let n of o)if(w.existsSync(n))try{w.rmSync(n,{recursive:!0,force:!0})}catch{}}getInstalledSkills(){let e=[];for(let t of this.getSkillDirs())if(w.existsSync(t))for(let o of w.readdirSync(t,{withFileTypes:!0})){if(!o.isDirectory()||o.name.startsWith("."))continue;let n=k.join(t,o.name),s=k.join(n,".skill-meta.json"),r=null;if(w.existsSync(s))try{r=JSON.parse(w.readFileSync(s,"utf8"))}catch{}e.push({name:o.name,dir:n,meta:r})}return e}async checkUpdates(e){let t=this.getInstalledSkills();if(t.length===0)return[];let o=O.replace(/\/$/,""),n=[];for(let s of t){let r=s.meta?.version||"0.0.1";try{let i=await this.fetchWithAuth(`${o}/.well-known/agent-skills/index.json?skill=${encodeURIComponent(s.name)}`,e);if(i.status===404||i.status!==200)continue;let l=(JSON.parse(i.body).skills||[])[0];if(!l?.version)continue;l.version!==r&&n.push({name:s.name,localVersion:r,remoteVersion:l.version})}catch{}}return n}notifyAndRefreshUpdates(e){let t=k.join(W.homedir(),".agents","skills",".update-cache.json");try{if(w.existsSync(t)){let r=JSON.parse(w.readFileSync(t,"utf8"));if(Array.isArray(r.updates)&&r.updates.length>0){let a=r.updates.length,l;if(a<=3)l=r.updates.map(d=>`${d.name} (${d.localVersion} \u2192 ${d.remoteVersion})`).join(", ");else{let d=r.updates[0];l=`${d.name} (${d.localVersion} \u2192 ${d.remoteVersion}) \u7B49 ${a} \u4E2A skill \u8981\u66F4\u65B0`}console.log(`\x1B[33m\u26A1 ${l}\uFF0C\u8FD0\u884C \`coder skills update\` \u5347\u7EA7\x1B[0m`),a>3&&console.log("\x1B[33m \u8FD0\u884C `coder skills check-updates` \u67E5\u770B\u5B8C\u6574\u5217\u8868\x1B[0m"),console.log()}}}catch{}let o=3600*1e3,n=0;try{n=JSON.parse(w.readFileSync(t,"utf8")).checkedAt||0}catch{}!this.getInstalledSkills().some(r=>!r.meta?.version)&&Date.now()-n<o||setImmediate(async()=>{try{let r=await this.checkUpdates(e);w.mkdirSync(k.dirname(t),{recursive:!0}),w.writeFileSync(t,JSON.stringify({checkedAt:Date.now(),updates:r},null,2),"utf8")}catch{}})}remove(e){let t=!1;for(let o of this.getSkillDirs()){let n=k.join(o,e);w.existsSync(n)&&(w.rmSync(n,{recursive:!0,force:!0}),console.log(` \u{1F5D1}\uFE0F ${n}`),t=!0)}return t?(console.log(`\u2705 ${e} \u5DF2\u5220\u9664`),0):(console.error(`\u274C \u672A\u627E\u5230\u5DF2\u5B89\u88C5\u7684 skill: ${e}`),1)}async search(e){let t=`${O}/api/web/skills?q=${encodeURIComponent(e)}&sort=relevance&page=0&size=12`;return new Promise(o=>{Ge.get(t,n=>{let s="";n.on("data",r=>{s+=r}),n.on("end",()=>{try{let r=JSON.parse(s);if(r.code!==0)return console.error(`\u274C \u67E5\u8BE2\u5931\u8D25: ${r.msg}`),o(1);let i=r.data.items;if(i.length===0)return console.log(`\u6CA1\u6709\u627E\u5230\u4E0E "${e}" \u76F8\u5173\u7684 skill`),o(0);console.log(`\u627E\u5230 ${r.data.total} \u4E2A\u7ED3\u679C:
|
|
32
|
+
`);for(let a of i)console.log(` ${a.slug.padEnd(20)} ${a.summary}`);o(0)}catch(r){console.error(`\u274C \u89E3\u6790\u54CD\u5E94\u5931\u8D25: ${r.message}`),o(1)}})}).on("error",n=>{console.error(`\u274C \u8BF7\u6C42\u5931\u8D25: ${n.message}`),o(1)})})}async publish(e,t){let{execSync:o}=require("child_process"),n=require("os"),s="global",r="PUBLIC",i=null,a=null,l=null,d=null;for(let y=0;y<e.length;y++)if(e[y]==="--namespace"||e[y]==="-n")s=e[++y];else if(e[y]==="--visibility"||e[y]==="-v")r=e[++y];else if(e[y]==="--meta-data"){let h=e[++y];try{JSON.parse(h)}catch(I){return console.error(`\u274C --meta-data \u4E0D\u662F\u5408\u6CD5\u7684 JSON\uFF1A${I.message}`),1}i=h}else if(!e[y].startsWith("-")){let h=e[y];w.existsSync(h)&&w.statSync(h).isDirectory()?d=h:a=h}if(!t)return console.error("\u274C \u7F3A\u5C11 API Key\uFF0C\u8BF7\u5148\u767B\u5F55: coder auth login"),1;let u=s.startsWith("@")?s.slice(1):s;u==="global"||(r="NAMESPACE_ONLY");let p=["PUBLIC","NAMESPACE_ONLY","PRIVATE"];if(!p.includes(r))return console.error(`\u274C visibility \u5FC5\u987B\u662F: ${p.join(", ")}`),1;if(a){if(!w.existsSync(a))return console.error(`\u274C \u6587\u4EF6\u4E0D\u5B58\u5728: ${a}`),1}else{let y=d?k.resolve(d):process.cwd();l=k.join(n.tmpdir(),`skill-pub-${Date.now()}.zip`),console.log(`\u{1F4E6} \u6B63\u5728\u6253\u5305 ${y}...`);try{w.existsSync(k.join(y,".git"))?(o(`git archive -o "${l}" HEAD`,{cwd:y,stdio:"pipe"}),console.log(" \u4F7F\u7528 git archive\uFF08\u5DF2\u6392\u9664 .gitignore \u6587\u4EF6\uFF09")):o(`zip -r "${l}" . -x ".git/*" -x "node_modules/*" -x ".env" -x "*.log"`,{cwd:y,stdio:"pipe"})}catch(h){return console.error(`\u274C \u6253\u5305\u5931\u8D25: ${h.message}`),1}a=l}let f=`${O}/api/v1/skills/${encodeURIComponent(u)}/publish?visibility=${encodeURIComponent(r)}`,g=t;console.log(`\u{1F680} \u6B63\u5728\u53D1\u5E03\u5230 ${O}...`),console.log(` namespace: ${u}`),console.log(` visibility: ${r}`);try{let y=i?` -F "meta_data=${i.replace(/"/g,'\\"')}"`:"",h=`curl -s -X POST "${f}" -H "Authorization: Bearer ${g}" -F "file=@${a}"${y}`,I=o(h,{encoding:"utf-8",stdio:["pipe","pipe","pipe"]}),b=JSON.parse(I);if(b.code===0){let S=b.data;return console.log(`
|
|
33
|
+
\u2705 \u53D1\u5E03\u6210\u529F!`),console.log(` ${S.namespace}/${S.slug}@${S.version}`),S.status==="PUBLISHED"?console.log(" \u72B6\u6001: \u5DF2\u53D1\u5E03"):console.log(" \u72B6\u6001: \u5F85\u5BA1\u6838"),0}else return console.error(`
|
|
34
|
+
\u274C \u53D1\u5E03\u5931\u8D25: ${b.msg||JSON.stringify(b)}`),1}catch(y){let h=y.stdout;if(h)try{let I=JSON.parse(h);return console.error(`
|
|
35
|
+
\u274C \u53D1\u5E03\u5931\u8D25: ${I.msg||h}`),1}catch{}return console.error(`\u274C \u8BF7\u6C42\u5931\u8D25: ${y.message}`),1}finally{l&&w.existsSync(l)&&w.unlinkSync(l)}}async unpublish(e,t){let{execSync:o}=require("child_process");if(!e)return console.error("\u274C \u8BF7\u6307\u5B9A skill: coder skills unpublish <namespace>/<slug>"),1;if(!t)return console.error("\u274C \u7F3A\u5C11 API Key\uFF0C\u8BF7\u5148\u767B\u5F55: coder auth login"),1;let n=e.split("/");if(n.length!==2||!n[0]||!n[1])return console.error("\u274C \u683C\u5F0F\u9519\u8BEF\uFF0C\u5E94\u4E3A <namespace>/<slug>\uFF0C\u4F8B\u5982: global/my-skill"),1;let[s,r]=n,i=s.startsWith("@")?s.slice(1):s,a=`${O}/api/v1/skills/${encodeURIComponent(i)}/${encodeURIComponent(r)}`,l=t;console.log(`\u{1F5D1}\uFE0F \u6B63\u5728\u4E0B\u67B6 ${i}/${r}...`);try{let d=o(`curl -s -X DELETE "${a}" -H "Authorization: Bearer ${l}"`,{encoding:"utf-8",stdio:["pipe","pipe","pipe"]}),u=JSON.parse(d);return u.code===0?(console.log(`\u2705 \u5DF2\u4E0B\u67B6 ${i}/${r}`),0):(console.error(`\u274C \u4E0B\u67B6\u5931\u8D25: ${u.msg||JSON.stringify(u)}`),1)}catch(d){return console.error(`\u274C \u8BF7\u6C42\u5931\u8D25: ${d.message}`),1}}async listMySkills(e){let{execSync:t}=require("child_process");if(!e)return console.error("\u274C \u7F3A\u5C11 API Key\uFF0C\u8BF7\u5148\u767B\u5F55: coder auth login"),1;let o=`${O}/api/v1/me/skills?size=50`,n=e;try{let s=t(`curl -s "${o}" -H "Authorization: Bearer ${n}"`,{encoding:"utf-8",stdio:["pipe","pipe","pipe"]}),r=JSON.parse(s);if(r.code!==0)return console.error(`\u274C \u83B7\u53D6\u5931\u8D25: ${r.msg}`),1;let i=r.data?.items||[],a=r.data?.total||0;if(i.length===0)return console.log("\u6682\u65E0\u5DF2\u53D1\u5E03\u7684 skill"),0;console.log(`\u5171 ${a} \u4E2A skill:
|
|
36
|
+
`);for(let l of i){let d=`${l.namespace}/${l.slug}`.padEnd(36),u=`\u2B50 ${l.starCount??0}`.padEnd(8),m=`\u2193 ${l.downloadCount??0}`.padEnd(10);console.log(` ${d} ${u} ${m} [${l.status}]`),l.displayName&&l.displayName!==l.slug&&console.log(` ${"".padEnd(36)} ${l.displayName}`)}return 0}catch(s){return console.error(`\u274C \u8BF7\u6C42\u5931\u8D25: ${s.message}`),1}}async listNamespaces(e){let{execSync:t}=require("child_process");if(!e)return console.error("\u274C \u7F3A\u5C11 API Key\uFF0C\u8BF7\u5148\u767B\u5F55: coder auth login"),1;let o=`${O}/api/v1/me/namespaces`,n=e;try{let s=t(`curl -s "${o}" -H "Authorization: Bearer ${n}"`,{encoding:"utf-8",stdio:["pipe","pipe","pipe"]}),r=JSON.parse(s);if(r.code!==0)return console.error(`\u274C \u83B7\u53D6\u5931\u8D25: ${r.msg}`),1;let i=r.data||[];if(i.length===0)return console.log("\u6682\u65E0\u547D\u540D\u7A7A\u95F4"),0;console.log(`\u5171 ${i.length} \u4E2A\u547D\u540D\u7A7A\u95F4:
|
|
37
|
+
`);for(let a of i){let l=a.type==="GLOBAL"?"\u5168\u5C40":"\u56E2\u961F";console.log(` @${a.slug.padEnd(20)} ${a.displayName.padEnd(20)} [${l}] ${a.status}`)}return 0}catch(s){return console.error(`\u274C \u8BF7\u6C42\u5931\u8D25: ${s.message}`),1}}showHelp(){console.log(["Usage: coder skills [subcommand] [options]","","Subcommands:"," add <name> \u5B89\u88C5 skill"," remove <name> \u5378\u8F7D skill"," update [name] \u66F4\u65B0 skill\uFF08\u4E0D\u6307\u5B9A\u540D\u79F0\u5219\u66F4\u65B0\u5168\u90E8\uFF09"," check-updates \u68C0\u67E5\u5DF2\u5B89\u88C5 skill \u662F\u5426\u6709\u65B0\u7248\u672C"," search <keyword> \u641C\u7D22 skill"," list \u67E5\u770B\u6211\u53D1\u5E03\u7684 skill"," publish [options] [<dir-or-zip>] \u53D1\u5E03 skill \u5230 skillhub"," unpublish <namespace>/<slug> \u4E0B\u67B6 skill"," namespaces \u67E5\u770B\u6211\u7684\u547D\u540D\u7A7A\u95F4","","Publish Options:"," --namespace <ns> \u76EE\u6807\u547D\u540D\u7A7A\u95F4\uFF08\u9ED8\u8BA4: global\uFF09"," --visibility <v> \u53EF\u89C1\u6027: PUBLIC | NAMESPACE_ONLY | PRIVATE"," \uFF08\u9ED8\u8BA4: PUBLIC\uFF0C\u975E global \u547D\u540D\u7A7A\u95F4\u65F6\u81EA\u52A8\u9501\u5B9A\u4E3A NAMESPACE_ONLY\uFF09"," --meta-data <json> \u9644\u52A0\u81EA\u5B9A\u4E49\u5143\u6570\u636E JSON","","Examples:"," coder skills add vue \u5B89\u88C5 vue skill"," coder skills search react \u641C\u7D22 react skills"," coder skills list \u67E5\u770B\u6211\u53D1\u5E03\u7684 skill"," coder skills publish ./my-skill-dir \u4ECE\u76EE\u5F55\u53D1\u5E03"," coder skills publish --namespace myteam ./my-skill-dir"," coder skills publish --visibility PRIVATE my-skill.zip",` coder skills publish --meta-data '{"category":"tool"}' ./my-skill-dir`," coder skills unpublish global/my-skill"," coder skills namespaces \u67E5\u770B\u6211\u7684\u547D\u540D\u7A7A\u95F4"].join(`
|
|
38
|
+
`))}};Ve.exports=ae});var ze=$((Ao,He)=>{var Mt=require("https"),Y="https://makecoder.com/wiki",Jt=`${Y}/api`,v=c=>`${Y}/doc/${c}`,le=c=>`${Y}/collection/${c}`;function Gt(c){return c.replace(/-([a-z])/g,(e,t)=>t.toUpperCase())}var Vt={"collection-info":{endpoint:"collections.info",requireId:"\u274C \u8BF7\u6307\u5B9A\u96C6\u5408 ID",buildBody:c=>({id:c}),print:c=>{let e=c.data;console.log(`ID: ${e.id}
|
|
39
39
|
\u540D\u79F0: ${e.name}
|
|
40
40
|
\u63CF\u8FF0: ${e.description||""}
|
|
41
|
-
\u6743\u9650: ${e.permission||"null"}`)}},"collection-members":{endpoint:"collections.memberships",requireId:"\u274C \u8BF7\u6307\u5B9A\u96C6\u5408 ID",buildBody:(c,e)=>{let t={id:c},o=e.indexOf("--query");o!==-1&&(t.query=e[o+1]);let
|
|
41
|
+
\u6743\u9650: ${e.permission||"null"}`)}},"collection-members":{endpoint:"collections.memberships",requireId:"\u274C \u8BF7\u6307\u5B9A\u96C6\u5408 ID",buildBody:(c,e)=>{let t={id:c},o=e.indexOf("--query");o!==-1&&(t.query=e[o+1]);let n=e.indexOf("--permission");return n!==-1&&(t.permission=e[n+1]),t},print:(c,e)=>{let t=c.data?.memberships||c.data||[];if(!t.length){console.log("\u6682\u65E0\u6210\u5458");return}e.printTable(t.map(o=>({userId:o.userId||"",\u59D3\u540D:o.user?.name||"",\u6743\u9650:o.permission||""})))}},"collection-add-user":{endpoint:"collections.add_user",requireId:"\u274C \u8BF7\u6307\u5B9A\u96C6\u5408 ID",requireArgs:(c,e)=>!e[1]&&"\u274C \u8BF7\u6307\u5B9A\u7528\u6237 ID\uFF08\u7B2C\u4E8C\u4E2A\u53C2\u6570\uFF09",buildBody:(c,e)=>{let t={id:c,userId:e[1]},o=e.indexOf("--permission");return o!==-1&&(t.permission=e[o+1]),t},print:()=>console.log("\u2705 \u5DF2\u6DFB\u52A0\u7528\u6237\u5230\u96C6\u5408")},"collection-remove-user":{endpoint:"collections.remove_user",requireId:"\u274C \u8BF7\u6307\u5B9A\u96C6\u5408 ID",requireArgs:(c,e)=>!e[1]&&"\u274C \u8BF7\u6307\u5B9A\u7528\u6237 ID\uFF08\u7B2C\u4E8C\u4E2A\u53C2\u6570\uFF09",buildBody:(c,e)=>({id:c,userId:e[1]}),expectOk:!0,print:()=>console.log("\u2705 \u5DF2\u4ECE\u96C6\u5408\u79FB\u9664\u7528\u6237")},"collection-add-group":{endpoint:"collections.add_group",requireId:"\u274C \u8BF7\u6307\u5B9A\u96C6\u5408 ID",requireArgs:(c,e)=>!e[1]&&"\u274C \u8BF7\u6307\u5B9A\u7FA4\u7EC4 ID\uFF08\u7B2C\u4E8C\u4E2A\u53C2\u6570\uFF09",buildBody:(c,e)=>{let t={id:c,groupId:e[1]},o=e.indexOf("--permission");return o!==-1&&(t.permission=e[o+1]),t},print:()=>console.log("\u2705 \u5DF2\u6DFB\u52A0\u7FA4\u7EC4\u5230\u96C6\u5408")},"collection-remove-group":{endpoint:"collections.remove_group",requireId:"\u274C \u8BF7\u6307\u5B9A\u96C6\u5408 ID",requireArgs:(c,e)=>!e[1]&&"\u274C \u8BF7\u6307\u5B9A\u7FA4\u7EC4 ID\uFF08\u7B2C\u4E8C\u4E2A\u53C2\u6570\uFF09",buildBody:(c,e)=>({id:c,groupId:e[1]}),expectOk:!0,print:()=>console.log("\u2705 \u5DF2\u4ECE\u96C6\u5408\u79FB\u9664\u7FA4\u7EC4")},"collection-group-members":{endpoint:"collections.group_memberships",requireId:"\u274C \u8BF7\u6307\u5B9A\u96C6\u5408 ID",buildBody:c=>({id:c}),print:(c,e)=>{let t=c.data?.groupMemberships||c.data||[];if(!t.length){console.log("\u6682\u65E0\u7FA4\u7EC4\u6210\u5458");return}e.printTable(t.map(o=>({groupId:o.groupId||"",\u7FA4\u7EC4\u540D:o.group?.name||"",\u6743\u9650:o.permission||""})))}},"collection-export":{endpoint:"collections.export",requireId:"\u274C \u8BF7\u6307\u5B9A\u96C6\u5408 ID",buildBody:(c,e)=>{let t={id:c},o=e.indexOf("--format");return o!==-1&&(t.format=e[o+1]),t},print:c=>console.log(`\u2705 \u5BFC\u51FA\u4EFB\u52A1\u5DF2\u521B\u5EFA: ${c.data?.id||""}`)},"export-all":{endpoint:"collections.export_all",buildBody:(c,e)=>{let t={},o=e.indexOf("--format");return o!==-1&&(t.format=e[o+1]),t},print:c=>console.log(`\u2705 \u5168\u91CF\u5BFC\u51FA\u4EFB\u52A1\u5DF2\u521B\u5EFA: ${c.data?.id||""}`)},"collection-move":{endpoint:"collections.move",requireId:"\u274C \u8BF7\u6307\u5B9A\u96C6\u5408 ID",requireArgs:(c,e)=>!e[1]&&"\u274C \u8BF7\u6307\u5B9A\u76EE\u6807 index\uFF08\u7B2C\u4E8C\u4E2A\u53C2\u6570\uFF09",buildBody:(c,e)=>({id:c,index:e[1]}),print:()=>console.log("\u2705 \u96C6\u5408\u5DF2\u79FB\u52A8")},archived:{endpoint:"documents.archived",buildBody:(c,e)=>{let t={},o=e.indexOf("--collection");o!==-1&&(t.collectionId=e[o+1]);let n=e.indexOf("--sort");n!==-1&&(t.sort=e[n+1]);let s=e.indexOf("--direction");return s!==-1&&(t.direction=e[s+1]),t},print:(c,e)=>{let t=c.data||[];if(!t.length){console.log("\u6682\u65E0\u5DF2\u5F52\u6863\u6587\u6863");return}e.printTable(t.map(o=>({ID:o.id,\u6807\u9898:o.title,URL:v(o.urlId||o.id)})))}},deleted:{endpoint:"documents.deleted",buildBody:(c,e)=>{let t={},o=e.indexOf("--sort");o!==-1&&(t.sort=e[o+1]);let n=e.indexOf("--direction");return n!==-1&&(t.direction=e[n+1]),t},print:(c,e)=>{let t=c.data||[];if(!t.length){console.log("\u6682\u65E0\u5DF2\u5220\u9664\u6587\u6863");return}e.printTable(t.map(o=>({ID:o.id,\u6807\u9898:o.title,\u5220\u9664\u65F6\u95F4:o.deletedAt||""})))}},insights:{endpoint:"documents.insights",requireId:"\u274C \u8BF7\u6307\u5B9A\u6587\u6863 ID",buildBody:(c,e)=>{let t={id:c},o=e.indexOf("--start-date");o!==-1&&(t.startDate=e[o+1]);let n=e.indexOf("--end-date");return n!==-1&&(t.endDate=e[n+1]),t},print:(c,e)=>{let t=c.data||[];if(!t.length){console.log("\u6682\u65E0\u8BBF\u95EE\u6570\u636E");return}e.printTable(t.map(o=>({userId:o.userId||"",\u59D3\u540D:o.user?.name||"",\u65F6\u95F4:o.createdAt||""})))}},export:{endpoint:"documents.export",requireId:"\u274C \u8BF7\u6307\u5B9A\u6587\u6863 ID",buildBody:(c,e)=>({id:c,includeChildDocuments:e.includes("--include-children")}),print:c=>{let e=c.data;console.log(typeof e=="string"?e:JSON.stringify(e,null,2))}},"search-titles":{endpoint:"documents.search_titles",requireId:"\u274C \u8BF7\u6307\u5B9A\u641C\u7D22\u5173\u952E\u8BCD",buildBody:(c,e)=>({query:[c,...e.slice(1)].join(" ")}),print:(c,e)=>{let t=c.data||[];if(!t.length){console.log("\u672A\u627E\u5230\u5339\u914D\u6807\u9898");return}e.printTable(t.map(o=>({ID:o.id,\u6807\u9898:o.title,URL:v(o.urlId||o.id)})))}},duplicate:{endpoint:"documents.duplicate",requireId:"\u274C \u8BF7\u6307\u5B9A\u6587\u6863 ID",buildBody:(c,e)=>{let t={id:c},o=e.indexOf("--title");o!==-1&&(t.title=e[o+1]);let n=e.indexOf("--collection");n!==-1&&(t.collectionId=e[n+1]);let s=e.indexOf("--parent");return s!==-1&&(t.parentDocumentId=e[s+1]),e.includes("--recursive")&&(t.recursive=!0),e.includes("--publish")&&(t.publish=!0),t},print:c=>{let t=(c.data?.documents||[])[0];console.log(t?`\u2705 \u6587\u6863\u5DF2\u590D\u5236: ${t.id} \u2014 ${t.title}`:"\u2705 \u6587\u6863\u5DF2\u590D\u5236")}},unpublish:{endpoint:"documents.unpublish",requireId:"\u274C \u8BF7\u6307\u5B9A\u6587\u6863 ID",buildBody:c=>({id:c}),print:()=>console.log("\u2705 \u6587\u6863\u5DF2\u53D6\u6D88\u53D1\u5E03")},templatize:{endpoint:"documents.templatize",requireId:"\u274C \u8BF7\u6307\u5B9A\u6587\u6863 ID",buildBody:(c,e)=>{let t={id:c,publish:!0},o=e.indexOf("--collection");return o!==-1&&(t.collectionId=e[o+1]),t},print:c=>console.log(`\u2705 \u5DF2\u8F6C\u4E3A\u6A21\u677F: ${c.data.id}`)},"doc-members":{endpoint:"documents.memberships",requireId:"\u274C \u8BF7\u6307\u5B9A\u6587\u6863 ID",buildBody:c=>({id:c}),print:(c,e)=>{let t=c.data?.memberships||c.data||[];if(!t.length){console.log("\u6682\u65E0\u6210\u5458");return}e.printTable(t.map(o=>({userId:o.userId||"",\u59D3\u540D:o.user?.name||"",\u6743\u9650:o.permission||""})))}},"doc-add-user":{endpoint:"documents.add_user",requireId:"\u274C \u8BF7\u6307\u5B9A\u6587\u6863 ID",requireArgs:(c,e)=>!e[1]&&"\u274C \u8BF7\u6307\u5B9A\u7528\u6237 ID\uFF08\u7B2C\u4E8C\u4E2A\u53C2\u6570\uFF09",buildBody:(c,e)=>{let t={id:c,userId:e[1]},o=e.indexOf("--permission");return o!==-1&&(t.permission=e[o+1]),t},print:()=>console.log("\u2705 \u5DF2\u6DFB\u52A0\u7528\u6237\u5230\u6587\u6863")},"doc-remove-user":{endpoint:"documents.remove_user",requireId:"\u274C \u8BF7\u6307\u5B9A\u6587\u6863 ID",requireArgs:(c,e)=>!e[1]&&"\u274C \u8BF7\u6307\u5B9A\u7528\u6237 ID\uFF08\u7B2C\u4E8C\u4E2A\u53C2\u6570\uFF09",buildBody:(c,e)=>({id:c,userId:e[1]}),expectOk:!0,print:()=>console.log("\u2705 \u5DF2\u4ECE\u6587\u6863\u79FB\u9664\u7528\u6237")},"doc-add-group":{endpoint:"documents.add_group",requireId:"\u274C \u8BF7\u6307\u5B9A\u6587\u6863 ID",requireArgs:(c,e)=>!e[1]&&"\u274C \u8BF7\u6307\u5B9A\u7FA4\u7EC4 ID\uFF08\u7B2C\u4E8C\u4E2A\u53C2\u6570\uFF09",buildBody:(c,e)=>{let t={id:c,groupId:e[1]},o=e.indexOf("--permission");return o!==-1&&(t.permission=e[o+1]),t},print:()=>console.log("\u2705 \u5DF2\u6DFB\u52A0\u7FA4\u7EC4\u5230\u6587\u6863")},"doc-remove-group":{endpoint:"documents.remove_group",requireId:"\u274C \u8BF7\u6307\u5B9A\u6587\u6863 ID",requireArgs:(c,e)=>!e[1]&&"\u274C \u8BF7\u6307\u5B9A\u7FA4\u7EC4 ID\uFF08\u7B2C\u4E8C\u4E2A\u53C2\u6570\uFF09",buildBody:(c,e)=>({id:c,groupId:e[1]}),expectOk:!0,print:()=>console.log("\u2705 \u5DF2\u4ECE\u6587\u6863\u79FB\u9664\u7FA4\u7EC4")},"doc-group-members":{endpoint:"documents.group_memberships",requireId:"\u274C \u8BF7\u6307\u5B9A\u6587\u6863 ID",buildBody:c=>({id:c}),print:(c,e)=>{let t=c.data?.groupMemberships||c.data||[];if(!t.length){console.log("\u6682\u65E0\u7FA4\u7EC4\u6210\u5458");return}e.printTable(t.map(o=>({groupId:o.groupId||"",\u7FA4\u7EC4\u540D:o.group?.name||"",\u6743\u9650:o.permission||""})))}},"empty-trash":{endpoint:"documents.empty_trash",buildBody:()=>({}),expectOk:!0,print:()=>console.log("\u2705 \u56DE\u6536\u7AD9\u5DF2\u6E05\u7A7A")},"sub-docs":{endpoint:"documents.documents",requireId:"\u274C \u8BF7\u6307\u5B9A\u6587\u6863 ID",buildBody:c=>({id:c}),print:(c,e)=>{let t=c.data?.children||[];if(!t.length){console.log("\u6682\u65E0\u5B50\u6587\u6863");return}e.printTree(t,"",1/0,0)}},shares:{endpoint:"shares.list",buildBody:(c,e)=>{let t={},o=e.indexOf("--document");return o!==-1&&(t.documentId=e[o+1]),t},print:(c,e)=>{let t=c.data||[];if(!t.length){console.log("\u6682\u65E0\u5206\u4EAB");return}e.printTable(t.map(o=>({shareId:o.id,\u6587\u6863:o.documentTitle||o.documentId||"",\u5DF2\u53D1\u5E03:o.published?"\u662F":"\u5426",URL:o.url||""})))}},"share-info":{endpoint:"shares.info",requireId:"\u274C \u8BF7\u6307\u5B9A\u5206\u4EAB ID",buildBody:c=>({id:c}),print:c=>{let e=c.data;console.log(`ID: ${e.id}
|
|
42
42
|
\u6587\u6863: ${e.documentTitle||e.documentId||""}
|
|
43
43
|
\u5DF2\u53D1\u5E03: ${e.published?"\u662F":"\u5426"}
|
|
44
44
|
URL: ${e.url||""}`)}},share:{endpoint:"shares.create",requireId:"\u274C \u8BF7\u6307\u5B9A\u6587\u6863 ID",buildBody:(c,e)=>({documentId:c,published:e.includes("--published"),includeChildDocuments:e.includes("--include-children")}),print:c=>console.log(`\u2705 \u5206\u4EAB\u5DF2\u521B\u5EFA: ${c.data.id}
|
|
45
|
-
${c.data.url||""}`)},"share-update":{endpoint:"shares.update",requireId:"\u274C \u8BF7\u6307\u5B9A\u5206\u4EAB ID",buildBody:(c,e)=>{let t={id:c};return e.includes("--published")&&(t.published=!0),e.includes("--no-published")&&(t.published=!1),e.includes("--include-children")&&(t.includeChildDocuments=!0),t},print:()=>console.log("\u2705 \u5206\u4EAB\u5DF2\u66F4\u65B0")},unshare:{endpoint:"shares.revoke",requireId:"\u274C \u8BF7\u6307\u5B9A\u5206\u4EAB ID",buildBody:c=>({id:c}),expectOk:!0,print:()=>console.log("\u2705 \u5206\u4EAB\u5DF2\u64A4\u9500")},users:{endpoint:"users.list",buildBody:(c,e)=>{let t={},o=e.indexOf("--query");o!==-1&&(t.query=e[o+1]);let
|
|
45
|
+
${c.data.url||""}`)},"share-update":{endpoint:"shares.update",requireId:"\u274C \u8BF7\u6307\u5B9A\u5206\u4EAB ID",buildBody:(c,e)=>{let t={id:c};return e.includes("--published")&&(t.published=!0),e.includes("--no-published")&&(t.published=!1),e.includes("--include-children")&&(t.includeChildDocuments=!0),t},print:()=>console.log("\u2705 \u5206\u4EAB\u5DF2\u66F4\u65B0")},unshare:{endpoint:"shares.revoke",requireId:"\u274C \u8BF7\u6307\u5B9A\u5206\u4EAB ID",buildBody:c=>({id:c}),expectOk:!0,print:()=>console.log("\u2705 \u5206\u4EAB\u5DF2\u64A4\u9500")},users:{endpoint:"users.list",buildBody:(c,e)=>{let t={},o=e.indexOf("--query");o!==-1&&(t.query=e[o+1]);let n=e.indexOf("--filter");return n!==-1&&(t.filter=e[n+1]),t},print:(c,e)=>{let t=c.data||[];if(!t.length){console.log("\u6682\u65E0\u7528\u6237");return}e.printTable(t.map(o=>({ID:o.id,\u59D3\u540D:o.name,\u90AE\u7BB1:o.email||"",\u89D2\u8272:o.role||""})))}},"user-info":{endpoint:"users.info",requireId:"\u274C \u8BF7\u6307\u5B9A\u7528\u6237 ID",buildBody:c=>({id:c}),print:c=>{let e=c.data;console.log(`ID: ${e.id}
|
|
46
46
|
\u59D3\u540D: ${e.name}
|
|
47
47
|
\u90AE\u7BB1: ${e.email||""}
|
|
48
|
-
\u89D2\u8272: ${e.role||""}`)}},invite:{endpoint:"users.invite",buildBody:(c,e)=>{let t=e.indexOf("--email"),o=e.indexOf("--name"),
|
|
48
|
+
\u89D2\u8272: ${e.role||""}`)}},invite:{endpoint:"users.invite",buildBody:(c,e)=>{let t=e.indexOf("--email"),o=e.indexOf("--name"),n=e.indexOf("--role"),s=t!==-1?e[t+1]:c||e[0],r=o!==-1?e[o+1]:e[1],i=n!==-1?e[n+1]:e[2];return{invites:[{email:s,name:r,role:i}]}},requireArgs:(c,e)=>{let t=e.indexOf("--email");return!(t!==-1?e[t+1]:c||e[0])&&"\u274C \u8BF7\u6307\u5B9A\u90AE\u7BB1\uFF08\u7B2C\u4E00\u4E2A\u53C2\u6570\u6216 --email\uFF09"},print:(c,e)=>{let t=c.data||[];if(!t.length){console.log("\u2705 \u9080\u8BF7\u5DF2\u53D1\u9001");return}e.printTable(t.map(o=>({ID:o.id,\u90AE\u7BB1:o.email||"",\u59D3\u540D:o.name||""})))}},"user-update-role":{endpoint:"users.update_role",requireId:"\u274C \u8BF7\u6307\u5B9A\u7528\u6237 ID",requireArgs:(c,e)=>!e[1]&&"\u274C \u8BF7\u6307\u5B9A\u89D2\u8272\uFF08\u7B2C\u4E8C\u4E2A\u53C2\u6570\uFF1Aadmin|member|viewer\uFF09",buildBody:(c,e)=>({id:c,role:e[1]}),print:()=>console.log("\u2705 \u7528\u6237\u89D2\u8272\u5DF2\u66F4\u65B0")},"user-suspend":{endpoint:"users.suspend",requireId:"\u274C \u8BF7\u6307\u5B9A\u7528\u6237 ID",buildBody:c=>({id:c}),print:()=>console.log("\u2705 \u7528\u6237\u5DF2\u6682\u505C")},"user-activate":{endpoint:"users.activate",requireId:"\u274C \u8BF7\u6307\u5B9A\u7528\u6237 ID",buildBody:c=>({id:c}),print:()=>console.log("\u2705 \u7528\u6237\u5DF2\u6FC0\u6D3B")},groups:{endpoint:"groups.list",buildBody:(c,e)=>{let t={},o=e.indexOf("--query");return o!==-1&&(t.query=e[o+1]),t},print:(c,e)=>{let t=c.data||[];if(!t.length){console.log("\u6682\u65E0\u7FA4\u7EC4");return}e.printTable(t.map(o=>({ID:o.id,\u540D\u79F0:o.name,\u6210\u5458\u6570:o.memberCount??""})))}},"group-info":{endpoint:"groups.info",requireId:"\u274C \u8BF7\u6307\u5B9A\u7FA4\u7EC4 ID",buildBody:c=>({id:c}),print:c=>{let e=c.data;console.log(`ID: ${e.id}
|
|
49
49
|
\u540D\u79F0: ${e.name}
|
|
50
|
-
\u6210\u5458: ${e.memberCount??""}`)}},"create-group":{endpoint:"groups.create",requireId:"\u274C \u8BF7\u6307\u5B9A\u7FA4\u7EC4\u540D\u79F0",buildBody:(c,e)=>({name:[c,...e.slice(1)].join(" ")}),print:c=>console.log(`\u2705 \u7FA4\u7EC4\u5DF2\u521B\u5EFA: ${c.data.id} \u2014 ${c.data.name}`)},"update-group":{endpoint:"groups.update",requireId:"\u274C \u8BF7\u6307\u5B9A\u7FA4\u7EC4 ID",buildBody:(c,e)=>{let t={id:c},o=e.indexOf("--name");return o!==-1&&(t.name=e[o+1]),t},print:()=>console.log("\u2705 \u7FA4\u7EC4\u5DF2\u66F4\u65B0")},"delete-group":{endpoint:"groups.delete",requireId:"\u274C \u8BF7\u6307\u5B9A\u7FA4\u7EC4 ID",buildBody:c=>({id:c}),expectOk:!0,print:()=>console.log("\u2705 \u7FA4\u7EC4\u5DF2\u5220\u9664")},"group-members":{endpoint:"groups.memberships",requireId:"\u274C \u8BF7\u6307\u5B9A\u7FA4\u7EC4 ID",buildBody:c=>({id:c}),print:(c,e)=>{let t=c.data?.groupMemberships||c.data||[];if(!t.length){console.log("\u6682\u65E0\u6210\u5458");return}e.printTable(t.map(o=>({userId:o.userId||o.user?.id||"",\u59D3\u540D:o.user?.name||""})))}},"group-add-user":{endpoint:"groups.add_user",requireId:"\u274C \u8BF7\u6307\u5B9A\u7FA4\u7EC4 ID",requireArgs:(c,e)=>!e[1]&&"\u274C \u8BF7\u6307\u5B9A\u7528\u6237 ID\uFF08\u7B2C\u4E8C\u4E2A\u53C2\u6570\uFF09",buildBody:(c,e)=>({id:c,userId:e[1]}),print:()=>console.log("\u2705 \u5DF2\u6DFB\u52A0\u7528\u6237\u5230\u7FA4\u7EC4")},"group-remove-user":{endpoint:"groups.remove_user",requireId:"\u274C \u8BF7\u6307\u5B9A\u7FA4\u7EC4 ID",requireArgs:(c,e)=>!e[1]&&"\u274C \u8BF7\u6307\u5B9A\u7528\u6237 ID\uFF08\u7B2C\u4E8C\u4E2A\u53C2\u6570\uFF09",buildBody:(c,e)=>({id:c,userId:e[1]}),expectOk:!0,print:()=>console.log("\u2705 \u5DF2\u4ECE\u7FA4\u7EC4\u79FB\u9664\u7528\u6237")},views:{endpoint:"views.list",requireId:"\u274C \u8BF7\u6307\u5B9A\u6587\u6863 ID",buildBody:c=>({documentId:c}),print:(c,e)=>{let t=c.data||[];if(!t.length){console.log("\u6682\u65E0\u6D4F\u89C8\u8BB0\u5F55");return}e.printTable(t.map(o=>({userId:o.userId||"",\u59D3\u540D:o.user?.name||"",\u6B21\u6570:o.count??"",\u6700\u8FD1:o.updatedAt||""})))}},view:{endpoint:"views.create",requireId:"\u274C \u8BF7\u6307\u5B9A\u6587\u6863 ID",buildBody:c=>({documentId:c}),print:()=>console.log("\u2705 \u6D4F\u89C8\u5DF2\u8BB0\u5F55")},subscriptions:{endpoint:"subscriptions.list",buildBody:(c,e)=>{let t={event:"documents.update"};c&&(t.documentId=c);let o=e.indexOf("--collection");return o!==-1&&(t.collectionId=e[o+1]),t},requireArgs:(c,e)=>!c&&e.indexOf("--collection")===-1&&"\u274C \u8BF7\u6307\u5B9A\u6587\u6863 ID \u6216 --collection <collectionId>",print:(c,e)=>{let t=c.data||[];if(!t.length){console.log("\u6682\u65E0\u8BA2\u9605");return}e.printTable(t.map(o=>({ID:o.id,\u6587\u6863:o.documentId||"",\u4E8B\u4EF6:o.event||""})))}},subscribe:{endpoint:"subscriptions.create",requireId:"\u274C \u8BF7\u6307\u5B9A\u6587\u6863 ID",buildBody:c=>({documentId:c,event:"documents.update"}),print:c=>console.log(`\u2705 \u5DF2\u8BA2\u9605: ${c.data.id}`)},unsubscribe:{endpoint:"subscriptions.delete",requireId:"\u274C \u8BF7\u6307\u5B9A\u8BA2\u9605 ID",buildBody:c=>({id:c}),expectOk:!0,print:()=>console.log("\u2705 \u5DF2\u53D6\u6D88\u8BA2\u9605")},events:{endpoint:"events.list",buildBody:(c,e)=>{let t={},o=e.indexOf("--actor");o!==-1&&(t.actorId=e[o+1]);let
|
|
50
|
+
\u6210\u5458: ${e.memberCount??""}`)}},"create-group":{endpoint:"groups.create",requireId:"\u274C \u8BF7\u6307\u5B9A\u7FA4\u7EC4\u540D\u79F0",buildBody:(c,e)=>({name:[c,...e.slice(1)].join(" ")}),print:c=>console.log(`\u2705 \u7FA4\u7EC4\u5DF2\u521B\u5EFA: ${c.data.id} \u2014 ${c.data.name}`)},"update-group":{endpoint:"groups.update",requireId:"\u274C \u8BF7\u6307\u5B9A\u7FA4\u7EC4 ID",buildBody:(c,e)=>{let t={id:c},o=e.indexOf("--name");return o!==-1&&(t.name=e[o+1]),t},print:()=>console.log("\u2705 \u7FA4\u7EC4\u5DF2\u66F4\u65B0")},"delete-group":{endpoint:"groups.delete",requireId:"\u274C \u8BF7\u6307\u5B9A\u7FA4\u7EC4 ID",buildBody:c=>({id:c}),expectOk:!0,print:()=>console.log("\u2705 \u7FA4\u7EC4\u5DF2\u5220\u9664")},"group-members":{endpoint:"groups.memberships",requireId:"\u274C \u8BF7\u6307\u5B9A\u7FA4\u7EC4 ID",buildBody:c=>({id:c}),print:(c,e)=>{let t=c.data?.groupMemberships||c.data||[];if(!t.length){console.log("\u6682\u65E0\u6210\u5458");return}e.printTable(t.map(o=>({userId:o.userId||o.user?.id||"",\u59D3\u540D:o.user?.name||""})))}},"group-add-user":{endpoint:"groups.add_user",requireId:"\u274C \u8BF7\u6307\u5B9A\u7FA4\u7EC4 ID",requireArgs:(c,e)=>!e[1]&&"\u274C \u8BF7\u6307\u5B9A\u7528\u6237 ID\uFF08\u7B2C\u4E8C\u4E2A\u53C2\u6570\uFF09",buildBody:(c,e)=>({id:c,userId:e[1]}),print:()=>console.log("\u2705 \u5DF2\u6DFB\u52A0\u7528\u6237\u5230\u7FA4\u7EC4")},"group-remove-user":{endpoint:"groups.remove_user",requireId:"\u274C \u8BF7\u6307\u5B9A\u7FA4\u7EC4 ID",requireArgs:(c,e)=>!e[1]&&"\u274C \u8BF7\u6307\u5B9A\u7528\u6237 ID\uFF08\u7B2C\u4E8C\u4E2A\u53C2\u6570\uFF09",buildBody:(c,e)=>({id:c,userId:e[1]}),expectOk:!0,print:()=>console.log("\u2705 \u5DF2\u4ECE\u7FA4\u7EC4\u79FB\u9664\u7528\u6237")},views:{endpoint:"views.list",requireId:"\u274C \u8BF7\u6307\u5B9A\u6587\u6863 ID",buildBody:c=>({documentId:c}),print:(c,e)=>{let t=c.data||[];if(!t.length){console.log("\u6682\u65E0\u6D4F\u89C8\u8BB0\u5F55");return}e.printTable(t.map(o=>({userId:o.userId||"",\u59D3\u540D:o.user?.name||"",\u6B21\u6570:o.count??"",\u6700\u8FD1:o.updatedAt||""})))}},view:{endpoint:"views.create",requireId:"\u274C \u8BF7\u6307\u5B9A\u6587\u6863 ID",buildBody:c=>({documentId:c}),print:()=>console.log("\u2705 \u6D4F\u89C8\u5DF2\u8BB0\u5F55")},subscriptions:{endpoint:"subscriptions.list",buildBody:(c,e)=>{let t={event:"documents.update"};c&&(t.documentId=c);let o=e.indexOf("--collection");return o!==-1&&(t.collectionId=e[o+1]),t},requireArgs:(c,e)=>!c&&e.indexOf("--collection")===-1&&"\u274C \u8BF7\u6307\u5B9A\u6587\u6863 ID \u6216 --collection <collectionId>",print:(c,e)=>{let t=c.data||[];if(!t.length){console.log("\u6682\u65E0\u8BA2\u9605");return}e.printTable(t.map(o=>({ID:o.id,\u6587\u6863:o.documentId||"",\u4E8B\u4EF6:o.event||""})))}},subscribe:{endpoint:"subscriptions.create",requireId:"\u274C \u8BF7\u6307\u5B9A\u6587\u6863 ID",buildBody:c=>({documentId:c,event:"documents.update"}),print:c=>console.log(`\u2705 \u5DF2\u8BA2\u9605: ${c.data.id}`)},unsubscribe:{endpoint:"subscriptions.delete",requireId:"\u274C \u8BF7\u6307\u5B9A\u8BA2\u9605 ID",buildBody:c=>({id:c}),expectOk:!0,print:()=>console.log("\u2705 \u5DF2\u53D6\u6D88\u8BA2\u9605")},events:{endpoint:"events.list",buildBody:(c,e)=>{let t={},o=e.indexOf("--actor");o!==-1&&(t.actorId=e[o+1]);let n=e.indexOf("--document");n!==-1&&(t.documentId=e[n+1]);let s=e.indexOf("--collection");s!==-1&&(t.collectionId=e[s+1]);let r=e.indexOf("--type");return r!==-1&&(t.name=e[r+1]),t},print:(c,e)=>{let t=c.data||[];if(!t.length){console.log("\u6682\u65E0\u4E8B\u4EF6");return}e.printTable(t.map(o=>({\u4E8B\u4EF6:o.name||"",actorId:o.actorId||"",\u65F6\u95F4:o.createdAt||""})))}},templates:{endpoint:"templates.list",buildBody:(c,e)=>{let t={},o=e.indexOf("--collection");return o!==-1&&(t.collectionId=e[o+1]),t},print:(c,e)=>{let t=c.data||[];if(!t.length){console.log("\u6682\u65E0\u6A21\u677F");return}e.printTable(t.map(o=>({ID:o.id,\u6807\u9898:o.title,\u96C6\u5408:o.collectionId||""})))}},"template-info":{endpoint:"templates.info",requireId:"\u274C \u8BF7\u6307\u5B9A\u6A21\u677F ID",buildBody:c=>({id:c}),print:c=>{let e=c.data;console.log(`ID: ${e.id}
|
|
51
51
|
\u6807\u9898: ${e.title}
|
|
52
|
-
\u96C6\u5408: ${e.collectionId||""}`)}},"create-template":{endpoint:"templates.create",requireId:"\u274C \u8BF7\u6307\u5B9A\u96C6\u5408 ID",requireArgs:(c,e)=>!e[1]&&"\u274C \u8BF7\u6307\u5B9A\u6A21\u677F\u6807\u9898\uFF08\u7B2C\u4E8C\u4E2A\u53C2\u6570\uFF09",buildBody:(c,e)=>{let t=e.indexOf("--text"),o=t!==-1?e[t+1]:"";return{collectionId:c,title:e[1],data:{type:"doc",content:o?[{type:"paragraph",content:[{type:"text",text:o}]}]:[]}}},print:c=>console.log(`\u2705 \u6A21\u677F\u5DF2\u521B\u5EFA: ${c.data.id} \u2014 ${c.data.title}`)},"update-template":{endpoint:"templates.update",requireId:"\u274C \u8BF7\u6307\u5B9A\u6A21\u677F ID",buildBody:(c,e)=>{let t={id:c},o=e.indexOf("--title");o!==-1&&(t.title=e[o+1]);let
|
|
52
|
+
\u96C6\u5408: ${e.collectionId||""}`)}},"create-template":{endpoint:"templates.create",requireId:"\u274C \u8BF7\u6307\u5B9A\u96C6\u5408 ID",requireArgs:(c,e)=>!e[1]&&"\u274C \u8BF7\u6307\u5B9A\u6A21\u677F\u6807\u9898\uFF08\u7B2C\u4E8C\u4E2A\u53C2\u6570\uFF09",buildBody:(c,e)=>{let t=e.indexOf("--text"),o=t!==-1?e[t+1]:"";return{collectionId:c,title:e[1],data:{type:"doc",content:o?[{type:"paragraph",content:[{type:"text",text:o}]}]:[]}}},print:c=>console.log(`\u2705 \u6A21\u677F\u5DF2\u521B\u5EFA: ${c.data.id} \u2014 ${c.data.title}`)},"update-template":{endpoint:"templates.update",requireId:"\u274C \u8BF7\u6307\u5B9A\u6A21\u677F ID",buildBody:(c,e)=>{let t={id:c},o=e.indexOf("--title");o!==-1&&(t.title=e[o+1]);let n=e.indexOf("--text");return n!==-1&&(t.data={type:"doc",content:[{type:"paragraph",content:[{type:"text",text:e[n+1]}]}]}),t},print:()=>console.log("\u2705 \u6A21\u677F\u5DF2\u66F4\u65B0")},"delete-template":{endpoint:"templates.delete",requireId:"\u274C \u8BF7\u6307\u5B9A\u6A21\u677F ID",buildBody:c=>({id:c}),expectOk:!0,print:()=>console.log("\u2705 \u6A21\u677F\u5DF2\u5220\u9664")},"duplicate-template":{endpoint:"templates.duplicate",requireId:"\u274C \u8BF7\u6307\u5B9A\u6A21\u677F ID",buildBody:(c,e)=>{let t={id:c},o=e.indexOf("--title");return o!==-1&&(t.title=e[o+1]),t},print:c=>console.log(`\u2705 \u6A21\u677F\u5DF2\u590D\u5236: ${c.data.id} \u2014 ${c.data.title}`)},"file-ops":{endpoint:"fileOperations.list",buildBody:(c,e)=>{let t={},o=e.indexOf("--type");return o!==-1&&(t.type=e[o+1]),t},print:(c,e)=>{let t=c.data||[];if(!t.length){console.log("\u6682\u65E0\u6587\u4EF6\u64CD\u4F5C\u8BB0\u5F55");return}e.printTable(t.map(o=>({ID:o.id,\u7C7B\u578B:o.type||"",\u72B6\u6001:o.state||"",\u65F6\u95F4:o.createdAt||""})))}},"file-op-info":{endpoint:"fileOperations.info",requireId:"\u274C \u8BF7\u6307\u5B9A\u6587\u4EF6\u64CD\u4F5C ID",buildBody:c=>({id:c}),print:c=>{let e=c.data;console.log(`ID: ${e.id}
|
|
53
53
|
\u7C7B\u578B: ${e.type||""}
|
|
54
54
|
\u72B6\u6001: ${e.state||""}
|
|
55
|
-
\u65F6\u95F4: ${e.createdAt||""}`)}},"file-op-delete":{endpoint:"fileOperations.delete",requireId:"\u274C \u8BF7\u6307\u5B9A\u6587\u4EF6\u64CD\u4F5C ID",buildBody:c=>({id:c}),expectOk:!0,print:()=>console.log("\u2705 \u6587\u4EF6\u64CD\u4F5C\u8BB0\u5F55\u5DF2\u5220\u9664")},reactions:{endpoint:"reactions.list",requireId:"\u274C \u8BF7\u6307\u5B9A\u8BC4\u8BBA ID",buildBody:c=>({commentId:c}),print:(c,e)=>{let t=c.data||[];if(!t.length){console.log("\u6682\u65E0\u53CD\u5E94");return}e.printTable(t.map(o=>({emoji:o.emoji||"",userId:o.userId||"",\u59D3\u540D:o.user?.name||""})))}},attachments:{endpoint:"attachments.list",buildBody:c=>c?{documentId:c}:{},print:(c,e)=>{let t=c.data||[];if(!t.length){console.log("\u6682\u65E0\u9644\u4EF6");return}e.printTable(t.map(o=>({ID:o.id,\u6587\u4EF6\u540D:o.name,\u7C7B\u578B:o.contentType||"",\u5927\u5C0F:o.size?`${Math.round(o.size/1024)}KB`:"",URL:o.url||""})))}},"delete-attachment":{endpoint:"attachments.delete",requireId:"\u274C \u8BF7\u6307\u5B9A\u9644\u4EF6 ID",buildBody:c=>({id:c}),expectOk:!0,print:()=>console.log("\u2705 \u9644\u4EF6\u5DF2\u5220\u9664")}},
|
|
56
|
-
${
|
|
55
|
+
\u65F6\u95F4: ${e.createdAt||""}`)}},"file-op-delete":{endpoint:"fileOperations.delete",requireId:"\u274C \u8BF7\u6307\u5B9A\u6587\u4EF6\u64CD\u4F5C ID",buildBody:c=>({id:c}),expectOk:!0,print:()=>console.log("\u2705 \u6587\u4EF6\u64CD\u4F5C\u8BB0\u5F55\u5DF2\u5220\u9664")},reactions:{endpoint:"reactions.list",requireId:"\u274C \u8BF7\u6307\u5B9A\u8BC4\u8BBA ID",buildBody:c=>({commentId:c}),print:(c,e)=>{let t=c.data||[];if(!t.length){console.log("\u6682\u65E0\u53CD\u5E94");return}e.printTable(t.map(o=>({emoji:o.emoji||"",userId:o.userId||"",\u59D3\u540D:o.user?.name||""})))}},attachments:{endpoint:"attachments.list",buildBody:c=>c?{documentId:c}:{},print:(c,e)=>{let t=c.data||[];if(!t.length){console.log("\u6682\u65E0\u9644\u4EF6");return}e.printTable(t.map(o=>({ID:o.id,\u6587\u4EF6\u540D:o.name,\u7C7B\u578B:o.contentType||"",\u5927\u5C0F:o.size?`${Math.round(o.size/1024)}KB`:"",URL:o.url||""})))}},"delete-attachment":{endpoint:"attachments.delete",requireId:"\u274C \u8BF7\u6307\u5B9A\u9644\u4EF6 ID",buildBody:c=>({id:c}),expectOk:!0,print:()=>console.log("\u2705 \u9644\u4EF6\u5DF2\u5220\u9664")}},de=class{constructor(e){this.argParser=e||null}post(e,t,o,n){return new Promise((s,r)=>{let i=JSON.stringify(t),a=new URL(`${Jt}/${e}`),l={"Content-Type":"application/json","Content-Length":Buffer.byteLength(i),Authorization:`Bearer ${o}`};n&&(l["X-Team-Id"]=n);let d={hostname:a.hostname,port:a.port||443,path:a.pathname,method:"POST",headers:l},u=Mt.request(d,m=>{let p="";m.on("data",f=>p+=f),m.on("end",()=>s({status:m.statusCode,body:p}))});u.on("error",r),u.write(i),u.end()})}parseJson(e){try{return JSON.parse(e)}catch{return null}}extractTeamFlag(e){let t=e.indexOf("--team");if(t!==-1&&e[t+1]){let o=e[t+1],n=[...e.slice(0,t),...e.slice(t+2)];return{teamId:o,remaining:n}}return{teamId:null,remaining:e}}resolveTeamId(e){let{teamId:t}=this.extractTeamFlag(e);if(t)return t;let o=this.argParser?this.argParser.getTeam():null;return o&&o.id?o.id:null}async handle({wikiSubcommand:e,wikiArg:t,wikiRemainingArgs:o,apikey:n}){if(!e||e==="--help"||e==="-h")return this.showHelp(),0;let s=n;if(!s)return console.error("\u274C \u7F3A\u5C11 API Key\uFF0C\u8BF7\u5148\u767B\u5F55: coder auth login"),1;let r=o||[],{teamId:i,remaining:a}=this.extractTeamFlag(r);if(!i&&this.argParser&&this.teamService&&!this.argParser.getTeamManual()){let m=this.argParser.getTeam();if(!m||!m.id)try{let p=encodeURIComponent(JSON.stringify({filter_is_joined:!0})),f=await this.teamService.request("GET",`/team?constraints=${p}&page=1&size=200`,s);if(f.status===200){let g=this.teamService.parseJson(f.body),y=g&&g.data&&g.data.items||[];y.length>0&&this.argParser.setTeam(y[0].id,y[0].name||"")}}catch{}}let l=i||(this.argParser?(()=>{let m=this.argParser.getTeam();return m&&m.id?m.id:null})():null),d=Gt(e);if(typeof this[d]=="function")return await this[d](t,a,s,l);let u=Vt[e];return u?await this._runCommand(u,t,a,s,l):(console.error(`\u274C \u672A\u77E5\u5B50\u547D\u4EE4: ${e}`),this.showHelp(),1)}async _runCommand(e,t,o,n,s){if(e.requireId&&!t)return console.error(e.requireId),1;if(e.requireArgs){let l=e.requireArgs(t,o);if(l)return console.error(l),1}let r=e.buildBody(t,o),i=await this.post(e.endpoint,r,n,s),a=this.parseJson(i.body);return e.expectOk?a?.ok===!1||i.status>=400?(console.error("\u274C \u64CD\u4F5C\u5931\u8D25:",i.body),1):(e.print?e.print(a,this):console.log("\u2705 \u64CD\u4F5C\u6210\u529F"),0):a?.data?(e.print(a,this),0):(console.error("\u274C \u8BF7\u6C42\u5931\u8D25:",i.body),1)}async list(e,t,o,n){let s=t.indexOf("-d"),r=s!==-1?parseInt(t[s+1],10):null;if(!e){let d=await this.post("collections.list",{},o,n),u=this.parseJson(d.body);if(!u?.data)return console.error("\u274C \u8BF7\u6C42\u5931\u8D25:",d.body),1;let m=u.data||[];return m.length?(this.printTable(m.map(p=>({collectionId:p.id,\u96C6\u5408\u540D\u79F0:p.name,\u63CF\u8FF0:p.description||"",URL:le(p.urlId||p.id)}))),0):(console.log("\u6682\u65E0\u96C6\u5408"),0)}if(r===null){let d=await this.post("documents.list",{collectionId:e,sort:"updatedAt",direction:"DESC"},o,n),u=this.parseJson(d.body);if(!u?.data)return console.error("\u274C \u8BF7\u6C42\u5931\u8D25:",d.body),1;let m=u.data||[];return m.length?(this.printTable(m.map(p=>({docId:p.id,\u6807\u9898:p.title,URL:v(p.urlId||p.id)}))),0):(console.log("\u6682\u65E0\u6587\u6863"),0)}let i=await this.post("collections.documents",{id:e},o,n),a=this.parseJson(i.body);if(!a?.data)return console.error("\u274C \u8BF7\u6C42\u5931\u8D25:",i.body),1;let l=r===-1?1/0:r;return this.printTree(a.data,"",l,0),0}async createCollection(e,t,o,n){let s=t.indexOf("--permission"),r="read_write";s!==-1&&(r=t[s+1]||"read_write",t.splice(s,2));let i=t.indexOf("--icon"),a;i!==-1&&(a=t[i+1],t.splice(i,2));let l=t.indexOf("--color"),d;l!==-1&&(d=t[l+1],t.splice(l,2));let u=e||t[0];if(!u)return console.error("\u274C \u8BF7\u6307\u5B9A\u96C6\u5408\u540D\u79F0"),1;let p=t.slice(1).filter(h=>!h.startsWith("--")).join(" "),f={name:u,description:p,sharing:!0};f.permission=r==="null"||r==="none"?null:r,a&&(f.icon=a),d&&(f.color=d);let g=await this.post("collections.create",f,o,n),y=this.parseJson(g.body);return y?.data?(console.log(`\u2705 \u96C6\u5408\u5DF2\u521B\u5EFA: ${y.data.id} \u2014 ${y.data.name}
|
|
56
|
+
${le(y.data.urlId||y.data.id)}`),0):(console.error("\u274C \u521B\u5EFA\u5931\u8D25:",g.body),1)}async updateCollection(e,t,o,n){if(!e)return console.error("\u274C \u8BF7\u6307\u5B9A\u96C6\u5408 ID"),1;let s={id:e},r=t.indexOf("--name");r!==-1&&(s.name=t[r+1]);let i=t.indexOf("--description");i!==-1&&(s.description=t[i+1]);let a=t.indexOf("--permission");if(a!==-1){let p=t[a+1];s.permission=p==="null"||p==="none"?null:p}let l=t.indexOf("--color");l!==-1&&(s.color=t[l+1]);let d=t.indexOf("--sharing");if(d!==-1&&(s.sharing=t[d+1]==="true"),Object.keys(s).length<=1)return console.error("\u274C \u8BF7\u81F3\u5C11\u6307\u5B9A\u4E00\u4E2A\u8981\u66F4\u65B0\u7684\u5B57\u6BB5\uFF08--name, --description, --permission, --color, --sharing\uFF09"),1;let u=await this.post("collections.update",s,o,n),m=this.parseJson(u.body);return m?.data?(console.log(`\u2705 \u96C6\u5408\u5DF2\u66F4\u65B0: ${m.data.id} \u2014 ${m.data.name}`),0):(console.error("\u274C \u66F4\u65B0\u96C6\u5408\u5931\u8D25:",u.body),1)}async deleteCollection(e,t,o,n){if(!e)return console.error("\u274C \u8BF7\u6307\u5B9A\u96C6\u5408 ID"),1;let s=await this.post("collections.delete",{id:e},o,n);return this.parseJson(s.body)?.ok===!1||s.status>=400?(console.error("\u274C \u5220\u9664\u96C6\u5408\u5931\u8D25:",s.body),1):(console.log("\u2705 \u96C6\u5408\u5DF2\u5220\u9664"),0)}async archiveCollection(e,t,o,n){if(!e)return console.error("\u274C \u8BF7\u6307\u5B9A\u96C6\u5408 ID"),1;let s=await this.post("collections.archive",{id:e},o,n);return this.parseJson(s.body)?.data?(console.log("\u2705 \u96C6\u5408\u5DF2\u5F52\u6863"),0):(console.error("\u274C \u5F52\u6863\u96C6\u5408\u5931\u8D25:",s.body),1)}async restoreCollection(e,t,o,n){if(!e)return console.error("\u274C \u8BF7\u6307\u5B9A\u96C6\u5408 ID"),1;let s=await this.post("collections.restore",{id:e},o,n);return this.parseJson(s.body)?.data?(console.log("\u2705 \u96C6\u5408\u5DF2\u6062\u590D"),0):(console.error("\u274C \u6062\u590D\u96C6\u5408\u5931\u8D25:",s.body),1)}async get(e,t,o,n){if(!e)return console.error("\u274C \u8BF7\u6307\u5B9A\u6587\u6863 ID"),1;let s=await this.post("documents.info",{id:e},o,n),r=this.parseJson(s.body);if(!r?.data)return console.error("\u274C \u8BF7\u6C42\u5931\u8D25:",s.body),1;let i=r.data;return console.log(`\u6807\u9898: ${i.title}
|
|
57
57
|
ID: ${i.id}
|
|
58
58
|
\u96C6\u5408: ${i.collectionId}
|
|
59
59
|
\u66F4\u65B0: ${i.updatedAt}`),i.text&&console.log(`
|
|
60
|
-
${i.text}`),0}async publish(e,t,o,
|
|
61
|
-
wiki publish <collectionId> --file <path> [--parent <parentDocId>]`),1;let i,a,l,d=t.indexOf("--file"),u=t.indexOf("--parent");if(u!==-1&&(l=t[u+1]),d!==-1){let
|
|
62
|
-
${
|
|
60
|
+
${i.text}`),0}async publish(e,t,o,n){let s=require("fs"),r=require("path");if(!e)return console.error(`\u274C \u7528\u6CD5: wiki publish <collectionId> <title> [text]
|
|
61
|
+
wiki publish <collectionId> --file <path> [--parent <parentDocId>]`),1;let i,a,l,d=t.indexOf("--file"),u=t.indexOf("--parent");if(u!==-1&&(l=t[u+1]),d!==-1){let I=t[d+1];if(!I)return console.error("\u274C \u8BF7\u6307\u5B9A --file \u8DEF\u5F84"),1;let b=r.resolve(I);if(!s.existsSync(b))return console.error(`\u274C \u6587\u4EF6\u4E0D\u5B58\u5728: ${b}`),1;a=s.readFileSync(b,"utf8");let S=a.match(/^#\s+(.+)/m);if(!S)return console.error("\u274C \u6587\u4EF6\u7F3A\u5C11 H1 \u6807\u9898\uFF08# \u6807\u9898\uFF09\uFF0C\u8BF7\u6DFB\u52A0\u540E\u91CD\u8BD5"),1;i=S[1].trim(),a=a.replace(/^#\s+.+\n?/,"").trimStart()}else if(i=t[1],a=t.slice(2).join(" "),!i)return console.error("\u274C \u8BF7\u6307\u5B9A\u6587\u6863\u6807\u9898"),1;let m={collectionId:e,title:i,text:"",publish:!0};l&&(m.parentDocumentId=l);let p=await this.post("documents.create",m,o,n),f=this.parseJson(p.body);if(!f?.data)return console.error("\u274C \u521B\u5EFA\u6587\u6863\u5931\u8D25:",p.body),1;let g=f.data.id;console.log(` \u521B\u5EFA\u6587\u6863: ${g}`);let y=await this.post("documents.update",{id:g,title:i,text:a,publish:!0},o,n),h=this.parseJson(y.body);return h?.data?(console.log(`\u2705 \u6587\u6863\u5DF2\u53D1\u5E03: ${h.data.title}
|
|
62
|
+
${v(h.data.urlId||g)}`),0):(console.error("\u274C \u66F4\u65B0\u5185\u5BB9\u5931\u8D25:",y.body),1)}async update(e,t,o,n){let s=require("fs"),r=require("path");if(!e)return console.error("\u274C \u7528\u6CD5: wiki update <docId> <title> [text] | <docId> --file <path>"),1;let i,a,l=t.indexOf("--file");if(l!==-1){let p=t[l+1];if(!p)return console.error("\u274C \u8BF7\u6307\u5B9A --file \u8DEF\u5F84"),1;let f=r.resolve(p);if(!s.existsSync(f))return console.error(`\u274C \u6587\u4EF6\u4E0D\u5B58\u5728: ${f}`),1;a=s.readFileSync(f,"utf8");let g=a.match(/^#\s+(.+)/m);if(!g)return console.error("\u274C \u6587\u4EF6\u7F3A\u5C11 H1 \u6807\u9898\uFF08# \u6807\u9898\uFF09\uFF0C\u8BF7\u6DFB\u52A0\u540E\u91CD\u8BD5"),1;i=g[1].trim(),a=a.replace(/^#\s+.+\n?/,"").trimStart()}else if(i=t[1],a=t.slice(2).join(" "),!i)return console.error("\u274C \u8BF7\u6307\u5B9A\u6587\u6863\u6807\u9898"),1;let d={id:e,title:i,publish:!0};a&&(d.text=a);let u=await this.post("documents.update",d,o,n),m=this.parseJson(u.body);return m?.data?(console.log(`\u2705 \u6587\u6863\u5DF2\u66F4\u65B0: ${m.data.title}`),0):(console.error("\u274C \u66F4\u65B0\u5931\u8D25:",u.body),1)}async delete(e,t,o,n){if(!e)return console.error("\u274C \u8BF7\u6307\u5B9A\u6587\u6863 ID"),1;let s=t.includes("--permanent"),r=await this.post("documents.delete",{id:e,...s?{permanent:!0}:{}},o,n);return this.parseJson(r.body)?.ok===!1||r.status>=400?(console.error("\u274C \u5220\u9664\u5931\u8D25:",r.body),1):(console.log(`\u2705 \u6587\u6863\u5DF2${s?"\u6C38\u4E45":""}\u5220\u9664`),0)}async move(e,t,o,n){if(!e)return console.error("\u274C \u7528\u6CD5: wiki move <docId> [collectionId] [parentDocId]"),1;let s={id:e,index:0};t[1]&&(s.collectionId=t[1]),t[2]&&(s.parentDocumentId=t[2]);let r=await this.post("documents.move",s,o,n);return this.parseJson(r.body)?.data?(console.log("\u2705 \u6587\u6863\u5DF2\u79FB\u52A8"),0):(console.error("\u274C \u79FB\u52A8\u5931\u8D25:",r.body),1)}async archive(e,t,o,n){if(!e)return console.error("\u274C \u8BF7\u6307\u5B9A\u6587\u6863 ID"),1;let s=await this.post("documents.archive",{id:e},o,n);return this.parseJson(s.body)?.data?(console.log("\u2705 \u6587\u6863\u5DF2\u5F52\u6863"),0):(console.error("\u274C \u5F52\u6863\u5931\u8D25:",s.body),1)}async restore(e,t,o,n){if(!e)return console.error("\u274C \u8BF7\u6307\u5B9A\u6587\u6863 ID"),1;let s={id:e},r=t.indexOf("--revision");r!==-1&&t[r+1]&&(s.revisionId=t[r+1]);let i=t.indexOf("--collection");i!==-1&&t[i+1]&&(s.collectionId=t[i+1]);let a=await this.post("documents.restore",s,o,n);return this.parseJson(a.body)?.data?(console.log("\u2705 \u6587\u6863\u5DF2\u6062\u590D"),0):(console.error("\u274C \u6062\u590D\u5931\u8D25:",a.body),1)}async revisions(e,t,o,n){if(!e)return console.error("\u274C \u8BF7\u6307\u5B9A\u6587\u6863 ID"),1;let s=await this.post("revisions.list",{documentId:e,sort:"createdAt",direction:"DESC"},o,n),r=this.parseJson(s.body);if(!r?.data)return console.error("\u274C \u8BF7\u6C42\u5931\u8D25:",s.body),1;let i=r.data||[];return i.length?(this.printTable(i.map(a=>({revisionId:a.id,\u7248\u672C\u540D:a.name||"",\u521B\u5EFA\u65F6\u95F4:a.createdAt}))),0):(console.log("\u6682\u65E0\u5386\u53F2\u7248\u672C"),0)}async revision(e,t,o,n){if(!e)return console.error("\u274C \u8BF7\u6307\u5B9A\u7248\u672C ID"),1;let s=await this.post("revisions.info",{id:e},o,n),r=this.parseJson(s.body);if(!r?.data)return console.error("\u274C \u8BF7\u6C42\u5931\u8D25:",s.body),1;let i=r.data;return console.log(`\u7248\u672C ID: ${i.id}
|
|
63
63
|
\u7248\u672C\u540D: ${i.name||""}
|
|
64
64
|
\u6587\u6863 ID: ${i.documentId}
|
|
65
65
|
\u521B\u5EFA\u65F6\u95F4: ${i.createdAt}`),i.text&&console.log(`
|
|
66
|
-
${i.text}`),0}async drafts(e,t,o,
|
|
67
|
-
`),this.printTable(a.map(l=>{let d=l.document||l;return{docId:d.id,\u6807\u9898:d.title,URL:
|
|
66
|
+
${i.text}`),0}async drafts(e,t,o,n){let s=await this.post("documents.drafts",{sort:"updatedAt",direction:"DESC"},o,n),r=this.parseJson(s.body);if(!r?.data)return console.error("\u274C \u8BF7\u6C42\u5931\u8D25:",s.body),1;let i=r.data||[];return i.length?(this.printTable(i.map(a=>({ID:a.id,\u6807\u9898:a.title,URL:v(a.urlId||a.id)}))),0):(console.log("\u6682\u65E0\u8349\u7A3F"),0)}async recent(e,t,o,n){let s=await this.post("documents.viewed",{sort:"updatedAt",direction:"DESC"},o,n),r=this.parseJson(s.body);if(!r?.data)return console.error("\u274C \u8BF7\u6C42\u5931\u8D25:",s.body),1;let i=r.data||[];return i.length?(this.printTable(i.map(a=>({ID:a.id,\u6807\u9898:a.title,URL:v(a.urlId||a.id)}))),0):(console.log("\u6682\u65E0\u6D4F\u89C8\u8BB0\u5F55"),0)}async search(e,t,o,n){if(!e)return console.error("\u274C \u8BF7\u6307\u5B9A\u641C\u7D22\u5173\u952E\u8BCD"),1;let s=[e,...t.slice(1)].join(" "),r=await this.post("documents.search",{query:s,snippetMinWords:20,snippetMaxWords:30},o,n),i=this.parseJson(r.body);if(!i?.data)return console.error("\u274C \u641C\u7D22\u5931\u8D25:",r.body),1;let a=i.data||[];return a.length?(console.log(`\u627E\u5230 ${a.length} \u4E2A\u7ED3\u679C:
|
|
67
|
+
`),this.printTable(a.map(l=>{let d=l.document||l;return{docId:d.id,\u6807\u9898:d.title,URL:v(d.urlId||d.id)}})),0):(console.log(`\u6CA1\u6709\u627E\u5230\u4E0E "${s}" \u76F8\u5173\u7684\u6587\u6863`),0)}async stars(e,t,o,n){let s=await this.post("stars.list",{},o,n),r=this.parseJson(s.body);if(!r?.data)return console.error("\u274C \u8BF7\u6C42\u5931\u8D25:",s.body),1;let i=r.data.stars||[];if(!i.length)return console.log("\u6682\u65E0\u6536\u85CF"),0;let a={};for(let l of r.data.documents||[])a[l.id]=l;return this.printTable(i.map(l=>{let d=l.documentId?a[l.documentId]:null,u=l.collectionId?{urlId:l.collectionId}:null;return{starId:l.id,\u6807\u9898:d?.title||l.collectionId||l.documentId||"",URL:d?v(d.urlId||d.id):u?le(u.urlId):l.documentId?v(l.documentId):""}})),0}async star(e,t,o,n){if(!e)return console.error("\u274C \u8BF7\u6307\u5B9A\u6587\u6863\u6216\u96C6\u5408 ID"),1;let r=t.includes("--collection")?{collectionId:e}:{documentId:e},i=await this.post("stars.create",r,o,n);return this.parseJson(i.body)?.data?(console.log("\u2705 \u5DF2\u6536\u85CF"),0):(console.error("\u274C \u6536\u85CF\u5931\u8D25:",i.body),1)}async unstar(e,t,o,n){if(!e)return console.error("\u274C \u8BF7\u6307\u5B9A\u6536\u85CF ID"),1;let s=await this.post("stars.delete",{id:e},o,n);return s.status>=400?(console.error("\u274C \u53D6\u6D88\u6536\u85CF\u5931\u8D25:",s.body),1):(console.log("\u2705 \u5DF2\u53D6\u6D88\u6536\u85CF"),0)}async pins(e,t,o,n){let s=e?{collectionId:e}:{},r=await this.post("pins.list",s,o,n),i=this.parseJson(r.body);if(!i?.data)return console.error("\u274C \u8BF7\u6C42\u5931\u8D25:",r.body),1;let a=i.data.pins||[];if(!a.length)return console.log("\u6682\u65E0\u7F6E\u9876"),0;let l={};for(let d of i.data.documents||[])l[d.id]=d;return this.printTable(a.map(d=>{let u=d.documentId?l[d.documentId]:null;return{pinId:d.id,\u6807\u9898:u?.title||d.documentId,URL:v(u?.urlId||d.documentId)}})),0}async pin(e,t,o,n){if(!e)return console.error("\u274C \u8BF7\u6307\u5B9A\u6587\u6863 ID"),1;let s={documentId:e,...t[1]?{collectionId:t[1]}:{}},r=await this.post("pins.create",s,o,n),i=this.parseJson(r.body);return i?.data?(console.log(`\u2705 \u5DF2\u7F6E\u9876: ${i.data.id}`),0):(console.error("\u274C \u7F6E\u9876\u5931\u8D25:",r.body),1)}async unpin(e,t,o,n){if(!e)return console.error("\u274C \u8BF7\u6307\u5B9A\u7F6E\u9876 ID"),1;let s=await this.post("pins.delete",{id:e},o,n);return s.status>=400?(console.error("\u274C \u53D6\u6D88\u7F6E\u9876\u5931\u8D25:",s.body),1):(console.log("\u2705 \u5DF2\u53D6\u6D88\u7F6E\u9876"),0)}async comments(e,t,o,n){if(!e)return console.error("\u274C \u8BF7\u6307\u5B9A\u6587\u6863 ID"),1;let s=await this.post("comments.list",{documentId:e,sort:"createdAt",direction:"ASC"},o,n),r=this.parseJson(s.body);if(!r?.data)return console.error("\u274C \u8BF7\u6C42\u5931\u8D25:",s.body),1;let i=r.data||[];if(!i.length)return console.log("\u6682\u65E0\u8BC4\u8BBA"),0;for(let a of i){let l=this.extractCommentText(a.data);console.log(` [${a.id}] ${a.createdBy?.name||"?"}: ${l}`)}return 0}async comment(e,t,o,n){let s=t.slice(1).join(" ");if(!e||!s)return console.error("\u274C \u7528\u6CD5: wiki comment <docId> <text>"),1;let r=await this.post("comments.create",{documentId:e,text:s},o,n),i=this.parseJson(r.body);return i?.data?(console.log(`\u2705 \u8BC4\u8BBA\u5DF2\u53D1\u5E03: ${i.data.id}`),0):(console.error("\u274C \u8BC4\u8BBA\u5931\u8D25:",r.body),1)}printTree(e,t,o,n){if(Array.isArray(e))for(let s=0;s<e.length;s++){let r=e[s],i=s===e.length-1,a=i?"\u2514\u2500\u2500 ":"\u251C\u2500\u2500 ",l=r.url?`${Y}${r.url}`:v(r.id);console.log(`${t}${a}${r.title||r.id} \x1B[90m${l}\x1B[0m`),r.children?.length&&n+1<o&&this.printTree(r.children,t+(i?" ":"\u2502 "),o,n+1)}}printTable(e){if(!e.length)return;let t=Object.keys(e[0]),o=i=>[...String(i)].reduce((a,l)=>a+(l.charCodeAt(0)>127?2:1),0),n=(i,a)=>i+" ".repeat(Math.max(0,a-o(i))),s=t.map(i=>Math.max(o(i),...e.map(a=>o(a[i]||"")))),r=s.map(i=>"-".repeat(i)).join("-+-");console.log(t.map((i,a)=>n(i,s[a])).join(" | ")),console.log(r);for(let i of e)console.log(t.map((a,l)=>n(String(i[a]||""),s[l])).join(" | "))}icons(e,t){let o=[{name:"academicCap",keywords:"\u5B66\u4E60 \u6559\u5B66 \u8BFE\u7A0B \u6307\u5357 \u6559\u7A0B \u57F9\u8BAD \u5165\u95E8"},{name:"beaker",keywords:"\u5B9E\u9A8C\u5BA4 \u7814\u7A76 \u5B9E\u9A8C \u6D4B\u8BD5"},{name:"bicycle",keywords:"\u81EA\u884C\u8F66 \u9A91\u884C"},{name:"bookmark",keywords:"\u4E66\u7B7E \u6536\u85CF"},{name:"browser",keywords:"\u6D4F\u89C8\u5668 \u7F51\u9875 \u5E94\u7528"},{name:"buildingBlocks",keywords:"\u79EF\u6728 \u6A21\u5757 \u4EA7\u54C1 \u539F\u578B"},{name:"camera",keywords:"\u76F8\u673A \u7167\u7247 \u56FE\u7247"},{name:"carrot",keywords:"\u98DF\u7269 \u852C\u83DC \u519C\u4EA7\u54C1"},{name:"clock",keywords:"\u65F6\u949F \u65F6\u95F4"},{name:"cloud",keywords:"\u4E91 \u4E91\u670D\u52A1 \u57FA\u7840\u8BBE\u65BD"},{name:"code",keywords:"\u4EE3\u7801 \u5F00\u53D1 \u7F16\u7A0B \u5DE5\u7A0B API"},{name:"coins",keywords:"\u91D1\u5E01 \u91D1\u94B1 \u8D22\u52A1 \u9500\u552E \u6536\u5165 \u73B0\u91D1"},{name:"collection",keywords:"\u96C6\u5408 \u6587\u4EF6\u5939"},{name:"database",keywords:"\u6570\u636E\u5E93 \u670D\u52A1\u5668 \u8FD0\u7EF4"},{name:"done",keywords:"\u5B8C\u6210 \u6210\u529F \u52FE\u9009 \u7ED3\u675F"},{name:"email",keywords:"\u90AE\u4EF6 \u90AE\u7BB1"},{name:"eye",keywords:"\u773C\u775B \u67E5\u770B \u9884\u89C8"},{name:"feedback",keywords:"\u53CD\u9988 \u5E2E\u52A9 \u652F\u6301 FAQ"},{name:"flame",keywords:"\u706B\u7130 \u70ED\u95E8"},{name:"globe",keywords:"\u5730\u7403 \u7FFB\u8BD1 \u56FD\u9645\u5316"},{name:"graph",keywords:"\u56FE\u8868 \u5206\u6790 \u6570\u636E \u7EDF\u8BA1"},{name:"hashtag",keywords:"\u6807\u7B7E \u8BDD\u9898 \u793E\u4EA4\u5A92\u4F53"},{name:"icecream",keywords:"\u51B0\u6DC7\u6DCB \u751C\u70B9 \u98DF\u7269"},{name:"image",keywords:"\u56FE\u7247 \u56FE\u50CF \u7167\u7247"},{name:"info",keywords:"\u4FE1\u606F \u8BF4\u660E"},{name:"internet",keywords:"\u7F51\u7EDC \u5168\u7403 \u4E92\u8054\u7F51"},{name:"leaf",keywords:"\u53F6\u5B50 \u690D\u7269 \u81EA\u7136 \u751F\u6001 \u73AF\u5883"},{name:"letter",keywords:"\u5B57\u6BCD \u4FE1\u4EF6"},{name:"library",keywords:"\u56FE\u4E66\u9986 \u6587\u5E93 \u5F52\u6863"},{name:"lightbulb",keywords:"\u706F\u6CE1 \u60F3\u6CD5 \u521B\u610F"},{name:"lightning",keywords:"\u95EA\u7535 \u5FEB\u901F"},{name:"math",keywords:"\u6570\u5B66 \u516C\u5F0F"},{name:"moon",keywords:"\u6708\u4EAE \u591C\u665A \u6697\u8272"},{name:"notepad",keywords:"\u8BB0\u4E8B\u672C \u7B14\u8BB0 \u65E5\u5FD7 \u5199\u4F5C"},{name:"padlock",keywords:"\u9501 \u79C1\u5BC6 \u5B89\u5168 \u8BA4\u8BC1 \u6743\u9650"},{name:"palette",keywords:"\u8C03\u8272\u677F \u8BBE\u8BA1 \u827A\u672F \u54C1\u724C"},{name:"pencil",keywords:"\u94C5\u7B14 \u5199\u4F5C \u535A\u5BA2 \u6587\u7AE0"},{name:"plane",keywords:"\u98DE\u673A \u65C5\u884C \u51FA\u884C \u5047\u671F"},{name:"promote",keywords:"\u63A8\u5E7F \u8425\u9500 \u5BA3\u4F20"},{name:"question",keywords:"\u95EE\u9898 \u5E2E\u52A9 \u652F\u6301 FAQ"},{name:"ramen",keywords:"\u62C9\u9762 \u6C64 \u98DF\u7269 \u9910\u996E"},{name:"server",keywords:"\u670D\u52A1\u5668 \u8FD0\u7EF4 \u57FA\u7840\u8BBE\u65BD"},{name:"shapes",keywords:"\u5F62\u72B6 \u79EF\u6728 \u73A9\u5177"},{name:"smiley",keywords:"\u7B11\u8138 \u8868\u60C5 \u5F00\u5FC3"},{name:"sport",keywords:"\u8FD0\u52A8 \u6237\u5916 \u6E38\u620F"},{name:"sun",keywords:"\u592A\u9633 \u767D\u5929 \u5929\u6C14"},{name:"target",keywords:"\u76EE\u6807 \u9500\u552E \u6307\u6807"},{name:"team",keywords:"\u56E2\u961F \u7EC4\u7EC7 \u529E\u516C\u5BA4"},{name:"terminal",keywords:"\u7EC8\u7AEF \u547D\u4EE4\u884C \u4EE3\u7801"},{name:"thumbsup",keywords:"\u70B9\u8D5E \u6536\u85CF \u793E\u4EA4 \u6295\u7968"},{name:"tools",keywords:"\u5DE5\u5177 \u8BBE\u7F6E \u914D\u7F6E"},{name:"truck",keywords:"\u5361\u8F66 \u8FD0\u8F93 \u7269\u6D41"},{name:"vehicle",keywords:"\u8F66\u8F86 \u4EA4\u901A \u51FA\u884C"},{name:"warning",keywords:"\u8B66\u544A \u63D0\u793A \u9519\u8BEF"}],n=t.indexOf("--query"),s=n!==-1?t[n+1]:e||"",r=s?o.filter(i=>i.name.toLowerCase().includes(s.toLowerCase())||i.keywords.toLowerCase().includes(s.toLowerCase())):o;return r.length?(console.log(`\u5171 ${r.length} \u4E2A\u56FE\u6807${s?`\uFF08\u5173\u952E\u8BCD: "${s}"\uFF09`:""}:
|
|
68
68
|
`),this.printTable(r.map(i=>({\u56FE\u6807\u540D:i.name,\u5173\u952E\u8BCD:i.keywords}))),console.log(`
|
|
69
69
|
\u7528\u6CD5\u793A\u4F8B:`),console.log(` coder wiki create-collection "\u6211\u7684\u96C6\u5408" --icon ${r[0].name}`),console.log(` coder wiki update-collection <id> --icon ${r[0].name}`),console.log(`
|
|
70
|
-
\u63D0\u793A: \u4E5F\u53EF\u4EE5\u76F4\u63A5\u4F7F\u7528 emoji\uFF0C\u5982 --icon \u{1F4DA}`),0):(console.log(`\u6CA1\u6709\u627E\u5230\u4E0E "${
|
|
70
|
+
\u63D0\u793A: \u4E5F\u53EF\u4EE5\u76F4\u63A5\u4F7F\u7528 emoji\uFF0C\u5982 --icon \u{1F4DA}`),0):(console.log(`\u6CA1\u6709\u627E\u5230\u4E0E "${s}" \u76F8\u5173\u7684\u56FE\u6807`),0)}async upload(e,t,o,n){let s=require("fs"),r=require("path"),i=t[1];if(!e||!i)return console.error("\u274C \u7528\u6CD5: wiki upload <docId> <filePath>"),1;let a=r.resolve(i);if(!s.existsSync(a))return console.error(`\u274C \u6587\u4EF6\u4E0D\u5B58\u5728: ${a}`),1;let l=s.readFileSync(a),d=r.basename(a),u=l.length,m=this._getContentType(a),p=await this.post("attachments.create",{name:d,documentId:e,size:u,contentType:m,preset:"documentAttachment"},o,n),f=this.parseJson(p.body);if(!f?.data)return console.error("\u274C \u521B\u5EFA\u9644\u4EF6\u5931\u8D25:",p.body),1;let{uploadUrl:g,form:y,attachment:h}=f.data;console.log(` \u4E0A\u4F20\u4E2D: ${d} (${Math.round(u/1024)}KB)`);let I=await this._uploadToS3(g,y,l,d,m);if(I.status>=300)return console.error(`\u274C \u4E0A\u4F20\u5931\u8D25 (HTTP ${I.status}):`,I.body.slice(0,300)),1;console.log(`\u2705 \u6587\u4EF6\u5DF2\u4E0A\u4F20: ${h.name}`),console.log(` ID: ${h.id}`),console.log(` URL: ${h.url}`);let b=m.startsWith("image/")?``:`[${h.name}](${h.url})`;return console.log(`
|
|
71
71
|
\u5728 Markdown \u4E2D\u4F7F\u7528:
|
|
72
|
-
${
|
|
72
|
+
${b}`),0}async uploadUrl(e,t,o,n){let s=t[1];if(!e||!s)return console.error("\u274C \u7528\u6CD5: wiki upload-url <docId> <url>"),1;let r=await this.post("attachments.createFromUrl",{url:s,documentId:e,preset:"documentAttachment"},o,n),i=this.parseJson(r.body);if(!i?.data)return console.error("\u274C \u4ECE URL \u521B\u5EFA\u9644\u4EF6\u5931\u8D25:",r.body),1;let a=i.data;console.log(`\u2705 \u9644\u4EF6\u5DF2\u521B\u5EFA: ${a.name}`),console.log(` ID: ${a.id}`),console.log(` URL: ${a.url}`);let l=a.contentType?.startsWith("image/")?``:`[${a.name}](${a.url})`;return console.log(`
|
|
73
73
|
\u5728 Markdown \u4E2D\u4F7F\u7528:
|
|
74
|
-
${l}`),0}_getContentType(e){let t=e.split(".").pop().toLowerCase();return{jpg:"image/jpeg",jpeg:"image/jpeg",png:"image/png",gif:"image/gif",webp:"image/webp",svg:"image/svg+xml",bmp:"image/bmp",ico:"image/x-icon",pdf:"application/pdf",doc:"application/msword",docx:"application/vnd.openxmlformats-officedocument.wordprocessingml.document",xls:"application/vnd.ms-excel",xlsx:"application/vnd.openxmlformats-officedocument.spreadsheetml.sheet",ppt:"application/vnd.ms-powerpoint",pptx:"application/vnd.openxmlformats-officedocument.presentationml.presentation",txt:"text/plain",md:"text/markdown",csv:"text/csv",zip:"application/zip",tar:"application/x-tar",gz:"application/gzip",mp4:"video/mp4",mov:"video/quicktime",avi:"video/x-msvideo",mp3:"audio/mpeg",wav:"audio/wav",json:"application/json",xml:"application/xml"}[t]||"application/octet-stream"}_uploadToS3(e,t,o,s
|
|
75
|
-
Content-Disposition: form-data; name="${
|
|
74
|
+
${l}`),0}_getContentType(e){let t=e.split(".").pop().toLowerCase();return{jpg:"image/jpeg",jpeg:"image/jpeg",png:"image/png",gif:"image/gif",webp:"image/webp",svg:"image/svg+xml",bmp:"image/bmp",ico:"image/x-icon",pdf:"application/pdf",doc:"application/msword",docx:"application/vnd.openxmlformats-officedocument.wordprocessingml.document",xls:"application/vnd.ms-excel",xlsx:"application/vnd.openxmlformats-officedocument.spreadsheetml.sheet",ppt:"application/vnd.ms-powerpoint",pptx:"application/vnd.openxmlformats-officedocument.presentationml.presentation",txt:"text/plain",md:"text/markdown",csv:"text/csv",zip:"application/zip",tar:"application/x-tar",gz:"application/gzip",mp4:"video/mp4",mov:"video/quicktime",avi:"video/x-msvideo",mp3:"audio/mpeg",wav:"audio/wav",json:"application/json",xml:"application/xml"}[t]||"application/octet-stream"}_uploadToS3(e,t,o,n,s){return new Promise((r,i)=>{let a=`----FormBoundary${Math.random().toString(36).slice(2)}${Date.now()}`,l=[];for(let[h,I]of Object.entries(t))l.push(Buffer.from(`--${a}\r
|
|
75
|
+
Content-Disposition: form-data; name="${h}"\r
|
|
76
76
|
\r
|
|
77
|
-
${
|
|
77
|
+
${I}\r
|
|
78
78
|
`));let d=Buffer.from(`--${a}\r
|
|
79
|
-
Content-Disposition: form-data; name="file"; filename="${
|
|
80
|
-
Content-Type: ${
|
|
79
|
+
Content-Disposition: form-data; name="file"; filename="${n}"\r
|
|
80
|
+
Content-Type: ${s}\r
|
|
81
81
|
\r
|
|
82
82
|
`),u=Buffer.from(`\r
|
|
83
83
|
--${a}--\r
|
|
84
|
-
`),p=Buffer.concat([...l,d,o,u]),h=new URL(e),f=h.protocol==="https:"?require("https"):require("http"),g={hostname:h.hostname,port:h.port||(h.protocol==="https:"?443:80),path:h.pathname+h.search,method:"POST",headers:{"Content-Type":`multipart/form-data; boundary=${a}`,"Content-Length":p.length}},y=f.request(g,m=>{let b="";m.on("data",w=>b+=w),m.on("end",()=>r({status:m.statusCode,body:b}))});y.on("error",i),y.write(p),y.end()})}extractCommentText(e){return e?.content?e.content.flatMap(t=>t.content||[]).filter(t=>t.type==="text").map(t=>t.text).join(""):""}showHelp(){console.log(["Usage: coder wiki [subcommand] [options]","","Global Options:"," --team <teamId> \u6307\u5B9A\u56E2\u961F\u4E0A\u4E0B\u6587\uFF08X-Team-Id\uFF09\uFF0C\u9ED8\u8BA4\u4F7F\u7528 coder team use \u8BBE\u7F6E\u7684\u56E2\u961F","","Collection Management:"," list \u5217\u51FA\u6240\u6709\u96C6\u5408"," list <collectionId> \u5217\u51FA\u96C6\u5408\u4E0B\u7684\u6839\u6587\u6863\uFF08\u8868\u683C\uFF09"," list <collectionId> -d <depth> \u5C55\u5F00\u6587\u6863\u6811\uFF08-d -1 \u5168\u90E8\u5C55\u5F00\uFF09"," create-collection <name> [desc] [--permission <perm>] [--icon <icon>] [--color <color>]"," \u521B\u5EFA\u96C6\u5408 (perm: read_write|read|null; icon: emoji \u6216\u56FE\u6807\u540D; color: \u5341\u516D\u8FDB\u5236\u989C\u8272\u5982 #4A90E2)"," icons [keyword] \u5217\u51FA\u6240\u6709\u652F\u6301\u7684\u56FE\u6807\u540D\uFF08\u53EF\u6309\u5173\u952E\u8BCD\u8FC7\u6EE4\uFF09"," update-collection <id> [--name <n>] [--description <d>] [--permission <p>] [--color <c>] [--sharing <bool>]"," \u66F4\u65B0\u96C6\u5408"," archive-collection <id> \u5F52\u6863\u96C6\u5408"," restore-collection <id> \u6062\u590D\u5DF2\u5F52\u6863\u96C6\u5408"," delete-collection <id> \u5220\u9664\u96C6\u5408"," collection-info <id> \u67E5\u770B\u96C6\u5408\u8BE6\u60C5"," collection-members <id> [--query <q>] [--permission <p>] \u96C6\u5408\u6210\u5458\u5217\u8868"," collection-add-user <id> <userId> [--permission <p>] \u6DFB\u52A0\u7528\u6237\u5230\u96C6\u5408"," collection-remove-user <id> <userId> \u4ECE\u96C6\u5408\u79FB\u9664\u7528\u6237"," collection-add-group <id> <groupId> [--permission <p>] \u6DFB\u52A0\u7FA4\u7EC4\u5230\u96C6\u5408"," collection-remove-group <id> <groupId> \u4ECE\u96C6\u5408\u79FB\u9664\u7FA4\u7EC4"," collection-group-members <id> \u96C6\u5408\u7FA4\u7EC4\u6210\u5458\u5217\u8868"," collection-export <id> [--format outline|markdown_zip] \u5BFC\u51FA\u96C6\u5408"," export-all [--format outline|markdown_zip] \u5BFC\u51FA\u6240\u6709\u96C6\u5408"," collection-move <id> <index> \u79FB\u52A8\u96C6\u5408\u4F4D\u7F6E","","Document Management:"," get <docId> \u67E5\u770B\u6587\u6863"," publish <collectionId> <title> [text] \u521B\u5EFA\u5E76\u53D1\u5E03\u6587\u6863"," publish <collectionId> --file <path> [--parent <parentDocId>]"," \u4ECE Markdown \u6587\u4EF6\u53D1\u5E03\uFF08\u9700\u542B H1 \u6807\u9898\uFF09"," update <docId> <title> [text] \u66F4\u65B0\u6587\u6863"," update <docId> --file <path> \u4ECE Markdown \u6587\u4EF6\u66F4\u65B0\u6587\u6863"," delete <docId> [--permanent] \u5220\u9664\u6587\u6863"," move <docId> [collectionId] [parentId] \u79FB\u52A8\u6587\u6863"," archive <docId> \u5F52\u6863\u6587\u6863"," restore <docId> [--revision <revisionId>] [--collection <collectionId>]"," \u6062\u590D\u6587\u6863"," archived [--collection <id>] \u5DF2\u5F52\u6863\u6587\u6863\u5217\u8868"," deleted \u5DF2\u5220\u9664\u6587\u6863\u5217\u8868"," insights <id> [--start-date <d>] [--end-date <d>] \u6587\u6863\u8BBF\u95EE\u7EDF\u8BA1"," export <id> [--include-children] \u5BFC\u51FA\u6587\u6863"," search-titles <query> \u6309\u6807\u9898\u641C\u7D22"," duplicate <id> [--title <t>] [--recursive] [--publish] [--collection <id>] [--parent <id>]"," \u590D\u5236\u6587\u6863"," unpublish <id> \u53D6\u6D88\u53D1\u5E03"," templatize <id> [--collection <collectionId>] \u8F6C\u4E3A\u6A21\u677F\uFF08\u9700\u6307\u5B9A\u96C6\u5408\u6216\u7BA1\u7406\u5458\u6743\u9650\uFF09"," doc-members <id> \u6587\u6863\u6210\u5458\u5217\u8868"," doc-add-user <id> <userId> [--permission <p>] \u6DFB\u52A0\u7528\u6237\u5230\u6587\u6863"," doc-remove-user <id> <userId> \u4ECE\u6587\u6863\u79FB\u9664\u7528\u6237"," doc-add-group <id> <groupId> [--permission <p>] \u6DFB\u52A0\u7FA4\u7EC4\u5230\u6587\u6863"," doc-remove-group <id> <groupId> \u4ECE\u6587\u6863\u79FB\u9664\u7FA4\u7EC4"," doc-group-members <id> \u6587\u6863\u7FA4\u7EC4\u6210\u5458\u5217\u8868"," empty-trash \u6E05\u7A7A\u56DE\u6536\u7AD9"," sub-docs <id> \u5B50\u6587\u6863\u5217\u8868","","Revision History:"," revisions <docId> \u5217\u51FA\u6587\u6863\u5386\u53F2\u7248\u672C"," revision <revisionId> \u67E5\u770B\u6307\u5B9A\u5386\u53F2\u7248\u672C\u5185\u5BB9","","Discovery:"," drafts \u8349\u7A3F\u5217\u8868"," recent \u6700\u8FD1\u6D4F\u89C8"," search <keyword> \u5168\u6587\u641C\u7D22","","Favorites & Pins:"," stars \u6536\u85CF\u5217\u8868"," star <id> [--collection] \u6536\u85CF\u6587\u6863\u6216\u96C6\u5408"," unstar <starId> \u53D6\u6D88\u6536\u85CF"," pins [collectionId] \u7F6E\u9876\u5217\u8868"," pin <docId> [collectionId] \u7F6E\u9876\u6587\u6863"," unpin <pinId> \u53D6\u6D88\u7F6E\u9876","","Comments:"," comments <docId> \u67E5\u770B\u8BC4\u8BBA"," comment <docId> <text> \u53D1\u8868\u8BC4\u8BBA","","Shares:"," shares [--document <id>] \u5206\u4EAB\u5217\u8868"," share-info <id> \u67E5\u770B\u5206\u4EAB\u8BE6\u60C5"," share <documentId> [--published] [--include-children] \u521B\u5EFA\u5206\u4EAB"," share-update <id> [--published] [--no-published] [--include-children] \u66F4\u65B0\u5206\u4EAB"," unshare <id> \u64A4\u9500\u5206\u4EAB","","Users:"," users [--query <q>] [--filter invited|viewers|admins|members|active|all|suspended]"," \u7528\u6237\u5217\u8868"," user-info <id> \u67E5\u770B\u7528\u6237\u8BE6\u60C5"," invite <email> <name> <role> \u9080\u8BF7\u7528\u6237"," user-update-role <id> <role> \u66F4\u65B0\u7528\u6237\u89D2\u8272 (admin|member|viewer)"," user-suspend <id> \u6682\u505C\u7528\u6237"," user-activate <id> \u6FC0\u6D3B\u7528\u6237","","Groups:"," groups [--query <q>] \u7FA4\u7EC4\u5217\u8868"," group-info <id> \u67E5\u770B\u7FA4\u7EC4\u8BE6\u60C5"," create-group <name> \u521B\u5EFA\u7FA4\u7EC4"," update-group <id> --name <name> \u66F4\u65B0\u7FA4\u7EC4"," delete-group <id> \u5220\u9664\u7FA4\u7EC4"," group-members <id> \u7FA4\u7EC4\u6210\u5458\u5217\u8868"," group-add-user <id> <userId> \u6DFB\u52A0\u7528\u6237\u5230\u7FA4\u7EC4"," group-remove-user <id> <userId> \u4ECE\u7FA4\u7EC4\u79FB\u9664\u7528\u6237","","Views / Subscriptions / Events:"," views <documentId> \u6587\u6863\u6D4F\u89C8\u8BB0\u5F55"," view <documentId> \u8BB0\u5F55\u6587\u6863\u6D4F\u89C8"," subscriptions <documentId> \u8BA2\u9605\u5217\u8868\uFF08\u6216 --collection <id>\uFF09"," subscribe <documentId> \u8BA2\u9605\u6587\u6863\u66F4\u65B0"," unsubscribe <subscriptionId> \u53D6\u6D88\u8BA2\u9605"," events [--actor <id>] [--document <id>] [--collection <id>] [--type <t>]"," \u4E8B\u4EF6\u5217\u8868","","Templates:"," templates [--collection <id>] \u6A21\u677F\u5217\u8868"," template-info <id> \u67E5\u770B\u6A21\u677F\u8BE6\u60C5"," create-template <collectionId> <title> [--text <t>] \u521B\u5EFA\u6A21\u677F"," update-template <id> [--title <t>] [--text <t>] \u66F4\u65B0\u6A21\u677F"," delete-template <id> \u5220\u9664\u6A21\u677F"," duplicate-template <id> [--title <t>] \u590D\u5236\u6A21\u677F","","File Operations:"," file-ops [--type import|export] \u6587\u4EF6\u64CD\u4F5C\u5217\u8868"," file-op-info <id> \u67E5\u770B\u6587\u4EF6\u64CD\u4F5C\u8BE6\u60C5"," file-op-delete <id> \u5220\u9664\u6587\u4EF6\u64CD\u4F5C\u8BB0\u5F55","","Reactions:"," reactions <commentId> \u67E5\u770B\u8BC4\u8BBA\u53CD\u5E94\u5217\u8868","","Attachments:"," attachments [docId] \u9644\u4EF6\u5217\u8868\uFF08\u53EF\u6309\u6587\u6863\u8FC7\u6EE4\uFF09"," upload <docId> <filePath> \u4E0A\u4F20\u672C\u5730\u6587\u4EF6\uFF08\u56FE\u7247/PDF/PPT \u7B49\uFF09\u5230\u6587\u6863"," upload-url <docId> <url> \u4ECE\u8FDC\u7A0B URL \u521B\u5EFA\u9644\u4EF6"," delete-attachment <id> \u5220\u9664\u9644\u4EF6","","Examples:"," coder wiki list \u5217\u51FA\u9ED8\u8BA4\u56E2\u961F\u7684\u6240\u6709\u96C6\u5408"," coder wiki list --team <teamId> \u5217\u51FA\u6307\u5B9A\u56E2\u961F\u7684\u96C6\u5408"," coder wiki list <collectionId> -d -1 \u5C55\u5F00\u5B8C\u6574\u6811",' coder wiki publish <collectionId> "\u6807\u9898" "\u5185\u5BB9"'," coder wiki publish <collectionId> --file ./doc.md",' coder wiki search "\u5173\u952E\u8BCD"',' coder wiki comment <docId> "\u5F88\u6709\u5E2E\u52A9\uFF01"'," coder wiki upload <docId> ./screenshot.png \u4E0A\u4F20\u56FE\u7247\u5E76\u83B7\u53D6 Markdown \u94FE\u63A5"," coder wiki upload <docId> ./report.pptx \u4E0A\u4F20 PPT \u6587\u4EF6"].join(`
|
|
85
|
-
`))}};
|
|
86
|
-
`)}getChannels(){return this.load().channels??[]}saveChannels(e){let t=this.load();t.channels=e,this.save(t)}async handle({channelSubcommand:e,channelArg:t,channelRemainingArgs:o,remainingArgs:
|
|
87
|
-
`),!await this.promptSetupChannel()||(
|
|
88
|
-
\u6E20\u9053\u5DF2\u5C31\u7EEA: [${i.type}] ${u} Bot ID: ${
|
|
89
|
-
`),await t.launch(o)}async promptSetupChannel(){let e=
|
|
84
|
+
`),m=Buffer.concat([...l,d,o,u]),p=new URL(e),f=p.protocol==="https:"?require("https"):require("http"),g={hostname:p.hostname,port:p.port||(p.protocol==="https:"?443:80),path:p.pathname+p.search,method:"POST",headers:{"Content-Type":`multipart/form-data; boundary=${a}`,"Content-Length":m.length}},y=f.request(g,h=>{let I="";h.on("data",b=>I+=b),h.on("end",()=>r({status:h.statusCode,body:I}))});y.on("error",i),y.write(m),y.end()})}extractCommentText(e){return e?.content?e.content.flatMap(t=>t.content||[]).filter(t=>t.type==="text").map(t=>t.text).join(""):""}showHelp(){console.log(["Usage: coder wiki [subcommand] [options]","","Global Options:"," --team <teamId> \u6307\u5B9A\u56E2\u961F\u4E0A\u4E0B\u6587\uFF08X-Team-Id\uFF09\uFF0C\u9ED8\u8BA4\u4F7F\u7528 coder team use \u8BBE\u7F6E\u7684\u56E2\u961F","","Collection Management:"," list \u5217\u51FA\u6240\u6709\u96C6\u5408"," list <collectionId> \u5217\u51FA\u96C6\u5408\u4E0B\u7684\u6839\u6587\u6863\uFF08\u8868\u683C\uFF09"," list <collectionId> -d <depth> \u5C55\u5F00\u6587\u6863\u6811\uFF08-d -1 \u5168\u90E8\u5C55\u5F00\uFF09"," create-collection <name> [desc] [--permission <perm>] [--icon <icon>] [--color <color>]"," \u521B\u5EFA\u96C6\u5408 (perm: read_write|read|null; icon: emoji \u6216\u56FE\u6807\u540D; color: \u5341\u516D\u8FDB\u5236\u989C\u8272\u5982 #4A90E2)"," icons [keyword] \u5217\u51FA\u6240\u6709\u652F\u6301\u7684\u56FE\u6807\u540D\uFF08\u53EF\u6309\u5173\u952E\u8BCD\u8FC7\u6EE4\uFF09"," update-collection <id> [--name <n>] [--description <d>] [--permission <p>] [--color <c>] [--sharing <bool>]"," \u66F4\u65B0\u96C6\u5408"," archive-collection <id> \u5F52\u6863\u96C6\u5408"," restore-collection <id> \u6062\u590D\u5DF2\u5F52\u6863\u96C6\u5408"," delete-collection <id> \u5220\u9664\u96C6\u5408"," collection-info <id> \u67E5\u770B\u96C6\u5408\u8BE6\u60C5"," collection-members <id> [--query <q>] [--permission <p>] \u96C6\u5408\u6210\u5458\u5217\u8868"," collection-add-user <id> <userId> [--permission <p>] \u6DFB\u52A0\u7528\u6237\u5230\u96C6\u5408"," collection-remove-user <id> <userId> \u4ECE\u96C6\u5408\u79FB\u9664\u7528\u6237"," collection-add-group <id> <groupId> [--permission <p>] \u6DFB\u52A0\u7FA4\u7EC4\u5230\u96C6\u5408"," collection-remove-group <id> <groupId> \u4ECE\u96C6\u5408\u79FB\u9664\u7FA4\u7EC4"," collection-group-members <id> \u96C6\u5408\u7FA4\u7EC4\u6210\u5458\u5217\u8868"," collection-export <id> [--format outline|markdown_zip] \u5BFC\u51FA\u96C6\u5408"," export-all [--format outline|markdown_zip] \u5BFC\u51FA\u6240\u6709\u96C6\u5408"," collection-move <id> <index> \u79FB\u52A8\u96C6\u5408\u4F4D\u7F6E","","Document Management:"," get <docId> \u67E5\u770B\u6587\u6863"," publish <collectionId> <title> [text] \u521B\u5EFA\u5E76\u53D1\u5E03\u6587\u6863"," publish <collectionId> --file <path> [--parent <parentDocId>]"," \u4ECE Markdown \u6587\u4EF6\u53D1\u5E03\uFF08\u9700\u542B H1 \u6807\u9898\uFF09"," update <docId> <title> [text] \u66F4\u65B0\u6587\u6863"," update <docId> --file <path> \u4ECE Markdown \u6587\u4EF6\u66F4\u65B0\u6587\u6863"," delete <docId> [--permanent] \u5220\u9664\u6587\u6863"," move <docId> [collectionId] [parentId] \u79FB\u52A8\u6587\u6863"," archive <docId> \u5F52\u6863\u6587\u6863"," restore <docId> [--revision <revisionId>] [--collection <collectionId>]"," \u6062\u590D\u6587\u6863"," archived [--collection <id>] \u5DF2\u5F52\u6863\u6587\u6863\u5217\u8868"," deleted \u5DF2\u5220\u9664\u6587\u6863\u5217\u8868"," insights <id> [--start-date <d>] [--end-date <d>] \u6587\u6863\u8BBF\u95EE\u7EDF\u8BA1"," export <id> [--include-children] \u5BFC\u51FA\u6587\u6863"," search-titles <query> \u6309\u6807\u9898\u641C\u7D22"," duplicate <id> [--title <t>] [--recursive] [--publish] [--collection <id>] [--parent <id>]"," \u590D\u5236\u6587\u6863"," unpublish <id> \u53D6\u6D88\u53D1\u5E03"," templatize <id> [--collection <collectionId>] \u8F6C\u4E3A\u6A21\u677F\uFF08\u9700\u6307\u5B9A\u96C6\u5408\u6216\u7BA1\u7406\u5458\u6743\u9650\uFF09"," doc-members <id> \u6587\u6863\u6210\u5458\u5217\u8868"," doc-add-user <id> <userId> [--permission <p>] \u6DFB\u52A0\u7528\u6237\u5230\u6587\u6863"," doc-remove-user <id> <userId> \u4ECE\u6587\u6863\u79FB\u9664\u7528\u6237"," doc-add-group <id> <groupId> [--permission <p>] \u6DFB\u52A0\u7FA4\u7EC4\u5230\u6587\u6863"," doc-remove-group <id> <groupId> \u4ECE\u6587\u6863\u79FB\u9664\u7FA4\u7EC4"," doc-group-members <id> \u6587\u6863\u7FA4\u7EC4\u6210\u5458\u5217\u8868"," empty-trash \u6E05\u7A7A\u56DE\u6536\u7AD9"," sub-docs <id> \u5B50\u6587\u6863\u5217\u8868","","Revision History:"," revisions <docId> \u5217\u51FA\u6587\u6863\u5386\u53F2\u7248\u672C"," revision <revisionId> \u67E5\u770B\u6307\u5B9A\u5386\u53F2\u7248\u672C\u5185\u5BB9","","Discovery:"," drafts \u8349\u7A3F\u5217\u8868"," recent \u6700\u8FD1\u6D4F\u89C8"," search <keyword> \u5168\u6587\u641C\u7D22","","Favorites & Pins:"," stars \u6536\u85CF\u5217\u8868"," star <id> [--collection] \u6536\u85CF\u6587\u6863\u6216\u96C6\u5408"," unstar <starId> \u53D6\u6D88\u6536\u85CF"," pins [collectionId] \u7F6E\u9876\u5217\u8868"," pin <docId> [collectionId] \u7F6E\u9876\u6587\u6863"," unpin <pinId> \u53D6\u6D88\u7F6E\u9876","","Comments:"," comments <docId> \u67E5\u770B\u8BC4\u8BBA"," comment <docId> <text> \u53D1\u8868\u8BC4\u8BBA","","Shares:"," shares [--document <id>] \u5206\u4EAB\u5217\u8868"," share-info <id> \u67E5\u770B\u5206\u4EAB\u8BE6\u60C5"," share <documentId> [--published] [--include-children] \u521B\u5EFA\u5206\u4EAB"," share-update <id> [--published] [--no-published] [--include-children] \u66F4\u65B0\u5206\u4EAB"," unshare <id> \u64A4\u9500\u5206\u4EAB","","Users:"," users [--query <q>] [--filter invited|viewers|admins|members|active|all|suspended]"," \u7528\u6237\u5217\u8868"," user-info <id> \u67E5\u770B\u7528\u6237\u8BE6\u60C5"," invite <email> <name> <role> \u9080\u8BF7\u7528\u6237"," user-update-role <id> <role> \u66F4\u65B0\u7528\u6237\u89D2\u8272 (admin|member|viewer)"," user-suspend <id> \u6682\u505C\u7528\u6237"," user-activate <id> \u6FC0\u6D3B\u7528\u6237","","Groups:"," groups [--query <q>] \u7FA4\u7EC4\u5217\u8868"," group-info <id> \u67E5\u770B\u7FA4\u7EC4\u8BE6\u60C5"," create-group <name> \u521B\u5EFA\u7FA4\u7EC4"," update-group <id> --name <name> \u66F4\u65B0\u7FA4\u7EC4"," delete-group <id> \u5220\u9664\u7FA4\u7EC4"," group-members <id> \u7FA4\u7EC4\u6210\u5458\u5217\u8868"," group-add-user <id> <userId> \u6DFB\u52A0\u7528\u6237\u5230\u7FA4\u7EC4"," group-remove-user <id> <userId> \u4ECE\u7FA4\u7EC4\u79FB\u9664\u7528\u6237","","Views / Subscriptions / Events:"," views <documentId> \u6587\u6863\u6D4F\u89C8\u8BB0\u5F55"," view <documentId> \u8BB0\u5F55\u6587\u6863\u6D4F\u89C8"," subscriptions <documentId> \u8BA2\u9605\u5217\u8868\uFF08\u6216 --collection <id>\uFF09"," subscribe <documentId> \u8BA2\u9605\u6587\u6863\u66F4\u65B0"," unsubscribe <subscriptionId> \u53D6\u6D88\u8BA2\u9605"," events [--actor <id>] [--document <id>] [--collection <id>] [--type <t>]"," \u4E8B\u4EF6\u5217\u8868","","Templates:"," templates [--collection <id>] \u6A21\u677F\u5217\u8868"," template-info <id> \u67E5\u770B\u6A21\u677F\u8BE6\u60C5"," create-template <collectionId> <title> [--text <t>] \u521B\u5EFA\u6A21\u677F"," update-template <id> [--title <t>] [--text <t>] \u66F4\u65B0\u6A21\u677F"," delete-template <id> \u5220\u9664\u6A21\u677F"," duplicate-template <id> [--title <t>] \u590D\u5236\u6A21\u677F","","File Operations:"," file-ops [--type import|export] \u6587\u4EF6\u64CD\u4F5C\u5217\u8868"," file-op-info <id> \u67E5\u770B\u6587\u4EF6\u64CD\u4F5C\u8BE6\u60C5"," file-op-delete <id> \u5220\u9664\u6587\u4EF6\u64CD\u4F5C\u8BB0\u5F55","","Reactions:"," reactions <commentId> \u67E5\u770B\u8BC4\u8BBA\u53CD\u5E94\u5217\u8868","","Attachments:"," attachments [docId] \u9644\u4EF6\u5217\u8868\uFF08\u53EF\u6309\u6587\u6863\u8FC7\u6EE4\uFF09"," upload <docId> <filePath> \u4E0A\u4F20\u672C\u5730\u6587\u4EF6\uFF08\u56FE\u7247/PDF/PPT \u7B49\uFF09\u5230\u6587\u6863"," upload-url <docId> <url> \u4ECE\u8FDC\u7A0B URL \u521B\u5EFA\u9644\u4EF6"," delete-attachment <id> \u5220\u9664\u9644\u4EF6","","Examples:"," coder wiki list \u5217\u51FA\u9ED8\u8BA4\u56E2\u961F\u7684\u6240\u6709\u96C6\u5408"," coder wiki list --team <teamId> \u5217\u51FA\u6307\u5B9A\u56E2\u961F\u7684\u96C6\u5408"," coder wiki list <collectionId> -d -1 \u5C55\u5F00\u5B8C\u6574\u6811",' coder wiki publish <collectionId> "\u6807\u9898" "\u5185\u5BB9"'," coder wiki publish <collectionId> --file ./doc.md",' coder wiki search "\u5173\u952E\u8BCD"',' coder wiki comment <docId> "\u5F88\u6709\u5E2E\u52A9\uFF01"'," coder wiki upload <docId> ./screenshot.png \u4E0A\u4F20\u56FE\u7247\u5E76\u83B7\u53D6 Markdown \u94FE\u63A5"," coder wiki upload <docId> ./report.pptx \u4E0A\u4F20 PPT \u6587\u4EF6"].join(`
|
|
85
|
+
`))}};He.exports=de});var Qe=$((Po,Ze)=>{var q=require("fs"),j=require("path"),Xe=require("os"),Kt=require("readline"),X=j.join(Xe.homedir(),".coder","config.json"),We=process.env.MCP_CHANNEL_DIR||j.join(Xe.homedir(),".claude","mcp-channel"),Ye=["wecom"];function Z(c){return!c||c.length<=8?"****":c.slice(0,3)+"****"+c.slice(-3)}var ue=class{load(){try{return JSON.parse(q.readFileSync(X,"utf8"))}catch{return{}}}save(e){let t=j.dirname(X);q.existsSync(t)||q.mkdirSync(t,{recursive:!0}),q.writeFileSync(X,JSON.stringify(e,null,2)+`
|
|
86
|
+
`)}getChannels(){return this.load().channels??[]}saveChannels(e){let t=this.load();t.channels=e,this.save(t)}async handle({channelSubcommand:e,channelArg:t,channelRemainingArgs:o,remainingArgs:n,claudeLauncher:s,parsedArgs:r}){return e?e==="--help"||e==="-h"?(this.showHelp(),0):e==="list"?this.list(t):e==="show"?this.show(t):e==="add"?this.add(t,o||[]):e==="remove"?this.remove(t):e==="update"?this.update(t,o||[]):(console.error(`\u274C \u672A\u77E5\u5B50\u547D\u4EE4: ${e}`),this.showHelp(),1):this.launch(o||[],s,r)}async launch(e,t,o){let n=this.getChannels().filter(p=>p.enabled!==!1);if(!n.length&&(console.log(`\u5C1A\u672A\u7ED1\u5B9A\u4EFB\u4F55\u6E20\u9053\uFF0C\u5F00\u59CB\u5F15\u5BFC\u914D\u7F6E...
|
|
87
|
+
`),!await this.promptSetupChannel()||(n=this.getChannels().filter(f=>f.enabled!==!1),!n.length)))return 1;let s=null,r=e.indexOf("--channel-id");r!==-1&&(s=e[r+1],e=e.filter((p,f)=>f!==r&&f!==r+1));let i;if(s){if(i=n.find(p=>p.id===s),!i)return console.error(`\u274C \u6E20\u9053\u4E0D\u5B58\u5728: ${s}`),1}else if(n.length===1)i=n[0];else if(i=await this.promptSelectChannel(n),!i)return 1;let a=j.join(We,i.type);if(!q.existsSync(a))return console.error(`\u274C MCP \u76EE\u5F55\u4E0D\u5B58\u5728: ${a}`),1;let l=["--plugin-dir",a,"--dangerously-load-development-channels",`plugin:${i.type}@${i.type}`],d={WECOM_CHANNEL_FILE:X,WECOM_CHANNEL_KEY:i.id};i.botId&&(d.WECOM_BOT_ID=i.botId),i.secret&&(d.WECOM_BOT_SECRET=i.secret),o.remainingArgs=[...l,...e,...o.remainingArgs||[]],o.extraEnv={...o.extraEnv||{},...d};let u=i.name||i.id,m=i.botId?Z(i.botId):"(\u672A\u914D\u7F6E)";return console.log(`
|
|
88
|
+
\u6E20\u9053\u5DF2\u5C31\u7EEA: [${i.type}] ${u} Bot ID: ${m}`),console.log(`\u6B63\u5728\u542F\u52A8 Claude\uFF0C\u7B49\u5F85\u4F01\u4E1A\u5FAE\u4FE1\u6D88\u606F...
|
|
89
|
+
`),await t.launch(o)}async promptSetupChannel(){let e=Kt.createInterface({input:process.stdin,output:process.stdout}),t=o=>new Promise(n=>e.question(o,n));try{for(;;){console.log(`\u8BF7\u914D\u7F6E\u4F01\u4E1A\u5FAE\u4FE1 AI Bot \u6E20\u9053\uFF1A
|
|
90
90
|
`);let o=(await t(" 1. \u8BF7\u7C98\u8D34 Bot ID: ")).trim();if(!o){console.error(`\u274C Bot ID \u4E0D\u80FD\u4E3A\u7A7A
|
|
91
|
-
`);continue}let
|
|
92
|
-
`);continue}if(process.stdout.write(`\x1B[1A\x1B[2K 2. \u8BF7\u7C98\u8D34 Secret: ${
|
|
91
|
+
`);continue}let n=(await t(" 2. \u8BF7\u7C98\u8D34 Secret: ")).trim();if(!n){console.error(`\u274C Secret \u4E0D\u80FD\u4E3A\u7A7A
|
|
92
|
+
`);continue}if(process.stdout.write(`\x1B[1A\x1B[2K 2. \u8BF7\u7C98\u8D34 Secret: ${Z(n)}
|
|
93
93
|
`),console.log(`
|
|
94
|
-
\u6B63\u5728\u9A8C\u8BC1\u8FDE\u63A5...`),!await this.testWecomConnection(o,
|
|
95
|
-
`);continue}let r=`wecom-${Date.now()}`,i={id:r,type:"wecom",enabled:!0,botId:o,secret:
|
|
96
|
-
`),i}}finally{e.close()}}async testWecomConnection(e,t){let o=
|
|
94
|
+
\u6B63\u5728\u9A8C\u8BC1\u8FDE\u63A5...`),!await this.testWecomConnection(o,n)){console.error(`\u274C \u8FDE\u63A5\u5931\u8D25\uFF0C\u8BF7\u68C0\u67E5 Bot ID \u548C Secret \u662F\u5426\u6B63\u786E\uFF0C\u91CD\u65B0\u8F93\u5165\u3002
|
|
95
|
+
`);continue}let r=`wecom-${Date.now()}`,i={id:r,type:"wecom",enabled:!0,botId:o,secret:n,createdAt:new Date().toISOString()},a=this.getChannels();return a.push(i),this.saveChannels(a),console.log(`\u2705 \u6E20\u9053\u7ED1\u5B9A\u6210\u529F: ${r}
|
|
96
|
+
`),i}}finally{e.close()}}async testWecomConnection(e,t){let o=j.join(We,"wecom"),n=j.join(o,"node_modules","@wecom","aibot-node-sdk");if(!q.existsSync(n))return!0;let s;try{({WSClient:s}=require(n))}catch{return this._testWecomConnectionSubprocess(e,t,n)}return this._runWecomClient(s,e,t)}_runWecomClient(e,t,o){return new Promise(n=>{let s=setTimeout(()=>{try{r.disconnect()}catch{}n(!1)},1e4),r=new e({botId:t,secret:o,maxReconnectAttempts:0,maxAuthFailureAttempts:0,logger:{debug:()=>{},info:()=>{},warn:()=>{},error:()=>{}}});r.on("authenticated",()=>{clearTimeout(s);try{r.disconnect()}catch{}n(!0)}),r.on("error",()=>{clearTimeout(s);try{r.disconnect()}catch{}n(!1)}),r.connect()})}_testWecomConnectionSubprocess(e,t,o){let{execSync:n,spawn:s}=require("child_process"),r;try{r=n("which node",{encoding:"utf8"}).trim()}catch{}if(!r)try{r=n("which bun",{encoding:"utf8"}).trim()}catch{}if(!r)return!0;let i=`
|
|
97
97
|
const { WSClient } = require(${JSON.stringify(o)});
|
|
98
98
|
const client = new WSClient({
|
|
99
99
|
botId: ${JSON.stringify(e)}, secret: ${JSON.stringify(t)},
|
|
@@ -104,15 +104,15 @@ const t = setTimeout(() => { try { client.disconnect(); } catch {} process.exit(
|
|
|
104
104
|
client.on("authenticated", () => { clearTimeout(t); try { client.disconnect(); } catch {} process.exit(0); });
|
|
105
105
|
client.on("error", () => { clearTimeout(t); try { client.disconnect(); } catch {} process.exit(1); });
|
|
106
106
|
client.connect();
|
|
107
|
-
`;return new Promise(a=>{let l=
|
|
107
|
+
`;return new Promise(a=>{let l=s(r,["-e",i],{stdio:"ignore"}),d=setTimeout(()=>{l.kill(),a(!1)},12e3);l.on("close",u=>{clearTimeout(d),a(u===0)}),l.on("error",()=>{clearTimeout(d),a(!1)})})}async promptSelectChannel(e){return new Promise(t=>{let o=0,n=()=>{process.stdout.write("\x1B[?25l"),process.stdout.write(`
|
|
108
108
|
\u8BF7\u9009\u62E9\u8981\u542F\u52A8\u7684\u6E20\u9053 (\u2191\u2193 \u79FB\u52A8, Enter \u786E\u8BA4):
|
|
109
109
|
|
|
110
|
-
`),e.forEach((i,a)=>{let l=i.botId?
|
|
110
|
+
`),e.forEach((i,a)=>{let l=i.botId?Z(i.botId):"(\u672A\u914D\u7F6E)",d=`[${i.type}] ${i.name||i.id} botId: ${l}`;a===o?process.stdout.write(` \x1B[38;2;231;76;60m\u276F ${d}\x1B[0m
|
|
111
111
|
`):process.stdout.write(` ${d}
|
|
112
112
|
`)}),process.stdout.write(`
|
|
113
|
-
`)},
|
|
114
|
-
`?(process.stdin.setRawMode(!1),process.stdin.pause(),process.stdin.removeListener("data",r),process.stdout.write("\x1B[?25h"),t(e[o])):i===""&&(process.stdin.setRawMode(!1),process.stdin.pause(),process.stdin.removeListener("data",r),process.stdout.write("\x1B[?25h"),t(null))};process.stdin.on("data",r)})}list(e){let t=this.getChannels();return e&&(t=t.filter(o=>o.type===e)),t.length?(this.printTable(t.map(o=>({id:o.id,type:o.type,name:o.name||"",enabled:o.enabled!==!1?"\u2713":"\u2717",botId:o.botId?
|
|
115
|
-
`))}};
|
|
113
|
+
`)},s=()=>{let i=e.length+4;process.stdout.write(`\x1B[${i}A\x1B[0J`)};n(),process.stdin.setRawMode(!0),process.stdin.resume(),process.stdin.setEncoding("utf8");let r=i=>{i==="\x1B[A"||i==="\x1B[D"?(o=(o-1+e.length)%e.length,s(),n()):i==="\x1B[B"||i==="\x1B[C"?(o=(o+1)%e.length,s(),n()):i==="\r"||i===`
|
|
114
|
+
`?(process.stdin.setRawMode(!1),process.stdin.pause(),process.stdin.removeListener("data",r),process.stdout.write("\x1B[?25h"),t(e[o])):i===""&&(process.stdin.setRawMode(!1),process.stdin.pause(),process.stdin.removeListener("data",r),process.stdout.write("\x1B[?25h"),t(null))};process.stdin.on("data",r)})}list(e){let t=this.getChannels();return e&&(t=t.filter(o=>o.type===e)),t.length?(this.printTable(t.map(o=>({id:o.id,type:o.type,name:o.name||"",enabled:o.enabled!==!1?"\u2713":"\u2717",botId:o.botId?Z(o.botId):"",allowFrom:(o.allowFrom??[]).join(", "),updatedAt:o.updatedAt||o.createdAt||""}))),0):(console.log(e?`\u6682\u65E0 ${e} \u6E20\u9053`:"\u6682\u65E0\u6E20\u9053\u7ED1\u5B9A"),0)}show(e){if(!e)return console.error("\u274C \u8BF7\u6307\u5B9A\u6E20\u9053 ID"),1;let t=this.getChannels().find(o=>o.id===e);return t?(console.log(JSON.stringify(t,null,2)),0):(console.error(`\u274C \u6E20\u9053\u4E0D\u5B58\u5728: ${e}`),1)}add(e,t){if(!e)return console.error("\u274C \u8BF7\u6307\u5B9A\u6E20\u9053\u7C7B\u578B\uFF0C\u4F8B\u5982: coder channel add wecom --bot-id xxx --secret yyy"),1;if(!Ye.includes(e))return console.error(`\u274C \u4E0D\u652F\u6301\u7684\u6E20\u9053\u7C7B\u578B: ${e}\uFF0C\u652F\u6301: ${Ye.join(", ")}`),1;let o=t.indexOf("--id"),n=(o!==-1?t[o+1]:void 0)||`${e}-${Date.now()}`,s=this.getChannels();if(s.find(i=>i.id===n))return console.error(`\u274C \u6E20\u9053 ID \u5DF2\u5B58\u5728: ${n}`),1;let r={id:n,type:e,enabled:!0,createdAt:new Date().toISOString()};return this._applyArgs(r,t),s.push(r),this.saveChannels(s),console.log(`\u2705 \u6E20\u9053\u5DF2\u6DFB\u52A0: ${n} (${e})`),0}remove(e){if(!e)return console.error("\u274C \u8BF7\u6307\u5B9A\u6E20\u9053 ID"),1;let t=this.getChannels(),o=t.findIndex(n=>n.id===e);return o===-1?(console.error(`\u274C \u6E20\u9053\u4E0D\u5B58\u5728: ${e}`),1):(t.splice(o,1),this.saveChannels(t),console.log(`\u2705 \u6E20\u9053\u5DF2\u5220\u9664: ${e}`),0)}update(e,t){if(!e)return console.error("\u274C \u8BF7\u6307\u5B9A\u6E20\u9053 ID"),1;let o=this.getChannels(),n=o.find(s=>s.id===e);return n?(t.includes("--enable")&&(n.enabled=!0),t.includes("--disable")&&(n.enabled=!1),this._applyArgs(n,t),n.updatedAt=new Date().toISOString(),this.saveChannels(o),console.log(`\u2705 \u6E20\u9053\u5DF2\u66F4\u65B0: ${e}`),0):(console.error(`\u274C \u6E20\u9053\u4E0D\u5B58\u5728: ${e}`),1)}_applyArgs(e,t){let o=r=>{let i=t.indexOf(r);return i!==-1?t[i+1]:void 0},n=r=>{if(r&&r.startsWith("@")){let i=r.slice(1);try{return q.readFileSync(i,"utf8").trim()}catch{console.error(`\u274C \u65E0\u6CD5\u8BFB\u53D6\u6587\u4EF6: ${i}`);return}}return r},s=o("--name");if(s!==void 0&&(e.name=s),e.type==="wecom"){let r=n(o("--bot-id"));r!==void 0&&(e.botId=r);let i=n(o("--secret"));i!==void 0&&(e.secret=i);let a=o("--allow");a!==void 0&&(e.allowFrom=e.allowFrom??[],e.allowFrom.includes(a)||e.allowFrom.push(a));let l=o("--deny");l!==void 0&&(e.allowFrom=(e.allowFrom??[]).filter(d=>d!==l))}}printTable(e){if(!e.length)return;let t=Object.keys(e[0]),o=i=>[...String(i)].reduce((a,l)=>a+(l.charCodeAt(0)>127?2:1),0),n=(i,a)=>i+" ".repeat(Math.max(0,a-o(i))),s=t.map(i=>Math.max(o(i),...e.map(a=>o(String(a[i]||""))))),r=s.map(i=>"-".repeat(i)).join("-+-");console.log(t.map((i,a)=>n(i,s[a])).join(" | ")),console.log(r);for(let i of e)console.log(t.map((a,l)=>n(String(i[a]||""),s[l])).join(" | "))}showHelp(){console.log(["Usage: coder channel [subcommand] [options]","","Subcommands:"," (no subcommand) \u542F\u52A8 Claude\uFF08\u81EA\u52A8\u9009\u62E9\u6216\u4EA4\u4E92\u9009\u62E9\u6E20\u9053\uFF09"," --channel-id <id> \u542F\u52A8\u6307\u5B9A\u6E20\u9053"," list [type] \u5217\u51FA\u6E20\u9053"," show <id> \u67E5\u770B\u6E20\u9053\u8BE6\u60C5"," add <type> [options] \u6DFB\u52A0\u6E20\u9053"," update <id> [options] \u66F4\u65B0\u6E20\u9053"," remove <id> \u5220\u9664\u6E20\u9053","","Supported Channel Types:"," wecom \u4F01\u4E1A\u5FAE\u4FE1 AI Bot","","WeChat Work Options:"," --bot-id <botId> \u4F01\u4E1A\u5FAE\u4FE1 AI Bot ID"," --secret <secret> \u4F01\u4E1A\u5FAE\u4FE1 AI Bot Secret\uFF08\u660E\u6587\uFF0C\u4F1A\u8BB0\u5F55\u5230 shell \u5386\u53F2\uFF09"," --secret @<file> \u4ECE\u6587\u4EF6\u8BFB\u53D6 Secret\uFF0C\u907F\u514D\u6CC4\u9732\u5230 shell \u5386\u53F2"," --allow <userId> \u5C06\u7528\u6237\u52A0\u5165\u767D\u540D\u5355"," --deny <userId> \u5C06\u7528\u6237\u79FB\u51FA\u767D\u540D\u5355"," --enable / --disable \u542F\u7528\u6216\u7981\u7528\u6E20\u9053"," --id <id> \u81EA\u5B9A\u4E49\u6E20\u9053 ID\uFF08add \u65F6\u4F7F\u7528\uFF09"," --name <name> \u6E20\u9053\u663E\u793A\u540D\u79F0","","Examples:",' coder channel add wecom --bot-id xxx --secret yyy --name "\u4E3B\u6E20\u9053"'," coder channel add wecom --bot-id xxx --secret @~/.coder/secret.txt",' coder channel add wecom --bot-id zzz --secret www --name "\u5907\u7528\u6E20\u9053"'," coder channel update wecom-xxx --allow zhangsan"," coder channel list \u5217\u51FA\u6240\u6709\u6E20\u9053"," coder channel \u591A\u6E20\u9053\u65F6\u4EA4\u4E92\u9009\u62E9"," coder channel --channel-id wecom-xxx \u76F4\u63A5\u542F\u52A8\u6307\u5B9A\u6E20\u9053","","\u914D\u7F6E\u6587\u4EF6: ~/.coder/config.json"].join(`
|
|
115
|
+
`))}};Ze.exports=ue});var tt=$((To,et)=>{var Ht=require("http"),pe=class{constructor(e={}){this.port=e.port||9380,this.timeout=e.timeout||300*1e3,this.server=null,this.timeoutId=null}validateTokenFormat(e){if(!e||typeof e!="string")return!1;let t=e.split(".");if(t.length!==2)return!1;let[o,n]=t;return o&&o.length>0&&n&&n.length>0}async waitForCallback(e){return new Promise((t,o)=>{let n=!1;this.server=Ht.createServer((s,r)=>{let i=new URL(s.url,`http://localhost:${this.port}`);if(i.pathname==="/callback"){let a=i.searchParams.get("token"),l=i.searchParams.get("state"),d=i.searchParams.get("error");if(d){r.writeHead(200,{"Content-Type":"text/html; charset=utf-8"}),r.end(`
|
|
116
116
|
<!DOCTYPE html>
|
|
117
117
|
<html>
|
|
118
118
|
<head>
|
|
@@ -137,7 +137,7 @@ client.connect();
|
|
|
137
137
|
</div>
|
|
138
138
|
</body>
|
|
139
139
|
</html>
|
|
140
|
-
`),
|
|
140
|
+
`),n||(n=!0,this.cleanup(),o(new Error(`OAuth error: ${d}`)));return}if(l!==e){r.writeHead(400,{"Content-Type":"text/html; charset=utf-8"}),r.end(`
|
|
141
141
|
<!DOCTYPE html>
|
|
142
142
|
<html>
|
|
143
143
|
<head>
|
|
@@ -159,7 +159,7 @@ client.connect();
|
|
|
159
159
|
</div>
|
|
160
160
|
</body>
|
|
161
161
|
</html>
|
|
162
|
-
`),
|
|
162
|
+
`),n||(n=!0,this.cleanup(),o(new Error("Invalid state parameter - possible CSRF attack")));return}if(!a){r.writeHead(400,{"Content-Type":"text/html; charset=utf-8"}),r.end(`
|
|
163
163
|
<!DOCTYPE html>
|
|
164
164
|
<html>
|
|
165
165
|
<head>
|
|
@@ -181,7 +181,7 @@ client.connect();
|
|
|
181
181
|
</div>
|
|
182
182
|
</body>
|
|
183
183
|
</html>
|
|
184
|
-
`),
|
|
184
|
+
`),n||(n=!0,this.cleanup(),o(new Error("No token received from OAuth callback")));return}if(!this.validateTokenFormat(a)){r.writeHead(400,{"Content-Type":"text/html; charset=utf-8"}),r.end(`
|
|
185
185
|
<!DOCTYPE html>
|
|
186
186
|
<html>
|
|
187
187
|
<head>
|
|
@@ -205,7 +205,7 @@ client.connect();
|
|
|
205
205
|
</div>
|
|
206
206
|
</body>
|
|
207
207
|
</html>
|
|
208
|
-
`),
|
|
208
|
+
`),n||(n=!0,this.cleanup(),o(new Error("Invalid token format - expected ak.sk format")));return}let[u,m]=a.split(".");r.writeHead(200,{"Content-Type":"text/html; charset=utf-8"}),r.end(`
|
|
209
209
|
<!DOCTYPE html>
|
|
210
210
|
<html>
|
|
211
211
|
<head>
|
|
@@ -237,27 +237,27 @@ client.connect();
|
|
|
237
237
|
</script>
|
|
238
238
|
</body>
|
|
239
239
|
</html>
|
|
240
|
-
`),
|
|
240
|
+
`),n||(n=!0,this.cleanup(),t({ak:u,sk:m}))}else r.writeHead(404,{"Content-Type":"text/plain"}),r.end("Not Found")}),this.server.on("error",s=>{if(s.code==="EADDRINUSE"){if(this.port++,this.port>9390){n||(n=!0,o(new Error("Could not find available port for OAuth callback server")));return}this.server.close(),this.server.listen(this.port)}else n||(n=!0,this.cleanup(),o(s))}),this.server.listen(this.port,()=>{process.env.CODEV_DEBUG&&console.log(`OAuth callback server listening on port ${this.port}`)}),this.timeoutId=setTimeout(()=>{n||(n=!0,this.cleanup(),o(new Error("OAuth login timeout - no response received within 5 minutes")))},this.timeout)})}getCallbackUrl(){return`http://localhost:${this.port}/callback`}cleanup(){this.timeoutId&&(clearTimeout(this.timeoutId),this.timeoutId=null),this.server&&(this.server.close(),this.server=null)}};et.exports=pe});var nt=$((qo,ot)=>{var zt=require("crypto"),Wt=tt(),me=class{constructor(e={}){this.baseUrl=e.baseUrl||"https://makecoder.com",this.callbackServer=null}generateState(){return zt.randomBytes(16).toString("hex")}buildAuthorizationUrl(e,t){let o=new URLSearchParams({redirect_uri:e,state:t,response_type:"token"});return`${this.baseUrl}/oauth/authorize?${o.toString()}`}async startOAuthFlow(){let e=this.generateState();this.callbackServer=new Wt;let t=this.callbackServer.getCallbackUrl(),o=this.buildAuthorizationUrl(t,e),n=!1;try{let r=(await import("open")).default;await r(o),n=!0}catch(r){process.env.CODEV_DEBUG&&console.error("Browser open error:",r)}let s=this.callbackServer.waitForCallback(e);return{authUrl:o,waitPromise:s,browserOpened:n}}async login(){try{let{authUrl:e,waitPromise:t,browserOpened:o}=await this.startOAuthFlow();console.log(`
|
|
241
241
|
\u{1F510} \u5F00\u59CB OAuth \u767B\u5F55\u6D41\u7A0B...
|
|
242
242
|
`),console.log(`\u{1F4CB} \u8BF7\u5728\u6D4F\u89C8\u5668\u4E2D\u5B8C\u6210\u767B\u5F55
|
|
243
243
|
`),console.log(`\u{1F310} \u6388\u6743\u5730\u5740: ${e}
|
|
244
244
|
`),console.log(`\u23F3 \u7B49\u5F85\u60A8\u7684\u6388\u6743...(\u8D85\u65F6\u65F6\u95F4: 5\u5206\u949F)
|
|
245
|
-
`),o||console.warn("\u26A0\uFE0F \u65E0\u6CD5\u81EA\u52A8\u6253\u5F00\u6D4F\u89C8\u5668,\u8BF7\u624B\u52A8\u590D\u5236\u4E0A\u8FF0\u94FE\u63A5\u5230\u6D4F\u89C8\u5668\u6253\u5F00");let
|
|
246
|
-
`),
|
|
245
|
+
`),o||console.warn("\u26A0\uFE0F \u65E0\u6CD5\u81EA\u52A8\u6253\u5F00\u6D4F\u89C8\u5668,\u8BF7\u624B\u52A8\u590D\u5236\u4E0A\u8FF0\u94FE\u63A5\u5230\u6D4F\u89C8\u5668\u6253\u5F00");let n=await t;return console.log(`\u2705 API Key \u83B7\u53D6\u6210\u529F!
|
|
246
|
+
`),n}catch(e){throw console.error(`
|
|
247
247
|
\u274C OAuth \u767B\u5F55\u5931\u8D25: ${e.message}
|
|
248
|
-
`),e}finally{this.callbackServer&&this.callbackServer.cleanup()}}cleanup(){this.callbackServer&&this.callbackServer.cleanup()}};
|
|
248
|
+
`),e}finally{this.callbackServer&&this.callbackServer.cleanup()}}cleanup(){this.callbackServer&&this.callbackServer.cleanup()}};ot.exports=me});var it=$((Bo,st)=>{var rt=require("readline"),Yt=nt(),he=class{constructor(e){this.argParser=e}async handle(e){let{authSubcommand:t,authRemainingArgs:o=[],codevServer:n}=e;if(t==="--help"||t===void 0)return this.showHelp(),0;switch(t){case"login":return await this.handleLogin(o,n);case"logout":return this.logout();case"status":return await this.status();default:return this.showHelp(),1}}async handleLogin(e,t){let o=null;for(let n=0;n<e.length;n++)if(e[n]==="--apikey"){o=e[n+1]||null;break}return o?this.loginWithApiKey(o):await this.dualLogin(t)}loginWithApiKey(e){let t=e.indexOf(".");if(t<=0||t===e.length-1)return console.error("\u274C API Key \u683C\u5F0F\u9519\u8BEF\uFF0C\u5E94\u4E3A <ak>.<sk> \u683C\u5F0F"),1;let o=e.substring(0,t).trim(),n=e.substring(t+1).trim();return!o||!n?(console.error("\u274C API Key \u683C\u5F0F\u9519\u8BEF\uFF0C\u5E94\u4E3A <ak>.<sk> \u683C\u5F0F"),1):this.argParser.saveAuthToConfig(e.trim())?(console.log(`\u2705 API Key \u5DF2\u4FDD\u5B58\u5230 ${this.argParser.configPath}`),0):(console.error("\u274C \u4FDD\u5B58\u5931\u8D25\uFF0C\u8BF7\u68C0\u67E5\u6587\u4EF6\u6743\u9650"),1)}async dualLogin(e){let t=new Yt({baseUrl:"https://makecoder.com"}),o,n,s;try{({authUrl:o,waitPromise:n,browserOpened:s}=await t.startOAuthFlow())}catch(l){return console.error(`\u274C \u542F\u52A8\u767B\u5F55\u6D41\u7A0B\u5931\u8D25: ${l.message}`),console.log(`
|
|
249
249
|
\u8BF7\u624B\u52A8\u8F93\u5165 API Key\uFF08\u83B7\u53D6\u5730\u5740: https://makecoder.com/my/apikeys\uFF09
|
|
250
250
|
`),await this.terminalOnlyLogin()}console.log(`
|
|
251
251
|
\u{1F510} \u767B\u5F55 MakeCoder
|
|
252
|
-
`),console.log(
|
|
252
|
+
`),console.log(s?" \u65B9\u5F0F\u4E00\uFF1A\u6D4F\u89C8\u5668\u5DF2\u6253\u5F00\u6388\u6743\u9875\u9762\uFF0C\u8BF7\u5728\u6D4F\u89C8\u5668\u4E2D\u5B8C\u6210\u767B\u5F55":" \u65B9\u5F0F\u4E00\uFF1A\u8BF7\u5728\u6D4F\u89C8\u5668\u4E2D\u6253\u5F00\u4EE5\u4E0B\u5730\u5740\u5B8C\u6210\u767B\u5F55"),console.log(` ${o}
|
|
253
253
|
`),console.log(` \u65B9\u5F0F\u4E8C\uFF1A\u7C98\u8D34 API Key\uFF08\u83B7\u53D6\u5730\u5740: https://makecoder.com/my/apikeys\uFF09
|
|
254
|
-
`);let r=
|
|
254
|
+
`);let r=rt.createInterface({input:process.stdin,output:process.stdout}),i=new Promise((l,d)=>{r.question("\u8BF7\u8F93\u5165 API Key\uFF08\u7559\u7A7A\u5219\u7B49\u5F85\u6D4F\u89C8\u5668\u767B\u5F55\uFF09: ",u=>{let m=u.trim();if(!m){d(new Error("__empty_input__"));return}let p=m.indexOf(".");if(p<=0||p===m.length-1){d(new Error("API Key \u683C\u5F0F\u9519\u8BEF\uFF0C\u5E94\u4E3A <ak>.<sk> \u683C\u5F0F"));return}l(m)})}),a;try{a=await Promise.race([n.then(l=>(r.close(),`${l.ak}.${l.sk}`)),i.then(l=>(t.cleanup(),l))])}catch(l){if(l.message==="__empty_input__"){console.log(`
|
|
255
255
|
\u23F3 \u7B49\u5F85\u6D4F\u89C8\u5668\u6388\u6743\u5B8C\u6210...\uFF08\u8D85\u65F6\u65F6\u95F4: 5\u5206\u949F\uFF09
|
|
256
|
-
`);try{let d=await
|
|
256
|
+
`);try{let d=await n;a=`${d.ak}.${d.sk}`}catch(d){return t.cleanup(),console.error(`
|
|
257
257
|
\u274C \u767B\u5F55\u5931\u8D25: ${d.message}`),1}}else return r.close(),t.cleanup(),console.error(`
|
|
258
258
|
\u274C ${l.message}`),1}return t.cleanup(),this.argParser.saveAuthToConfig(a)?(console.log(`
|
|
259
259
|
\u2705 \u767B\u5F55\u6210\u529F\uFF01API Key \u5DF2\u4FDD\u5B58\u5230 ${this.argParser.configPath}`),0):(console.error(`
|
|
260
|
-
\u26A0\uFE0F \u767B\u5F55\u6210\u529F\u4F46\u4FDD\u5B58\u914D\u7F6E\u5931\u8D25\uFF0C\u8BF7\u68C0\u67E5\u6587\u4EF6\u6743\u9650`),1)}async terminalOnlyLogin(){let e=
|
|
260
|
+
\u26A0\uFE0F \u767B\u5F55\u6210\u529F\u4F46\u4FDD\u5B58\u914D\u7F6E\u5931\u8D25\uFF0C\u8BF7\u68C0\u67E5\u6587\u4EF6\u6743\u9650`),1)}async terminalOnlyLogin(){let e=rt.createInterface({input:process.stdin,output:process.stdout});return new Promise(t=>{e.question("\u8BF7\u8F93\u5165 API Key: ",o=>{e.close();let n=o.trim();if(!n){console.error("\u274C \u672A\u8F93\u5165 API Key"),t(1);return}let s=n.indexOf(".");if(s<=0||s===n.length-1){console.error("\u274C API Key \u683C\u5F0F\u9519\u8BEF\uFF0C\u5E94\u4E3A <ak>.<sk> \u683C\u5F0F"),t(1);return}this.argParser.saveAuthToConfig(n)?(console.log(`\u2705 \u767B\u5F55\u6210\u529F\uFF01API Key \u5DF2\u4FDD\u5B58\u5230 ${this.argParser.configPath}`),t(0)):(console.error("\u274C \u4FDD\u5B58\u5931\u8D25\uFF0C\u8BF7\u68C0\u67E5\u6587\u4EF6\u6743\u9650"),t(1))})})}logout(){return this.argParser.clearAuthFromConfig()?(console.log("\u2705 \u5DF2\u9000\u51FA\u767B\u5F55\uFF0CAPI Key \u5DF2\u6E05\u9664"),0):(console.error("\u274C \u9000\u51FA\u767B\u5F55\u5931\u8D25\uFF0C\u8BF7\u68C0\u67E5\u6587\u4EF6\u6743\u9650"),1)}async status(){let e=this.argParser.loadConfig(),t=this.argParser.getApiKeyFromConfig(e);if(!t)return console.log("\u274C \u672A\u767B\u5F55"),console.log(" \u8FD0\u884C coder auth login \u5F00\u59CB\u767B\u5F55"),0;let o=t.substring(0,4)+"****";console.log(`\u2705 \u5DF2\u767B\u5F55 (${o})`),console.log(` \u914D\u7F6E\u6587\u4EF6: ${this.argParser.configPath}`);try{let n=require("https"),s=require("http"),r=new URL("https://makecoder.com/bigapis/auth/v1/users/me"),i=r.protocol==="https:"?n:s,a=await new Promise((l,d)=>{let u=i.request(r,{method:"GET",headers:{Authorization:`Bearer ${t}`,"Content-Type":"application/json"},timeout:5e3},m=>{let p="";m.on("data",f=>{p+=f}),m.on("end",()=>{if(m.statusCode===200)try{l(JSON.parse(p))}catch{d(new Error("\u89E3\u6790\u54CD\u5E94\u5931\u8D25"))}else m.statusCode===401?d(new Error("unauthorized")):d(new Error(`HTTP ${m.statusCode}`))})});u.on("error",d),u.on("timeout",()=>{u.destroy(),d(new Error("\u8BF7\u6C42\u8D85\u65F6"))}),u.end()});a.data?.id&&console.log(` \u7528\u6237 ID: ${a.data.id}`),a.data?.username&&console.log(` \u7528\u6237\u540D: ${a.data.username}`)}catch(n){n.message==="unauthorized"&&console.log(" \u26A0\uFE0F API Key \u53EF\u80FD\u5DF2\u8FC7\u671F\uFF0C\u8BF7\u91CD\u65B0\u767B\u5F55: coder auth login")}return 0}showHelp(){console.log(`
|
|
261
261
|
\u7528\u6CD5:
|
|
262
262
|
coder auth <command>
|
|
263
263
|
|
|
@@ -276,36 +276,36 @@ client.connect();
|
|
|
276
276
|
coder auth status # \u67E5\u770B\u767B\u5F55\u72B6\u6001
|
|
277
277
|
|
|
278
278
|
\u83B7\u53D6 API Key: https://makecoder.com/my/apikeys
|
|
279
|
-
`)}};
|
|
279
|
+
`)}};st.exports=he});var at=$((jo,ct)=>{var fe=require("crypto"),{URL:Xt}=require("url"),ge=class{static generateSignature(e,t,o,n){try{let s=new Xt(e),r=Buffer.from(s.pathname),i=Buffer.from(r),a=t?typeof t=="string"?Buffer.from(t):Buffer.from(JSON.stringify(t)):Buffer.alloc(0),l=Buffer.concat([i,a,Buffer.from(n)]),d=fe.createHmac("sha256",o);return d.update(l),d.digest("hex")}catch(s){throw new Error(`Failed to generate signature: ${s.message}`)}}static validateSignature(e,t,o,n,s){return this.generateSignature(e,t,o,n)===s}static generateTimestamp(){return Date.now().toString()}static generateStrongPassword(e=16){let t="abcdefghijkmnpqrstuvwxyz",o="ABCDEFGHJKLMNPQRSTUVWXYZ",n="23456789",s="!@#$%^&*-_=+",r=t+o+n+s;e<8&&(e=8);let i=l=>l[fe.randomBytes(1)[0]%l.length],a=[i(t),i(o),i(n),i(s)];for(;a.length<e;)a.push(i(r));for(let l=a.length-1;l>0;l--){let d=fe.randomBytes(1)[0]%(l+1);[a[l],a[d]]=[a[d],a[l]]}return a.join("")}};ct.exports=ge});var ut=$((Lo,dt)=>{var Zt=require("https"),{URL:Qt}=require("url"),K=require("fs"),B=require("path"),eo=at(),to="https://makecoder.com/bigapis/auth/v1",oo="https://makecoder.com/bigapis/kbb2/v1",be=class{constructor(e){this.argParser=e||null}request(e,t,o,n,s){return new Promise((r,i)=>{let a=s||to,l=new Qt(`${a}${t}`),d={"Content-Type":"application/json",Authorization:`Bearer ${o}`},u=null;n!=null&&(u=JSON.stringify(n),d["Content-Length"]=Buffer.byteLength(u));let m={hostname:l.hostname,port:l.port||443,path:l.pathname+l.search,method:e,headers:d},p=Zt.request(m,f=>{let g="";f.on("data",y=>g+=y),f.on("end",()=>r({status:f.statusCode,body:g}))});p.on("error",i),u&&p.write(u),p.end()})}parseJson(e){try{return JSON.parse(e)}catch{return null}}exitCodeForStatus(e){return e===401?2:e===403?5:e===404?4:e===409?6:1}parseOutputFlags(e){let t={json:!1,quiet:!1,field:null},o=[];for(let n=0;n<e.length;n++){let s=e[n];if(s==="--json"){t.json=!0;continue}if(s==="--quiet"){t.quiet=!0;continue}if(s!=="--no-color"){if(s==="--field"){t.field=e[n+1],n++;continue}o.push(s)}}return{out:t,remaining:o}}async handle({teamSubcommand:e,teamArg:t,teamRemainingArgs:o,apikey:n}){if(!e||e==="--help"||e==="-h")return this.showHelp(),0;let s=n;if(!s)return console.error("\u274C 2: \u672A\u767B\u5F55\uFF0C\u8BF7\u5148\u8FD0\u884C coder auth login"),2;let r=o||[];return e==="list"||e==="ls"?await this.list(r,s):e==="current"?await this.current(r,s):e==="use"?await this.use(t,r,s):e==="info"?await this.info(t,r,s):e==="members"?await this.members(t,r,s):e==="member-get"?await this.memberGet(t,r,s):e==="search-member"?await this.searchMember(t,r,s):e==="member-create"?await this.memberCreate(t,r,s):e==="member-delete"?await this.memberDelete(t,r,s):e==="set-points"?await this.setPoints(t,r,s):(console.error(`\u274C 3: \u672A\u77E5\u5B50\u547D\u4EE4: ${e}`),this.showHelp(),3)}async list(e,t){let{out:o}=this.parseOutputFlags(e),s=`/team?constraints=${encodeURIComponent(JSON.stringify({filter_is_joined:!0}))}&page=1&size=200`,r;try{r=await this.request("GET",s,t)}catch(d){return console.error(`\u274C 1: \u7F51\u7EDC\u9519\u8BEF ${d.message}`),1}if(r.status!==200)return console.error(`\u274C ${this.exitCodeForStatus(r.status)}: HTTP ${r.status}`),r.body&&console.error(r.body),this.exitCodeForStatus(r.status);let i=this.parseJson(r.body);if(!i||!i.data)return console.error("\u274C 1: \u54CD\u5E94\u89E3\u6790\u5931\u8D25"),1;let a=i.data.items||[];if(o.json){let d={items:a,total:i.data.total??a.length};if(o.field){let u=D(d,o.field);process.stdout.write(A(u)+`
|
|
280
280
|
`)}else process.stdout.write(JSON.stringify(d,null,2)+`
|
|
281
|
-
`);return 0}if(o.quiet){for(let d of a)console.log(d.id);return 0}if(!a.length)return console.log("\uFF08\u4F60\u8FD8\u6CA1\u6709\u52A0\u5165\u4EFB\u4F55\u56E2\u961F\uFF09"),0;let l=a.map(d=>({id:d.id||"",name:d.name||"",members:(d.members_count??d.member_count??"")+"",points:d.points!=null?String(d.points):""}));return
|
|
281
|
+
`);return 0}if(o.quiet){for(let d of a)console.log(d.id);return 0}if(!a.length)return console.log("\uFF08\u4F60\u8FD8\u6CA1\u6709\u52A0\u5165\u4EFB\u4F55\u56E2\u961F\uFF09"),0;let l=a.map(d=>({id:d.id||"",name:d.name||"",members:(d.members_count??d.member_count??"")+"",points:d.points!=null?String(d.points):""}));return ye(["id","name","members","points"],l),0}resolveTeamId(e,t){if(e&&!e.startsWith("--"))return e;let o=t.indexOf("--team");if(o>=0&&t[o+1])return t[o+1];let n=this.argParser?this.argParser.getTeam():null;return n&&n.id?n.id:null}async fetchTeam(e,t){let n=`/team?constraints=${encodeURIComponent(JSON.stringify({id__in:[e]}))}`,s=await this.request("GET",n,t);if(s.status!==200)return{error:{code:this.exitCodeForStatus(s.status),status:s.status,body:s.body}};let r=this.parseJson(s.body),i=r&&r.data&&r.data.items||[];return i.length?{team:i[0]}:{error:{code:4,status:404,body:`team ${e} not found`}}}filterMembersByType(e,t){return t?e.filter(o=>o.user_type===t):e}async info(e,t,o){let{out:n}=this.parseOutputFlags(t),s=this.resolveTeamId(e,t);if(!s)return console.error("\u274C 3: \u672A\u6307\u5B9A teamId \u4E14\u65E0\u9ED8\u8BA4\u56E2\u961F\u3002\u8FD0\u884C 'coder team use <id>' \u6216\u5E26 [teamId] \u53C2\u6570"),3;let r;try{r=await this.fetchTeam(s,o)}catch(u){return console.error(`\u274C 1: \u7F51\u7EDC\u9519\u8BEF ${u.message}`),1}if(r.error)return console.error(`\u274C ${r.error.code}: HTTP ${r.error.status}`),r.error.body&&console.error(r.error.body),r.error.code;let i=r.team,a=Array.isArray(i.members)?i.members:[],l=a.filter(u=>u.user_type==="ai").length,d=a.filter(u=>u.user_type==="human").length;if(n.json){let u={id:i.id,name:i.name,description:i.description||"",points:i.points,points_expire_at:i.points_expire_at||null,is_active:!!i.is_active,members_total:a.length,members_ai:l,members_human:d};return n.field?process.stdout.write(A(D(u,n.field))+`
|
|
282
282
|
`):process.stdout.write(JSON.stringify(u,null,2)+`
|
|
283
|
-
`),0}return
|
|
284
|
-
`):process.stdout.write(JSON.stringify(h,null,2)+`
|
|
285
|
-
`),0}if(s.quiet){for(let h of u)console.log(h.user_id||h.id||"");return 0}if(!u.length)return console.log(r?`\uFF08\u65E0 ${r} \u7C7B\u578B\u6210\u5458\uFF09`:"\uFF08\u56E2\u961F\u6682\u65E0\u6210\u5458\uFF09"),0;let p=u.map(h=>({username:h.username||"",user_id:h.user_id||"",type:h.user_type||"",role:h.role||"",points:h.points==null?"\u221E":String(h.points),joined_at:(h.created_at||"").slice(0,10)}));return Te(["username","user_id","type","role","points","joined_at"],p),0}async memberGet(e,t,o){let{out:s,remaining:n}=this.parseOutputFlags(t),r=[];for(let h=0;h<n.length;h++){if(n[h]==="--team"){h++;continue}r.push(n[h])}let i=r[0];if(!i)return console.error("\u274C 3: \u7F3A\u5C11 userId \u53C2\u6570\u3002\u7528\u6CD5: coder team member-get <userId> [teamId]"),3;let l=r[1]||this.resolveTeamId(void 0,n);if(!l)return console.error("\u274C 3: \u672A\u6307\u5B9A teamId \u4E14\u65E0\u9ED8\u8BA4\u56E2\u961F\u3002\u8FD0\u884C 'coder team use <id>' \u6216\u5E26 [teamId] \u53C2\u6570"),3;let d;try{d=await this.fetchTeam(l,o)}catch(h){return console.error(`\u274C 1: \u7F51\u7EDC\u9519\u8BEF ${h.message}`),1}if(d.error)return console.error(`\u274C ${d.error.code}: HTTP ${d.error.status}`),d.error.body&&console.error(d.error.body),d.error.code;let p=(Array.isArray(d.team.members)?d.team.members:[]).find(h=>h.user_id===i||h.id===i||h.username===i);return p?s.json?(s.field?process.stdout.write(q(A(p,s.field))+`
|
|
283
|
+
`),0}return n.quiet?(console.log(i.id),0):(console.log(`team: ${i.name} (${i.id})`),i.description&&console.log(`description: ${i.description}`),console.log(`points: ${i.points??""}`),i.points_expire_at&&console.log(`points_expire_at: ${i.points_expire_at}`),console.log(`active: ${i.is_active?"yes":"no"}`),console.log(`members: ${a.length} (ai=${l}, human=${d})`),0)}async members(e,t,o){let{out:n,remaining:s}=this.parseOutputFlags(t),r=null,i=[];for(let p=0;p<s.length;p++){if(s[p]==="--type"){r=s[p+1],p++;continue}i.push(s[p])}let a=this.resolveTeamId(e,i);if(!a)return console.error("\u274C 3: \u672A\u6307\u5B9A teamId \u4E14\u65E0\u9ED8\u8BA4\u56E2\u961F\u3002\u8FD0\u884C 'coder team use <id>' \u6216\u5E26 [teamId] \u53C2\u6570"),3;if(r&&r!=="human"&&r!=="ai")return console.error(`\u274C 3: --type \u4EC5\u652F\u6301 human \u6216 ai\uFF0C\u6536\u5230 '${r}'`),3;let l;try{l=await this.fetchTeam(a,o)}catch(p){return console.error(`\u274C 1: \u7F51\u7EDC\u9519\u8BEF ${p.message}`),1}if(l.error)return console.error(`\u274C ${l.error.code}: HTTP ${l.error.status}`),l.error.body&&console.error(l.error.body),l.error.code;let d=Array.isArray(l.team.members)?l.team.members:[],u=this.filterMembersByType(d,r);if(n.json){let p={team_id:l.team.id,team_name:l.team.name,items:u,total:u.length};return n.field?process.stdout.write(A(D(p,n.field))+`
|
|
286
284
|
`):process.stdout.write(JSON.stringify(p,null,2)+`
|
|
287
|
-
`),0
|
|
285
|
+
`),0}if(n.quiet){for(let p of u)console.log(p.user_id||p.id||"");return 0}if(!u.length)return console.log(r?`\uFF08\u65E0 ${r} \u7C7B\u578B\u6210\u5458\uFF09`:"\uFF08\u56E2\u961F\u6682\u65E0\u6210\u5458\uFF09"),0;let m=u.map(p=>({username:p.username||"",user_id:p.user_id||"",type:p.user_type||"",role:p.role||"",points:p.points==null?"\u221E":String(p.points),joined_at:(p.created_at||"").slice(0,10)}));return ye(["username","user_id","type","role","points","joined_at"],m),0}async memberGet(e,t,o){let{out:n,remaining:s}=this.parseOutputFlags(t),r=[];for(let p=0;p<s.length;p++){if(s[p]==="--team"){p++;continue}r.push(s[p])}let i=r[0];if(!i)return console.error("\u274C 3: \u7F3A\u5C11 userId \u53C2\u6570\u3002\u7528\u6CD5: coder team member-get <userId> [teamId]"),3;let l=r[1]||this.resolveTeamId(void 0,s);if(!l)return console.error("\u274C 3: \u672A\u6307\u5B9A teamId \u4E14\u65E0\u9ED8\u8BA4\u56E2\u961F\u3002\u8FD0\u884C 'coder team use <id>' \u6216\u5E26 [teamId] \u53C2\u6570"),3;let d;try{d=await this.fetchTeam(l,o)}catch(p){return console.error(`\u274C 1: \u7F51\u7EDC\u9519\u8BEF ${p.message}`),1}if(d.error)return console.error(`\u274C ${d.error.code}: HTTP ${d.error.status}`),d.error.body&&console.error(d.error.body),d.error.code;let m=(Array.isArray(d.team.members)?d.team.members:[]).find(p=>p.user_id===i||p.id===i||p.username===i);return m?n.json?(n.field?process.stdout.write(A(D(m,n.field))+`
|
|
288
286
|
`):process.stdout.write(JSON.stringify(m,null,2)+`
|
|
289
|
-
`),0
|
|
287
|
+
`),0):n.quiet?(console.log(m.user_id||m.id),0):(console.log(`username: ${m.username||""}`),console.log(`user_id: ${m.user_id||""}`),console.log(`type: ${m.user_type||""}`),console.log(`role: ${m.role||""}`),console.log(`status: ${m.status||""}`),console.log(`points: ${m.points==null?"\u221E":m.points}`),console.log(`joined_at: ${m.created_at||""}`),m.im_bindings&&m.im_bindings.length&&console.log(`im_bindings: ${m.im_bindings.map(p=>p.channel).join(",")}`),0):(console.error(`\u274C 4: \u6210\u5458 '${i}' \u4E0D\u5728\u56E2\u961F '${d.team.name}' \u4E2D`),4)}async searchMember(e,t,o){let{out:n,remaining:s}=this.parseOutputFlags(t),r=[],i=null;for(let h=0;h<s.length;h++){if(s[h]==="--team"){h++;continue}if(s[h]==="--type"){i=s[h+1],h++;continue}r.push(s[h])}let a=r[0];if(!a)return console.error("\u274C 3: \u7F3A\u5C11 keyword \u53C2\u6570\u3002\u7528\u6CD5: coder team search-member <keyword> [teamId]"),3;let d=r[1]||this.resolveTeamId(void 0,s);if(!d)return console.error("\u274C 3: \u672A\u6307\u5B9A teamId \u4E14\u65E0\u9ED8\u8BA4\u56E2\u961F"),3;if(i&&i!=="human"&&i!=="ai")return console.error(`\u274C 3: --type \u4EC5\u652F\u6301 human \u6216 ai\uFF0C\u6536\u5230 '${i}'`),3;let u;try{u=await this.fetchTeam(d,o)}catch(h){return console.error(`\u274C 1: \u7F51\u7EDC\u9519\u8BEF ${h.message}`),1}if(u.error)return console.error(`\u274C ${u.error.code}: HTTP ${u.error.status}`),u.error.body&&console.error(u.error.body),u.error.code;let m=Array.isArray(u.team.members)?u.team.members:[],p=this.filterMembersByType(m,i),f=a.toLowerCase(),g=p.filter(h=>{let I=(h.username||"").toLowerCase(),b=(h.user_id||"").toLowerCase(),S=(h.id||"").toLowerCase();return I.includes(f)||b.includes(f)||S.includes(f)});if(n.json){let h={team_id:u.team.id,keyword:a,items:g,total:g.length};return n.field?process.stdout.write(A(D(h,n.field))+`
|
|
288
|
+
`):process.stdout.write(JSON.stringify(h,null,2)+`
|
|
289
|
+
`),0}if(n.quiet){for(let h of g)console.log(h.user_id||h.id||"");return 0}if(!g.length)return console.log(`\uFF08\u672A\u5339\u914D\u5230 '${a}'\uFF09`),0;let y=g.map(h=>({username:h.username||"",user_id:h.user_id||"",type:h.user_type||"",role:h.role||""}));return ye(["username","user_id","type","role"],y),0}parseMemberCreateFlags(e){let t=[],o={type:"human",password:null,phone:null,points:null,team:null,saveTo:null};for(let n=0;n<e.length;n++){let s=e[n];if(s==="--type"){o.type=e[++n];continue}if(s==="--password"){o.password=e[++n];continue}if(s==="--phone"){o.phone=e[++n];continue}if(s==="--points"){o.points=e[++n];continue}if(s==="--team"){o.team=e[++n];continue}if(s==="--save-to"){o.saveTo=e[++n];continue}t.push(s)}return o.type!=="human"&&o.type!=="ai"?{error:`--type \u4EC5\u652F\u6301 human \u6216 ai\uFF0C\u6536\u5230 '${o.type}'`}:{remaining:t,opts:o}}isInsideGitRepo(e){let t=B.resolve(e);for((!K.existsSync(t)||!K.statSync(t).isDirectory())&&(t=B.dirname(t));t&&t!==B.dirname(t);){if(K.existsSync(B.join(t,".git")))return!0;t=B.dirname(t)}return!1}async memberCreate(e,t,o){let{out:n,remaining:s}=this.parseOutputFlags(t),r=this.parseMemberCreateFlags(s);if(r.error)return console.error(`\u274C 3: ${r.error}`),3;let{remaining:i,opts:a}=r,l=i[0];if(!l)return console.error("\u274C 3: \u7F3A\u5C11 username \u53C2\u6570\u3002\u7528\u6CD5: coder team member-create <username> [...]"),3;let d=a.team||this.resolveTeamId(void 0,[]);if(!d)return console.error("\u274C 3: \u672A\u6307\u5B9A --team \u4E14\u65E0\u9ED8\u8BA4\u56E2\u961F\u3002\u8FD0\u884C 'coder team use <id>' \u6216\u52A0 --team <id>"),3;if(a.type==="human"&&!a.phone)return console.error("\u274C 3: \u521B\u5EFA human \u6210\u5458\u5FC5\u987B\u63D0\u4F9B --phone <phone>"),3;if(a.saveTo){let b=B.resolve(a.saveTo);if(this.isInsideGitRepo(b))return console.error(`\u274C 3: --save-to \u8DEF\u5F84\u5728 git \u4ED3\u5E93\u5185\uFF08${b}\uFF09\uFF0C\u62D2\u7EDD\u5199\u5165\u907F\u514D\u8BEF\u63D0\u4EA4`),3}let u=a.password||eo.generateStrongPassword(16),m=!a.password,p=null;if(a.points!==null&&a.points!==void 0){let b=Number(a.points);if(!Number.isFinite(b))return console.error(`\u274C 3: --points \u5E94\u4E3A\u6570\u5B57\uFF0C\u6536\u5230 '${a.points}'`),3;p=b}let f={payload:{username:l,password:u,phone:a.phone||null,team_id:d,points:p,user_type:a.type},auto_login:!1,auth_name:"UserPass"},g;try{g=await this.request("POST","/users",o,f)}catch(b){return console.error(`\u274C 1: \u7F51\u7EDC\u9519\u8BEF ${b.message}`),1}if(g.status<200||g.status>=300)return console.error(`\u274C ${this.exitCodeForStatus(g.status)}: HTTP ${g.status}`),g.body&&console.error(g.body),this.exitCodeForStatus(g.status);let y=this.parseJson(g.body),h=null;if(a.saveTo){let b=B.resolve(a.saveTo),S=`# Coder team member credentials
|
|
290
290
|
# Created: ${new Date().toISOString()}
|
|
291
291
|
username: ${l}
|
|
292
292
|
password: ${u}
|
|
293
293
|
team_id: ${d}
|
|
294
294
|
type: ${a.type}
|
|
295
|
-
`;try{
|
|
296
|
-
`):process.stdout.write(JSON.stringify(
|
|
297
|
-
`),0):
|
|
298
|
-
`):(console.log(`\u5C06\u5220\u9664\u6210\u5458 ${
|
|
299
|
-
`),0):
|
|
300
|
-
`):process.stdout.write(JSON.stringify(
|
|
301
|
-
`),0):
|
|
302
|
-
`):process.stdout.write(JSON.stringify(
|
|
303
|
-
`),0}return o.quiet?(
|
|
304
|
-
`),0}return
|
|
305
|
-
`))}};function
|
|
295
|
+
`;try{K.writeFileSync(b,S,{mode:384});try{K.chmodSync(b,384)}catch{}h=b}catch(x){console.error(`\u26A0\uFE0F \u4FDD\u5B58\u51ED\u636E\u5931\u8D25: ${x.message}`)}}let I={username:l,password:u,team_id:d,user_type:a.type,saved_to:h,response:y&&y.data?y.data:y};return n.json?(n.field?process.stdout.write(A(D(I,n.field))+`
|
|
296
|
+
`):process.stdout.write(JSON.stringify(I,null,2)+`
|
|
297
|
+
`),0):n.quiet?(console.log(l),0):(console.log("\u2705 \u6210\u5458\u521B\u5EFA\u6210\u529F"),console.log(`username: ${l}`),console.log(`password: ${u} ${m?"(\u968F\u673A\u751F\u6210\uFF0C\u8BF7\u59A5\u5584\u4FDD\u7BA1)":""}`),console.log(`team_id: ${d}`),console.log(`type: ${a.type}`),console.log(h?`\u26A0\uFE0F \u51ED\u636E\u5DF2\u4FDD\u5B58\u5230 ${h} (mode 0600)\uFF0C\u8BF7\u59A5\u5584\u4FDD\u7BA1\uFF0C\u5EFA\u8BAE\u52A0\u5165 .gitignore`:"\u26A0\uFE0F \u4EE5\u4E0A\u51ED\u636E\u4EC5\u663E\u793A\u4E00\u6B21\uFF0C\u672A --save-to \u65F6\u8BF7\u7ACB\u5373\u8BB0\u5F55"),0)}async memberDelete(e,t,o){let{out:n,remaining:s}=this.parseOutputFlags(t),r=[],i=!1,a=null;for(let g=0;g<s.length;g++){if(s[g]==="--yes"||s[g]==="-y"){i=!0;continue}if(s[g]==="--team"){a=s[++g];continue}r.push(s[g])}let l=r[0];if(!l)return console.error("\u274C 3: \u7F3A\u5C11 userId \u53C2\u6570\u3002\u7528\u6CD5: coder team member-delete <userId> [--yes]"),3;let d=a||r[1]||this.resolveTeamId(void 0,[]);if(!d)return console.error("\u274C 3: \u672A\u6307\u5B9A --team \u4E14\u65E0\u9ED8\u8BA4\u56E2\u961F"),3;let u;try{u=await this.fetchTeam(d,o)}catch(g){return console.error(`\u274C 1: \u7F51\u7EDC\u9519\u8BEF ${g.message}`),1}if(u.error)return console.error(`\u274C ${u.error.code}: HTTP ${u.error.status}`),u.error.body&&console.error(u.error.body),u.error.code;let p=(Array.isArray(u.team.members)?u.team.members:[]).find(g=>g.user_id===l||g.id===l||g.username===l);if(!p)return console.error(`\u274C 4: \u6210\u5458 '${l}' \u4E0D\u5728\u56E2\u961F '${u.team.name}' \u4E2D`),4;if(!i){let g="\u9AD8\u5F71\u54CD\u64CD\u4F5C\uFF0C\u5FC5\u987B\u52A0 --yes \u624D\u4F1A\u6267\u884C";return n.json?process.stdout.write(JSON.stringify({method:"DELETE",path:`/team/${d}/members/${p.id}`,target:{username:p.username,user_id:p.user_id,role:p.role},note:g},null,2)+`
|
|
298
|
+
`):(console.log(`\u5C06\u5220\u9664\u6210\u5458 ${p.username} (user_id=${p.user_id}, role=${p.role})`),console.log(`\u4ECE\u56E2\u961F: ${u.team.name} (${d})`),console.log(`endpoint: DELETE /team/${d}/members/${p.id}`),console.log(`\u26A0\uFE0F ${g}`)),10}let f;try{f=await this.request("DELETE",`/team/${d}/members/${p.id}`,o)}catch(g){return console.error(`\u274C 1: \u7F51\u7EDC\u9519\u8BEF ${g.message}`),1}return f.status<200||f.status>=300?(console.error(`\u274C ${this.exitCodeForStatus(f.status)}: HTTP ${f.status}`),f.body&&console.error(f.body),this.exitCodeForStatus(f.status)):n.json?(process.stdout.write(JSON.stringify({deleted:!0,username:p.username,user_id:p.user_id,team_id:d},null,2)+`
|
|
299
|
+
`),0):n.quiet?(console.log(p.user_id),0):(console.log(`\u2705 \u5DF2\u5220\u9664\u6210\u5458 ${p.username} (${p.user_id}) from ${u.team.name}`),0)}async setPoints(e,t,o){let{out:n,remaining:s}=this.parseOutputFlags(t),r=[],i={unlimited:!1,inherit:!1,points:null,team:null};for(let x=0;x<s.length;x++){let L=s[x];if(L==="--unlimited"){i.unlimited=!0;continue}if(L==="--inherit"){i.inherit=!0;continue}if(L==="--points"){i.points=s[++x];continue}if(L==="--team"){i.team=s[++x];continue}r.push(L)}let a=r[0];if(!a)return console.error("\u274C 3: \u7F3A\u5C11 userId \u53C2\u6570\u3002\u7528\u6CD5: coder team set-points <userId> --unlimited|--points <n>|--inherit"),3;let l=[i.unlimited,i.inherit,i.points!==null].filter(Boolean).length;if(l===0)return console.error("\u274C 3: \u5FC5\u987B\u63D0\u4F9B --unlimited\u3001--points <n> \u6216 --inherit \u4E2D\u7684\u4E00\u4E2A"),3;if(l>1)return console.error("\u274C 3: --unlimited / --points / --inherit \u4E92\u65A5\uFF0C\u53EA\u80FD\u9009\u4E00\u4E2A"),3;let d;if(i.unlimited||i.inherit)d=null;else{let x=Number(i.points);if(!Number.isFinite(x)||x<0)return console.error(`\u274C 3: --points \u5E94\u4E3A\u975E\u8D1F\u6570\u5B57\uFF0C\u6536\u5230 '${i.points}'`),3;d=x}let u=i.team||r[1]||this.resolveTeamId(void 0,[]);if(!u)return console.error("\u274C 3: \u672A\u6307\u5B9A --team \u4E14\u65E0\u9ED8\u8BA4\u56E2\u961F\u3002\u8FD0\u884C 'coder team use <id>' \u6216\u52A0 --team <id>"),3;let m;try{m=await this.fetchTeam(u,o)}catch(x){return console.error(`\u274C 1: \u7F51\u7EDC\u9519\u8BEF ${x.message}`),1}if(m.error)return console.error(`\u274C ${m.error.code}: HTTP ${m.error.status}`),m.error.body&&console.error(m.error.body),m.error.code;let f=(Array.isArray(m.team.members)?m.team.members:[]).find(x=>x.user_id===a||x.id===a||x.username===a);if(!f)return console.error(`\u274C 4: \u6210\u5458 '${a}' \u4E0D\u5728\u56E2\u961F '${m.team.name}' \u4E2D`),4;let g=`/refactor/coder/teams/${u}/members/${f.user_id}/points`,y={points:d},h=d===null?"\u4E0D\u9650\u91CF\uFF08\u7EE7\u627F\u56E2\u961F\u6C60\uFF09":String(d),I;try{I=await this.request("POST",g,o,y,oo)}catch(x){return console.error(`\u274C 1: \u7F51\u7EDC\u9519\u8BEF ${x.message}`),1}if(I.status<200||I.status>=300){let x=this.exitCodeForStatus(I.status);return console.error(`\u274C ${x}: HTTP ${I.status}`),I.body&&console.error(I.body),x}let b=this.parseJson(I.body);if(b&&b.code!==void 0&&b.code!==0&&b.code!==null)return console.error(`\u274C 1: \u540E\u7AEF\u8FD4\u56DE code=${b.code} message=${b.message||""}`),1;let S={username:f.username,user_id:f.user_id,team_id:u,points:d,quota:h};return n.json?(n.field?process.stdout.write(A(D(S,n.field))+`
|
|
300
|
+
`):process.stdout.write(JSON.stringify(S,null,2)+`
|
|
301
|
+
`),0):n.quiet?(console.log(f.user_id),0):(console.log(`\u2705 \u5DF2\u4E3A ${f.username} (${f.user_id}) \u8BBE\u7F6E\u79EF\u5206\u914D\u989D: ${h}`),0)}async current(e,t){let{out:o}=this.parseOutputFlags(e),n=this.argParser?this.argParser.getTeam():null;if(o.json){let s=n?{id:n.id,name:n.name||""}:null;return o.field?process.stdout.write(A(D(s,o.field))+`
|
|
302
|
+
`):process.stdout.write(JSON.stringify(s,null,2)+`
|
|
303
|
+
`),0}return o.quiet?(n&&n.id&&console.log(n.id),0):!n||!n.id?(console.log("\uFF08\u672A\u8BBE\u7F6E\u9ED8\u8BA4\u56E2\u961F\uFF0C\u8FD0\u884C 'coder team use <teamId>' \u6765\u8BBE\u7F6E\uFF09"),0):(console.log(`\u9ED8\u8BA4\u56E2\u961F: ${n.name||""} (${n.id})`),0)}async use(e,t,o){let{out:n,remaining:s}=this.parseOutputFlags(t),r=s[0];if(!r)return console.error("\u274C 3: \u7F3A\u5C11 teamId \u53C2\u6570\u3002\u7528\u6CD5: coder team use <teamId>"),3;if(!this.argParser)return console.error("\u274C 1: \u5185\u90E8\u9519\u8BEF\uFF1AargParser \u672A\u6CE8\u5165"),1;let i=encodeURIComponent(JSON.stringify({filter_is_joined:!0})),a;try{a=await this.request("GET",`/team?constraints=${i}&page=1&size=200`,o)}catch(p){return console.error(`\u274C 1: \u7F51\u7EDC\u9519\u8BEF ${p.message}`),1}if(a.status!==200)return console.error(`\u274C ${this.exitCodeForStatus(a.status)}: HTTP ${a.status}`),a.body&&console.error(a.body),this.exitCodeForStatus(a.status);let l=this.parseJson(a.body),u=(l&&l.data&&l.data.items||[]).find(p=>p.id===r);if(!u)return console.error(`\u274C 4: \u56E2\u961F '${r}' \u4E0D\u5728\u4F60\u5DF2\u52A0\u5165\u7684\u5217\u8868\u4E2D\u3002\u8FD0\u884C 'coder team list' \u67E5\u770B\u53EF\u7528\u56E2\u961F`),4;if(!this.argParser.setTeam(u.id,u.name||""))return console.error("\u274C 1: \u5199\u5165\u914D\u7F6E\u5931\u8D25"),1;if(this.argParser.setTeamManual(!0),n.json){let p={id:u.id,name:u.name||""};return process.stdout.write(JSON.stringify(p,null,2)+`
|
|
304
|
+
`),0}return n.quiet?(console.log(u.id),0):(console.log(`\u2705 \u5DF2\u5207\u6362\u5230\u9ED8\u8BA4\u56E2\u961F: ${u.name||""} (${u.id})`),0)}showHelp(){console.log(["Usage: coder team <subcommand> [options]","","\u9762\u5411 AI \u4F18\u5148\u7684\u56E2\u961F\u4E0E\u6210\u5458\u7BA1\u7406\u3002","","Team Management:"," list \u5217\u51FA\u6211\u52A0\u5165\u7684\u56E2\u961F\uFF08\u522B\u540D: ls\uFF09"," current \u663E\u793A\u5F53\u524D\u9ED8\u8BA4\u56E2\u961F"," use <teamId> \u5207\u6362\u9ED8\u8BA4\u56E2\u961F\uFF08\u5199\u5165 ~/.coder/config.json\uFF09"," info [teamId] \u56E2\u961F\u8BE6\u60C5\uFF1A\u79EF\u5206\u3001\u6210\u5458\u6570\u3001\u6709\u6548\u671F\u7B49","","Members:"," members [teamId] \u6210\u5458\u5217\u8868"," member-get <userId> [teamId] \u5355\u4E2A\u6210\u5458\u8BE6\u60C5"," member-create <username> \u521B\u5EFA\u6210\u5458\uFF08\u9ED8\u8BA4 user_type=human\uFF09"," [--type human|ai]"," [--password <pwd>] \u7701\u7565 = \u968F\u673A\u751F\u6210 16 \u4F4D\u5F3A\u5BC6\u7801"," [--phone <phone>] human \u5FC5\u586B\uFF0Cai \u53EF\u7701"," [--points <n>] \u79EF\u5206\u914D\u989D\uFF0C\u9ED8\u8BA4 null = \u7EE7\u627F\u56E2\u961F"," [--team <teamId>]"," [--save-to <path>] \u4FDD\u5B58\u51ED\u636E\u5230\u6587\u4EF6 (chmod 600)"," member-delete <userId> \u5220\u9664\u6210\u5458\uFF08\u9AD8\u5F71\u54CD\uFF0C\u9700 --yes\uFF09"," [--team <teamId>] [--yes]"," set-points <userId> \u8BBE\u7F6E\u6210\u5458\u79EF\u5206\u914D\u989D\uFF08owner / manager \u53EF\u7528\uFF09"," --unlimited \u4E0D\u9650\u91CF\uFF08points = null\uFF09"," --points <n> \u6307\u5B9A\u6570\u503C"," --inherit \u7B49\u4EF7 --unlimited\uFF08\u8BED\u4E49\uFF1A\u7EE7\u627F\u56E2\u961F\u6C60\uFF09"," [--team <teamId>]","","Discovery:"," search-member <keyword> [teamId] \u6210\u5458\u4E2D\u641C\u7D22\uFF08\u672C\u5730\u8FC7\u6EE4\uFF09","","Output (AI-friendly):"," --json \u8F93\u51FA\u7ED3\u6784\u5316 JSON\uFF08\u53EF\u88AB jq \u89E3\u6790\uFF09"," --quiet \u53EA\u8F93\u51FA\u4E3B\u952E\uFF08id / username\uFF09\uFF0C\u6362\u884C\u5206\u9694"," --field <jq-path> \u4EC5\u8F93\u51FA\u6307\u5B9A\u5B57\u6BB5\uFF08dot path\uFF0C\u5982 items[0].id\uFF09","","Exit codes:"," 0 \u6210\u529F | 1 \u901A\u7528\u9519\u8BEF | 2 \u672A\u767B\u5F55 | 3 \u53C2\u6570\u9519\u8BEF | 4 \u8D44\u6E90\u4E0D\u5B58\u5728"," 5 \u6743\u9650\u4E0D\u8DB3 | 6 \u51B2\u7A81\uFF08\u5DF2\u5B58\u5728\uFF09 | 10 \u5F85\u786E\u8BA4\uFF08\u9AD8\u5F71\u54CD\u64CD\u4F5C\u672A\u52A0 --yes\uFF09","","Examples:"," coder team list"," coder team list --json | jq '.items[].id'"," coder team list --quiet"].join(`
|
|
305
|
+
`))}};function D(c,e){if(!e)return c;let t=[],o=/[^.\[\]]+|\[(\d+)\]/g,n;for(;(n=o.exec(e))!==null;)t.push(n[1]!==void 0?Number(n[1]):n[0]);let s=c;for(let r of t){if(s==null)return;s=s[r]}return s}function A(c){return c==null?"":typeof c=="string"?c:typeof c=="number"||typeof c=="boolean"?String(c):JSON.stringify(c)}function ye(c,e){let t=c.map(n=>Math.max(n.length,...e.map(s=>lt(String(s[n]??""))))),o=(n,s)=>n+" ".repeat(Math.max(0,s-lt(n)));console.log(c.map((n,s)=>o(n,t[s])).join(" ")),console.log(t.map(n=>"-".repeat(n)).join(" "));for(let n of e)console.log(c.map((s,r)=>o(String(n[s]??""),t[r])).join(" "))}function lt(c){let e=0;for(let t of c){let o=t.codePointAt(0);o>=19968&&o<=40959||o>=12288&&o<=12351||o>=65280&&o<=65519?e+=2:e+=1}return e}dt.exports=be});var ht=$((Ro,mt)=>{var No=require("path"),no=Se(),pt=Oe(),ro=Ae(),so=qe(),io=je(),co=Re(),ao=Je(),lo=Ke(),uo=ze(),po=Qe(),mo=it(),ho=ut(),{isPrintMode:Uo}=U(),Ie=class{constructor(){this.argParser=new no,this.claudeLauncher=this._createClaudeLauncher(),this.geminiLauncher=new so,this.codexLauncher=new io,this.vscodeExtensionService=new co,this.publishService=new ao,this.skillsService=new lo,this.wikiService=new uo(this.argParser),this.channelService=new po,this.authCommandService=new mo(this.argParser),this.teamService=new ho(this.argParser),this.wikiService.teamService=this.teamService}_createClaudeLauncher(){let e=process.env.CODEV_DEBUG;if(process.env.CODEV_USE_NODE==="1")return e&&console.error("[DEBUG] CODEV_USE_NODE=1, forcing ClaudeLauncher (node fallback)"),new pt;try{let t=new ro,o=t.findExecutablePath();return e&&console.error(`[DEBUG] ClaudeBunLauncher selected, executable: ${o}`),t}catch(t){return e&&console.error(`[DEBUG] ClaudeBunLauncher unavailable: ${t.message}, falling back to ClaudeLauncher (node)`),new pt}}async run(e=process.argv.slice(2)){try{try{await this.vscodeExtensionService.ensureExtensionInstalled()}catch(o){process.env.CODEV_DEBUG&&console.error("VSCode Extension Service Error:",o)}if(!e.includes("--agent")&&!e.includes("-a")){let o=e.length>0&&["claude","gemini","codex"].includes(e[0]),n=e.length>0&&["pub","auth","update","skills","wiki","channel","team"].includes(e[0]);if(!o&&!n&&(e.includes("--help")||e.includes("-h")))return this.argParser.showHelp(),0;if(!o&&!n&&(e.includes("--version")||e.includes("-v")))return this.showVersion(),0}let t=await this.argParser.parse(e);return t.command==="auth"?await this.authCommandService.handle(t):t.command==="update"?this.handleUpdate():t.command==="skills"?await this.skillsService.handle(t):t.command==="wiki"?await this.wikiService.handle(t):t.command==="channel"?await this.channelService.handle({...t,claudeLauncher:this.claudeLauncher,parsedArgs:t}):t.command==="team"?await this.teamService.handle(t):t.command==="pub"?e.includes("--help")||e.includes("-h")?(this.publishService.showHelp(),0):await this.publishService.publish({name:t.pubName,apikey:t.apikey,serverBaseUrl:t.codevServer,allowClone:t.allowClone}):(t.apikey&&this.skillsService.notifyAndRefreshUpdates(t.apikey),await this.launchAgent(t))}catch(t){return console.error(`Error: ${t.message}`),process.env.CODEV_DEBUG&&console.error("Stack trace:",t.stack),1}}async launchAgent(e){let{agent:t}=e;return t==="claude"?await this.claudeLauncher.launch(e):t==="gemini"?await this.geminiLauncher.launch(e):t==="codex"?await this.codexLauncher.launch(e):1}handleUpdate(){let{execSync:e}=require("child_process"),t=N();console.log(`\u5F53\u524D\u7248\u672C: ${t.version}`),console.log(`\u6B63\u5728\u5347\u7EA7 Coder...
|
|
306
306
|
`);try{return e("npm install -g makecoder@latest",{stdio:"inherit"}),console.log(`
|
|
307
307
|
\u2705 \u5347\u7EA7\u6210\u529F`),0}catch(o){return console.error(`
|
|
308
|
-
\u274C \u5347\u7EA7\u5931\u8D25:`,o.message),1}}showVersion(){let e=
|
|
309
|
-
Shutting down...`),process.exit(0)}};
|
|
308
|
+
\u274C \u5347\u7EA7\u5931\u8D25:`,o.message),1}}showVersion(){let e=N();console.log(`coder version: ${e.version}`)}async shutdown(){console.log(`
|
|
309
|
+
Shutting down...`),process.exit(0)}};mt.exports=Ie});var ft=process.env.CODER_ARGV0;if(ft){let e={rg:"rg",ugrep:"ugrep",bfs:"bfs"}[ft];if(e){let t=require("path").join(__dirname,"..","dist",`${process.platform}-${process.arch}`,e);require("fs").existsSync(t)||(console.error(`${e} is not available. Use system default command instead (grep, find, etc.)`),process.exit(1));let{spawnSync:o}=require("child_process"),n=o(t,process.argv.slice(2),{stdio:"inherit"});process.exit(n.status??1)}}var fo=ht(),{isPrintMode:Fo}=U();process.on("unhandledRejection",(c,e)=>{console.error("Unhandled Promise Rejection:",c),process.exit(1)});process.on("uncaughtException",c=>{console.error("Uncaught Exception:",c.message),process.env.CODEV_DEBUG&&console.error(c.stack),process.exit(1)});function go(c,e){let t=s=>s.replace(/^v/,"").split(".").map(Number),[o,n]=[t(c),t(e)];for(let s=0;s<3;s++){if((o[s]||0)>(n[s]||0))return!0;if((o[s]||0)<(n[s]||0))return!1}return!1}function yo(){let c=require("https"),{version:e}=N(),o=c.get("https://registry.npmmirror.com/makecoder/latest",{timeout:5e3},n=>{let s="";n.on("data",r=>{s+=r}),n.on("end",()=>{try{let r=JSON.parse(s).version;r&&go(r,e)&&console.log(`\x1B[33m\u26A1 \u68C0\u6D4B\u5230\u65B0\u7248\u672C ${r}\uFF08\u5F53\u524D ${e}\uFF09\uFF0C\u8FD0\u884C coder update \u5347\u7EA7\x1B[0m`)}catch{}})});o.on("error",()=>{}),o.on("timeout",()=>o.destroy())}async function bo(){yo();let c=new fo;process.on("SIGINT",async()=>{console.log(`
|
|
310
310
|
Received SIGINT, shutting down gracefully...`),await c.shutdown()}),process.on("SIGTERM",async()=>{console.log(`
|
|
311
|
-
Received SIGTERM, shutting down gracefully...`),await c.shutdown()});try{let e=await c.run();process.exit(e)}catch(e){console.error(`Fatal error: ${e.message}`),process.env.CODEV_DEBUG&&console.error(e.stack),process.exit(1)}}
|
|
311
|
+
Received SIGTERM, shutting down gracefully...`),await c.shutdown()});try{let e=await c.run();process.exit(e)}catch(e){console.error(`Fatal error: ${e.message}`),process.env.CODEV_DEBUG&&console.error(e.stack),process.exit(1)}}bo().catch(c=>{console.error(`Startup error: ${c.message}`),process.exit(1)});
|