@coze/cli 0.2.0-alpha.e81ff3 → 0.2.0-alpha.f62ab3

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.
@@ -0,0 +1,27 @@
1
+ #!/usr/bin/env node
2
+ // ABOUTME: npm postinstall 钩子:安装/升级后提示用户执行 `coze guide sync`,
3
+ // ABOUTME: 把 CLI 自带 skills 同步给本机 AI agents。绝不抛错,避免阻断安装。
4
+
5
+ try {
6
+ // CI / 非交互环境(如流水线、rush update)不打印提示
7
+ if (process.env.CI || !process.stdout.isTTY) {
8
+ process.exit(0);
9
+ }
10
+
11
+ const useColor = !process.env.NO_COLOR;
12
+ const cyan = text => (useColor ? `${text}` : text);
13
+
14
+ process.stdout.write(
15
+ [
16
+ '',
17
+ 'Coze CLI installed.',
18
+ `Run ${cyan('coze guide sync')} to sync the bundled skills to your AI agents (Claude Code, Trae, Comate, ...).`,
19
+ '',
20
+ '',
21
+ ].join('\n'),
22
+ );
23
+ // eslint-disable-next-line @coze-arch/no-empty-catch -- postinstall hint is best-effort and must never block install
24
+ } catch {
25
+ // postinstall 提示失败不应阻断安装
26
+ }
27
+ process.exit(0);
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-C6r1MTLx.js"),o=require("chalk"),i=require("node:path"),s=require("node:fs/promises"),n=require("node:fs"),r=require("node:child_process"),a=require("./task-worker-C08RI2za.js"),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("http"),require("https"),require("http2"),require("util"),require("stream"),require("assert"),require("tty"),require("zlib"),require("events"),require("mitt"),require("process");const I=C(i),A=C(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 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))};function Y(e,t){return null!=e?e:t()}function Z(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 X={claude:"claude-code"};let ee=null;function te(){if(ee)return ee;const t=function(){let e=__dirname;for(let t=0;t<12;t++){const t=i.join(e,"node_modules","skills","package.json");if(n.existsSync(t))return i.dirname(t);const o=i.dirname(e);if(o===e)break;e=o}}();if(t){const o=e.safeJsonParse(n.readFileSync(i.join(t,"package.json"),"utf8")),s="string"==typeof Z([o,"optionalAccess",e=>e.bin])?o.bin:Z([o,"optionalAccess",e=>e.bin,"optionalAccess",e=>e.skills]);if(s)return ee={cmd:process.execPath,prefix:[i.join(t,s)]},ee}return ee={cmd:"skills",prefix:[]},ee}function oe(e){const{cmd:t,prefix:o}=te(),i=r.spawnSync(t,[...o,...e],{encoding:"utf8"});return{ok:0===i.status,stdout:Y(i.stdout,(()=>"")),stderr:Y(i.stderr,(()=>"")),code:i.status}}function ie(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),oe(o)}function se(e,t={}){const o=["remove",e];return t.global&&o.push("-g"),o.push("-y"),oe(o)}function ne(t={}){const o=["ls","--json"];t.global&&o.push("-g");const i=oe(o);if(!i.ok)return[];const s=e.safeJsonParse(i.stdout);return Array.isArray(s)?s:[]}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.getGlobalSkillLockFile()}async function ce(e){try{return await s.access(e),!0}catch(e){return!1}}async function le(){let t=__dirname;for(let o=0;o<12;o++){const o=i.join(t,"package.json");if(await ce(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,"..")}async function de(){return i.join(await le(),"skills")}async function pe(){return i.join(await le(),"docs","skills")}const ue=new Set(["SKILL.md","MODULE.md"]);function me(e){return`sha256:${c.createHash("sha256").update(e,"utf8").digest("hex")}`}function ge(e){return ue.has(i.basename(e))}async function he(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 he(o,t)):s.isFile()&&n.push(i.relative(t,o).split(i.sep).join("/"))}return n.sort()}function fe(e,t){const o=ye(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 _e(e,t){const o=ye(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 ye(e){if(!e.startsWith("---"))return;const t=e.match(/^---\n([\s\S]*?)\n---/);return t?t[1]:void 0}async function be(){const e=await de();if(await ce(i.join(e,"manifest.json")))return{root:e,source:"bundled"};const t=await pe();if(await ce(t))return{root:t,source:"docs"};throw new Error(`未找到 skill 来源:既无包内 ${e}/manifest.json,也无开发态 ${t}。`)}async function ve(){const t=await de(),o=i.join(t,"manifest.json");if(await ce(o)){const n=e.safeJsonParse(await s.readFile(o,"utf8")),r=(await he(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 pe();if(!await ce(n))throw new Error(`未找到 skill 来源:既无包内 ${o},也无开发态 ${n}。`);const r=await async function(){const t=i.join(await le(),"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 he(e),n=[],r={};for(const l of o){const o=await s.readFile(i.join(e,l),"utf8"),d=ge(l),p=d?_e(o,t):o;n.push({rel:l,content:p}),d&&(r[(a=fe(p,"name"),c=()=>l,null!=a?a:c())]={path:l,hash:me(p)})}var a,c;return{manifest:{cliVersion:t,skills:r},files:n}}(n,r);return{manifest:a,files:c,source:"docs"}}async function we(){try{const t=await s.readFile(ae(),"utf8");return e.safeJsonParse(t)}catch(e){return}}function Ee(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 Ie(e){try{return me(await s.readFile(e,"utf8"))}catch(e){return}}function Ae(e){return[...new Set(Object.values(e.skills).map((e=>e.path.split("/")[0])))]}function Se(e){return e[0]?i.dirname(e[0].path):void 0}async function je(e={}){const{manifest:t}=await ve(),{root:o}=await be(),n=Ae(t),r=await we(),a=ne({global:!0}),c=await async function(e,t,o){const s=Se(t);if(!s)return[];const n=new Set(t.map((e=>e.name))),r=[];for(const[t,a]of Object.entries(e.skills)){const e=a.path.split("/")[0];if(!n.has(e))continue;const c=await Ie(i.join(s,a.path));if(void 0===c)continue;if(c===a.hash)continue;const l=Ce([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,r);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")?Ee(e.targets,(()=>[])).map((e=>Y(X[e],(()=>e)))):void 0;let d=!0;for(const e of n){ie(i.join(o,e),{global:!0,yes:!0,agents:l}).ok||(d=!1)}const p=ne({global:!0}).filter((e=>n.includes(e.name))),u=Ce([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=ae();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:Ee(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 Pe(e,t,o){return void 0===e?"missing":e===t?"ok":o===e?"drift":"modified"}async function ke(){const{manifest:e}=await ve(),t=await we(),o=Ee(process.argv[1],(()=>process.execPath)),s=ne({global:!0}),n=Se(s),r=new Set(s.map((e=>e.name))),a=[];for(const[o,s]of Object.entries(e.skills)){const e=s.path.split("/")[0],c=Boolean(n)&&r.has(e),l=c?await Ie(i.join(n,s.path)):void 0,d=c?Pe(l,s.hash,Ce([t,"optionalAccess",e=>e.skills,"access",e=>e[o],"optionalAccess",e=>e.hash])):"missing";a.push({name:o,path:s.path,state:d})}const c=Ce([s,"access",e=>e.find,"call",e=>e((e=>r.has(e.name))),"optionalAccess",e=>e.path]);return{lockExists:Boolean(t),cliVersion:e.cliVersion,installedVersion:Ce([t,"optionalAccess",e=>e.cliVersion]),versionMatch:Boolean(t)&&Ce([t,"optionalAccess",e=>e.cliVersion])===e.cliVersion,installedBin:Ce([t,"optionalAccess",e=>e.installedBin]),currentBin:o,binMatch:!Ce([t,"optionalAccess",e=>e.installedBin])||t.installedBin===o,poolPath:c,targets:Ee(Ce([t,"optionalAccess",e=>e.targets]),(()=>[])),skills:a}}async function Te(){const{manifest:e}=await ve(),t=Ae(e),o=ne({global:!0}),i=[];for(const e of t){const t=o.find((t=>t.name===e));if(!t)continue;se(e,{global:!0}).ok&&i.push({name:e,agents:t.agents})}return await async function(){await s.rm(ae(),{force:!0})}(),{removed:i}}const ze="0.2.0-alpha.e81ff3",Re="@coze/cli";function xe(){return ze}function Le(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 Oe(t,o=!1,i="latest"){const s=xe(),{config:n}=t;if(!o&&n.latestVersion&&n.lastCheckTime&&Date.now()-n.lastCheckTime<864e5)return{currentVersion:s,latestVersion:n.latestVersion,hasUpdate:Le(s,n.latestVersion)};const c=function(){try{return r.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}/${Re}/${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,i);return await a.saveConfig({latestVersion:l,lastCheckTime:Date.now()},n.configScope),{currentVersion:s,latestVersion:l,hasUpdate:Le(s,l)}}async function De(e,t){if(await t(),!0===e.config.autoCheckUpdate)try{const t=await Oe(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 ve(),{cliVersion:t}=e,o=await we();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 je({})).blocked}catch(e){return!1}}(t);if(e)return}t.message&&e.ui.info(`\n${t.message}\n`)}catch(e){}}(e)}var Ue=e.requireSrc();const qe=e.getDefaultExportFromCjs(Ue);function Be(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-C6r1MTLx.js"),o=require("chalk"),i=require("node:path"),s=require("node:fs/promises"),n=require("node:fs"),r=require("node:child_process"),a=require("./task-worker-C08RI2za.js"),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("http"),require("https"),require("http2"),require("util"),require("stream"),require("assert"),require("tty"),require("zlib"),require("events"),require("mitt"),require("process");const I=C(i),A=C(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 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))};function Y(e,t){return null!=e?e:t()}function Z(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 X={claude:"claude-code"};let ee=null;function te(){if(ee)return ee;const t=function(){let e=__dirname;for(let t=0;t<12;t++){const t=i.join(e,"node_modules","skills","package.json");if(n.existsSync(t))return i.dirname(t);const o=i.dirname(e);if(o===e)break;e=o}}();if(t){const o=e.safeJsonParse(n.readFileSync(i.join(t,"package.json"),"utf8")),s="string"==typeof Z([o,"optionalAccess",e=>e.bin])?o.bin:Z([o,"optionalAccess",e=>e.bin,"optionalAccess",e=>e.skills]);if(s)return ee={cmd:process.execPath,prefix:[i.join(t,s)]},ee}return ee={cmd:"skills",prefix:[]},ee}function oe(e){const{cmd:t,prefix:o}=te(),i=r.spawnSync(t,[...o,...e],{encoding:"utf8"});return{ok:0===i.status,stdout:Y(i.stdout,(()=>"")),stderr:Y(i.stderr,(()=>"")),code:i.status}}function ie(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),oe(o)}function se(e,t={}){const o=["remove",e];return t.global&&o.push("-g"),o.push("-y"),oe(o)}function ne(t={}){const o=["ls","--json"];t.global&&o.push("-g");const i=oe(o);if(!i.ok)return[];const s=e.safeJsonParse(i.stdout);return Array.isArray(s)?s:[]}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.getGlobalSkillLockFile()}async function ce(e){try{return await s.access(e),!0}catch(e){return!1}}async function le(){let t=__dirname;for(let o=0;o<12;o++){const o=i.join(t,"package.json");if(await ce(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,"..")}async function de(){return i.join(await le(),"skills")}async function pe(){return i.join(await le(),"docs","skills")}const ue=new Set(["SKILL.md","MODULE.md"]);function me(e){return`sha256:${c.createHash("sha256").update(e,"utf8").digest("hex")}`}function ge(e){return ue.has(i.basename(e))}async function he(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 he(o,t)):s.isFile()&&n.push(i.relative(t,o).split(i.sep).join("/"))}return n.sort()}function fe(e,t){const o=ye(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 _e(e,t){const o=ye(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 ye(e){if(!e.startsWith("---"))return;const t=e.match(/^---\n([\s\S]*?)\n---/);return t?t[1]:void 0}async function be(){const e=await de();if(await ce(i.join(e,"manifest.json")))return{root:e,source:"bundled"};const t=await pe();if(await ce(t))return{root:t,source:"docs"};throw new Error(`未找到 skill 来源:既无包内 ${e}/manifest.json,也无开发态 ${t}。`)}async function ve(){const t=await de(),o=i.join(t,"manifest.json");if(await ce(o)){const n=e.safeJsonParse(await s.readFile(o,"utf8")),r=(await he(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 pe();if(!await ce(n))throw new Error(`未找到 skill 来源:既无包内 ${o},也无开发态 ${n}。`);const r=await async function(){const t=i.join(await le(),"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 he(e),n=[],r={};for(const l of o){const o=await s.readFile(i.join(e,l),"utf8"),d=ge(l),p=d?_e(o,t):o;n.push({rel:l,content:p}),d&&(r[(a=fe(p,"name"),c=()=>l,null!=a?a:c())]={path:l,hash:me(p)})}var a,c;return{manifest:{cliVersion:t,skills:r},files:n}}(n,r);return{manifest:a,files:c,source:"docs"}}async function we(){try{const t=await s.readFile(ae(),"utf8");return e.safeJsonParse(t)}catch(e){return}}function Ee(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 Ie(e){try{return me(await s.readFile(e,"utf8"))}catch(e){return}}function Ae(e){return[...new Set(Object.values(e.skills).map((e=>e.path.split("/")[0])))]}function Se(e){return e[0]?i.dirname(e[0].path):void 0}async function je(e={}){const{manifest:t}=await ve(),{root:o}=await be(),n=Ae(t),r=await we(),a=ne({global:!0}),c=await async function(e,t,o){const s=Se(t);if(!s)return[];const n=new Set(t.map((e=>e.name))),r=[];for(const[t,a]of Object.entries(e.skills)){const e=a.path.split("/")[0];if(!n.has(e))continue;const c=await Ie(i.join(s,a.path));if(void 0===c)continue;if(c===a.hash)continue;const l=Ce([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,r);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")?Ee(e.targets,(()=>[])).map((e=>Y(X[e],(()=>e)))):void 0;let d=!0;for(const e of n){ie(i.join(o,e),{global:!0,yes:!0,agents:l}).ok||(d=!1)}const p=ne({global:!0}).filter((e=>n.includes(e.name))),u=Ce([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=ae();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:Ee(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 Pe(e,t,o){return void 0===e?"missing":e===t?"ok":o===e?"drift":"modified"}async function ke(){const{manifest:e}=await ve(),t=await we(),o=Ee(process.argv[1],(()=>process.execPath)),s=ne({global:!0}),n=Se(s),r=new Set(s.map((e=>e.name))),a=[];for(const[o,s]of Object.entries(e.skills)){const e=s.path.split("/")[0],c=Boolean(n)&&r.has(e),l=c?await Ie(i.join(n,s.path)):void 0,d=c?Pe(l,s.hash,Ce([t,"optionalAccess",e=>e.skills,"access",e=>e[o],"optionalAccess",e=>e.hash])):"missing";a.push({name:o,path:s.path,state:d})}const c=Ce([s,"access",e=>e.find,"call",e=>e((e=>r.has(e.name))),"optionalAccess",e=>e.path]);return{lockExists:Boolean(t),cliVersion:e.cliVersion,installedVersion:Ce([t,"optionalAccess",e=>e.cliVersion]),versionMatch:Boolean(t)&&Ce([t,"optionalAccess",e=>e.cliVersion])===e.cliVersion,installedBin:Ce([t,"optionalAccess",e=>e.installedBin]),currentBin:o,binMatch:!Ce([t,"optionalAccess",e=>e.installedBin])||t.installedBin===o,poolPath:c,targets:Ee(Ce([t,"optionalAccess",e=>e.targets]),(()=>[])),skills:a}}async function Te(){const{manifest:e}=await ve(),t=Ae(e),o=ne({global:!0}),i=[];for(const e of t){const t=o.find((t=>t.name===e));if(!t)continue;se(e,{global:!0}).ok&&i.push({name:e,agents:t.agents})}return await async function(){await s.rm(ae(),{force:!0})}(),{removed:i}}const ze="0.2.0-alpha.f62ab3",Re="@coze/cli";function xe(){return ze}function Le(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 Oe(t,o=!1,i="latest"){const s=xe(),{config:n}=t;if(!o&&n.latestVersion&&n.lastCheckTime&&Date.now()-n.lastCheckTime<864e5)return{currentVersion:s,latestVersion:n.latestVersion,hasUpdate:Le(s,n.latestVersion)};const c=function(){try{return r.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}/${Re}/${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,i);return await a.saveConfig({latestVersion:l,lastCheckTime:Date.now()},n.configScope),{currentVersion:s,latestVersion:l,hasUpdate:Le(s,l)}}async function De(e,t){if(await t(),!0===e.config.autoCheckUpdate)try{const t=await Oe(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 ve(),{cliVersion:t}=e,o=await we();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 je({})).blocked}catch(e){return!1}}(t);if(e)return}t.message&&e.ui.info(`\n${t.message}\n`)}catch(e){}}(e)}var Ue=e.requireSrc();const qe=e.getDefaultExportFromCjs(Ue);function Be(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.e81ff3",
3
+ "version": "0.2.0-alpha.f62ab3",
4
4
  "private": false,
5
5
  "description": "Coze CLI - A command-line interface for Coze platform",
6
6
  "license": "MIT",
@@ -24,6 +24,7 @@
24
24
  "audit:pre": "pack-audit pre",
25
25
  "prebuild": "tsx scripts/prebuild.ts",
26
26
  "build": "CUSTOM_VERSION=release REGION=cn tsx scripts/build.ts",
27
+ "postinstall": "node bin/postinstall.js",
27
28
  "knip": "knip --include files",
28
29
  "knip:all": "knip",
29
30
  "lint": "eslint ./ --cache",
@@ -1,25 +1,25 @@
1
1
  {
2
- "cliVersion": "0.2.0-alpha.e81ff3",
2
+ "cliVersion": "0.2.0-alpha.f62ab3",
3
3
  "skills": {
4
4
  "using-coze-cli": {
5
5
  "path": "using-coze-cli/SKILL.md",
6
- "hash": "sha256:eee5742b5b7102e33027164a86c9c08d88b3d1fbf8b357daae9069c8f3a623aa"
6
+ "hash": "sha256:b4a5954f33fa301311ae131cdc0fe9b1655f38e6756a92d3d65f3c519f1384a6"
7
7
  },
8
8
  "coze-claw": {
9
9
  "path": "using-coze-cli/coze-claw/MODULE.md",
10
- "hash": "sha256:cc9715f0514f1beb5be2aa55be0268ae24c22598b08a08c2950ec8f90710b1cb"
10
+ "hash": "sha256:b55694ec029f4730f941966b3158d61cf05e46893a5b4ad889fd42c3d61139dc"
11
11
  },
12
12
  "coze-code": {
13
13
  "path": "using-coze-cli/coze-code/MODULE.md",
14
- "hash": "sha256:50bafa04670f4b05d6abc3d61c7e2342c96c656e5749f0a9f96aead495eb89ee"
14
+ "hash": "sha256:11ecae726c9451eb6e80d7a7fc966465d3a9f1108a8fa10b6c1f1c5969efae7e"
15
15
  },
16
16
  "coze-file": {
17
17
  "path": "using-coze-cli/coze-file/MODULE.md",
18
- "hash": "sha256:278ab592fb8495df627abc179cef89f216e8d48c2586cada0c22417d55f2bc7c"
18
+ "hash": "sha256:2539293874fb133048e9f77a2bb7d67f9ba1505bad1aaa2e8131cfef284d893a"
19
19
  },
20
20
  "coze-generate": {
21
21
  "path": "using-coze-cli/coze-generate/MODULE.md",
22
- "hash": "sha256:fdfc2a1c258ecbd6188cf3c7a8fb2a5bfe56f67eefe557c156aa326c4ba7006e"
22
+ "hash": "sha256:eef9e383b6bee3ff6f7fcaeaaae4c0d80f59f596ccdf42b5d01772a67aba201d"
23
23
  }
24
24
  }
25
25
  }
@@ -1,6 +1,6 @@
1
1
  ---
2
2
  name: using-coze-cli
3
- version: 0.2.0-alpha.e81ff3
3
+ version: 0.2.0-alpha.f62ab3
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:
@@ -1,6 +1,6 @@
1
1
  ---
2
2
  name: coze-claw
3
- version: 0.2.0-alpha.e81ff3
3
+ version: 0.2.0-alpha.f62ab3
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.e81ff3
3
+ version: 0.2.0-alpha.f62ab3
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.e81ff3
3
+ version: 0.2.0-alpha.f62ab3
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.e81ff3
3
+ version: 0.2.0-alpha.f62ab3
4
4
  description: "Coze 媒体生成:文本生成图片、文本转语音(TTS)、视频生成。当用户需要使用 coze generate image/audio/video 生成音频、图片或视频时触发。"
5
5
  metadata:
6
6
  requires: