@coze/cli 0.2.0-alpha.c1b76c → 0.2.0-alpha.c23a50

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/lib/cli.js CHANGED
@@ -1,5 +1,5 @@
1
1
  #!/usr/bin/env node
2
- "use strict";const e=require("./fetch-client-DC0c3ox3.js"),t=require("./index-DNmOe3vH.js"),o=require("chalk"),i=require("node:path"),s=require("node:fs/promises"),n=require("node:os"),r=require("node:fs"),a=require("./task-worker-4JFWlT-Q.js"),c=require("node:crypto"),l=require("node:child_process"),d=require("node:http"),p=require("node:https"),u=require("node:buffer"),m=require("undici"),g=require("path"),h=require("fs/promises"),f=require("fs"),_=require("form-data"),y=require("omelette"),b=require("lodash"),v=require("child_process"),w=require("ws"),C=require("commander");function E(e){const t=Object.create(null);if(e)for(const o in e)if("default"!==o){const i=Object.getOwnPropertyDescriptor(e,o);Object.defineProperty(t,o,i.get?i:{enumerable:!0,get:function(){return e[o]}})}return t.default=e,Object.freeze(t)}require("crypto"),require("url"),require("http"),require("https"),require("http2"),require("util"),require("stream"),require("assert"),require("tty"),require("zlib"),require("events"),require("mitt"),require("process");const I=E(i),A=E(s);function S(e,t){return null!=e?e:t()}class j{format(e){const t=JSON.stringify(e,null,2);return t.endsWith("\n")?t:`${t}\n`}formatError(e){const t={code:e.code,errorName:S(e.errorName,(()=>"UNKNOWN_ERROR")),desc:S(e.desc,(()=>e.message)),trigger:S(e.trigger,(()=>null)),fix:S(e.fix,(()=>null)),example:S(e.example,(()=>null))},o=JSON.stringify(t,null,2);return o.endsWith("\n")?o:`${o}\n`}}function P(e,t){return null!=e?e:t()}function k(e){let t,o=e[0],i=1;for(;i<e.length;){const s=e[i],n=e[i+1];if(i+=2,("optionalAccess"===s||"optionalCall"===s)&&null==o)return;"access"===s||"optionalAccess"===s?(t=o,o=n(o)):"call"!==s&&"optionalCall"!==s||(o=n(((...e)=>o.call(t,...e))),t=void 0)}return o}function T(e){const t=String.fromCharCode(27),o=new RegExp(`${t}(?:[@-Z\\\\-_]|\\[[0-?]*[ -/]*[@-~])`,"g");return e.replace(o,"")}function z(e){return e>=4352&&e<=4447||(9001===e||9002===e||(e>=11904&&e<=12350||(e>=12352&&e<=42191||(e>=44032&&e<=55203||(e>=63744&&e<=64255||(e>=65040&&e<=65049||(e>=65072&&e<=65135||(e>=65280&&e<=65376||(e>=65504&&e<=65510||(e>=127744&&e<=129695||e>=131072&&e<=262141))))))))))}function R(e){const t=T(e);if(!t)return 0;const o=/[\u0300-\u036F\u1AB0-\u1AFF\u1DC0-\u1DFF\u20D0-\u20FF\uFE20-\uFE2F]/u;let i=0;const s=Array.from(t);for(let e=0;e<s.length;e+=1){const t=P(s[e],(()=>""));if(o.test(t))continue;const n=t.codePointAt(0);void 0!==n&&(i+=z(n)?2:1)}return i}function x(e,t){const o=R(e);return o>=t?e:`${e}${" ".repeat(t-o)}`}function L(e,t){if(t<=0)return"";if(R(e)<=t)return e;if(1===t)return"…";const o=T(e),i=Array.from(o),s=Math.max(0,t-R("…"));let n="",r=0;for(let e=0;e<i.length;e+=1){const t=P(i[e],(()=>"")),o=R(t);if(r+o>s)break;n+=t,r+=o}return`${n}…`}function O(e,t={}){if(0===e.length)return"";const o=function(e,t){if(0===e.length)return[];const o=new Set,i=[],s=P(e[0],(()=>({})));for(const e of Object.keys(s))o.has(e)||(o.add(e),i.push(e));for(const t of e)for(const e of Object.keys(t))o.has(e)||(o.add(e),i.push(e));const n=[];for(const t of i){let o=R(t);for(const i of e){const e=i[t],s=void 0===e?"":String(e);o=Math.max(o,R(s))}n.push({key:t,width:o})}const r=P(t.columnGap,(()=>2)),a=P(P(t.maxWidth,(()=>process.stdout.columns)),(()=>120)),c=Math.max(1,Math.floor((a+r)/(6+r))),l=Math.min(P(t.maxColumns,(()=>c)),c);n.length>l&&n.splice(l);const d=Math.max(0,a-r*Math.max(0,n.length-1));for(;n.reduce(((e,t)=>e+t.width),0)>d;){let e=-1,t=-1;for(let o=0;o<n.length;o+=1){const i=P(k([n,"access",e=>e[o],"optionalAccess",e=>e.width]),(()=>0));i>t&&(t=i,e=o)}if(-1===e)break;const o=P(k([n,"access",t=>t[e],"optionalAccess",e=>e.width]),(()=>0));if(o<=6)break;n[e]={...n[e],width:o-1}}for(let e=0;e<n.length;e+=1){const t=n[e];t&&(n[e]={...t,width:Math.max(6,t.width)})}return n}(e,t);if(0===o.length)return"";const i=P(t.columnGap,(()=>2)),s=" ".repeat(i),n=o.map((e=>x(L(e.key,e.width),e.width))).join(s),r=o.map((e=>"-".repeat(e.width))).join(s),a=[];for(const t of e){const e=o.map((e=>{const o=t[e.key];return x(L(void 0===o?"":String(o),e.width),e.width)}));a.push(e.join(s))}return`${[n,r,...a].join("\n")}\n`}function D(e,t={}){const o=Object.entries(e);if(0===o.length)return"";let i=0;for(const[e]of o)i=Math.max(i,R(e));const s=P(P(t.maxWidth,(()=>process.stdout.columns)),(()=>120)),n=P(t.columnGap,(()=>2)),r=P(t.minValueWidth,(()=>12));let a=Math.min(i,P(t.keyMaxWidth,(()=>32)));const c=Math.max(6,s-n-r);a=Math.min(a,c);const l=Math.max(0,s-a-n),d=" ".repeat(n);return`${o.map((([e,t])=>{const o=x(L(e,a),a),i=(void 0===t?"undefined":null===t?"null":String(t)).replace(/\s*\n\s*/g," "),s=l>0?L(i,l):"";return`${o}${d}${s}`})).join("\n")}\n`}function U(e,t="",o=0){const i={};if(null==e)return i;if("object"!=typeof(s=e)||null===s||Array.isArray(s))return i;var s;for(const[s,n]of Object.entries(e)){const e=t?`${t}.${s}`:s;if(null!=n)if(Array.isArray(n))o>=5?i[e]="[Array]":0===n.length?i[e]="[]":n.every((e=>"object"!=typeof e||null===e))?i[e]=n.map((e=>{return String((o=()=>"null",null!=(t=e)?t:o()));var t,o})).join(", "):i[e]="[Array]";else if("object"!=typeof n)i[e]=n;else if(o>=5)i[e]="[Object]";else{const t=U(n,e,o+1);Object.assign(i,t)}else i[e]=n}return i}function B(e,t){return null!=e?e:t()}function q(e){return"object"==typeof e&&null!==e&&!Array.isArray(e)}class M{format(e){if(null===e)return"null\n";if(void 0===e)return"undefined\n";if(Array.isArray(e)){if(0===e.length)return"\n";if(t=e,Array.isArray(t)&&t.length>0&&t.every(q)){return O(e.map((e=>U(e))))}return function(e){return Array.isArray(e)&&e.length>0&&e.every((e=>null==e||"object"!=typeof e))}(e)?`${e.map((e=>String(B(e,(()=>"null"))))).join("\n")}\n`:"[Array]\n"}var t;if(q(e)){const t=U(e);return 0===Object.keys(t).length?"{}\n":D(t)}return`${String(e)}\n`}formatError(e){const t=[],o=B(e.errorName,(()=>"UNKNOWN_ERROR")),i=B(e.desc,(()=>e.message));return t.push(`ERROR [${e.code}] ${o}: ${i}`),e.trigger&&t.push(` Trigger: ${e.trigger}`),e.fix&&t.push(` Fix: ${e.fix}`),e.example&&t.push(` Example: ${e.example}`),e.details&&(t.push(" Error Details:"),t.push(`${function(e,t){if(null==e)return"";if("string"==typeof e)return`${t}${e}\n`;if(Array.isArray(e))return 0===e.length?"":`${e.map((e=>"object"==typeof e&&null!==e?D(U(e)):String(e))).map((e=>`${t}- ${e.trim()}`)).join("\n")}\n`;if(q(e)){const o=U(e);return 0===Object.keys(o).length?"":`${D(o).split("\n").filter((e=>e.trim())).map((e=>`${t}${e}`)).join("\n")}\n`}return`${t}${String(e)}\n`}(e.details," ")}`)),`${t.join("\n")}\n`}}function N(e,t){return null!=e?e:t()}function $(e){let t,o=e[0],i=1;for(;i<e.length;){const s=e[i],n=e[i+1];if(i+=2,("optionalAccess"===s||"optionalCall"===s)&&null==o)return;"access"===s||"optionalAccess"===s?(t=o,o=n(o)):"call"!==s&&"optionalCall"!==s||(o=n(((...e)=>o.call(t,...e))),t=void 0)}return o}function G(e,t){if(null==e)return;const o=String(e).replace(/\s*\n\s*/g," ").replace(/\s+/g," ").trim();return o?o.length<=t?o:`${o.slice(0,Math.max(0,t-3))}...`:void 0}function F(e){const t=$([e,"optionalAccess",e=>e.help,"optionalAccess",e=>e.errors]);if(t&&t.length>0)return t;const o=$([e,"optionalAccess",e=>e.errors]);return Array.isArray(o)?o:void 0}function V(t,o){const i=N(t.trigger,(()=>function(e){if(!e||0===e.length)return;return G(("coze"===e[0]?e:["coze",...e]).join(" "),150)}($([o,"optionalAccess",e=>e.argv])))),s=$([F,"call",e=>e($([o,"optionalAccess",e=>e.commandConfig])),"optionalAccess",e=>e.find,"call",e=>e((e=>e.code===t.code))]),n=N($([s,"optionalAccess",e=>e.name]),(()=>e.ErrorNameByCode[t.code])),r=N(G(n,80),(()=>"UNKNOWN_ERROR"));let a=n;t.isMessageExplicit&&t.message.trim()?a=t.message:$([s,"optionalAccess",e=>e.desc])&&(a=s.desc);const c=N(G(a,200),(()=>"An unexpected error occurred")),l=N(G(t.fix,150),(()=>G($([s,"optionalAccess",e=>e.fix]),150))),d=N(G(t.example,150),(()=>G($([s,"optionalAccess",e=>e.example]),150)));return{code:t.code,errorName:r,desc:c,trigger:i,fix:l,example:d}}function W(e,t){const o=V(e,t);return e.errorName=o.errorName,e.desc=o.desc,e.message=o.desc,e.trigger=o.trigger,e.fix=o.fix,e.example=o.example,e}function H(e){let t,o=e[0],i=1;for(;i<e.length;){const s=e[i],n=e[i+1];if(i+=2,("optionalAccess"===s||"optionalCall"===s)&&null==o)return;"access"===s||"optionalAccess"===s?(t=o,o=n(o)):"call"!==s&&"optionalCall"!==s||(o=n(((...e)=>o.call(t,...e))),t=void 0)}return o}var J;function K(o,i,s,n){if(o instanceof e.CozeError)throw o;if(e.isHttpError(o)){const e=H([o,"access",e=>e.response,"optionalAccess",e=>e.status]);if("ECONNREFUSED"===o.code||"ETIMEDOUT"===o.code||"number"==typeof e&&e>=500)throw o}if(o instanceof t.ChatCoreError&&"number"==typeof H([o,"access",e=>e.ext,"optionalAccess",e=>e.code])&&o.ext.code>=500)throw o;throw new e.CozeError(i,s,{...n,cause:o instanceof Error?o.message:String(o)})}!function(e){e[e.NOT_LOGIN=700012006]="NOT_LOGIN"}(J||(J={}));const Q=(o,i)=>{const s=W(function(o){if(o instanceof e.CozeError)return o;if(o instanceof t.ChatCoreError){const{ext:t}=o;let i=e.ErrorCode.E5000;"number"==typeof t.code&&(t.code===J.NOT_LOGIN?i=e.ErrorCode.E2001:t.code>=500&&(i=e.ErrorCode.E5002));const{message:s}=o;return new e.CozeError(i,s,t)}if(e.isHttpError(o)){const t=o.toJSON();let i=e.ErrorCode.E5000;const s=H([o,"access",e=>e.response,"optionalAccess",e=>e.status]);o.code===J.NOT_LOGIN||401===s?i=e.ErrorCode.E2001:"ECONNREFUSED"===o.code||"ETIMEDOUT"===o.code?i=e.ErrorCode.E5001:403===s?i=e.ErrorCode.E2003:404===s?i=e.ErrorCode.E3000:429===s?i=e.ErrorCode.E4001:s&&s>=500&&(i=e.ErrorCode.E5002);const n=H([o,"access",e=>e.response,"optionalAccess",e=>e.headers,"optionalAccess",e=>e["x-tt-logid"]]),{message:r}=o;return new e.CozeError(i,r,{logId:n,...t})}return o instanceof Error?new e.CozeError(e.ErrorCode.E5000,o.message,o.stack):"string"==typeof o?new e.CozeError(e.ErrorCode.E5000,o):new e.CozeError(e.ErrorCode.E5000,"An unexpected error occurred")}(o),i?{argv:i.argv,commandConfig:i.commandConfig}:void 0);var n,r;if(s.code===e.ErrorCode.E2001&&process.stdout.write(`${n=s.desc,r=()=>s.message,null!=n?n:r()}\n`),i)i.response.eprint(s);else{const e=new M;process.stderr.write(e.formatError(s))}process.exit(e.exitCodeForError(s.code))};async function Y(e){try{return(await s.stat(e)).isDirectory()}catch(e){return!1}}async function Z(e){for(const t of e)if(await Y(t))return!0;return!1}const X=()=>n.homedir(),ee=(...e)=>()=>i.join(X(),...e),te=(...e)=>()=>i.join(X(),".config",...e);function oe(e,t,o){return{name:e,get skillsDir(){return t()},detect:()=>Z(o.map((e=>e())))}}const ie=[oe("antigravity",ee(".gemini","antigravity","skills"),[ee(".gemini","antigravity")]),oe("cortex",ee(".snowflake","cortex","skills"),[ee(".snowflake","cortex")]),oe("deepagents",ee(".deepagents","agent","skills"),[ee(".deepagents")]),oe("github-copilot",ee(".copilot","skills"),[ee(".copilot")]),oe("pi",ee(".pi","agent","skills"),[ee(".pi","agent")]),oe("tabnine-cli",ee(".tabnine","agent","skills"),[ee(".tabnine")]),oe("windsurf",ee(".codeium","windsurf","skills"),[ee(".codeium","windsurf")]),oe("kimi-cli",te("agents","skills"),[ee(".kimi")]),oe("amp",te("agents","skills"),[te("amp")]),oe("crush",te("crush","skills"),[te("crush")]),oe("devin",te("devin","skills"),[te("devin")]),oe("goose",te("goose","skills"),[te("goose")]),oe("opencode",te("opencode","skills"),[te("opencode")]),oe("cline",ee(".agents","skills"),[ee(".cline")]),oe("dexto",ee(".agents","skills"),[ee(".dexto")]),oe("warp",ee(".agents","skills"),[ee(".warp")]),oe("zed",ee(".agents","skills"),[te("zed")]),function(){const e=[".openclaw",".clawdbot",".moltbot"];return{name:"openclaw",get skillsDir(){return i.join((()=>{const t=e.find((e=>r.existsSync(i.join(X(),e))));return i.join(X(),(s=()=>e[0],null!=(o=t)?o:s()));var o,s})(),"skills")},detect:()=>Z(e.map((e=>i.join(X(),e))))}}()],se=[...[["claude",".claude"],["trae",".trae"],["trae-cn",".trae-cn"],["comate",".comate"],["cursor",".cursor"],["augment",".augment"],["bob",".bob"],["aider-desk",".aider-desk"],["codebuddy",".codebuddy"],["codemaker",".codemaker"],["codestudio",".codestudio"],["codearts-agent",".codeartsdoer"],["command-code",".commandcode"],["continue",".continue"],["forgecode",".forge"],["droid",".factory"],["gemini-cli",".gemini"],["firebender",".firebender"],["hermes-agent",".hermes"],["junie",".junie"],["iflow-cli",".iflow"],["kilo",".kilocode"],["kiro-cli",".kiro"],["kode",".kode"],["mcpjam",".mcpjam"],["mux",".mux"],["openhands",".openhands"],["qoder",".qoder"],["qwen-code",".qwen"],["rovodev",".rovodev"],["roo",".roo"],["zencoder",".zencoder"],["neovate",".neovate"],["pochi",".pochi"],["adal",".adal"]].map((([e,t])=>oe(e,ee(t,"skills"),[ee(t)]))),...ie];function ne(e){return se.find((t=>t.name===e))}function re(e){let t,o=e[0],i=1;for(;i<e.length;){const s=e[i],n=e[i+1];if(i+=2,("optionalAccess"===s||"optionalCall"===s)&&null==o)return;"access"===s||"optionalAccess"===s?(t=o,o=n(o)):"call"!==s&&"optionalCall"!==s||(o=n(((...e)=>o.call(t,...e))),t=void 0)}return o}function ae(){return a.getGlobalSkillsDir()}function ce(){return a.getGlobalSkillLockFile()}async function le(e){try{return await s.access(e),!0}catch(e){return!1}}async function de(){let t=__dirname;for(let o=0;o<12;o++){const o=i.join(t,"package.json");if(await le(o)){if("@coze/cli"===re([e.safeJsonParse(await s.readFile(o,"utf8")),"optionalAccess",e=>e.name]))return t}const n=i.dirname(t);if(n===t)break;t=n}return i.resolve(__dirname,"..")}const pe=new Set(["SKILL.md","MODULE.md"]);function ue(e){return`sha256:${c.createHash("sha256").update(e,"utf8").digest("hex")}`}function me(e){return pe.has(i.basename(e))}async function ge(e,t=e){const o=await s.readdir(e,{withFileTypes:!0}),n=[];for(const s of o){if(s.name.startsWith("."))continue;const o=i.join(e,s.name);s.isDirectory()?n.push(...await ge(o,t)):s.isFile()&&n.push(i.relative(t,o).split(i.sep).join("/"))}return n.sort()}function he(e,t){const o=_e(e);if(void 0===o)return;const i=new RegExp(`^${t}:\\s*(.+?)\\s*$`,"m"),s=o.match(i);return s?s[1].replace(/^['"]|['"]$/g,"").trim():void 0}function fe(e,t){const o=_e(e);if(void 0===o)return e;const i=`version: ${t}`;let s;return s=/^version:\s*.+$/m.test(o)?o.replace(/^version:\s*.+$/m,i):/^name:\s*.+$/m.test(o)?o.replace(/^(name:\s*.+)$/m,`$1\n${i}`):`${i}\n${o}`,e.replace(o,s)}function _e(e){if(!e.startsWith("---"))return;const t=e.match(/^---\n([\s\S]*?)\n---/);return t?t[1]:void 0}function ye(e){const t=new Set;for(const o of e){const e=o.rel.split("/")[0];e&&t.add(e)}return[...t].sort()}async function be(){const t=await async function(){return i.join(await de(),"skills")}(),o=i.join(t,"manifest.json");if(await le(o)){const n=e.safeJsonParse(await s.readFile(o,"utf8")),r=(await ge(t)).filter((e=>"manifest.json"!==e)),a=[];for(const e of r)a.push({rel:e,content:await s.readFile(i.join(t,e),"utf8")});return{manifest:n,files:a,source:"bundled"}}const n=await async function(){return i.join(await de(),"docs","skills")}();if(!await le(n))throw new Error(`未找到 skill 来源:既无包内 ${o},也无开发态 ${n}。`);const r=await async function(){const t=i.join(await de(),"package.json"),o=e.safeJsonParse(await s.readFile(t,"utf8"));return n=function(e){let t,o=e[0],i=1;for(;i<e.length;){const s=e[i],n=e[i+1];if(i+=2,("optionalAccess"===s||"optionalCall"===s)&&null==o)return;"access"===s||"optionalAccess"===s?(t=o,o=n(o)):"call"!==s&&"optionalCall"!==s||(o=n(((...e)=>o.call(t,...e))),t=void 0)}return o}([o,"optionalAccess",e=>e.version]),r=()=>"0.0.0",null!=n?n:r();var n,r}(),{manifest:a,files:c}=await async function(e,t){const o=await ge(e),n=[],r={};for(const l of o){const o=await s.readFile(i.join(e,l),"utf8"),d=me(l),p=d?fe(o,t):o;n.push({rel:l,content:p}),d&&(r[(a=he(p,"name"),c=()=>l,null!=a?a:c())]={path:l,hash:ue(p)})}var a,c;return{manifest:{cliVersion:t,skills:r},files:n}}(n,r);return{manifest:a,files:c,source:"docs"}}async function ve(){try{const t=await s.readFile(ce(),"utf8");return e.safeJsonParse(t)}catch(e){return}}function we(e,t){return null!=e?e:t()}function Ce(e){let t,o=e[0],i=1;for(;i<e.length;){const s=e[i],n=e[i+1];if(i+=2,("optionalAccess"===s||"optionalCall"===s)&&null==o)return;"access"===s||"optionalAccess"===s?(t=o,o=n(o)):"call"!==s&&"optionalCall"!==s||(o=n(((...e)=>o.call(t,...e))),t=void 0)}return o}async function Ee(e){try{return ue(await s.readFile(e,"utf8"))}catch(e){return}}async function Ie(e){try{return await s.lstat(e)}catch(e){return null}}async function Ae(e,t,o,n){const r=i.join(t,e),a=i.join(o.skillsDir,e);await s.mkdir(o.skillsDir,{recursive:!0});const c=await Ie(a);if(c)if(c.isSymbolicLink())await s.rm(a,{force:!0});else{if(!n)return`已存在非软链的 ${a}(用户定制?),使用 --force 覆盖`;await s.rm(a,{recursive:!0,force:!0})}return await s.symlink(r,a,"dir"),"linked"}async function Se(e={}){const{manifest:t,files:o}=await be(),n=ae(),r=await ve(),a=await async function(e,t,o){const s=[];for(const[n,r]of Object.entries(e.skills)){const e=await Ee(i.join(t,r.path));if(void 0===e)continue;if(e===r.hash)continue;const a=Ce([o,"optionalAccess",e=>e.skills,"access",e=>e[n],"optionalAccess",e=>e.hash]);void 0!==a&&e===a||s.push(n)}return s}(t,n,r);if(a.length>0&&!e.force)return{blocked:!0,cliVersion:t.cliVersion,neutralDir:n,linkedTargets:[],skipped:[],unknownTargets:[],modifiedSkills:a};await async function(e,t){const o=ye(t);for(const t of o)await s.rm(i.join(e,t),{recursive:!0,force:!0});for(const o of t){const t=i.join(e,o.rel);await s.mkdir(i.dirname(t),{recursive:!0}),await s.writeFile(t,o.content,"utf8")}}(n,o);const{targets:c,unknown:l}=await async function(e){if(!e||0===e.length||e.includes("all")){const e=[];for(const t of se)await t.detect()&&e.push(t);return{targets:e,unknown:[]}}const t=[],o=[];for(const i of e){const e=ne(i);e?t.push(e):o.push(i)}return{targets:t,unknown:o}}(e.targets),d=ye(o),p=[],u=[];for(const t of c){const o=[];for(const i of d){const s=await Ae(i,n,t,we(e.force,(()=>!1)));"linked"!==s&&o.push(s)}0===o.length?p.push(t.name):u.push({target:t.name,reason:o.join("; ")})}const m=(new Date).toISOString(),g={};for(const[e,o]of Object.entries(t.skills))g[e]={hash:o.hash,expectedHash:o.hash,installedAt:m};return await async function(e){const t=ce();await s.mkdir(i.dirname(t),{recursive:!0}),await s.writeFile(t,`${JSON.stringify(e,null,2)}\n`,"utf8")}({version:1,cliVersion:t.cliVersion,installedBin:we(process.argv[1],(()=>process.execPath)),targets:p,skills:g}),{blocked:!1,cliVersion:t.cliVersion,neutralDir:n,linkedTargets:p,skipped:u,unknownTargets:l,modifiedSkills:[]}}async function je(){const e=ae(),t=[];let o=[];try{o=(await s.readdir(e,{withFileTypes:!0})).filter((e=>!e.name.startsWith("."))).map((e=>e.name))}catch(e){o=[]}for(const n of se)for(const r of o){const o=i.join(n.skillsDir,r),a=await Ie(o);if(!a||!a.isSymbolicLink())continue;const c=await s.readlink(o).catch((()=>null));if(null===c)continue;i.resolve(n.skillsDir,c).startsWith(e)&&(await s.rm(o,{force:!0}),t.push({target:n.name,unit:r}))}return await s.rm(e,{recursive:!0,force:!0}),await async function(){await s.rm(ce(),{force:!0})}(),{neutralDir:e,unlinked:t}}const Pe="0.2.0-alpha.c1b76c",ke="@coze/cli";function Te(){return Pe}function ze(e,t){const o=e=>{const t=e.replace(/^v/,"").split(".");return{major:parseInt(t[0]||"0",10),minor:parseInt(t[1]||"0",10),patch:parseInt(t[2]||"0",10)}},i=o(e),s=o(t);return s.major!==i.major?s.major>i.major:s.minor!==i.minor?s.minor>i.minor:s.patch>i.patch}async function Re(t,o=!1,i="latest"){const s=Te(),{config:n}=t;if(!o&&n.latestVersion&&n.lastCheckTime&&Date.now()-n.lastCheckTime<864e5)return{currentVersion:s,latestVersion:n.latestVersion,hasUpdate:ze(s,n.latestVersion)};const r=function(){try{return l.execSync("npm config get registry",{encoding:"utf8",stdio:["pipe","pipe","pipe"]}).trim().replace(/\/+$/,"")}catch(e){return"https://registry.npmjs.org"}}(),c=await async function(t,o="latest"){const i=`${t}/${ke}/${o}`,s=await e.customFetch.fetch(i,{headers:{accept:"application/json"}});if(!s.ok)throw new Error(`Failed to fetch latest version: ${s.status} ${s.statusText}`);return(await s.json()).version}(r,i);return await a.saveConfig({latestVersion:c,lastCheckTime:Date.now()},n.configScope),{currentVersion:s,latestVersion:c,hasUpdate:ze(s,c)}}async function xe(e,t){if(await t(),!0===e.config.autoCheckUpdate)try{const t=await Re(e);if(t.hasUpdate){const i=`\nUpdate available: ${o.gray(t.currentVersion)} → ${o.green(t.latestVersion)}\nRun ${o.cyan("coze upgrade")} to update\n`;e.ui.info(i)}}catch(e){}await async function(e){if("guide"===e.argv[0])return;try{const t=await async function(){const{manifest:e}=await be(),{cliVersion:t}=e,o=await ve();return o?o.cliVersion!==t?{state:"mismatch",cliVersion:t,installedVersion:o.cliVersion,message:`Skills (${o.cliVersion}) are out of sync with CLI (${t}). Run \`coze guide sync\`.`}:{state:"ok",cliVersion:t,installedVersion:o.cliVersion}:{state:"missing",cliVersion:t,message:"Bundled skills not installed yet. Run `coze guide sync` to sync them to your AI tools."}}();if("ok"===t.state)return;const o=e.config.autoSyncSkill,i=!0===o||"true"===o;if("mismatch"===t.state&&i){const e=await async function(e){if("mismatch"!==e.state)return!1;try{return!(await Se({})).blocked}catch(e){return!1}}(t);if(e)return}t.message&&e.ui.info(`\n${t.message}\n`)}catch(e){}}(e)}var Le=e.requireSrc();const Oe=e.getDefaultExportFromCjs(Le);function De(e){var t,o,i=e.transport,s=e.endpoint,n=e.size,r=void 0===n?10:n,a=e.wait,c=void 0===a?1e3:a,l=[],d=0;function p(){if(l.length){var e=this.getBatchData();i.post({url:s,data:e,fail:function(o){t&&t(o,e)},success:function(){o&&o(e)}}),l=[]}}return{getSize:function(){return r},getWait:function(){return c},setSize:function(e){r=e},setWait:function(e){c=e},getEndpoint:function(){return s},setEndpoint:function(e){s=e},send:function(e){l.push(e),l.length>=r&&p.call(this),clearTimeout(d),d=setTimeout(p.bind(this),c)},flush:function(){clearTimeout(d),p.call(this)},getBatchData:function(){return l.length?(e=l,JSON.stringify({ev_type:"batch",list:e})):"";var e},clear:function(){clearTimeout(d),l=[]},fail:function(e){t=e},success:function(e){o=e}}}
2
+ "use strict";const e=require("./fetch-client-DC0c3ox3.js"),t=require("./index-DNmOe3vH.js"),o=require("chalk"),i=require("node:path"),s=require("node:fs/promises"),n=require("node:os"),r=require("node:fs"),a=require("./task-worker-4JFWlT-Q.js"),c=require("node:crypto"),l=require("node:child_process"),d=require("node:http"),p=require("node:https"),u=require("node:buffer"),m=require("undici"),g=require("path"),h=require("fs/promises"),f=require("fs"),_=require("form-data"),y=require("omelette"),b=require("lodash"),v=require("child_process"),w=require("ws"),C=require("commander");function E(e){const t=Object.create(null);if(e)for(const o in e)if("default"!==o){const i=Object.getOwnPropertyDescriptor(e,o);Object.defineProperty(t,o,i.get?i:{enumerable:!0,get:function(){return e[o]}})}return t.default=e,Object.freeze(t)}require("crypto"),require("url"),require("http"),require("https"),require("http2"),require("util"),require("stream"),require("assert"),require("tty"),require("zlib"),require("events"),require("mitt"),require("process");const I=E(i),A=E(s);function S(e,t){return null!=e?e:t()}class j{format(e){const t=JSON.stringify(e,null,2);return t.endsWith("\n")?t:`${t}\n`}formatError(e){const t={code:e.code,errorName:S(e.errorName,(()=>"UNKNOWN_ERROR")),desc:S(e.desc,(()=>e.message)),trigger:S(e.trigger,(()=>null)),fix:S(e.fix,(()=>null)),example:S(e.example,(()=>null))},o=JSON.stringify(t,null,2);return o.endsWith("\n")?o:`${o}\n`}}function P(e,t){return null!=e?e:t()}function k(e){let t,o=e[0],i=1;for(;i<e.length;){const s=e[i],n=e[i+1];if(i+=2,("optionalAccess"===s||"optionalCall"===s)&&null==o)return;"access"===s||"optionalAccess"===s?(t=o,o=n(o)):"call"!==s&&"optionalCall"!==s||(o=n(((...e)=>o.call(t,...e))),t=void 0)}return o}function T(e){const t=String.fromCharCode(27),o=new RegExp(`${t}(?:[@-Z\\\\-_]|\\[[0-?]*[ -/]*[@-~])`,"g");return e.replace(o,"")}function z(e){return e>=4352&&e<=4447||(9001===e||9002===e||(e>=11904&&e<=12350||(e>=12352&&e<=42191||(e>=44032&&e<=55203||(e>=63744&&e<=64255||(e>=65040&&e<=65049||(e>=65072&&e<=65135||(e>=65280&&e<=65376||(e>=65504&&e<=65510||(e>=127744&&e<=129695||e>=131072&&e<=262141))))))))))}function R(e){const t=T(e);if(!t)return 0;const o=/[\u0300-\u036F\u1AB0-\u1AFF\u1DC0-\u1DFF\u20D0-\u20FF\uFE20-\uFE2F]/u;let i=0;const s=Array.from(t);for(let e=0;e<s.length;e+=1){const t=P(s[e],(()=>""));if(o.test(t))continue;const n=t.codePointAt(0);void 0!==n&&(i+=z(n)?2:1)}return i}function x(e,t){const o=R(e);return o>=t?e:`${e}${" ".repeat(t-o)}`}function L(e,t){if(t<=0)return"";if(R(e)<=t)return e;if(1===t)return"…";const o=T(e),i=Array.from(o),s=Math.max(0,t-R("…"));let n="",r=0;for(let e=0;e<i.length;e+=1){const t=P(i[e],(()=>"")),o=R(t);if(r+o>s)break;n+=t,r+=o}return`${n}…`}function O(e,t={}){if(0===e.length)return"";const o=function(e,t){if(0===e.length)return[];const o=new Set,i=[],s=P(e[0],(()=>({})));for(const e of Object.keys(s))o.has(e)||(o.add(e),i.push(e));for(const t of e)for(const e of Object.keys(t))o.has(e)||(o.add(e),i.push(e));const n=[];for(const t of i){let o=R(t);for(const i of e){const e=i[t],s=void 0===e?"":String(e);o=Math.max(o,R(s))}n.push({key:t,width:o})}const r=P(t.columnGap,(()=>2)),a=P(P(t.maxWidth,(()=>process.stdout.columns)),(()=>120)),c=Math.max(1,Math.floor((a+r)/(6+r))),l=Math.min(P(t.maxColumns,(()=>c)),c);n.length>l&&n.splice(l);const d=Math.max(0,a-r*Math.max(0,n.length-1));for(;n.reduce(((e,t)=>e+t.width),0)>d;){let e=-1,t=-1;for(let o=0;o<n.length;o+=1){const i=P(k([n,"access",e=>e[o],"optionalAccess",e=>e.width]),(()=>0));i>t&&(t=i,e=o)}if(-1===e)break;const o=P(k([n,"access",t=>t[e],"optionalAccess",e=>e.width]),(()=>0));if(o<=6)break;n[e]={...n[e],width:o-1}}for(let e=0;e<n.length;e+=1){const t=n[e];t&&(n[e]={...t,width:Math.max(6,t.width)})}return n}(e,t);if(0===o.length)return"";const i=P(t.columnGap,(()=>2)),s=" ".repeat(i),n=o.map((e=>x(L(e.key,e.width),e.width))).join(s),r=o.map((e=>"-".repeat(e.width))).join(s),a=[];for(const t of e){const e=o.map((e=>{const o=t[e.key];return x(L(void 0===o?"":String(o),e.width),e.width)}));a.push(e.join(s))}return`${[n,r,...a].join("\n")}\n`}function D(e,t={}){const o=Object.entries(e);if(0===o.length)return"";let i=0;for(const[e]of o)i=Math.max(i,R(e));const s=P(P(t.maxWidth,(()=>process.stdout.columns)),(()=>120)),n=P(t.columnGap,(()=>2)),r=P(t.minValueWidth,(()=>12));let a=Math.min(i,P(t.keyMaxWidth,(()=>32)));const c=Math.max(6,s-n-r);a=Math.min(a,c);const l=Math.max(0,s-a-n),d=" ".repeat(n);return`${o.map((([e,t])=>{const o=x(L(e,a),a),i=(void 0===t?"undefined":null===t?"null":String(t)).replace(/\s*\n\s*/g," "),s=l>0?L(i,l):"";return`${o}${d}${s}`})).join("\n")}\n`}function U(e,t="",o=0){const i={};if(null==e)return i;if("object"!=typeof(s=e)||null===s||Array.isArray(s))return i;var s;for(const[s,n]of Object.entries(e)){const e=t?`${t}.${s}`:s;if(null!=n)if(Array.isArray(n))o>=5?i[e]="[Array]":0===n.length?i[e]="[]":n.every((e=>"object"!=typeof e||null===e))?i[e]=n.map((e=>{return String((o=()=>"null",null!=(t=e)?t:o()));var t,o})).join(", "):i[e]="[Array]";else if("object"!=typeof n)i[e]=n;else if(o>=5)i[e]="[Object]";else{const t=U(n,e,o+1);Object.assign(i,t)}else i[e]=n}return i}function B(e,t){return null!=e?e:t()}function q(e){return"object"==typeof e&&null!==e&&!Array.isArray(e)}class M{format(e){if(null===e)return"null\n";if(void 0===e)return"undefined\n";if(Array.isArray(e)){if(0===e.length)return"\n";if(t=e,Array.isArray(t)&&t.length>0&&t.every(q)){return O(e.map((e=>U(e))))}return function(e){return Array.isArray(e)&&e.length>0&&e.every((e=>null==e||"object"!=typeof e))}(e)?`${e.map((e=>String(B(e,(()=>"null"))))).join("\n")}\n`:"[Array]\n"}var t;if(q(e)){const t=U(e);return 0===Object.keys(t).length?"{}\n":D(t)}return`${String(e)}\n`}formatError(e){const t=[],o=B(e.errorName,(()=>"UNKNOWN_ERROR")),i=B(e.desc,(()=>e.message));return t.push(`ERROR [${e.code}] ${o}: ${i}`),e.trigger&&t.push(` Trigger: ${e.trigger}`),e.fix&&t.push(` Fix: ${e.fix}`),e.example&&t.push(` Example: ${e.example}`),e.details&&(t.push(" Error Details:"),t.push(`${function(e,t){if(null==e)return"";if("string"==typeof e)return`${t}${e}\n`;if(Array.isArray(e))return 0===e.length?"":`${e.map((e=>"object"==typeof e&&null!==e?D(U(e)):String(e))).map((e=>`${t}- ${e.trim()}`)).join("\n")}\n`;if(q(e)){const o=U(e);return 0===Object.keys(o).length?"":`${D(o).split("\n").filter((e=>e.trim())).map((e=>`${t}${e}`)).join("\n")}\n`}return`${t}${String(e)}\n`}(e.details," ")}`)),`${t.join("\n")}\n`}}function N(e,t){return null!=e?e:t()}function $(e){let t,o=e[0],i=1;for(;i<e.length;){const s=e[i],n=e[i+1];if(i+=2,("optionalAccess"===s||"optionalCall"===s)&&null==o)return;"access"===s||"optionalAccess"===s?(t=o,o=n(o)):"call"!==s&&"optionalCall"!==s||(o=n(((...e)=>o.call(t,...e))),t=void 0)}return o}function G(e,t){if(null==e)return;const o=String(e).replace(/\s*\n\s*/g," ").replace(/\s+/g," ").trim();return o?o.length<=t?o:`${o.slice(0,Math.max(0,t-3))}...`:void 0}function F(e){const t=$([e,"optionalAccess",e=>e.help,"optionalAccess",e=>e.errors]);if(t&&t.length>0)return t;const o=$([e,"optionalAccess",e=>e.errors]);return Array.isArray(o)?o:void 0}function V(t,o){const i=N(t.trigger,(()=>function(e){if(!e||0===e.length)return;return G(("coze"===e[0]?e:["coze",...e]).join(" "),150)}($([o,"optionalAccess",e=>e.argv])))),s=$([F,"call",e=>e($([o,"optionalAccess",e=>e.commandConfig])),"optionalAccess",e=>e.find,"call",e=>e((e=>e.code===t.code))]),n=N($([s,"optionalAccess",e=>e.name]),(()=>e.ErrorNameByCode[t.code])),r=N(G(n,80),(()=>"UNKNOWN_ERROR"));let a=n;t.isMessageExplicit&&t.message.trim()?a=t.message:$([s,"optionalAccess",e=>e.desc])&&(a=s.desc);const c=N(G(a,200),(()=>"An unexpected error occurred")),l=N(G(t.fix,150),(()=>G($([s,"optionalAccess",e=>e.fix]),150))),d=N(G(t.example,150),(()=>G($([s,"optionalAccess",e=>e.example]),150)));return{code:t.code,errorName:r,desc:c,trigger:i,fix:l,example:d}}function W(e,t){const o=V(e,t);return e.errorName=o.errorName,e.desc=o.desc,e.message=o.desc,e.trigger=o.trigger,e.fix=o.fix,e.example=o.example,e}function H(e){let t,o=e[0],i=1;for(;i<e.length;){const s=e[i],n=e[i+1];if(i+=2,("optionalAccess"===s||"optionalCall"===s)&&null==o)return;"access"===s||"optionalAccess"===s?(t=o,o=n(o)):"call"!==s&&"optionalCall"!==s||(o=n(((...e)=>o.call(t,...e))),t=void 0)}return o}var J;function K(o,i,s,n){if(o instanceof e.CozeError)throw o;if(e.isHttpError(o)){const e=H([o,"access",e=>e.response,"optionalAccess",e=>e.status]);if("ECONNREFUSED"===o.code||"ETIMEDOUT"===o.code||"number"==typeof e&&e>=500)throw o}if(o instanceof t.ChatCoreError&&"number"==typeof H([o,"access",e=>e.ext,"optionalAccess",e=>e.code])&&o.ext.code>=500)throw o;throw new e.CozeError(i,s,{...n,cause:o instanceof Error?o.message:String(o)})}!function(e){e[e.NOT_LOGIN=700012006]="NOT_LOGIN"}(J||(J={}));const Q=(o,i)=>{const s=W(function(o){if(o instanceof e.CozeError)return o;if(o instanceof t.ChatCoreError){const{ext:t}=o;let i=e.ErrorCode.E5000;"number"==typeof t.code&&(t.code===J.NOT_LOGIN?i=e.ErrorCode.E2001:t.code>=500&&(i=e.ErrorCode.E5002));const{message:s}=o;return new e.CozeError(i,s,t)}if(e.isHttpError(o)){const t=o.toJSON();let i=e.ErrorCode.E5000;const s=H([o,"access",e=>e.response,"optionalAccess",e=>e.status]);o.code===J.NOT_LOGIN||401===s?i=e.ErrorCode.E2001:"ECONNREFUSED"===o.code||"ETIMEDOUT"===o.code?i=e.ErrorCode.E5001:403===s?i=e.ErrorCode.E2003:404===s?i=e.ErrorCode.E3000:429===s?i=e.ErrorCode.E4001:s&&s>=500&&(i=e.ErrorCode.E5002);const n=H([o,"access",e=>e.response,"optionalAccess",e=>e.headers,"optionalAccess",e=>e["x-tt-logid"]]),{message:r}=o;return new e.CozeError(i,r,{logId:n,...t})}return o instanceof Error?new e.CozeError(e.ErrorCode.E5000,o.message,o.stack):"string"==typeof o?new e.CozeError(e.ErrorCode.E5000,o):new e.CozeError(e.ErrorCode.E5000,"An unexpected error occurred")}(o),i?{argv:i.argv,commandConfig:i.commandConfig}:void 0);var n,r;if(s.code===e.ErrorCode.E2001&&process.stdout.write(`${n=s.desc,r=()=>s.message,null!=n?n:r()}\n`),i)i.response.eprint(s);else{const e=new M;process.stderr.write(e.formatError(s))}process.exit(e.exitCodeForError(s.code))};async function Y(e){try{return(await s.stat(e)).isDirectory()}catch(e){return!1}}async function Z(e){for(const t of e)if(await Y(t))return!0;return!1}const X=()=>n.homedir(),ee=(...e)=>()=>i.join(X(),...e),te=(...e)=>()=>i.join(X(),".config",...e);function oe(e,t,o){return{name:e,get skillsDir(){return t()},detect:()=>Z(o.map((e=>e())))}}const ie=[oe("antigravity",ee(".gemini","antigravity","skills"),[ee(".gemini","antigravity")]),oe("cortex",ee(".snowflake","cortex","skills"),[ee(".snowflake","cortex")]),oe("deepagents",ee(".deepagents","agent","skills"),[ee(".deepagents")]),oe("github-copilot",ee(".copilot","skills"),[ee(".copilot")]),oe("pi",ee(".pi","agent","skills"),[ee(".pi","agent")]),oe("tabnine-cli",ee(".tabnine","agent","skills"),[ee(".tabnine")]),oe("windsurf",ee(".codeium","windsurf","skills"),[ee(".codeium","windsurf")]),oe("kimi-cli",te("agents","skills"),[ee(".kimi")]),oe("amp",te("agents","skills"),[te("amp")]),oe("crush",te("crush","skills"),[te("crush")]),oe("devin",te("devin","skills"),[te("devin")]),oe("goose",te("goose","skills"),[te("goose")]),oe("opencode",te("opencode","skills"),[te("opencode")]),oe("cline",ee(".agents","skills"),[ee(".cline")]),oe("dexto",ee(".agents","skills"),[ee(".dexto")]),oe("warp",ee(".agents","skills"),[ee(".warp")]),oe("zed",ee(".agents","skills"),[te("zed")]),function(){const e=[".openclaw",".clawdbot",".moltbot"];return{name:"openclaw",get skillsDir(){return i.join((()=>{const t=e.find((e=>r.existsSync(i.join(X(),e))));return i.join(X(),(s=()=>e[0],null!=(o=t)?o:s()));var o,s})(),"skills")},detect:()=>Z(e.map((e=>i.join(X(),e))))}}()],se=[...[["claude",".claude"],["trae",".trae"],["trae-cn",".trae-cn"],["comate",".comate"],["cursor",".cursor"],["augment",".augment"],["bob",".bob"],["aider-desk",".aider-desk"],["codebuddy",".codebuddy"],["codemaker",".codemaker"],["codestudio",".codestudio"],["codearts-agent",".codeartsdoer"],["command-code",".commandcode"],["continue",".continue"],["forgecode",".forge"],["droid",".factory"],["gemini-cli",".gemini"],["firebender",".firebender"],["hermes-agent",".hermes"],["junie",".junie"],["iflow-cli",".iflow"],["kilo",".kilocode"],["kiro-cli",".kiro"],["kode",".kode"],["mcpjam",".mcpjam"],["mux",".mux"],["openhands",".openhands"],["qoder",".qoder"],["qwen-code",".qwen"],["rovodev",".rovodev"],["roo",".roo"],["zencoder",".zencoder"],["neovate",".neovate"],["pochi",".pochi"],["adal",".adal"]].map((([e,t])=>oe(e,ee(t,"skills"),[ee(t)]))),...ie];function ne(e){return se.find((t=>t.name===e))}function re(e){let t,o=e[0],i=1;for(;i<e.length;){const s=e[i],n=e[i+1];if(i+=2,("optionalAccess"===s||"optionalCall"===s)&&null==o)return;"access"===s||"optionalAccess"===s?(t=o,o=n(o)):"call"!==s&&"optionalCall"!==s||(o=n(((...e)=>o.call(t,...e))),t=void 0)}return o}function ae(){return a.getGlobalSkillsDir()}function ce(){return a.getGlobalSkillLockFile()}async function le(e){try{return await s.access(e),!0}catch(e){return!1}}async function de(){let t=__dirname;for(let o=0;o<12;o++){const o=i.join(t,"package.json");if(await le(o)){if("@coze/cli"===re([e.safeJsonParse(await s.readFile(o,"utf8")),"optionalAccess",e=>e.name]))return t}const n=i.dirname(t);if(n===t)break;t=n}return i.resolve(__dirname,"..")}const pe=new Set(["SKILL.md","MODULE.md"]);function ue(e){return`sha256:${c.createHash("sha256").update(e,"utf8").digest("hex")}`}function me(e){return pe.has(i.basename(e))}async function ge(e,t=e){const o=await s.readdir(e,{withFileTypes:!0}),n=[];for(const s of o){if(s.name.startsWith("."))continue;const o=i.join(e,s.name);s.isDirectory()?n.push(...await ge(o,t)):s.isFile()&&n.push(i.relative(t,o).split(i.sep).join("/"))}return n.sort()}function he(e,t){const o=_e(e);if(void 0===o)return;const i=new RegExp(`^${t}:\\s*(.+?)\\s*$`,"m"),s=o.match(i);return s?s[1].replace(/^['"]|['"]$/g,"").trim():void 0}function fe(e,t){const o=_e(e);if(void 0===o)return e;const i=`version: ${t}`;let s;return s=/^version:\s*.+$/m.test(o)?o.replace(/^version:\s*.+$/m,i):/^name:\s*.+$/m.test(o)?o.replace(/^(name:\s*.+)$/m,`$1\n${i}`):`${i}\n${o}`,e.replace(o,s)}function _e(e){if(!e.startsWith("---"))return;const t=e.match(/^---\n([\s\S]*?)\n---/);return t?t[1]:void 0}function ye(e){const t=new Set;for(const o of e){const e=o.rel.split("/")[0];e&&t.add(e)}return[...t].sort()}async function be(){const t=await async function(){return i.join(await de(),"skills")}(),o=i.join(t,"manifest.json");if(await le(o)){const n=e.safeJsonParse(await s.readFile(o,"utf8")),r=(await ge(t)).filter((e=>"manifest.json"!==e)),a=[];for(const e of r)a.push({rel:e,content:await s.readFile(i.join(t,e),"utf8")});return{manifest:n,files:a,source:"bundled"}}const n=await async function(){return i.join(await de(),"docs","skills")}();if(!await le(n))throw new Error(`未找到 skill 来源:既无包内 ${o},也无开发态 ${n}。`);const r=await async function(){const t=i.join(await de(),"package.json"),o=e.safeJsonParse(await s.readFile(t,"utf8"));return n=function(e){let t,o=e[0],i=1;for(;i<e.length;){const s=e[i],n=e[i+1];if(i+=2,("optionalAccess"===s||"optionalCall"===s)&&null==o)return;"access"===s||"optionalAccess"===s?(t=o,o=n(o)):"call"!==s&&"optionalCall"!==s||(o=n(((...e)=>o.call(t,...e))),t=void 0)}return o}([o,"optionalAccess",e=>e.version]),r=()=>"0.0.0",null!=n?n:r();var n,r}(),{manifest:a,files:c}=await async function(e,t){const o=await ge(e),n=[],r={};for(const l of o){const o=await s.readFile(i.join(e,l),"utf8"),d=me(l),p=d?fe(o,t):o;n.push({rel:l,content:p}),d&&(r[(a=he(p,"name"),c=()=>l,null!=a?a:c())]={path:l,hash:ue(p)})}var a,c;return{manifest:{cliVersion:t,skills:r},files:n}}(n,r);return{manifest:a,files:c,source:"docs"}}async function ve(){try{const t=await s.readFile(ce(),"utf8");return e.safeJsonParse(t)}catch(e){return}}function we(e,t){return null!=e?e:t()}function Ce(e){let t,o=e[0],i=1;for(;i<e.length;){const s=e[i],n=e[i+1];if(i+=2,("optionalAccess"===s||"optionalCall"===s)&&null==o)return;"access"===s||"optionalAccess"===s?(t=o,o=n(o)):"call"!==s&&"optionalCall"!==s||(o=n(((...e)=>o.call(t,...e))),t=void 0)}return o}async function Ee(e){try{return ue(await s.readFile(e,"utf8"))}catch(e){return}}async function Ie(e){try{return await s.lstat(e)}catch(e){return null}}async function Ae(e,t,o,n){const r=i.join(t,e),a=i.join(o.skillsDir,e);await s.mkdir(o.skillsDir,{recursive:!0});const c=await Ie(a);if(c)if(c.isSymbolicLink())await s.rm(a,{force:!0});else{if(!n)return`已存在非软链的 ${a}(用户定制?),使用 --force 覆盖`;await s.rm(a,{recursive:!0,force:!0})}return await s.symlink(r,a,"dir"),"linked"}async function Se(e={}){const{manifest:t,files:o}=await be(),n=ae(),r=await ve(),a=await async function(e,t,o){const s=[];for(const[n,r]of Object.entries(e.skills)){const e=await Ee(i.join(t,r.path));if(void 0===e)continue;if(e===r.hash)continue;const a=Ce([o,"optionalAccess",e=>e.skills,"access",e=>e[n],"optionalAccess",e=>e.hash]);void 0!==a&&e===a||s.push(n)}return s}(t,n,r);if(a.length>0&&!e.force)return{blocked:!0,cliVersion:t.cliVersion,neutralDir:n,linkedTargets:[],skipped:[],unknownTargets:[],modifiedSkills:a};await async function(e,t){const o=ye(t);for(const t of o)await s.rm(i.join(e,t),{recursive:!0,force:!0});for(const o of t){const t=i.join(e,o.rel);await s.mkdir(i.dirname(t),{recursive:!0}),await s.writeFile(t,o.content,"utf8")}}(n,o);const{targets:c,unknown:l}=await async function(e){if(!e||0===e.length||e.includes("all")){const e=[];for(const t of se)await t.detect()&&e.push(t);return{targets:e,unknown:[]}}const t=[],o=[];for(const i of e){const e=ne(i);e?t.push(e):o.push(i)}return{targets:t,unknown:o}}(e.targets),d=ye(o),p=[],u=[];for(const t of c){const o=[];for(const i of d){const s=await Ae(i,n,t,we(e.force,(()=>!1)));"linked"!==s&&o.push(s)}0===o.length?p.push(t.name):u.push({target:t.name,reason:o.join("; ")})}const m=(new Date).toISOString(),g={};for(const[e,o]of Object.entries(t.skills))g[e]={hash:o.hash,expectedHash:o.hash,installedAt:m};return await async function(e){const t=ce();await s.mkdir(i.dirname(t),{recursive:!0}),await s.writeFile(t,`${JSON.stringify(e,null,2)}\n`,"utf8")}({version:1,cliVersion:t.cliVersion,installedBin:we(process.argv[1],(()=>process.execPath)),targets:p,skills:g}),{blocked:!1,cliVersion:t.cliVersion,neutralDir:n,linkedTargets:p,skipped:u,unknownTargets:l,modifiedSkills:[]}}async function je(){const e=ae(),t=[];let o=[];try{o=(await s.readdir(e,{withFileTypes:!0})).filter((e=>!e.name.startsWith("."))).map((e=>e.name))}catch(e){o=[]}for(const n of se)for(const r of o){const o=i.join(n.skillsDir,r),a=await Ie(o);if(!a||!a.isSymbolicLink())continue;const c=await s.readlink(o).catch((()=>null));if(null===c)continue;i.resolve(n.skillsDir,c).startsWith(e)&&(await s.rm(o,{force:!0}),t.push({target:n.name,unit:r}))}return await s.rm(e,{recursive:!0,force:!0}),await async function(){await s.rm(ce(),{force:!0})}(),{neutralDir:e,unlinked:t}}const Pe="0.2.0-alpha.c23a50",ke="@coze/cli";function Te(){return Pe}function ze(e,t){const o=e=>{const t=e.replace(/^v/,"").split(".");return{major:parseInt(t[0]||"0",10),minor:parseInt(t[1]||"0",10),patch:parseInt(t[2]||"0",10)}},i=o(e),s=o(t);return s.major!==i.major?s.major>i.major:s.minor!==i.minor?s.minor>i.minor:s.patch>i.patch}async function Re(t,o=!1,i="latest"){const s=Te(),{config:n}=t;if(!o&&n.latestVersion&&n.lastCheckTime&&Date.now()-n.lastCheckTime<864e5)return{currentVersion:s,latestVersion:n.latestVersion,hasUpdate:ze(s,n.latestVersion)};const r=function(){try{return l.execSync("npm config get registry",{encoding:"utf8",stdio:["pipe","pipe","pipe"]}).trim().replace(/\/+$/,"")}catch(e){return"https://registry.npmjs.org"}}(),c=await async function(t,o="latest"){const i=`${t}/${ke}/${o}`,s=await e.customFetch.fetch(i,{headers:{accept:"application/json"}});if(!s.ok)throw new Error(`Failed to fetch latest version: ${s.status} ${s.statusText}`);return(await s.json()).version}(r,i);return await a.saveConfig({latestVersion:c,lastCheckTime:Date.now()},n.configScope),{currentVersion:s,latestVersion:c,hasUpdate:ze(s,c)}}async function xe(e,t){if(await t(),!0===e.config.autoCheckUpdate)try{const t=await Re(e);if(t.hasUpdate){const i=`\nUpdate available: ${o.gray(t.currentVersion)} → ${o.green(t.latestVersion)}\nRun ${o.cyan("coze upgrade")} to update\n`;e.ui.info(i)}}catch(e){}await async function(e){if("guide"===e.argv[0])return;try{const t=await async function(){const{manifest:e}=await be(),{cliVersion:t}=e,o=await ve();return o?o.cliVersion!==t?{state:"mismatch",cliVersion:t,installedVersion:o.cliVersion,message:`Skills (${o.cliVersion}) are out of sync with CLI (${t}). Run \`coze guide sync\`.`}:{state:"ok",cliVersion:t,installedVersion:o.cliVersion}:{state:"missing",cliVersion:t,message:"Bundled skills not installed yet. Run `coze guide sync` to sync them to your AI tools."}}();if("ok"===t.state)return;const o=e.config.autoSyncSkill,i=!0===o||"true"===o;if("mismatch"===t.state&&i){const e=await async function(e){if("mismatch"!==e.state)return!1;try{return!(await Se({})).blocked}catch(e){return!1}}(t);if(e)return}t.message&&e.ui.info(`\n${t.message}\n`)}catch(e){}}(e)}var Le=e.requireSrc();const Oe=e.getDefaultExportFromCjs(Le);function De(e){var t,o,i=e.transport,s=e.endpoint,n=e.size,r=void 0===n?10:n,a=e.wait,c=void 0===a?1e3:a,l=[],d=0;function p(){if(l.length){var e=this.getBatchData();i.post({url:s,data:e,fail:function(o){t&&t(o,e)},success:function(){o&&o(e)}}),l=[]}}return{getSize:function(){return r},getWait:function(){return c},setSize:function(e){r=e},setWait:function(e){c=e},getEndpoint:function(){return s},setEndpoint:function(e){s=e},send:function(e){l.push(e),l.length>=r&&p.call(this),clearTimeout(d),d=setTimeout(p.bind(this),c)},flush:function(){clearTimeout(d),p.call(this)},getBatchData:function(){return l.length?(e=l,JSON.stringify({ev_type:"batch",list:e})):"";var e},clear:function(){clearTimeout(d),l=[]},fail:function(e){t=e},success:function(e){o=e}}}
3
3
  /*! *****************************************************************************
4
4
  Copyright (c) Microsoft Corporation.
5
5
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@coze/cli",
3
- "version": "0.2.0-alpha.c1b76c",
3
+ "version": "0.2.0-alpha.c23a50",
4
4
  "private": false,
5
5
  "description": "Coze CLI - A command-line interface for Coze platform",
6
6
  "license": "MIT",
@@ -1,25 +1,25 @@
1
1
  {
2
- "cliVersion": "0.2.0-alpha.c1b76c",
2
+ "cliVersion": "0.2.0-alpha.c23a50",
3
3
  "skills": {
4
4
  "using-coze-cli": {
5
5
  "path": "using-coze-cli/SKILL.md",
6
- "hash": "sha256:7ee66af617d15d15a62da7ae9e79f680f1e9803b3b50793a93a3a7a11dcf88f5"
6
+ "hash": "sha256:522fcf30c86c66d60d4d9dbfe541ad155b7ad76b2776a46b3baf969309bc2d0f"
7
7
  },
8
8
  "coze-claw": {
9
9
  "path": "using-coze-cli/coze-claw/MODULE.md",
10
- "hash": "sha256:c492be83678fc580406f8d5ed0991dae3c0fb7b1100c17eecfd44cdb6f5071ba"
10
+ "hash": "sha256:546f54c9f9f180b1cce15e267aead989258039632314c92cad8d00dd1485ffa9"
11
11
  },
12
12
  "coze-code": {
13
13
  "path": "using-coze-cli/coze-code/MODULE.md",
14
- "hash": "sha256:d59e362448f01a49e03295a30c21a56baef7e5798d1b30bc933db9326125b317"
14
+ "hash": "sha256:a1c5145a17167643c38b90a34e50562064bd3b73b5531389132bb57e47251422"
15
15
  },
16
16
  "coze-file": {
17
17
  "path": "using-coze-cli/coze-file/MODULE.md",
18
- "hash": "sha256:30460c7df40b40de7e990ac1b57342eb1b661f8b762600a974b156f1575f9150"
18
+ "hash": "sha256:c1b5c39842afa2fdae3fb59f84a20c3543e6a1c944c41e54f963d82c6036d49e"
19
19
  },
20
20
  "coze-generate": {
21
21
  "path": "using-coze-cli/coze-generate/MODULE.md",
22
- "hash": "sha256:ac990d43e4e098950790fb3e4539e87612a1cd2b3ee06e221b0ab4a91ebf7111"
22
+ "hash": "sha256:fd7a20e7183d6a5285b7ef087ebf144bcba4fe2014c13659113da43c57600ea8"
23
23
  }
24
24
  }
25
25
  }
@@ -1,6 +1,6 @@
1
1
  ---
2
2
  name: using-coze-cli
3
- version: 0.2.0-alpha.c1b76c
3
+ version: 0.2.0-alpha.c23a50
4
4
  description: "Coze CLI 共享基础:安装、认证登录(OAuth)、组织与空间切换、配置管理、全局执行原则、安全规则、错误码处理、代理配置。当用户首次使用 coze-cli、需要登录授权、遇到权限不足、切换组织/空间、操作 Coze Claw Session/coze session *,或任何操作前的基础检查时触发。"
5
5
  metadata:
6
6
  requires:
@@ -1,6 +1,6 @@
1
1
  ---
2
2
  name: coze-claw
3
- version: 0.2.0-alpha.c1b76c
3
+ version: 0.2.0-alpha.c23a50
4
4
  description: "Coze Claw Session 会话工作流:创建/找回 claw session、发送 session message、监听回复、查询后台 progress、处理文件/PPT/播客产物。当用户需要使用 coze session * 任意命令时触发。"
5
5
  metadata:
6
6
  requires:
@@ -1,6 +1,6 @@
1
1
  ---
2
2
  name: coze-code
3
- version: 0.2.0-alpha.c1b76c
3
+ version: 0.2.0-alpha.c23a50
4
4
  description: "Coze Coding 项目开发工作流:创建项目、发送需求消息、查询状态、预览、部署、环境变量管理、域名管理、技能管理、数据库管理。当用户需要创建/管理 Coze 项目、发送开发需求、部署应用、管理数据库、或使用 coze code * 任意命令时触发。"
5
5
  metadata:
6
6
  requires:
@@ -1,6 +1,6 @@
1
1
  ---
2
2
  name: coze-file
3
- version: 0.2.0-alpha.c1b76c
3
+ version: 0.2.0-alpha.c23a50
4
4
  description: "Coze 文件操作:上传本地文件获取在线访问地址。当用户需要上传文件、或将本地生成的文件转换为在线可访问链接时触发。"
5
5
  metadata:
6
6
  requires:
@@ -1,6 +1,6 @@
1
1
  ---
2
2
  name: coze-generate
3
- version: 0.2.0-alpha.c1b76c
3
+ version: 0.2.0-alpha.c23a50
4
4
  description: "Coze 媒体生成:文本生成图片、文本转语音(TTS)、视频生成。当用户需要使用 coze generate image/audio/video 生成音频、图片或视频时触发。"
5
5
  metadata:
6
6
  requires: