@coze/cli 0.3.0-alpha.0aeac0 → 0.3.0-alpha.c640f9
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 +1 -1
- package/package.json +1 -1
- package/skills/manifest.json +6 -6
- package/skills/using-coze-cli/SKILL.md +1 -1
- package/skills/using-coze-cli/coze-claw/MODULE.md +1 -1
- package/skills/using-coze-cli/coze-code/MODULE.md +1 -1
- package/skills/using-coze-cli/coze-file/MODULE.md +1 -1
- package/skills/using-coze-cli/coze-generate/MODULE.md +1 -1
package/lib/cli.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
-
"use strict";const e=require("./fetch-client-CgQGE-CR.js"),t=require("./index-DN7-Fdfx.js"),o=require("chalk"),i=require("node:child_process"),s=require("./task-worker-Bt8hYeP2.js"),n=require("node:path"),r=require("node:fs/promises"),a=require("node:fs"),c=require("node:crypto"),l=require("node:http"),d=require("node:https"),p=require("node:buffer"),u=require("undici"),m=require("path"),g=require("fs/promises"),h=require("fs"),f=require("form-data"),_=require("omelette"),y=require("node:os"),b=require("child_process"),v=require("lodash"),w=require("commander"),E=require("ws");function C(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("https-proxy-agent"),require("http"),require("https"),require("http2"),require("util"),require("stream"),require("assert"),require("tty"),require("zlib"),require("events"),require("mitt"),require("process");const I=C(n),A=C(r);function S(e,t){return null!=e?e:t()}class k{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 j(e,t){return null!=e?e:t()}function P(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 z(e){const t=String.fromCharCode(27),o=new RegExp(`${t}(?:[@-Z\\\\-_]|\\[[0-?]*[ -/]*[@-~])`,"g");return e.replace(o,"")}function T(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=z(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=j(s[e],(()=>""));if(o.test(t))continue;const n=t.codePointAt(0);void 0!==n&&(i+=T(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=z(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=j(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=j(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=j(t.columnGap,(()=>2)),a=j(j(t.maxWidth,(()=>process.stdout.columns)),(()=>120)),c=Math.max(1,Math.floor((a+r)/(6+r))),l=Math.min(j(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=j(P([n,"access",e=>e[o],"optionalAccess",e=>e.width]),(()=>0));i>t&&(t=i,e=o)}if(-1===e)break;const o=j(P([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=j(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=j(j(t.maxWidth,(()=>process.stdout.columns)),(()=>120)),n=j(t.columnGap,(()=>2)),r=j(t.minValueWidth,(()=>12));let a=Math.min(i,j(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 q(e,t){return null!=e?e:t()}function B(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(B)){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(q(e,(()=>"null"))))).join("\n")}\n`:"[Array]\n"}var t;if(B(e)){const t=U(e);return 0===Object.keys(t).length?"{}\n":D(t)}return`${String(e)}\n`}formatError(e){const t=[],o=q(e.errorName,(()=>"UNKNOWN_ERROR")),i=q(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(B(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))};const Y="@coze/cli",Z="0.3.0-alpha.0aeac0",X=Y;function ee(){const e=[{pm:"npm",cmd:`npm ls -g ${X} --json 2>/dev/null`},{pm:"pnpm",cmd:`pnpm ls -g ${X} --json 2>/dev/null`},{pm:"yarn",cmd:"yarn global list --json 2>/dev/null"}];for(const{pm:t,cmd:o}of e)try{if(i.execSync(o,{encoding:"utf8",stdio:["pipe","pipe","pipe"]}).includes(X))return t}catch(e){}return"npm"}const te=Y,oe=864e5;function ie(){return Z}function se(e){const t=e.trim().replace(/^v/,"").split("+")[0],o=t.indexOf("-"),i=-1===o?t:t.slice(0,o),s=-1===o?"":t.slice(o+1),n=i.split(".");return{major:parseInt(n[0]||"0",10),minor:parseInt(n[1]||"0",10),patch:parseInt(n[2]||"0",10),prerelease:""===s?[]:s.split(".")}}function ne(e,t){const o=/^\d+$/.test(e),i=/^\d+$/.test(t);if(o&&i){const o=parseInt(e,10)-parseInt(t,10);return 0===o?0:o>0?1:-1}return o?-1:i?1:e===t?0:e>t?1:-1}function re(e,t){const o=se(e),i=se(t);return o.major!==i.major?o.major>i.major?1:-1:o.minor!==i.minor?o.minor>i.minor?1:-1:o.patch!==i.patch?o.patch>i.patch?1:-1:function(e,t){if(0===e.length&&0===t.length)return 0;if(0===e.length)return 1;if(0===t.length)return-1;const o=Math.max(e.length,t.length);for(let i=0;i<o;i++){const o=e[i],s=t[i];if(void 0===o)return-1;if(void 0===s)return 1;const n=ne(o,s);if(0!==n)return n}return 0}(o.prerelease,i.prerelease)}function ae(e,t){return re(t,e)>0}function ce(){if(process.env.COZE_CLI_NO_UPDATE_NOTIFIER)return!0;const e=(t=process.env.CI,o=()=>"",null!=t?t:o()).toLowerCase();var t,o;return""!==e&&"false"!==e&&"0"!==e||function(e){return!e||"0.0.0"===e||/dev/i.test(e)}(ie())}function le(e){const t=e.upgradeMode;if("auto"===t||"notify"===t||"off"===t)return t;const o=e.autoCheckUpdate;return!1===o||"false"===o?"off":!0===o||"true"===o?"notify":"auto"}async function de(t,o=!1,n="latest"){const r=ie(),{config:a}=t;if(!o&&a.latestVersion&&a.lastCheckTime&&Date.now()-a.lastCheckTime<oe)return{currentVersion:r,latestVersion:a.latestVersion,hasUpdate:ae(r,a.latestVersion)};const c=function(){try{return i.execSync("npm config get registry",{encoding:"utf8",stdio:["pipe","pipe","pipe"]}).trim().replace(/\/+$/,"")}catch(e){return"https://registry.npmjs.org"}}(),l=await async function(t,o="latest"){const i=`${t}/${te}/${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}(c,n);return await s.saveConfig({latestVersion:l,lastCheckTime:Date.now()},a.configScope),{currentVersion:r,latestVersion:l,hasUpdate:ae(r,l)}}async function pe(e,t){const{lastUpgradeAttempt:o}=e.config;if(o&&Date.now()-o<oe)return;try{await s.saveConfig({lastUpgradeAttempt:Date.now()},e.config.configScope)}catch(e){}const n=ee(),{command:r,args:a}=function(e,t){const o=`${X}@${t}`;switch(e){case"pnpm":return{command:"pnpm",args:["add","-g",o]};case"yarn":return{command:"yarn",args:["global","add",o]};default:return{command:"npm",args:["install","-g",o]}}}(n,t);try{i.spawn(r,a,{detached:!0,stdio:"ignore",shell:"win32"===process.platform}).unref()}catch(e){}}function ue(e,t){return null!=e?e:t()}function me(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}const ge={claude:"claude-code"};let he=null;function fe(){if(he)return he;const t=function(){let e=__dirname;for(let t=0;t<12;t++){const t=n.join(e,"node_modules","skills","package.json");if(a.existsSync(t))return n.dirname(t);const o=n.dirname(e);if(o===e)break;e=o}}();if(t){const o=e.safeJsonParse(a.readFileSync(n.join(t,"package.json"),"utf8")),i="string"==typeof me([o,"optionalAccess",e=>e.bin])?o.bin:me([o,"optionalAccess",e=>e.bin,"optionalAccess",e=>e.skills]);if(i)return he={cmd:process.execPath,prefix:[n.join(t,i)]},he}return he={cmd:"skills",prefix:[]},he}function _e(e){const{cmd:t,prefix:o}=fe(),s=i.spawnSync(t,[...o,...e],{encoding:"utf8"});return{ok:0===s.status,stdout:ue(s.stdout,(()=>"")),stderr:ue(s.stderr,(()=>"")),code:s.status}}function ye(e,t={}){const o=["add",e];return t.global&&o.push("-g"),t.yes&&o.push("-y"),t.agents&&t.agents.length>0&&o.push("-a",...t.agents),_e(o)}function be(e,t={}){const o=["remove",e];return t.global&&o.push("-g"),o.push("-y"),_e(o)}function ve(t={}){const o=["ls","--json"];t.global&&o.push("-g");const i=_e(o);if(!i.ok)return[];const s=e.safeJsonParse(i.stdout);return Array.isArray(s)?s:[]}function we(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 Ee(){return s.getGlobalSkillLockFile()}async function Ce(e){try{return await r.access(e),!0}catch(e){return!1}}async function Ie(){let t=__dirname;for(let o=0;o<12;o++){const o=n.join(t,"package.json");if(await Ce(o)){if("@coze/cli"===we([e.safeJsonParse(await r.readFile(o,"utf8")),"optionalAccess",e=>e.name]))return t}const i=n.dirname(t);if(i===t)break;t=i}return n.resolve(__dirname,"..")}async function Ae(){return n.join(await Ie(),"skills")}async function Se(){return n.join(await Ie(),"docs","skills")}const ke=new Set(["SKILL.md","MODULE.md"]);function je(e){return`sha256:${c.createHash("sha256").update(e,"utf8").digest("hex")}`}function Pe(e){return ke.has(n.basename(e))}async function ze(e,t=e){const o=await r.readdir(e,{withFileTypes:!0}),i=[];for(const s of o){if(s.name.startsWith("."))continue;const o=n.join(e,s.name);s.isDirectory()?i.push(...await ze(o,t)):s.isFile()&&i.push(n.relative(t,o).split(n.sep).join("/"))}return i.sort()}function Te(e,t){const o=xe(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 Re(e,t){const o=xe(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 xe(e){if(!e.startsWith("---"))return;const t=e.match(/^---\n([\s\S]*?)\n---/);return t?t[1]:void 0}function Le(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 Oe(){const e=await Ae();if(await Ce(n.join(e,"manifest.json")))return{root:e,source:"bundled"};const t=await Se();if(await Ce(t))return{root:t,source:"docs"};throw new Error(`未找到 skill 来源:既无包内 ${e}/manifest.json,也无开发态 ${t}。`)}async function De(){const t=n.join(await Ie(),"package.json"),o=e.safeJsonParse(await r.readFile(t,"utf8"));return i=Le([o,"optionalAccess",e=>e.version]),s=()=>"0.0.0",null!=i?i:s();var i,s}async function Ue(){const t=await Ae(),o=n.join(t,"manifest.json");if(await Ce(o)){const i=e.safeJsonParse(await r.readFile(o,"utf8")),s=(await ze(t)).filter((e=>"manifest.json"!==e)),a=[];for(const e of s)a.push({rel:e,content:await r.readFile(n.join(t,e),"utf8")});return{manifest:i,files:a,source:"bundled"}}const i=await Se();if(!await Ce(i))throw new Error(`未找到 skill 来源:既无包内 ${o},也无开发态 ${i}。`);const s=await De(),{manifest:a,files:c}=await async function(e,t){const o=await ze(e),i=[],s={};for(const l of o){const o=await r.readFile(n.join(e,l),"utf8"),d=Pe(l),p=d?Re(o,t):o;i.push({rel:l,content:p}),d&&(s[(a=Te(p,"name"),c=()=>l,null!=a?a:c())]={path:l,hash:je(p)})}var a,c;return{manifest:{cliVersion:t,skills:s},files:i}}(i,s);return{manifest:a,files:c,source:"docs"}}async function qe(){try{const t=await r.readFile(Ee(),"utf8");return e.safeJsonParse(t)}catch(e){return}}function Be(e,t){return null!=e?e:t()}function Me(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 Ne(e){try{return je(await r.readFile(e,"utf8"))}catch(e){return}}function $e(e){return[...new Set(Object.values(e.skills).map((e=>e.path.split("/")[0])))]}function Ge(e){return e[0]?n.dirname(e[0].path):void 0}async function Fe(e={}){const{manifest:t}=await Ue(),{root:o}=await Oe(),i=$e(t),s=await qe(),a=ve({global:!0}),c=await async function(e,t,o){const i=Ge(t);if(!i)return[];const s=new Set(t.map((e=>e.name))),r=[];for(const[t,a]of Object.entries(e.skills)){const e=a.path.split("/")[0];if(!s.has(e))continue;const c=await Ne(n.join(i,a.path));if(void 0===c)continue;if(c===a.hash)continue;const l=Me([o,"optionalAccess",e=>e.skills,"access",e=>e[t],"optionalAccess",e=>e.hash]);void 0!==l&&c===l||r.push(t)}return r}(t,a,s);if(c.length>0&&!e.force)return{blocked:!0,cliVersion:t.cliVersion,sourceRoot:o,linkedTargets:[],skillsOk:!1,unknownTargets:[],modifiedSkills:c};const l=e.targets&&e.targets.length>0&&!e.targets.includes("all")?Be(e.targets,(()=>[])).map((e=>ue(ge[e],(()=>e)))):void 0;let d=!0;for(const e of i){ye(n.join(o,e),{global:!0,yes:!0,agents:l}).ok||(d=!1)}const p=ve({global:!0}).filter((e=>i.includes(e.name))),u=Me([p,"access",e=>e[0],"optionalAccess",e=>e.path]),m=[...new Set(p.flatMap((e=>e.agents)))],g=(new Date).toISOString(),h={};for(const[e,o]of Object.entries(t.skills))h[e]={hash:o.hash,expectedHash:o.hash,installedAt:g};return await async function(e){const t=Ee();await r.mkdir(n.dirname(t),{recursive:!0}),await r.writeFile(t,`${JSON.stringify(e,null,2)}\n`,"utf8")}({version:1,cliVersion:t.cliVersion,installedBin:Be(process.argv[1],(()=>process.execPath)),poolPath:u,targets:m,skills:h}),{blocked:!1,cliVersion:t.cliVersion,sourceRoot:o,poolPath:u,linkedTargets:m,skillsOk:d,unknownTargets:[],modifiedSkills:[]}}function Ve(e,t,o){return void 0===e?"missing":e===t?"ok":o===e?"drift":"modified"}async function We(){const{manifest:e}=await Ue(),t=await qe(),o=Be(process.argv[1],(()=>process.execPath)),i=ve({global:!0}),s=Ge(i),r=new Set(i.map((e=>e.name))),a=[];for(const[o,i]of Object.entries(e.skills)){const e=i.path.split("/")[0],c=Boolean(s)&&r.has(e),l=c?await Ne(n.join(s,i.path)):void 0,d=c?Ve(l,i.hash,Me([t,"optionalAccess",e=>e.skills,"access",e=>e[o],"optionalAccess",e=>e.hash])):"missing";a.push({name:o,path:i.path,state:d})}const c=Me([i,"access",e=>e.find,"call",e=>e((e=>r.has(e.name))),"optionalAccess",e=>e.path]);return{lockExists:Boolean(t),cliVersion:e.cliVersion,installedVersion:Me([t,"optionalAccess",e=>e.cliVersion]),versionMatch:Boolean(t)&&Me([t,"optionalAccess",e=>e.cliVersion])===e.cliVersion,installedBin:Me([t,"optionalAccess",e=>e.installedBin]),currentBin:o,binMatch:!Me([t,"optionalAccess",e=>e.installedBin])||t.installedBin===o,poolPath:c,targets:Be(Me([t,"optionalAccess",e=>e.targets]),(()=>[])),skills:a}}async function He(){const{manifest:e}=await Ue(),t=$e(e),o=ve({global:!0}),i=[];for(const e of t){const t=o.find((t=>t.name===e));if(!t)continue;be(e,{global:!0}).ok&&i.push({name:e,agents:t.agents})}return await async function(){await r.rm(Ee(),{force:!0})}(),{removed:i}}async function Je(){const t=await async function(){const t=n.join(await Ae(),"manifest.json");if(await Ce(t)){const o=e.safeJsonParse(await r.readFile(t,"utf8"));if(Le([o,"optionalAccess",e=>e.cliVersion]))return o.cliVersion}return De()}(),o=await qe();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 self skill install\`.`}:{state:"ok",cliVersion:t,installedVersion:o.cliVersion}:{state:"missing",cliVersion:t,message:"Bundled skills not installed yet. Run `coze self skill install` to sync them to your AI tools."}}function Ke(e){const t={};let o;const i=[];let s=!1;for(let n=0;n<e.length;n++){const r=e[n];if("--help"!==r&&"-h"!==r)if("--version"!==r&&"-v"!==r)if("--output"!==r)if("--format"!==r)"--no-color"!==r?"--config"!==r?"--org-id"!==r?"--space-id"!==r?"--verbose"!==r?"--debug"!==r?"--log-file"!==r?"--print-logs"!==r?s||r.startsWith("-")?i.push(r):(o=r,s=!0):t.printLogs=!0:t.logFile=e[++n]:t.debug=!0:t.verbose=!0:t.spaceId=e[++n]:t.orgId=e[++n]:t.config=e[++n]:t.noColor=!0;else{const o=e[++n];"json"!==o&&"text"!==o||(t.format=o)}else t.output=e[++n];else t.version=!0;else t.help=!0}return{globalOptions:t,commandName:o,commandArgs:i}}async function Qe(e,t){const i=await async function(e){if("self"===Ke(e.argv).commandName)return;const t=function(){const e=(t=process.env.CI,o=()=>"",null!=t?t:o()).toLowerCase();var t,o;return""!==e&&"false"!==e&&"0"!==e||Boolean(process.env.COZE_CLI_NO_SKILL_NOTIFIER)}(),o=function(e){const t=e.config.autoSyncSkill;return!0===t||"true"===t}(e);if(t&&!o)return;try{const i=await Je();if("ok"===i.state)return;if("mismatch"===i.state&&o&&await async function(e){if("mismatch"!==e.state)return!1;try{return!(await Fe({})).blocked}catch(e){return!1}}(i))return;if(t)return;return"json"===e.format&&e.response.setNotice({skill:{state:i.state,cliVersion:i.cliVersion,installedVersion:i.installedVersion,message:i.message,command:"coze self skill install"}}),i}catch(e){return}}(e),s=await async function(e){if("upgrade"===Ke(e.argv).commandName)return;if(ce())return;const t=le(e.config);if("off"===t)return;const o=e.config.latestVersion;if(!o)return;const i=ie();if(!ae(i,o))return;const{lastUpgradeAttempt:s}=e.config,n="number"==typeof s&&Date.now()-s<oe;let r;"auto"===t?n?r=`Auto-upgrade to ${o} did not take effect (current ${i}). Run \`coze upgrade\` manually; on an internal network verify your npm registry.`:(r=`Coze CLI ${o} available (current ${i}). Upgrading in the background; it will take effect on next run.`,pe(e,o)):r=`Coze CLI ${o} available (current ${i}). Run \`coze upgrade\` to update.`;"json"===e.format&&e.response.setNotice({update:{current:i,latest:o,message:r,command:"coze upgrade"}});return{current:i,latest:o,message:r}}(e);await t(),function(e,t){if(!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}([t,"optionalAccess",e=>e.message]))return;if("json"===e.format)return void(e.response.hasPendingNotice()&&process.stderr.write(`${t.message}\n`));e.ui.info(`\n${t.message}\n`)}(e,i),function(e,t){if(!t)return;if("json"===e.format)return void(e.response.hasPendingNotice()&&process.stderr.write(`${t.message}\n`));e.ui.info(`\n${o.gray(t.current)} → ${o.green(t.latest)} ${t.message}\n`)}(e,s),async function(e){if("upgrade"===Ke(e.argv).commandName)return;if(ce())return;const t=le(e.config);if("off"===t)return;try{const i=await de(e,!1,(o=e.config,o.upgradeChannel||"latest"));i.hasUpdate&&"auto"===t&&await pe(e,i.latestVersion)}catch(e){}var o}(e)}var Ye=e.requireSrc();const Ze=e.getDefaultExportFromCjs(Ye);function Xe(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-CgQGE-CR.js"),t=require("./index-DN7-Fdfx.js"),o=require("chalk"),i=require("node:child_process"),s=require("./task-worker-Bt8hYeP2.js"),n=require("node:path"),r=require("node:fs/promises"),a=require("node:fs"),c=require("node:crypto"),l=require("node:http"),d=require("node:https"),p=require("node:buffer"),u=require("undici"),m=require("path"),g=require("fs/promises"),h=require("fs"),f=require("form-data"),_=require("omelette"),y=require("node:os"),b=require("child_process"),v=require("lodash"),w=require("commander"),E=require("ws");function C(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("https-proxy-agent"),require("http"),require("https"),require("http2"),require("util"),require("stream"),require("assert"),require("tty"),require("zlib"),require("events"),require("mitt"),require("process");const I=C(n),A=C(r);function S(e,t){return null!=e?e:t()}class k{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 j(e,t){return null!=e?e:t()}function P(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 z(e){const t=String.fromCharCode(27),o=new RegExp(`${t}(?:[@-Z\\\\-_]|\\[[0-?]*[ -/]*[@-~])`,"g");return e.replace(o,"")}function T(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=z(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=j(s[e],(()=>""));if(o.test(t))continue;const n=t.codePointAt(0);void 0!==n&&(i+=T(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=z(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=j(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=j(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=j(t.columnGap,(()=>2)),a=j(j(t.maxWidth,(()=>process.stdout.columns)),(()=>120)),c=Math.max(1,Math.floor((a+r)/(6+r))),l=Math.min(j(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=j(P([n,"access",e=>e[o],"optionalAccess",e=>e.width]),(()=>0));i>t&&(t=i,e=o)}if(-1===e)break;const o=j(P([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=j(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=j(j(t.maxWidth,(()=>process.stdout.columns)),(()=>120)),n=j(t.columnGap,(()=>2)),r=j(t.minValueWidth,(()=>12));let a=Math.min(i,j(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 q(e,t){return null!=e?e:t()}function B(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(B)){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(q(e,(()=>"null"))))).join("\n")}\n`:"[Array]\n"}var t;if(B(e)){const t=U(e);return 0===Object.keys(t).length?"{}\n":D(t)}return`${String(e)}\n`}formatError(e){const t=[],o=q(e.errorName,(()=>"UNKNOWN_ERROR")),i=q(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(B(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))};const Y="@coze/cli",Z="0.3.0-alpha.c640f9",X=Y;function ee(){const e=[{pm:"npm",cmd:`npm ls -g ${X} --json 2>/dev/null`},{pm:"pnpm",cmd:`pnpm ls -g ${X} --json 2>/dev/null`},{pm:"yarn",cmd:"yarn global list --json 2>/dev/null"}];for(const{pm:t,cmd:o}of e)try{if(i.execSync(o,{encoding:"utf8",stdio:["pipe","pipe","pipe"]}).includes(X))return t}catch(e){}return"npm"}const te=Y,oe=864e5;function ie(){return Z}function se(e){const t=e.trim().replace(/^v/,"").split("+")[0],o=t.indexOf("-"),i=-1===o?t:t.slice(0,o),s=-1===o?"":t.slice(o+1),n=i.split(".");return{major:parseInt(n[0]||"0",10),minor:parseInt(n[1]||"0",10),patch:parseInt(n[2]||"0",10),prerelease:""===s?[]:s.split(".")}}function ne(e,t){const o=/^\d+$/.test(e),i=/^\d+$/.test(t);if(o&&i){const o=parseInt(e,10)-parseInt(t,10);return 0===o?0:o>0?1:-1}return o?-1:i?1:e===t?0:e>t?1:-1}function re(e,t){const o=se(e),i=se(t);return o.major!==i.major?o.major>i.major?1:-1:o.minor!==i.minor?o.minor>i.minor?1:-1:o.patch!==i.patch?o.patch>i.patch?1:-1:function(e,t){if(0===e.length&&0===t.length)return 0;if(0===e.length)return 1;if(0===t.length)return-1;const o=Math.max(e.length,t.length);for(let i=0;i<o;i++){const o=e[i],s=t[i];if(void 0===o)return-1;if(void 0===s)return 1;const n=ne(o,s);if(0!==n)return n}return 0}(o.prerelease,i.prerelease)}function ae(e,t){return re(t,e)>0}function ce(){if(process.env.COZE_CLI_NO_UPDATE_NOTIFIER)return!0;const e=(t=process.env.CI,o=()=>"",null!=t?t:o()).toLowerCase();var t,o;return""!==e&&"false"!==e&&"0"!==e||function(e){return!e||"0.0.0"===e||/dev/i.test(e)}(ie())}function le(e){const t=e.upgradeMode;if("auto"===t||"notify"===t||"off"===t)return t;const o=e.autoCheckUpdate;return!1===o||"false"===o?"off":!0===o||"true"===o?"notify":"auto"}async function de(t,o=!1,n="latest"){const r=ie(),{config:a}=t;if(!o&&a.latestVersion&&a.lastCheckTime&&Date.now()-a.lastCheckTime<oe)return{currentVersion:r,latestVersion:a.latestVersion,hasUpdate:ae(r,a.latestVersion)};const c=function(){try{return i.execSync("npm config get registry",{encoding:"utf8",stdio:["pipe","pipe","pipe"]}).trim().replace(/\/+$/,"")}catch(e){return"https://registry.npmjs.org"}}(),l=await async function(t,o="latest"){const i=`${t}/${te}/${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}(c,n);return await s.saveConfig({latestVersion:l,lastCheckTime:Date.now()},a.configScope),{currentVersion:r,latestVersion:l,hasUpdate:ae(r,l)}}async function pe(e,t){const{lastUpgradeAttempt:o}=e.config;if(o&&Date.now()-o<oe)return;try{await s.saveConfig({lastUpgradeAttempt:Date.now()},e.config.configScope)}catch(e){}const n=ee(),{command:r,args:a}=function(e,t){const o=`${X}@${t}`;switch(e){case"pnpm":return{command:"pnpm",args:["add","-g",o]};case"yarn":return{command:"yarn",args:["global","add",o]};default:return{command:"npm",args:["install","-g",o]}}}(n,t);try{i.spawn(r,a,{detached:!0,stdio:"ignore",shell:"win32"===process.platform}).unref()}catch(e){}}function ue(e,t){return null!=e?e:t()}function me(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}const ge={claude:"claude-code"};let he=null;function fe(){if(he)return he;const t=function(){let e=__dirname;for(let t=0;t<12;t++){const t=n.join(e,"node_modules","skills","package.json");if(a.existsSync(t))return n.dirname(t);const o=n.dirname(e);if(o===e)break;e=o}}();if(t){const o=e.safeJsonParse(a.readFileSync(n.join(t,"package.json"),"utf8")),i="string"==typeof me([o,"optionalAccess",e=>e.bin])?o.bin:me([o,"optionalAccess",e=>e.bin,"optionalAccess",e=>e.skills]);if(i)return he={cmd:process.execPath,prefix:[n.join(t,i)]},he}return he={cmd:"skills",prefix:[]},he}function _e(e){const{cmd:t,prefix:o}=fe(),s=i.spawnSync(t,[...o,...e],{encoding:"utf8"});return{ok:0===s.status,stdout:ue(s.stdout,(()=>"")),stderr:ue(s.stderr,(()=>"")),code:s.status}}function ye(e,t={}){const o=["add",e];return t.global&&o.push("-g"),t.yes&&o.push("-y"),t.agents&&t.agents.length>0&&o.push("-a",...t.agents),_e(o)}function be(e,t={}){const o=["remove",e];return t.global&&o.push("-g"),o.push("-y"),_e(o)}function ve(t={}){const o=["ls","--json"];t.global&&o.push("-g");const i=_e(o);if(!i.ok)return[];const s=e.safeJsonParse(i.stdout);return Array.isArray(s)?s:[]}function we(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 Ee(){return s.getGlobalSkillLockFile()}async function Ce(e){try{return await r.access(e),!0}catch(e){return!1}}async function Ie(){let t=__dirname;for(let o=0;o<12;o++){const o=n.join(t,"package.json");if(await Ce(o)){if("@coze/cli"===we([e.safeJsonParse(await r.readFile(o,"utf8")),"optionalAccess",e=>e.name]))return t}const i=n.dirname(t);if(i===t)break;t=i}return n.resolve(__dirname,"..")}async function Ae(){return n.join(await Ie(),"skills")}async function Se(){return n.join(await Ie(),"docs","skills")}const ke=new Set(["SKILL.md","MODULE.md"]);function je(e){return`sha256:${c.createHash("sha256").update(e,"utf8").digest("hex")}`}function Pe(e){return ke.has(n.basename(e))}async function ze(e,t=e){const o=await r.readdir(e,{withFileTypes:!0}),i=[];for(const s of o){if(s.name.startsWith("."))continue;const o=n.join(e,s.name);s.isDirectory()?i.push(...await ze(o,t)):s.isFile()&&i.push(n.relative(t,o).split(n.sep).join("/"))}return i.sort()}function Te(e,t){const o=xe(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 Re(e,t){const o=xe(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 xe(e){if(!e.startsWith("---"))return;const t=e.match(/^---\n([\s\S]*?)\n---/);return t?t[1]:void 0}function Le(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 Oe(){const e=await Ae();if(await Ce(n.join(e,"manifest.json")))return{root:e,source:"bundled"};const t=await Se();if(await Ce(t))return{root:t,source:"docs"};throw new Error(`未找到 skill 来源:既无包内 ${e}/manifest.json,也无开发态 ${t}。`)}async function De(){const t=n.join(await Ie(),"package.json"),o=e.safeJsonParse(await r.readFile(t,"utf8"));return i=Le([o,"optionalAccess",e=>e.version]),s=()=>"0.0.0",null!=i?i:s();var i,s}async function Ue(){const t=await Ae(),o=n.join(t,"manifest.json");if(await Ce(o)){const i=e.safeJsonParse(await r.readFile(o,"utf8")),s=(await ze(t)).filter((e=>"manifest.json"!==e)),a=[];for(const e of s)a.push({rel:e,content:await r.readFile(n.join(t,e),"utf8")});return{manifest:i,files:a,source:"bundled"}}const i=await Se();if(!await Ce(i))throw new Error(`未找到 skill 来源:既无包内 ${o},也无开发态 ${i}。`);const s=await De(),{manifest:a,files:c}=await async function(e,t){const o=await ze(e),i=[],s={};for(const l of o){const o=await r.readFile(n.join(e,l),"utf8"),d=Pe(l),p=d?Re(o,t):o;i.push({rel:l,content:p}),d&&(s[(a=Te(p,"name"),c=()=>l,null!=a?a:c())]={path:l,hash:je(p)})}var a,c;return{manifest:{cliVersion:t,skills:s},files:i}}(i,s);return{manifest:a,files:c,source:"docs"}}async function qe(){try{const t=await r.readFile(Ee(),"utf8");return e.safeJsonParse(t)}catch(e){return}}function Be(e,t){return null!=e?e:t()}function Me(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 Ne(e){try{return je(await r.readFile(e,"utf8"))}catch(e){return}}function $e(e){return[...new Set(Object.values(e.skills).map((e=>e.path.split("/")[0])))]}function Ge(e){return e[0]?n.dirname(e[0].path):void 0}async function Fe(e={}){const{manifest:t}=await Ue(),{root:o}=await Oe(),i=$e(t),s=await qe(),a=ve({global:!0}),c=await async function(e,t,o){const i=Ge(t);if(!i)return[];const s=new Set(t.map((e=>e.name))),r=[];for(const[t,a]of Object.entries(e.skills)){const e=a.path.split("/")[0];if(!s.has(e))continue;const c=await Ne(n.join(i,a.path));if(void 0===c)continue;if(c===a.hash)continue;const l=Me([o,"optionalAccess",e=>e.skills,"access",e=>e[t],"optionalAccess",e=>e.hash]);void 0!==l&&c===l||r.push(t)}return r}(t,a,s);if(c.length>0&&!e.force)return{blocked:!0,cliVersion:t.cliVersion,sourceRoot:o,linkedTargets:[],skillsOk:!1,unknownTargets:[],modifiedSkills:c};const l=e.targets&&e.targets.length>0&&!e.targets.includes("all")?Be(e.targets,(()=>[])).map((e=>ue(ge[e],(()=>e)))):void 0;let d=!0;for(const e of i){ye(n.join(o,e),{global:!0,yes:!0,agents:l}).ok||(d=!1)}const p=ve({global:!0}).filter((e=>i.includes(e.name))),u=Me([p,"access",e=>e[0],"optionalAccess",e=>e.path]),m=[...new Set(p.flatMap((e=>e.agents)))],g=(new Date).toISOString(),h={};for(const[e,o]of Object.entries(t.skills))h[e]={hash:o.hash,expectedHash:o.hash,installedAt:g};return await async function(e){const t=Ee();await r.mkdir(n.dirname(t),{recursive:!0}),await r.writeFile(t,`${JSON.stringify(e,null,2)}\n`,"utf8")}({version:1,cliVersion:t.cliVersion,installedBin:Be(process.argv[1],(()=>process.execPath)),poolPath:u,targets:m,skills:h}),{blocked:!1,cliVersion:t.cliVersion,sourceRoot:o,poolPath:u,linkedTargets:m,skillsOk:d,unknownTargets:[],modifiedSkills:[]}}function Ve(e,t,o){return void 0===e?"missing":e===t?"ok":o===e?"drift":"modified"}async function We(){const{manifest:e}=await Ue(),t=await qe(),o=Be(process.argv[1],(()=>process.execPath)),i=ve({global:!0}),s=Ge(i),r=new Set(i.map((e=>e.name))),a=[];for(const[o,i]of Object.entries(e.skills)){const e=i.path.split("/")[0],c=Boolean(s)&&r.has(e),l=c?await Ne(n.join(s,i.path)):void 0,d=c?Ve(l,i.hash,Me([t,"optionalAccess",e=>e.skills,"access",e=>e[o],"optionalAccess",e=>e.hash])):"missing";a.push({name:o,path:i.path,state:d})}const c=Me([i,"access",e=>e.find,"call",e=>e((e=>r.has(e.name))),"optionalAccess",e=>e.path]);return{lockExists:Boolean(t),cliVersion:e.cliVersion,installedVersion:Me([t,"optionalAccess",e=>e.cliVersion]),versionMatch:Boolean(t)&&Me([t,"optionalAccess",e=>e.cliVersion])===e.cliVersion,installedBin:Me([t,"optionalAccess",e=>e.installedBin]),currentBin:o,binMatch:!Me([t,"optionalAccess",e=>e.installedBin])||t.installedBin===o,poolPath:c,targets:Be(Me([t,"optionalAccess",e=>e.targets]),(()=>[])),skills:a}}async function He(){const{manifest:e}=await Ue(),t=$e(e),o=ve({global:!0}),i=[];for(const e of t){const t=o.find((t=>t.name===e));if(!t)continue;be(e,{global:!0}).ok&&i.push({name:e,agents:t.agents})}return await async function(){await r.rm(Ee(),{force:!0})}(),{removed:i}}async function Je(){const t=await async function(){const t=n.join(await Ae(),"manifest.json");if(await Ce(t)){const o=e.safeJsonParse(await r.readFile(t,"utf8"));if(Le([o,"optionalAccess",e=>e.cliVersion]))return o.cliVersion}return De()}(),o=await qe();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 self skill install\`.`}:{state:"ok",cliVersion:t,installedVersion:o.cliVersion}:{state:"missing",cliVersion:t,message:"Bundled skills not installed yet. Run `coze self skill install` to sync them to your AI tools."}}function Ke(e){const t={};let o;const i=[];let s=!1;for(let n=0;n<e.length;n++){const r=e[n];if("--help"!==r&&"-h"!==r)if("--version"!==r&&"-v"!==r)if("--output"!==r)if("--format"!==r)"--no-color"!==r?"--config"!==r?"--org-id"!==r?"--space-id"!==r?"--verbose"!==r?"--debug"!==r?"--log-file"!==r?"--print-logs"!==r?s||r.startsWith("-")?i.push(r):(o=r,s=!0):t.printLogs=!0:t.logFile=e[++n]:t.debug=!0:t.verbose=!0:t.spaceId=e[++n]:t.orgId=e[++n]:t.config=e[++n]:t.noColor=!0;else{const o=e[++n];"json"!==o&&"text"!==o||(t.format=o)}else t.output=e[++n];else t.version=!0;else t.help=!0}return{globalOptions:t,commandName:o,commandArgs:i}}async function Qe(e,t){const i=await async function(e){if("self"===Ke(e.argv).commandName)return;const t=function(){const e=(t=process.env.CI,o=()=>"",null!=t?t:o()).toLowerCase();var t,o;return""!==e&&"false"!==e&&"0"!==e||Boolean(process.env.COZE_CLI_NO_SKILL_NOTIFIER)}(),o=function(e){const t=e.config.autoSyncSkill;return!0===t||"true"===t}(e);if(t&&!o)return;try{const i=await Je();if("ok"===i.state)return;if("mismatch"===i.state&&o&&await async function(e){if("mismatch"!==e.state)return!1;try{return!(await Fe({})).blocked}catch(e){return!1}}(i))return;if(t)return;return"json"===e.format&&e.response.setNotice({skill:{state:i.state,cliVersion:i.cliVersion,installedVersion:i.installedVersion,message:i.message,command:"coze self skill install"}}),i}catch(e){return}}(e),s=await async function(e){if("upgrade"===Ke(e.argv).commandName)return;if(ce())return;const t=le(e.config);if("off"===t)return;const o=e.config.latestVersion;if(!o)return;const i=ie();if(!ae(i,o))return;const{lastUpgradeAttempt:s}=e.config,n="number"==typeof s&&Date.now()-s<oe;let r;"auto"===t?n?r=`Auto-upgrade to ${o} did not take effect (current ${i}). Run \`coze upgrade\` manually; on an internal network verify your npm registry.`:(r=`Coze CLI ${o} available (current ${i}). Upgrading in the background; it will take effect on next run.`,pe(e,o)):r=`Coze CLI ${o} available (current ${i}). Run \`coze upgrade\` to update.`;"json"===e.format&&e.response.setNotice({update:{current:i,latest:o,message:r,command:"coze upgrade"}});return{current:i,latest:o,message:r}}(e);await t(),function(e,t){if(!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}([t,"optionalAccess",e=>e.message]))return;if("json"===e.format)return void(e.response.hasPendingNotice()&&process.stderr.write(`${t.message}\n`));e.ui.info(`\n${t.message}\n`)}(e,i),function(e,t){if(!t)return;if("json"===e.format)return void(e.response.hasPendingNotice()&&process.stderr.write(`${t.message}\n`));e.ui.info(`\n${o.gray(t.current)} → ${o.green(t.latest)} ${t.message}\n`)}(e,s),async function(e){if("upgrade"===Ke(e.argv).commandName)return;if(ce())return;const t=le(e.config);if("off"===t)return;try{const i=await de(e,!1,(o=e.config,o.upgradeChannel||"latest"));i.hasUpdate&&"auto"===t&&await pe(e,i.latestVersion)}catch(e){}var o}(e)}var Ye=e.requireSrc();const Ze=e.getDefaultExportFromCjs(Ye);function Xe(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
package/skills/manifest.json
CHANGED
|
@@ -1,25 +1,25 @@
|
|
|
1
1
|
{
|
|
2
|
-
"cliVersion": "0.3.0-alpha.
|
|
2
|
+
"cliVersion": "0.3.0-alpha.c640f9",
|
|
3
3
|
"skills": {
|
|
4
4
|
"using-coze-cli": {
|
|
5
5
|
"path": "using-coze-cli/SKILL.md",
|
|
6
|
-
"hash": "sha256:
|
|
6
|
+
"hash": "sha256:da565b86869d9bbf74a8fc0f2b913e8cc58fdde3a0f0eaf7d139977b4da18edd"
|
|
7
7
|
},
|
|
8
8
|
"coze-claw": {
|
|
9
9
|
"path": "using-coze-cli/coze-claw/MODULE.md",
|
|
10
|
-
"hash": "sha256:
|
|
10
|
+
"hash": "sha256:7b6a085729bfba17d1519b21033716c07c5de490053e3dd597407b0957ca6c8c"
|
|
11
11
|
},
|
|
12
12
|
"coze-code": {
|
|
13
13
|
"path": "using-coze-cli/coze-code/MODULE.md",
|
|
14
|
-
"hash": "sha256:
|
|
14
|
+
"hash": "sha256:da42bc3d34aecbf1f4f69dbba02049efd2c2132eda9552226fcfcadb797ca7a5"
|
|
15
15
|
},
|
|
16
16
|
"coze-file": {
|
|
17
17
|
"path": "using-coze-cli/coze-file/MODULE.md",
|
|
18
|
-
"hash": "sha256:
|
|
18
|
+
"hash": "sha256:cac59476c30eefeee3f541d97d611be2b6d0bde444e9a308058d0e24f801ccba"
|
|
19
19
|
},
|
|
20
20
|
"coze-generate": {
|
|
21
21
|
"path": "using-coze-cli/coze-generate/MODULE.md",
|
|
22
|
-
"hash": "sha256:
|
|
22
|
+
"hash": "sha256:d1b0737aea8c982a7801c99460230f4a3b420c4a2b54c022eb96bea22004bd74"
|
|
23
23
|
}
|
|
24
24
|
}
|
|
25
25
|
}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
---
|
|
2
2
|
name: using-coze-cli
|
|
3
|
-
version: 0.3.0-alpha.
|
|
3
|
+
version: 0.3.0-alpha.c640f9
|
|
4
4
|
description: "Coze CLI(coze 命令)统一入口与共享基础,使用任何 coze 能力前必读(登录授权、组织/空间、配置、错误码与权限排查)。四个子模块:coze code(创建/迭代网页·App·小程序·Agent·工作流等编程项目、发需求、预览、部署、环境变量/域名/数据库)、coze session(Claw 对话、PPT、播客、长任务产物)、coze generate(图片/语音 TTS/视频生成)、coze file(本地文件转在线链接)。触发场景(满足任一即触发,无需用户显式点名 coze):想做网页/App/小程序、开发或迭代项目、上线部署;生成图片/语音/视频;做 PPT/播客;把本地文件转成在线链接;登录授权/No permission/切换组织空间;输入以 /coze-cli、/coze 开头(前缀仅作路由)。"
|
|
5
5
|
metadata:
|
|
6
6
|
requires:
|