@luban-code/luban-code 1.100.0 → 1.100.2

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.
@@ -1,225 +1,225 @@
1
1
  #!/usr/bin/env node
2
2
  /*! Luban | Copyright 2026 eppen (liuhualiang) | SPDX-License-Identifier: Apache-2.0 */
3
- "use strict";var Zi=Object.create;var rn=Object.defineProperty;var eo=Object.getOwnPropertyDescriptor;var to=Object.getOwnPropertyNames;var no=Object.getPrototypeOf,so=Object.prototype.hasOwnProperty;var Ge=(e,t)=>()=>(e&&(t=e(e=0)),t);var me=(e,t)=>()=>(t||e((t={exports:{}}).exports,t),t.exports),ro=(e,t)=>{for(var n in t)rn(e,n,{get:t[n],enumerable:!0})},io=(e,t,n,s)=>{if(t&&typeof t=="object"||typeof t=="function")for(let r of to(t))!so.call(e,r)&&r!==n&&rn(e,r,{get:()=>t[r],enumerable:!(s=eo(t,r))||s.enumerable});return e};var Qe=(e,t,n)=>(n=e!=null?Zi(no(e)):{},io(t||!e||!e.__esModule?rn(n,"default",{value:e,enumerable:!0}):n,e));var un=me((qu,_s)=>{"use strict";var Ze=require("fs"),on=require("path"),xt=require("crypto"),oo=require("os"),Ss=new Set(["node_modules",".git",".DS_Store"]);function ao(e){return String(e??"").replace(/^~(?=$|[\\/])/,oo.homedir())}function an(e){return Array.isArray(e)?e.map(an):e&&typeof e=="object"?Object.fromEntries(Object.keys(e).sort().map(t=>[t,an(e[t])])):e}function vs(e){let{signature:t,...n}=e;return JSON.stringify(an(n))}function uo(e,t){let n=[];(function r(i,o){for(let a of Ze.readdirSync(i)){if(Ss.has(a))continue;let u=on.join(i,a),l=o?o+"/"+a:a,f=Ze.lstatSync(u);if(f.isSymbolicLink()){t&&t("\u8DF3\u8FC7\u7B26\u53F7\u94FE\u63A5 "+l);continue}f.isDirectory()?r(u,l):f.isFile()&&n.push(l)}})(e,""),n.sort(function(r,i){return Buffer.compare(Buffer.from(r,"utf8"),Buffer.from(i,"utf8"))});let s=xt.createHash("sha256");for(let r of n){let i=xt.createHash("sha256").update(Ze.readFileSync(on.join(e,r))).digest("hex");s.update(Buffer.from(r,"utf8")),s.update("\0"),s.update(i),s.update(`
4
- `)}return s.digest("hex")}function lo(e){return xt.createPublicKey({key:Buffer.from(e,"base64"),format:"der",type:"spki"})}function co(e,t){if(!e||!e.signature)return{ok:!1,reason:"\u672A\u7B7E\u540D"};let{algo:n,keyId:s,sig:r}=e.signature;if(n!=="ed25519")return{ok:!1,reason:"\u4E0D\u652F\u6301\u7684\u7B7E\u540D\u7B97\u6CD5 "+n};let i=t[s];if(!i)return{ok:!1,reason:"\u627E\u4E0D\u5230\u516C\u94A5 keyId="+s};try{return xt.verify(null,Buffer.from(vs(e)),i,Buffer.from(r||"","base64"))?{ok:!0}:{ok:!1,reason:"\u7B7E\u540D\u6821\u9A8C\u5931\u8D25\uFF1A\u6761\u76EE\u5185\u5BB9\u4E0E\u7B7E\u540D\u4E0D\u7B26\uFF08\u88AB\u7BE1\u6539\u6216\u6539\u4E86\u5B57\u6BB5\u672A\u91CD\u7B7E\uFF09"}}catch(o){return{ok:!1,reason:"\u7B7E\u540D\u89E3\u6790\u5931\u8D25\uFF1A"+o.message}}}function fo(e,t){return e+"-v"+t}function xs(e){let t=/^---\r?\n([\s\S]*?)\r?\n---/.exec(String(e));if(!t)return{};let n=t[1].split(/\r?\n/),s={};for(let r=0;r<n.length;r++){let i=n[r];if(/^\s/.test(i))continue;let o=i.indexOf(":");if(o<=0)continue;let a=i.slice(0,o).trim().toLowerCase();if(!a)continue;let u=i.slice(o+1).trim(),l=/^([|>])([-+]?)$/.exec(u);if(l){let f=[];for(let d=r+1;d<n.length;d++){let h=n[d];if(!h.trim()){f.push(""),r=d;continue}if(!/^\s/.test(h))break;f.push(h.trim()),r=d}s[a]=(l[1]==="|"?f.join(`
5
- `):f.join(" ").replace(/\s+/g," ")).trim();continue}s[a]=u}return s}var ho=2e4;function po(e){let t=on.join(e,"SKILL.md");if(!Ze.existsSync(t))return{ok:!1,message:"\u5305\u91CC\u6CA1\u6709 SKILL.md"};let n;try{n=Ze.readFileSync(t,"utf8").slice(0,ho)}catch(i){return{ok:!1,message:"SKILL.md \u8BFB\u53D6\u5931\u8D25\uFF1A"+i.message}}let s=xs(n),r=String(s.name||"").trim();return r?{ok:!0,manifest:{name:r,version:String(s.version||"").trim(),description:String(s.description||"").trim(),file:t}}:{ok:!1,message:"SKILL.md \u7684 frontmatter \u6CA1\u5199 name"}}function mo(e,t){return t?t.name!==e.name?{ok:!1,message:"name \u4E0D\u4E00\u81F4\uFF1A\u7D22\u5F15 "+e.name+"\u3001\u5305\u5185 "+t.name}:t.version&&t.version!==e.version?{ok:!1,message:"version \u4E0D\u4E00\u81F4\uFF1A\u7D22\u5F15 "+e.version+"\u3001\u5305\u5185 "+t.version}:{ok:!0}:{ok:!1,message:"\u6CA1\u6709\u6280\u80FD\u6E05\u5355"}}function go(e,t){let n=s=>JSON.stringify((s||[]).map(r=>[r.name,r.description,r.readOnly===!0,r.parameters]));return n(e)===n(t)}_s.exports={HASH_SKIP:Ss,expandHome:ao,canonical:vs,dirHash:uo,parsePublicKey:lo,verifyEntry:co,tagFor:fo,sameTools:go,parseFrontmatter:xs,readSkillManifest:po,sameSkill:mo}});var Ls=me((Pu,Fs)=>{"use strict";var B=require("fs"),Es=require("os"),V=require("path"),et=un(),Is="skills-trash",ln=".installed.json",Os={root:""};function yo(e){let t=e||{};t.root&&(Os.root=String(t.root))}function bo(){return V.resolve(Os.root||process.cwd())}function _t(){return V.join(Es.homedir(),".luban","skills")}function kt(){return V.join(Es.homedir(),".luban",Is)}function cn(e){return V.join(e||bo(),".luban","skills")}function Ts(e){return e==="project"?cn():_t()}function tt(e){let t=V.resolve(String(e||"")),n=[{scope:"global",base:_t()},{scope:"project",base:cn()}];for(let s of n){let r=V.relative(s.base,t);if(r&&r.indexOf("..")!==0&&!V.isAbsolute(r)&&r.indexOf(V.sep)<0)return{scope:s.scope,base:s.base,name:r}}return null}function ks(){let e=new Date,t=function(n){return(n<10?"0":"")+n};return String(e.getFullYear())+t(e.getMonth()+1)+t(e.getDate())+"-"+t(e.getHours())+t(e.getMinutes())+t(e.getSeconds())}function Et(e,t){B.mkdirSync(t,{recursive:!0});for(let n of B.readdirSync(e,{withFileTypes:!0})){if(n.name===".git"||n.isSymbolicLink())continue;let s=V.join(e,n.name),r=V.join(t,n.name);n.isDirectory()?Et(s,r):n.isFile()&&B.copyFileSync(s,r)}}function It(e){try{let t=JSON.parse(B.readFileSync(V.join(e,ln),"utf8"));if(t&&typeof t=="object"&&t.skills&&typeof t.skills=="object")return t}catch{}return{version:1,skills:{}}}function fn(e,t){B.mkdirSync(e,{recursive:!0}),B.writeFileSync(V.join(e,ln),JSON.stringify(t,null,2)+`
6
- `)}function js(){let e=[];for(let t of["global","project"]){let n=Ts(t),s=It(n),r;try{r=B.readdirSync(n,{withFileTypes:!0})}catch{continue}for(let i of r){if(!i.isDirectory()||i.name.startsWith("."))continue;let o=V.join(n,i.name),a=et.readSkillManifest(o);if(!a.ok)continue;let u=s.skills[i.name]||{};e.push({name:a.manifest.name,version:String(u.version||a.manifest.version||""),description:a.manifest.description,dir:o,scope:t,managed:!!s.skills[i.name],tag:String(u.tag||""),sourceSha256:String(u.sourceSha256||""),repo:String(u.repo||""),installedAt:String(u.installedAt||"")})}}return e}function Ms(e){let t=String(e||"").trim();if(!t)return null;let n=js();return n.find(function(s){return s.name===t&&s.scope==="project"})||n.find(function(s){return s.name===t})||null}function As(e,t,n){let s=V.resolve(e),r=tt(s);if(!r)throw new Error("\u62D2\u7EDD\u64CD\u4F5C\uFF1A\u4E0D\u5728\u6280\u80FD\u76EE\u5F55\u4E0B\u7684\u4E00\u7EA7\u5B50\u76EE\u5F55\uFF1A"+s);let i=kt();B.mkdirSync(i,{recursive:!0,mode:448});let o=r.name.replace(/[^a-z0-9._-]/gi,"_"),a=o+"-"+ks(),u=2;for(;B.existsSync(V.join(i,a))||B.existsSync(V.join(i,a+".json"));)a=o+"-"+ks()+"-"+u,u++;let l=V.join(i,a);try{B.renameSync(s,l)}catch(f){if(f&&f.code==="EXDEV")Et(s,l),B.rmSync(s,{recursive:!0,force:!0});else throw f}return B.writeFileSync(l+".json",JSON.stringify(Object.assign({name:r.name,from:s,scope:r.scope,at:new Date().toISOString(),why:t||""},n||{}),null,2)+`
7
- `),a}function wo(e,t){let n=t||{},s=V.resolve(String(e||"")),r;try{r=B.statSync(s)}catch{return{ok:!1,code:"missing",message:"\u76EE\u5F55\u4E0D\u5B58\u5728\uFF1A"+s}}if(!r.isDirectory())return{ok:!1,code:"not-dir",message:"\u4E0D\u662F\u76EE\u5F55\uFF1A"+s};let i=et.readSkillManifest(s);if(i.ok&&!/^[a-z0-9][a-z0-9-]{1,39}$/.test(i.manifest.name))return{ok:!1,code:"bad-name",message:"\u6280\u80FD\u540D\u4E0D\u80FD\u4F5C\u4E3A\u76EE\u5F55\u540D\uFF1A"+i.manifest.name};if(!i.ok)return{ok:!1,code:"bad-manifest",message:"\u4E0D\u662F\u5408\u6CD5\u7684\u6280\u80FD\u76EE\u5F55\uFF1A"+i.message};let o=i.manifest.name,a=n.target==="project"?"project":"global",u=Ts(a),l=V.join(u,o);if(V.resolve(s)===l)return{ok:!1,code:"same-dir",message:"\u6E90\u76EE\u5F55\u5C31\u662F\u6280\u80FD\u76EE\u5F55\u672C\u8EAB\uFF1A"+l};let f=!1;if(B.existsSync(l)){if(!n.replace)return{ok:!1,code:"exists",name:o,dir:l,message:"\u5DF2\u5B58\u5728\u540C\u540D\u6280\u80FD\uFF1A"+o};try{As(l,"replaced-by-install")}catch(p){return{ok:!1,code:"trash-failed",message:"\u65E7\u7248\u672C\u79FB\u8FDB\u56DE\u6536\u7AD9\u5931\u8D25\uFF1A"+p.message}}f=!0}try{Et(s,l)}catch(p){try{B.rmSync(l,{recursive:!0,force:!0})}catch{}return{ok:!1,code:"copy-failed",message:"\u590D\u5236\u5931\u8D25\uFF1A"+p.message}}let d=et.readSkillManifest(l);if(!d.ok){try{B.rmSync(l,{recursive:!0,force:!0})}catch{}return{ok:!1,code:"bad-copy",message:"\u590D\u5236\u540E\u7684\u76EE\u5F55\u4E0D\u5B8C\u6574\uFF1A"+d.message}}let h=It(u);return h.skills[o]={version:String(n.version||d.manifest.version||""),tag:String(n.tag||""),sourceSha256:String(n.sourceSha256||""),repo:String(n.repo||""),installedAt:new Date().toISOString()},fn(u,h),{ok:!0,name:o,dir:l,scope:a,replaced:f,version:h.skills[o].version}}function $o(e,t){let n=t||{},s=String(e||"").trim();if(!s)return{ok:!1,message:"\u7F3A\u5C11\u6280\u80FD\u540D"};let r=s.indexOf("/")>=0||s.indexOf("\\")>=0||/^[A-Za-z]:/.test(s),i="";if(r)i=V.resolve(s);else{let f=Ms(s);if(!f)return{ok:!1,message:"\u6CA1\u6709\u8FD9\u4E2A\u6280\u80FD\uFF1A"+s};i=f.dir}let o=tt(i);if(!o)return{ok:!1,message:"\u62D2\u7EDD\u64CD\u4F5C\uFF1A\u4E0D\u5728\u6280\u80FD\u76EE\u5F55\u4E0B\u7684\u4E00\u7EA7\u5B50\u76EE\u5F55\uFF1A"+i};let a="";try{a=As(i,n.why||"uninstall")}catch(f){return{ok:!1,message:"\u5378\u8F7D\u5931\u8D25\uFF1A"+f.message}}let u=o.base,l=It(u);return l.skills[o.name]&&(delete l.skills[o.name],fn(u,l)),{ok:!0,name:o.name,dir:i,trash:a}}function So(){let e=kt(),t;try{t=B.readdirSync(e,{withFileTypes:!0})}catch{return[]}let n=[];for(let s of t){if(!s.isDirectory()||s.name.startsWith("."))continue;let r=V.join(e,s.name),i={};try{i=JSON.parse(B.readFileSync(r+".json","utf8"))||{}}catch{i={}}let o=et.readSkillManifest(r);n.push({entry:s.name,name:o.ok?o.manifest.name:String(i.name||""),description:o.ok?o.manifest.description:"",dir:r,from:String(i.from||""),scope:String(i.scope||""),why:String(i.why||""),at:String(i.at||""),valid:o.ok,error:o.ok?"":o.message})}return n.sort(function(s,r){return s.at!==r.at?s.at<r.at?1:-1:s.entry<r.entry?1:s.entry>r.entry?-1:0}),n}function vo(e,t){let n=t||{},s=String(e||"").trim();if(!s||s.startsWith(".")||s.indexOf("/")>=0||s.indexOf("\\")>=0)return{ok:!1,message:"\u975E\u6CD5\u7684\u56DE\u6536\u7AD9\u6761\u76EE\uFF1A"+s};let r=V.join(kt(),s);if(!B.existsSync(r))return{ok:!1,message:"\u56DE\u6536\u7AD9\u91CC\u6CA1\u6709\u8FD9\u4E00\u6761\uFF1A"+s};let i={};try{i=JSON.parse(B.readFileSync(r+".json","utf8"))||{}}catch{i={}}let o=et.readSkillManifest(r),a=o.ok?o.manifest.name:String(i.name||"");if(!a)return{ok:!1,message:"\u56DE\u6536\u7AD9\u6761\u76EE\u91CC\u6CA1\u6709\u53EF\u7528\u7684 SKILL.md\uFF1A"+s};let u="",l=String(i.from||"");if(l){let d=V.resolve(l);B.existsSync(V.dirname(d))&&!B.existsSync(d)&&tt(d)&&(u=d)}if(u||(u=V.join(_t(),a)),B.existsSync(u))return{ok:!1,message:"\u76EE\u6807\u4F4D\u7F6E\u5DF2\u5B58\u5728\u540C\u540D\u6280\u80FD\uFF1A"+u};B.mkdirSync(V.dirname(u),{recursive:!0});try{B.renameSync(r,u)}catch(d){if(d&&d.code==="EXDEV")Et(r,u),B.rmSync(r,{recursive:!0,force:!0});else return{ok:!1,message:"\u8FD8\u539F\u5931\u8D25\uFF1A"+d.message}}try{B.rmSync(r+".json",{force:!0})}catch{}let f=tt(u);if(f){let d=It(f.base);d.skills[f.name]||(d.skills[f.name]={version:o.ok?o.manifest.version:"",tag:"",sourceSha256:"",repo:"",installedAt:new Date().toISOString()},fn(f.base,d))}return{ok:!0,name:a,dir:u,scope:f?f.scope:""}}Fs.exports={TRASH_DIRNAME:Is,LIST_FILENAME:ln,configure:yo,globalDir:_t,projectDir:cn,trashDir:kt,scopeOf:tt,installed:js,find:Ms,installFromDir:wo,uninstall:$o,trashList:So,restoreFromTrash:vo}});var ut=me((Bu,xn)=>{var _=require("fs"),_e=require("os"),x=require("path"),Rs=require("crypto"),qs=2e3,Ps=6e4,xo=18e4,Cs=8e3,dn=500,Tt=64,_o=30,Ns=65536,y={root:"",version:"0",rec:function(){},confirm:null,enabled:!1,maxTools:_o,timeoutMs:Ps,plugins:new Map,exposed:new Map,disabled:new Set,pending:[],trust:null,trustLoaded:!1,trustDirty:!1,dirs:[],errors:[],scannedAt:"",scannedMs:0};function Ae(e){let t=e||{};if(t.root&&String(t.root)!==y.root&&(y.scannedMs=0),t.root&&(y.root=String(t.root)),typeof t.rec=="function"&&(y.rec=t.rec),typeof t.confirm=="function"&&(y.confirm=t.confirm),t.enabled!==void 0){let r=t.enabled===!0;!r&&y.enabled&&(y.plugins=new Map,y.exposed.clear(),y.dirs=[],y.errors=[],y.scannedMs=0),y.enabled=r}let n=Number(t.maxTools);if(isFinite(n)&&n>0){let r=Math.min(Math.floor(n),200);r!==y.maxTools&&(y.maxTools=r,y.scannedMs=0)}let s=Number(t.timeoutMs);isFinite(s)&&s>=1&&(y.timeoutMs=Math.min(Math.floor(s),xo))}function ae(e,t){try{y.rec(e,t)}catch{}}function hn(e,t){let n=String(e??"");return n.length>t?n.slice(0,t)+"\u2026":n}function Fe(e){return String(e??"").replace(/[^A-Za-z0-9_-]+/g,"_").replace(/^_+|_+$/g,"")||"x"}function ko(e){return Rs.createHash("sha1").update(String(e)).digest("hex").slice(0,6)}function Bs(e,t){let n="pl__"+Fe(e)+"__"+Fe(t);if(n.length>Tt){let s="_"+ko(e+"/"+t);n=n.slice(0,Tt-s.length)+s}return n}function Vs(){return x.join(_e.homedir(),".luban","plugins-trust.json")}function bn(){if(y.trustLoaded)return;y.trustLoaded=!0,y.trust=new Map;let e;try{e=JSON.parse(_.readFileSync(Vs(),"utf8"))}catch{return}if(!(!e||typeof e!="object"||!e.trusted||typeof e.trusted!="object"))for(let t of Object.keys(e.trusted)){let n=e.trusted[t];typeof n=="string"&&n&&y.trust.set(t,n)}}function Us(){if(!y.trustDirty||!y.trust)return;let e={trusted:{}};for(let[t,n]of y.trust)e.trusted[t]=n;try{let t=Vs();_.mkdirSync(x.dirname(t),{recursive:!0}),_.writeFileSync(t,JSON.stringify(e,null,2)+`
8
- `),y.trustDirty=!1}catch(t){ae("plugin_trust_save_failed",{message:t.message})}}function st(e){let t=[];(function s(r){let i;try{i=_.readdirSync(r,{withFileTypes:!0})}catch{return}for(let o of i){if(o.name==="node_modules"||o.name===".git")continue;let a=x.join(r,o.name);o.isDirectory()?s(a):o.isFile()&&t.push(a)}})(e),t.sort();let n=Rs.createHash("sha1");for(let s of t){n.update(x.relative(e,s));try{n.update(_.readFileSync(s))}catch{}}return n.digest("hex")}function wn(e,t){return bn(),y.trust.get(e)===t}function Ws(e,t){bn(),y.trust.set(e,t),y.trustDirty=!0,Us()}function ke(e){let t=x.join(e,"plugin.json"),n;try{n=_.statSync(t)}catch{return{error:"\u7F3A\u5C11 plugin.json"}}if(!n.isFile())return{error:"plugin.json \u4E0D\u662F\u6587\u4EF6"};if(n.size>Ns)return{error:"plugin.json \u8D85\u8FC7 "+Ns+" \u5B57\u8282"};let s;try{s=JSON.parse(_.readFileSync(t,"utf8"))}catch(h){return{error:"plugin.json \u89E3\u6790\u5931\u8D25\uFF1A"+h.message}}if(!s||typeof s!="object")return{error:"plugin.json \u4E0D\u662F\u5BF9\u8C61"};let r=Fe(s.name||x.basename(e));if(!s.name||typeof s.name!="string")return{error:"\u7F3A\u5C11 name"};let i=typeof s.main=="string"&&s.main.trim()?s.main.trim():"index.js",o=x.resolve(e,i),a=x.relative(e,o);if(!a||a.startsWith("..")||x.isAbsolute(a))return{error:"main \u8D8A\u754C\uFF1A"+i};if(!/\.js$/i.test(o))return{error:"main \u5FC5\u987B\u662F .js \u6587\u4EF6\uFF1A"+i};let u=s.tools;if(!Array.isArray(u)||!u.length)return{error:"\u7F3A\u5C11 tools \u6570\u7EC4"};let l=s.readOnly===!0,f=[],d=Object.create(null);for(let h of u){if(!h||typeof h!="object")continue;let p=Fe(h.name);if(!h.name||typeof h.name!="string"||!p||d[p])continue;d[p]=!0;let m=h.parameters&&typeof h.parameters=="object"?h.parameters:{type:"object",properties:{}};f.push({name:p,description:hn(typeof h.description=="string"?h.description:"",dn),parameters:m,readOnly:h.readOnly===!0||h.readOnly!==!1&&l})}return f.length?{name:r,version:typeof s.version=="string"?s.version:"",description:hn(typeof s.description=="string"?s.description:"",dn),main:i,mainAbs:o,dir:e,tools:f,readOnly:l}:{error:"tools \u91CC\u6CA1\u6709\u5408\u6CD5\u5DE5\u5177"}}function Eo(e){let t=e||y.root||process.cwd(),n=_e.homedir();return[x.join(n,".luban","plugins"),x.join(t,".luban","plugins")]}function Gs(){y.exposed.clear();let e=[];for(let t of y.plugins.values())e.push(t.name);e.sort();for(let t of e){let n=y.plugins.get(t);for(let s of n.tools){if(y.exposed.size>=y.maxTools)return;let r=Bs(n.name,s.name);if(y.exposed.has(r)){let i=2;for(;y.exposed.has(r+"_"+i);)i++;let o="_"+i;r=r.length+o.length>Tt?r.slice(0,Tt-o.length)+o:r+o}y.exposed.set(r,{plugin:n.name,tool:s.name,def:s,readOnly:s.readOnly===!0})}}}function rt(){let e=Eo(y.root),t=[],n=new Map;for(let s of e){let r;try{r=_.readdirSync(s,{withFileTypes:!0})}catch{continue}for(let i of r){if(!i.isDirectory()||i.name.startsWith("."))continue;let o=x.join(s,i.name),a=ke(o);if(a.error){t.push(i.name+"\uFF1A"+a.error),ae("plugin_manifest_bad",{dir:o,message:a.error});continue}n.set(a.name,{manifest:a,source:s})}}return{dirs:e,errors:t,merged:n}}async function ge(e,t){let n=t||{};if(e&&(y.root=String(e)),!y.enabled)return y.plugins=new Map,y.exposed.clear(),y.dirs=[],y.errors=[],y.pending=[],y.scannedAt=new Date().toISOString(),y.scannedMs=Date.now(),[];let s=rt(),r=s.dirs;y.dirs=r;let i=s.errors,o=s.merged,a=new Map,u=[];for(let[l,f]of o){let d=f.manifest,h=st(d.dir);if(wn(d.dir,h)){a.set(l,d);continue}if(y.disabled.has(d.dir)||typeof y.confirm!="function"){u.push(d),typeof y.confirm!="function"&&(i.push(l+"\uFF1A\u672A\u4FE1\u4EFB\u4E14\u65E0\u786E\u8BA4\u901A\u9053\uFF0C\u5DF2\u8DF3\u8FC7"),ae("plugin_untrusted_skip",{plugin:l,dir:d.dir}));continue}let p=!1;try{p=await y.confirm({name:d.name,version:d.version,description:d.description,dir:d.dir,source:f.source,tools:d.tools.map(function(m){return m.name}),fingerprint:h})}catch{p=!1}p===!0?(Ws(d.dir,h),a.set(l,d),ae("plugin_trusted",{plugin:l,dir:d.dir})):(y.disabled.add(d.dir),u.push(d),ae("plugin_rejected",{plugin:l,dir:d.dir}))}return y.plugins=a,y.pending=u,Gs(),y.errors=i,y.scannedAt=new Date().toISOString(),y.scannedMs=Date.now(),n.quiet||ae("plugins_scanned",{count:y.plugins.size,tools:y.exposed.size,root:y.root,names:Array.from(y.plugins.keys()),errors:i}),Array.from(y.plugins.values())}function it(){if(!y.enabled||!y.root){y.exposed.size&&(y.plugins=new Map,y.exposed.clear());return}if(y.scannedMs&&Date.now()-y.scannedMs<qs)return;let e=y.exposed.size,t=rt().merged,n=new Map,s=[];for(let[r,i]of t){let o=i.manifest,a=st(o.dir);wn(o.dir,a)?n.set(r,o):s.push(o)}y.plugins=n,y.pending=s,Gs(),y.scannedMs=Date.now(),y.scannedAt=new Date().toISOString(),y.exposed.size!==e&&ae("plugins_changed",{count:y.plugins.size,tools:y.exposed.size})}function Io(e){let t=e||{};y.scannedMs=0,t.keepDisabled||(y.disabled=new Set);for(let n of y.plugins.values())try{delete require.cache[vn(n)]}catch{}return ge(y.root)}var Oo="plugins-trash";function ot(){return x.join(_e.homedir(),".luban","plugins")}function at(){return x.join(_e.homedir(),".luban",Oo)}function Ee(e){let t=x.resolve(String(e||"")),n=[{scope:"global",base:ot()},{scope:"project",base:x.join(x.resolve(y.root||process.cwd()),".luban","plugins")}];for(let s of n){let r=x.relative(s.base,t);if(r&&r.indexOf("..")!==0&&!x.isAbsolute(r)&&r.indexOf(x.sep)<0)return{scope:s.scope,base:s.base,name:r}}return null}function Ds(){let e=new Date,t=function(n){return(n<10?"0":"")+n};return String(e.getFullYear())+t(e.getMonth()+1)+t(e.getDate())+"-"+t(e.getHours())+t(e.getMinutes())+t(e.getSeconds())}function jt(e,t){_.mkdirSync(t,{recursive:!0});for(let n of _.readdirSync(e,{withFileTypes:!0})){if(n.name===".git"||n.isSymbolicLink())continue;let s=x.join(e,n.name),r=x.join(t,n.name);n.isDirectory()?jt(s,r):n.isFile()&&_.copyFileSync(s,r)}}function Hs(e){try{let t=JSON.parse(_.readFileSync(e+".json","utf8"));return t&&typeof t=="object"?t:{}}catch{return{}}}function To(e,t){try{_.writeFileSync(e+".json",JSON.stringify(t,null,2)+`
9
- `)}catch{}}function jo(e){bn(),y.trust.delete(x.resolve(e))&&(y.trustDirty=!0,Us())}function $n(e){let t=x.resolve(String(e||""));if(!Ee(t))throw new Error("\u62D2\u7EDD\u64CD\u4F5C\uFF1A\u4E0D\u5728\u63D2\u4EF6\u76EE\u5F55\u4E0B\u7684\u4E00\u7EA7\u5B50\u76EE\u5F55\uFF1A"+t);let n=ke(t);if(n.error)throw new Error("\u4E0D\u662F\u5408\u6CD5\u7684\u63D2\u4EF6\u76EE\u5F55\uFF1A"+n.error);return Ws(t,st(t)),y.disabled.delete(t),y.scannedMs=0,n}function Ks(e,t){let n=x.resolve(e),s=Ee(n);if(!s)throw new Error("\u62D2\u7EDD\u64CD\u4F5C\uFF1A\u4E0D\u5728\u63D2\u4EF6\u76EE\u5F55\u4E0B\u7684\u4E00\u7EA7\u5B50\u76EE\u5F55\uFF1A"+n);let r=at();_.mkdirSync(r,{recursive:!0,mode:448});let i=Fe(s.name),o=i+"-"+Ds(),a=2;for(;_.existsSync(x.join(r,o))||_.existsSync(x.join(r,o+".json"));)o=i+"-"+Ds()+"-"+a,a++;let u=x.join(r,o);try{_.renameSync(n,u)}catch(l){if(l&&l.code==="EXDEV")jt(n,u),_.rmSync(n,{recursive:!0,force:!0});else throw l}return To(u,{name:s.name,from:n,scope:s.scope,at:new Date().toISOString(),why:t||""}),jo(n),y.scannedMs=0,o}async function Ot(e,t){let n=t||{},s=x.resolve(String(e||"")),r;try{r=_.statSync(s)}catch{return{ok:!1,code:"missing",message:"\u76EE\u5F55\u4E0D\u5B58\u5728\uFF1A"+s}}if(!r.isDirectory())return{ok:!1,code:"not-dir",message:"\u4E0D\u662F\u76EE\u5F55\uFF1A"+s};let i=ke(s);if(i.error)return{ok:!1,code:"bad-manifest",message:"\u4E0D\u662F\u5408\u6CD5\u7684\u63D2\u4EF6\u76EE\u5F55\uFF1A"+i.error};let o=n.target==="project"?"project":"global",a=o==="project"?x.join(x.resolve(y.root||process.cwd()),".luban","plugins"):ot(),u=x.join(a,i.name);if(x.resolve(s)===u)return{ok:!1,code:"same-dir",message:"\u6E90\u76EE\u5F55\u5C31\u662F\u63D2\u4EF6\u76EE\u5F55\u672C\u8EAB\uFF1A"+u};let l=!1;if(_.existsSync(u)){if(!n.replace)return{ok:!1,code:"exists",name:i.name,dir:u,message:"\u5DF2\u5B58\u5728\u540C\u540D\u63D2\u4EF6\uFF1A"+i.name};Ks(u,"replaced-by-install"),l=!0}try{jt(s,u)}catch(d){try{_.rmSync(u,{recursive:!0,force:!0})}catch{}return{ok:!1,code:"copy-failed",message:"\u590D\u5236\u5931\u8D25\uFF1A"+d.message}}let f=ke(u);if(f.error){try{_.rmSync(u,{recursive:!0,force:!0})}catch{}return{ok:!1,code:"bad-copy",message:"\u590D\u5236\u540E\u7684\u76EE\u5F55\u4E0D\u5B8C\u6574\uFF1A"+f.error}}if(n.trust)try{$n(u)}catch(d){ae("plugin_trust_failed",{dir:u,message:d.message})}return y.scannedMs=0,await ge(y.root,{quiet:!0}),ae("plugin_installed",{name:f.name,dir:u,replaced:l,trust:!!n.trust}),{ok:!0,name:f.name,version:f.version,dir:u,scope:o,replaced:l,tools:f.tools.map(function(d){return d.name})}}async function pn(e,t){let n=String(e||"").trim();if(!n)return{ok:!1,message:"\u7F3A\u5C11\u63D2\u4EF6\u540D"};let s=n.indexOf("/")>=0||n.indexOf("\\")>=0||/^[A-Za-z]:/.test(n),r="";if(s)r=x.resolve(n);else{let l=rt().merged.get(n);if(!l)return{ok:!1,message:"\u6CA1\u6709\u8FD9\u4E2A\u63D2\u4EF6\uFF1A"+n};r=l.manifest.dir}let i=Ee(r);if(!i)return{ok:!1,message:"\u62D2\u7EDD\u64CD\u4F5C\uFF1A\u4E0D\u5728\u63D2\u4EF6\u76EE\u5F55\u4E0B\u7684\u4E00\u7EA7\u5B50\u76EE\u5F55\uFF1A"+r};let o=ke(r),a=o.error?i.name:o.name,u="";try{u=Ks(r,t&&t.why||"uninstall")}catch(l){return{ok:!1,message:"\u5378\u8F7D\u5931\u8D25\uFF1A"+l.message}}if(!o.error)try{delete require.cache[vn(o)]}catch{}return await ge(y.root,{quiet:!0}),ae("plugin_uninstalled",{name:a,dir:r,trash:u}),{ok:!0,name:a,dir:r,trash:u}}function mn(){let e=at(),t;try{t=_.readdirSync(e,{withFileTypes:!0})}catch{return[]}let n=[];for(let s of t){if(!s.isDirectory()||s.name.startsWith("."))continue;let r=x.join(e,s.name),i=Hs(r),o=ke(r),a=s.name.lastIndexOf("-");n.push({entry:s.name,name:o.error?String(i.name||(a>0?s.name.slice(0,a):s.name)):o.name,version:o.error?"":o.version,description:o.error?"":o.description,dir:r,from:String(i.from||""),scope:String(i.scope||""),why:String(i.why||""),at:String(i.at||""),valid:!o.error,error:o.error||""})}return n.sort(function(s,r){return s.at!==r.at?s.at<r.at?1:-1:s.entry<r.entry?1:s.entry>r.entry?-1:0}),n}async function gn(e,t){let n=t||{},s=String(e||"").trim();if(!s||s.startsWith(".")||s.indexOf("/")>=0||s.indexOf("\\")>=0)return{ok:!1,message:"\u975E\u6CD5\u7684\u56DE\u6536\u7AD9\u6761\u76EE\uFF1A"+s};let r=x.join(at(),s);if(!_.existsSync(r))return{ok:!1,message:"\u56DE\u6536\u7AD9\u91CC\u6CA1\u6709\u8FD9\u4E00\u6761\uFF1A"+s};let i=Hs(r),o=ke(r),a=o.error?String(i.name||s):o.name,u="",l=String(i.from||"");if(l){let f=x.resolve(l),d=x.dirname(f);_.existsSync(d)&&!_.existsSync(f)&&Ee(f)&&(u=f)}if(u||(u=x.join(ot(),Fe(a))),_.existsSync(u))return{ok:!1,message:"\u76EE\u6807\u4F4D\u7F6E\u5DF2\u5B58\u5728\u540C\u540D\u63D2\u4EF6\uFF1A"+u};_.mkdirSync(x.dirname(u),{recursive:!0});try{_.renameSync(r,u)}catch(f){if(f&&f.code==="EXDEV")jt(r,u),_.rmSync(r,{recursive:!0,force:!0});else return{ok:!1,message:"\u8FD8\u539F\u5931\u8D25\uFF1A"+f.message}}try{_.unlinkSync(r+".json")}catch{}if(n.trust!==!1)try{$n(u)}catch(f){ae("plugin_restore_trust_failed",{dir:u,message:f.message})}return await ge(y.root,{quiet:!0}),ae("plugin_restored",{name:a,dir:u,from:s}),{ok:!0,name:a,dir:u}}function He(e){return it(),y.exposed.has(String(e))}function Sn(e){return it(),y.exposed.get(String(e))||null}function Js(e){let t=Sn(e);return t?t.readOnly===!0:!1}function Ke(e){it();let t=!!(e&&e.planOnly),n=[];for(let s of y.exposed){let r=s[0],i=s[1];if(t&&i.readOnly!==!0)continue;let o=i.def||{},a=o.description||"\u63D2\u4EF6\u5DE5\u5177 "+i.plugin+"/"+i.tool;if(n.push({type:"function",function:{name:r,description:hn(a,dn)+"\uFF08\u6765\u81EA\u672C\u5730\u63D2\u4EF6\u300C"+i.plugin+"\u300D\uFF09",parameters:o.parameters||{type:"object",properties:{}}}}),n.length>=y.maxTools)break}return n.sort(function(s,r){return s.function.name<r.function.name?-1:s.function.name>r.function.name?1:0}),n}function vn(e){let t=x.resolve(e.mainAbs);try{return _.realpathSync(t)}catch{return t}}function Mo(e){let t=y.plugins.get(e.plugin);if(!t)throw new Error("\u63D2\u4EF6\u5DF2\u5378\u8F7D: "+e.plugin);let n=vn(t),s;try{require.cache[n]&&delete require.cache[n],s=require(n)}catch(o){throw new Error("\u63D2\u4EF6\u300C"+e.plugin+"\u300D\u52A0\u8F7D\u5931\u8D25\uFF1A"+o.message)}if(!s||typeof s!="object")throw new Error("\u63D2\u4EF6\u300C"+e.plugin+"\u300D\u7684 main \u6CA1\u6709\u5BFC\u51FA\u5BF9\u8C61");let r=s.tools&&typeof s.tools=="object"?s.tools:null,i=r?r[e.tool]:null;if(i&&typeof i.handler=="function")return i.handler;if(i&&typeof i=="function")return i;if(typeof s.call=="function")return function(o,a){return s.call(e.tool,o,a)};throw new Error("\u63D2\u4EF6\u300C"+e.plugin+"\u300D\u6CA1\u6709\u5DE5\u5177 "+e.tool+" \u7684 handler\uFF08\u8981 exports.tools."+e.tool+".handler \u6216 exports.call\uFF09")}function Ao(e,t,n){let s,r=new Promise(function(i,o){s=setTimeout(function(){o(new Error(n+" \u8D85\u65F6\uFF08"+t+"ms\uFF09"))},t)});return Promise.race([e,r]).finally(function(){clearTimeout(s)})}async function nt(e,t,n){let s=Sn(e);if(!s)throw new Error("\u672A\u77E5\u63D2\u4EF6\u5DE5\u5177: "+e);let r=n||{},i=Date.now(),o=!1;try{let a=Mo(s),u={root:r.root||y.root,sessionId:r.sessionId||"",mode:r.mode||"",signal:r.signal||null,log:typeof r.log=="function"?r.log:function(){}},l=await Ao(Promise.resolve().then(function(){return a(t||{},u)}),y.timeoutMs,"\u63D2\u4EF6\u5DE5\u5177 "+e);o=!0;let f;return l==null?f="(\u65E0\u8F93\u51FA)":typeof l=="string"?f=l:f=JSON.stringify(l),f=f.trim()||"(\u65E0\u8F93\u51FA)",f.length>Cs&&(f=f.slice(0,Cs)+`
10
- \u2026[\u8F93\u51FA\u5DF2\u622A\u65AD]`),f}catch(a){let u=String(a&&a.message||a);throw ae("plugin_call_failed",{plugin:s.plugin,tool:s.tool,message:u}),new Error("\u63D2\u4EF6\u5DE5\u5177 "+e+" \u5931\u8D25\uFF1A"+u)}finally{ae("plugin_call",{plugin:s.plugin,tool:s.tool,ok:o,ms:Date.now()-i})}}function Xs(){it();let e=[];for(let t of y.plugins.values()){let n=Ee(t.dir);e.push({name:t.name,version:t.version,description:t.description,dir:t.dir,scope:n?n.scope:"",trusted:!0,readOnly:t.readOnly===!0,tools:t.tools.map(function(s){return{name:s.name,readOnly:s.readOnly===!0}})})}return e}function Fo(){return it(),y.pending.map(function(e){let t=Ee(e.dir);return{name:e.name,version:e.version,description:e.description,dir:e.dir,scope:t?t.scope:"",trusted:!1,readOnly:e.readOnly===!0,tools:e.tools.map(function(n){return{name:n.name,readOnly:n.readOnly===!0}})}})}function Ys(){let e=rt(),t=[],n=[];for(let s of e.merged.values()){let r=s.manifest,i=Ee(r.dir),o={name:r.name,version:r.version,description:r.description,dir:r.dir,scope:i?i.scope:"",readOnly:r.readOnly===!0,trusted:wn(r.dir,st(r.dir)),tools:r.tools.map(function(a){return{name:a.name,readOnly:a.readOnly===!0}})};(o.trusted?t:n).push(o)}return t.sort(function(s,r){return s.name<r.name?-1:s.name>r.name?1:0}),n.sort(function(s,r){return s.name<r.name?-1:s.name>r.name?1:0}),{dirs:e.dirs,errors:e.errors,plugins:t,pending:n}}function yn(){return{root:y.root,enabled:y.enabled,dirs:y.dirs.slice(),globalDir:ot(),trashDir:at(),errors:y.errors.slice(),scannedAt:y.scannedAt,plugins:Xs(),pending:Fo(),tools:Array.from(y.exposed.entries()).map(function(e){return{name:e[0],plugin:e[1].plugin,tool:e[1].tool,readOnly:e[1].readOnly===!0}})}}if(require.main===xn){let e=require("assert"),t=_.promises;(async function(){let n=_.mkdtempSync(x.join(_e.tmpdir(),"luban-plugin-test-")),s=x.join(n,"proj"),r=x.join(n,"home",".luban","plugins"),i=x.join(s,".luban","plugins");_.mkdirSync(r,{recursive:!0}),_.mkdirSync(i,{recursive:!0});let o=_e.homedir;_e.homedir=function(){return x.join(n,"home")};let a=x.join(r,"demo");_.mkdirSync(a,{recursive:!0}),_.writeFileSync(x.join(a,"plugin.json"),JSON.stringify({name:"demo",version:"1.0.0",description:"\u6D4B\u8BD5\u63D2\u4EF6",readOnly:!0,tools:[{name:"echo",description:"\u56DE\u663E",parameters:{type:"object",properties:{text:{type:"string"}}}}]})),_.writeFileSync(x.join(a,"index.js"),'module.exports={tools:{echo:{handler:async(a)=>"echo:"+(a&&a.text||"")}}};');let u=x.join(i,"demo");_.mkdirSync(u,{recursive:!0}),_.writeFileSync(x.join(u,"plugin.json"),JSON.stringify({name:"demo",version:"2.0.0",readOnly:!1,tools:[{name:"boom",description:"\u629B\u9519",parameters:{type:"object",properties:{}}}]})),_.writeFileSync(x.join(u,"index.js"),'module.exports={tools:{boom:{handler:async()=>{throw new Error("\u70B8\u4E86")}}}};');let l=x.join(r,"bad");_.mkdirSync(l,{recursive:!0}),_.writeFileSync(x.join(l,"plugin.json"),"{ not json");let f=[],d=[];Ae({root:s,enabled:!0,rec:function(te,ce){f.push([te,ce])},confirm:async function(te){return d.push(te.name),!0}}),await ge(s);let h=yn();e.strictEqual(h.plugins.length,1,"\u5E94\u6709 1 \u4E2A\u63D2\u4EF6\uFF08demo \u9879\u76EE\u7248\u8986\u76D6\u5BB6\u76EE\u5F55\u7248\uFF0Cbad \u6E05\u5355\u574F\u88AB\u8DF3\u8FC7\uFF09");let p=h.plugins.find(function(te){return te.name==="demo"});e.strictEqual(p.version,"2.0.0","\u9879\u76EE\u63D2\u4EF6\u8986\u76D6\u5BB6\u76EE\u5F55"),e.strictEqual(p.tools.length,1),e.strictEqual(p.tools[0].name,"boom"),e.strictEqual(h.errors.some(function(te){return te.indexOf("bad")===0}),!0,"\u574F\u6E05\u5355\u8981\u8BB0 error"),e.strictEqual(He("pl__demo__boom"),!0),e.strictEqual(He("pl__demo__echo"),!1,"\u88AB\u9879\u76EE\u8986\u76D6\u7684 echo \u4E0D\u8BE5\u51FA\u73B0"),e.strictEqual(Js("pl__demo__boom"),!1);let m=JSON.stringify(Ke({})),w=JSON.stringify(Ke({}));e.strictEqual(m,w,"\u4E24\u6B21 toolDefs \u9010\u5B57\u8282\u76F8\u540C"),e.strictEqual(Ke({planOnly:!0}).length,0,"\u975E\u53EA\u8BFB\u5DE5\u5177\u4E0D\u8FDB Plan");let b="";try{await nt("pl__demo__boom",{},{root:s})}catch(te){b=te.message}e.ok(b.indexOf("\u70B8\u4E86")>=0,"\u629B\u9519\u8981\u5E26\u4E0A\u539F\u56E0\uFF0C\u5B9E\u9645: "+b);let $=x.join(r,"echo");_.mkdirSync($,{recursive:!0}),_.writeFileSync(x.join($,"plugin.json"),JSON.stringify({name:"echo",readOnly:!0,tools:[{name:"say",description:"\u56DE\u663E",parameters:{type:"object",properties:{text:{type:"string"}}}}]})),_.writeFileSync(x.join($,"index.js"),'module.exports={tools:{say:{handler:async(a)=>"say:"+(a&&a.text||"")}}}'),y.scannedMs=0,await ge(s,{quiet:!0});let k=await nt("pl__echo__say",{text:"hi"},{root:s});e.strictEqual(k,"say:hi","echo \u6B63\u5E38\u8FD4\u56DE\uFF0C\u5B9E\u9645: "+k);let T=x.join(r,"slow");_.mkdirSync(T,{recursive:!0}),_.writeFileSync(x.join(T,"plugin.json"),JSON.stringify({name:"slow",readOnly:!0,tools:[{name:"hang",description:"\u6302\u4F4F",parameters:{type:"object",properties:{}}}]})),_.writeFileSync(x.join(T,"index.js"),"module.exports={tools:{hang:{handler:()=>new Promise(()=>{})}}}"),Ae({timeoutMs:300}),y.scannedMs=0,await ge(s,{quiet:!0});let F="";try{await nt("pl__slow__hang",{},{root:s})}catch(te){F=te.message}e.ok(F.indexOf("\u8D85\u65F6")>=0,"\u8981\u8D85\u65F6\uFF0C\u5B9E\u9645: "+F),Ae({timeoutMs:Ps}),e.strictEqual(d.indexOf("demo")>=0,!0,"\u9996\u6B21\u8981\u786E\u8BA4 demo");let j=x.join(n,"home",".luban","plugins-trust.json");e.ok(_.existsSync(j),"\u4FE1\u4EFB\u8868\u8981\u843D\u76D8");let L=d.length;_.writeFileSync(x.join($,"index.js"),'module.exports={tools:{say:{handler:async()=>"changed"}}}'),y.scannedMs=0,await ge(s,{quiet:!0}),e.ok(d.length>L,"\u5185\u5BB9\u53D8\u4E86\u8981\u91CD\u65B0\u786E\u8BA4"),Ae({confirm:async function(){return!1}}),y.trust=new Map,y.trustDirty=!0,y.disabled=new Set,y.scannedMs=0,await ge(s,{quiet:!0}),e.strictEqual(Ke({}).length,0,"\u5168\u62D2\u7EDD\u540E\u6E05\u5355\u4E3A\u7A7A"),e.ok(yn().pending.length>0,"\u88AB\u62D2\u7684\u63D2\u4EF6\u8981\u8FDB pending"),Ae({enabled:!0,confirm:async function(){return!0}}),y.trust=new Map,y.disabled=new Set,y.scannedMs=0,await ge(s,{quiet:!0});let M=x.join(n,"downloads","pkgs","fresh");_.mkdirSync(M,{recursive:!0}),_.writeFileSync(x.join(M,"plugin.json"),JSON.stringify({name:"fresh",version:"3.1.0",readOnly:!0,tools:[{name:"ping",description:"ping",parameters:{type:"object",properties:{}}}]})),_.writeFileSync(x.join(M,"index.js"),'module.exports={tools:{ping:{handler:async()=>"pong"}}}'),_.mkdirSync(x.join(M,".git"),{recursive:!0}),_.writeFileSync(x.join(M,".git","HEAD"),"ref: refs/heads/main");let C=await Ot(M,{trust:!0});e.strictEqual(C.ok,!0,"\u5B89\u88C5\u5E94\u6210\u529F\uFF1A"+JSON.stringify(C)),e.strictEqual(C.name,"fresh"),e.strictEqual(C.replaced,!1);let N=x.join(r,"fresh");e.strictEqual(_.existsSync(x.join(N,"plugin.json")),!0,"\u6587\u4EF6\u8981\u843D\u8FDB\u5168\u5C40\u63D2\u4EF6\u6839"),e.strictEqual(_.existsSync(x.join(N,".git")),!1,".git \u4E0D\u8BE5\u88AB\u590D\u5236"),e.strictEqual(He("pl__fresh__ping"),!0,"\u88C5\u5B8C\u7ACB\u5373\u53EF\u7528\uFF08\u4FE1\u4EFB + \u91CD\u626B\uFF09"),e.strictEqual(await nt("pl__fresh__ping",{},{root:s}),"pong");let U=await Ot(M,{trust:!0});e.strictEqual(U.ok,!1,"\u540C\u540D\u4E0D\u5E26 replace \u5E94\u62D2\u7EDD"),e.strictEqual(U.code,"exists");let R=await Ot(M,{trust:!0,replace:!0});e.strictEqual(R.ok,!0,"replace \u5E94\u6210\u529F"),e.strictEqual(R.replaced,!0);let Z=mn();e.ok(Z.some(function(te){return te.why==="replaced-by-install"}),"\u65E7\u7248\u8981\u8FDB\u56DE\u6536\u7AD9");let ee=await pn("fresh");e.strictEqual(ee.ok,!0,"\u5378\u8F7D\u5E94\u6210\u529F\uFF1A"+JSON.stringify(ee)),e.strictEqual(_.existsSync(N),!1,"\u63D2\u4EF6\u76EE\u5F55\u8981\u79FB\u8D70"),e.strictEqual(He("pl__fresh__ping"),!1,"\u5378\u8F7D\u540E\u5DE5\u5177\u6D88\u5931");let P=mn().find(function(te){return te.name==="fresh"});e.ok(P,"\u56DE\u6536\u7AD9\u91CC\u5E94\u6709 fresh"),e.strictEqual(P.valid,!0,"\u56DE\u6536\u7AD9\u6761\u76EE\u5E94\u80FD\u89E3\u6790\u6E05\u5355"),e.strictEqual(P.version,"3.1.0"),e.strictEqual(P.from,N,"\u5143\u6570\u636E\u8981\u8BB0\u4F4F\u539F\u4F4D\u7F6E");let J=await gn(P.entry);e.strictEqual(J.ok,!0,"\u8FD8\u539F\u5E94\u6210\u529F\uFF1A"+JSON.stringify(J)),e.strictEqual(J.dir,N,"\u8981\u8FD8\u539F\u56DE\u539F\u4F4D\u7F6E"),e.strictEqual(He("pl__fresh__ping"),!0,"\u8FD8\u539F\u540E\u7ACB\u5373\u53EF\u7528");let G=x.join(n,"outside");_.mkdirSync(G,{recursive:!0}),_.writeFileSync(x.join(G,"plugin.json"),JSON.stringify({name:"evil",tools:[{name:"x",description:"x"}]}));let pe=await pn(G);e.strictEqual(pe.ok,!1,"\u63D2\u4EF6\u6839\u4E4B\u5916\u7684\u76EE\u5F55\u5FC5\u987B\u62D2\u7EDD\u5378\u8F7D"),e.strictEqual(_.existsSync(G),!0,"\u62D2\u7EDD\u540E\u76EE\u5F55\u8FD8\u5728");let Se=await gn("../outside");e.strictEqual(Se.ok,!1,"\u5E26 / \u7684\u56DE\u6536\u7AD9\u6761\u76EE\u8981\u62D2\u7EDD"),_.writeFileSync(x.join($,"index.js"),'module.exports={tools:{say:{handler:async()=>"dirty"}}}'),Ae({enabled:!1}),await ge(s,{quiet:!0}),e.strictEqual(Ke({}).length,0,"\u5173\u95ED\u540E\u6E05\u5355\u4E3A\u7A7A");let $e=Ys();e.ok($e.plugins.length>0,"\u5173\u95ED\u5F00\u5173\u540E inventory \u4ECD\u5217\u51FA\u5DF2\u4FE1\u4EFB\u63D2\u4EF6\uFF0C\u5B9E\u9645 "+$e.plugins.length),e.ok($e.pending.length>0,"\u5173\u95ED\u5F00\u5173\u540E inventory \u4ECD\u5217\u51FA\u672A\u4FE1\u4EFB\u63D2\u4EF6\uFF0C\u5B9E\u9645 "+$e.pending.length),_e.homedir=o,_.rmSync(n,{recursive:!0,force:!0}),console.log("plugin.js \u81EA\u6D4B\u901A\u8FC7"),process.exit(0)})().catch(function(n){console.error("plugin.js \u81EA\u6D4B\u5931\u8D25\uFF1A",n),process.exit(1)})}xn.exports={configure:Ae,refresh:ge,reload:Io,list:Xs,status:yn,toolDefs:Ke,hasTool:He,findTool:Sn,readOnlyOf:Js,callTool:nt,installFromDir:Ot,uninstall:pn,trashList:mn,restoreFromTrash:gn,trustDir:$n,inventory:Ys,scopeOf:Ee,globalDir:ot,trashDir:at,_cleanName:Fe,_exposedBase:Bs,_parseManifest:ke,_dirFingerprint:st,_scanRaw:rt,_state:y,_ttl:qs}});var Zs=me((Vu,En)=>{function Le(e,t){let n=String(e??"").replace(/\s+/g," ").trim();return n?n.length>t?n.slice(0,t):n:""}function Lo(e,t){if(!e||typeof e!="object")return null;let n=Le(e.id,64),s=Le(e.label!=null?e.label:e.text,120);if(!s)return null;n||(n="o"+(t+1));let r={id:n,label:s};return(e.recommended===!0||e.recommended==="true")&&(r.recommended=!0),r}function Co(e,t){if(!e||typeof e!="object")return null;let n=Le(e.id,64),s=Le(e.prompt!=null?e.prompt:e.question,240);if(!s)return null;n||(n="q"+(t+1));let r=Array.isArray(e.options)?e.options:[],i=[],o=Object.create(null);for(let a=0;a<r.length&&i.length<6;a++){let u=Lo(r[a],a);u&&(o[u.id]||(o[u.id]=1,i.push(u)))}return i.length<2?null:{id:n,prompt:s,allow_multiple:!!(e.allow_multiple||e.allowMultiple),options:i}}function Ie(e){let t=e&&typeof e=="object"?e:{},n=Le(t.title,80),s=Array.isArray(t.questions)?t.questions:[];if(!s.length)throw new Error("ask_question \u9700\u8981\u975E\u7A7A questions \u6570\u7EC4");let r=[],i=Object.create(null);for(let o=0;o<s.length&&r.length<4;o++){let a=Co(s[o],o);a&&(i[a.id]||(i[a.id]=1,r.push(a)))}if(!r.length)throw new Error("ask_question \u6CA1\u6709\u6709\u6548\u9898\u76EE\uFF08\u6BCF\u9898\u9700 prompt\uFF0C\u4E14 options 2~6 \u9879\uFF09");return{title:n,questions:r}}function _n(e,t){let n=e&&e.questions||[],s=t&&typeof t=="object"?t:{},r={};for(let i=0;i<n.length;i++){let o=n[i],a=Object.create(null);for(let l=0;l<o.options.length;l++)a[o.options[l].id]=o.options[l];let u=s[o.id];if(o.allow_multiple){let l=Array.isArray(u)?u:u==null||u===""?[]:[u],f=[],d=Object.create(null);for(let h=0;h<l.length;h++){let p=Le(l[h],64);!p||!a[p]||d[p]||(d[p]=1,f.push(p))}if(!f.length)throw new Error("\u9898\u76EE\u300C"+o.id+"\u300D\u9700\u8981\u81F3\u5C11\u9009\u4E00\u9879");r[o.id]=f}else{let l=Le(Array.isArray(u)?u[0]:u,64);if(!l||!a[l])throw new Error("\u9898\u76EE\u300C"+o.id+"\u300D\u9700\u8981\u9009\u62E9\u4E00\u4E2A\u6709\u6548\u9009\u9879");r[o.id]=l}}return r}function zs(e,t){for(let n=0;n<e.options.length;n++)if(e.options[n].id===t)return e.options[n].label;return t}function Qs(e,t){let n=e&&e.questions||[],s=["\u7528\u6237\u56DE\u7B54\uFF1A"];e&&e.title&&s.unshift("\u63D0\u95EE\uFF1A"+e.title);for(let r=0;r<n.length;r++){let i=n[r],o=t[i.id],a;Array.isArray(o)?a=o.map(function(u){return u+"\uFF08"+zs(i,u)+"\uFF09"}).join("\u3001"):a=o+"\uFF08"+zs(i,o)+"\uFF09",s.push("- "+i.id+"\uFF08"+i.prompt+"\uFF09: "+a)}return s.join(`
11
- `)}function kn(e){let t=e&&e.questions||[];return t.length!==1?!0:!!t[0].allow_multiple}En.exports={MAX_QUESTIONS:4,MIN_OPTIONS:2,MAX_OPTIONS:6,normalize:Ie,normalizeAnswers:_n,formatAnswers:Qs,needsConfirm:kn};if(require.main===En){let e=function(s,r){if(!s)throw new Error(r||"assert failed")},t=0,n=function(s,r){try{r(),t++,console.log("ok "+s)}catch(i){console.error("FAIL "+s+": "+i.message),process.exitCode=1}};n("normalize basic",function(){let s=Ie({title:"\u65B9\u5411",questions:[{id:"q1",prompt:"\u8981\u4E0D\u8981\u8D85\u51FA\u5C04\u7A0B\u53D8\u6A59\uFF1F",options:[{id:"yes",label:"\u8981\u505A"},{id:"no",label:"\u4E0D\u505A"}]}]});e(s.title==="\u65B9\u5411","title"),e(s.questions.length===1&&s.questions[0].options.length===2,"q"),e(!kn(s),"single select no confirm")}),n("normalize rejects empty / short options",function(){let s=!1;try{Ie({questions:[]})}catch{s=!0}e(s,"empty"),s=!1;try{Ie({questions:[{prompt:"x",options:[{id:"a",label:"A"}]}]})}catch{s=!0}e(s,"one option")}),n("normalize fills missing ids + caps",function(){let s=[];for(let i=0;i<8;i++)s.push({label:"L"+i});let r=Ie({questions:[{prompt:"P1",options:s},{prompt:"P2",options:[{label:"A"},{label:"B"}]},{prompt:"P3",options:[{label:"A"},{label:"B"}]},{prompt:"P4",options:[{label:"A"},{label:"B"}]},{prompt:"P5",options:[{label:"A"},{label:"B"}]}]});e(r.questions.length===4,"max q"),e(r.questions[0].options.length===6,"max opt"),e(r.questions[0].id==="q1","auto id")}),n("normalizeAnswers single + multi",function(){let s=Ie({questions:[{id:"a",prompt:"\u5355\u9009",options:[{id:"x",label:"X"},{id:"y",label:"Y"}]},{id:"b",prompt:"\u591A\u9009",allow_multiple:!0,options:[{id:"p",label:"P"},{id:"q",label:"Q"}]}]});e(kn(s),"confirm");let r=_n(s,{a:"x",b:["p","q"]});e(r.a==="x"&&r.b.length===2,JSON.stringify(r));let i=Qs(s,r);e(i.indexOf("\u7528\u6237\u56DE\u7B54")>=0&&i.indexOf("x\uFF08X\uFF09")>=0,i)}),n("normalizeAnswers rejects bad",function(){let s=Ie({questions:[{id:"a",prompt:"\u5355\u9009",options:[{id:"x",label:"X"},{id:"y",label:"Y"}]}]}),r=!1;try{_n(s,{a:"z"})}catch{r=!0}e(r,"bad id")}),n("normalize recommended flag",function(){let s=Ie({questions:[{id:"q1",prompt:"\u65B9\u5411",options:[{id:"yes",label:"\u8981\u505A",recommended:!0},{id:"no",label:"\u4E0D\u505A"}]}]});e(s.questions[0].options[0].recommended===!0,"rec"),e(!s.questions[0].options[1].recommended,"no rec")}),process.exitCode||console.log("ALL PASS pass="+t)}});var ar=me((Uu,or)=>{"use strict";var On="\u73ED\u73ED",Tn="Banban",jn="\u5C0F\u6728\u5320",Mn="\u5148\u91CF\u4E09\u904D\uFF0C\u518D\u4E0B\u4E00\u51FF",No=[" _____"," / \\"," /_______\\"],Do=" \\_______/",Ro=[" | |"," /| |\\"," \\|_____|/"," |_| |_|"],An={idle:[" | o o |"," | . |"," | \\___/ |"],think:[" | o o |"," | . |"," | ___ |"],plan:[" | o o |"," | . |"," | --- |"],explore:[" | O o |"," | . |"," | \\_/ |"],work:[" | > < |"," | . |"," | ___ |"],done:[" | ^ ^ |"," | . |"," | \\___/ |"],tired:[" | - - |"," | . |"," | --- |"],error:[" | x x |"," | . |"," | ~~~ |"]},er={idle:"(o o)",think:"(o.o)",plan:"[o o]",explore:"(o o)?",work:"(>_<)",done:"(^ ^)",tired:"(-_-)",error:"(x_x)"},In=[{mood:"idle",when:"\u7A7A\u95F2",say:"\u7B49\u4F60\u6D3E\u6D3B\uFF1B\u53EA\u8BFB\uFF0C\u5148\u91CF\u5C3A\u5BF8"},{mood:"plan",when:"plan",say:"\u53EA\u753B\u7EBF\u4E0D\u52A8\u624B\uFF1A\u5199\u5DE5\u5177\u4F1A\u88AB\u53EA\u8BFB\u95F8\u95E8\u62E6\u4E0B"},{mood:"explore",when:"explore",say:"\u53EA\u8BFB\u8C03\u7814\uFF0C\u770B\u89C1\u4EC0\u4E48\u5148\u8BB0\u4E0B\u6765"},{mood:"work",when:"agent",say:"--apply \u5F00\u4E86\u5199\u6743\u9650\uFF0C\u4E0A\u51FF\u5B50"},{mood:"think",when:"\u601D\u8003\u4E2D",say:"\u6A21\u578B\u81EA\u5DF1\u5728\u60F3\uFF08\u53EA\u663E\u793A\u7D2F\u8BA1\u5B57\u6570\uFF09"},{mood:"done",when:"final",say:"\u5E72\u5B8C\u4E86\uFF0C\u62A5\u4E00\u53E5\u8F6E\u6570 / \u5DE5\u5177\u6570 / \u8017\u65F6"},{mood:"tired",when:"maxRounds / timeout",say:"\u6536\u5DE5\uFF1A\u8F6E\u6570\u6216\u5899\u949F\u5230\u9876\uFF0C\u6216\u7528\u6237\u53D6\u6D88"},{mood:"error",when:"\u62A5\u9519",say:"\u5DE5\u5177\u8FDE\u7EED\u5931\u8D25\uFF0C\u6216\u8FD9\u4E00\u8F6E\u76F4\u63A5\u70B8\u4E86"}];function Mt(e,t){let n=String(e??"");return n.length>=t?n:n+" ".repeat(t-n.length)}function qo(e){return e<4352?1:e<=4447||e>=11904&&e<=42191||e>=44032&&e<=55203||e>=63744&&e<=64255||e>=65072&&e<=65135||e>=65280&&e<=65376||e>=65504&&e<=65510?2:1}function tr(e){let t=String(e??""),n=0;for(let s=0;s<t.length;s++)n+=qo(t.charCodeAt(s));return n}function nr(e,t){let n=String(e??""),s=t-tr(n);return s>0?n+" ".repeat(s):n}function sr(e){return Object.prototype.hasOwnProperty.call(An,e)?e:"idle"}function Po(e){let t=String(e||"");return t==="plan"?"plan":t==="explore"?"explore":"idle"}function Bo(e){let t=String(e||"");return t==="final"?"done":"tired"}function Fn(e){return No.concat(An[sr(e)],[Do])}function rr(e){return Fn(e).concat(Ro)}function ir(e){return er[sr(e)]}function Vo(e,t){let n=t||{},s=typeof e=="function"?e:function(a,u){return String(u)},r=Fn(n.mood||"plan"),i={};i[2]=" "+s("bold",On)+s("gray"," \xB7 "+jn+"\uFF08"+Tn+"\uFF09"),i[3]=" "+s("gray",Mn),i[5]=" "+s("dim",String(n.tip||""));let o=[];for(let a=0;a<r.length;a++){let u=i[a];if(!u){o.push(s("cyan",r[a]));continue}o.push(s("cyan",Mt(r[a],12))+u)}return o}function Uo(e){let t=typeof e=="function"?e:function(o,a){return String(a)},n=rr("idle"),s=[t("bold",On+"\uFF08"+Tn+"\uFF09")+t("gray"," \xB7 "+jn),t("gray",Mn),t("dim","Luban CLI \u7684\u642D\u6863\uFF1A\u53EA\u8BFB\u7684\u65F6\u5019\u753B\u7EBF\uFF0C--apply \u4E4B\u540E\u624D\u52A8\u51FF\u5B50\u3002")],r=[],i=Math.max(n.length,s.length);for(let o=0;o<i;o++){let a=n[o]||"",u=s[o]||"";if(!u){r.push(a?t("cyan",a):"");continue}r.push(t("cyan",Mt(a,14))+u)}r.push(""),r.push(t("bold"," \u8868\u60C5\uFF08\u6309 CLI \u72B6\u6001\u81EA\u52A8\u5207\u6362\uFF09"));for(let o=0;o<In.length;o++){let a=In[o];r.push(" "+t("cyan",Mt(ir(a.mood),9))+t("gray",nr(a.when,22))+a.say)}return r}or.exports={NAME:On,NAME_EN:Tn,KIND:jn,TAGLINE:Mn,MOODS:An,FACES:er,NOTES:In,padRight:Mt,padDisplay:nr,displayWidth:tr,moodForMode:Po,moodForStop:Bo,portrait:Fn,full:rr,face:ir,banner:Vo,sheet:Uo}});var lr=me((Wu,ur)=>{function lt(e){let t=String(e??"");return t===""?[]:t.split(`
12
- `)}function Ln(e){return(e||[]).join(`
13
- `)}function Wo(e,t){let n=e.length,s=t.length,r=s+1,i=new Int32Array((n+1)*r);for(let l=n-1;l>=0;l--){let f=l*r,d=(l+1)*r;for(let h=s-1;h>=0;h--)i[f+h]=e[l]===t[h]?i[d+h+1]+1:Math.max(i[d+h],i[f+h+1])}let o=[],a=0,u=0;for(;a<n&&u<s;)e[a]===t[u]?(o.push({t:" ",s:e[a]}),a++,u++):i[(a+1)*r+u]>=i[a*r+u+1]?(o.push({t:"-",s:e[a]}),a++):(o.push({t:"+",s:t[u]}),u++);for(;a<n;)o.push({t:"-",s:e[a++]});for(;u<s;)o.push({t:"+",s:t[u++]});return o}function Go(e,t,n){let s=0,r=0;for(let f=0;f<t;f++)e[f].t!=="+"&&s++,e[f].t!=="-"&&r++;let i=e.slice(t,n).map(function(f){return{t:f.t,s:f.s}}),o=0,a=0,u=0,l=0;for(let f of i)f.t!=="+"&&o++,f.t!=="-"&&a++,f.t==="+"&&u++,f.t==="-"&&l++;return{oldStart:s,oldLines:o,newStart:r,newLines:a,add:u,del:l,header:"@@ -"+(s+1)+","+o+" +"+(r+1)+","+a+" @@",lines:i}}function Ho(e){let t=[];for(let r=0;r<e.length;r++)e[r].t!==" "&&t.push(r);let n=[],s=0;for(;s<t.length;){let r=t[s],i=r,o=s+1;for(;o<t.length&&t[o]-i-1<=2*3;)i=t[o],o++;s=o;let a=Math.max(0,r-3),u=Math.min(e.length,i+3+1);n.push(Go(e,a,u))}return n.forEach(function(r,i){r.id="h"+(i+1)}),n}function Ko(e,t){let n=lt(e),s=lt(t),r=n.length,i=s.length,o=0;for(;o<r&&o<i&&n[o]===s[o];)o++;let a=0;for(;a<r-o&&a<i-o&&n[r-1-a]===s[i-1-a];)a++;let u=n.slice(o,r-a),l=s.slice(o,i-a);if(!u.length&&!l.length)return[];let f;u.length*l.length>1e6?f=u.map(function(h){return{t:"-",s:h}}).concat(l.map(function(h){return{t:"+",s:h}})):f=Wo(u,l);let d=[];for(let h=0;h<o;h++)d.push({t:" ",s:n[h]});for(let h of f)d.push(h);for(let h=r-a;h<r;h++)d.push({t:" ",s:n[h]});return Ho(d)}function Jo(e){let t=0,n=0;for(let s of e||[])t+=s.add,n+=s.del;return{add:t,del:n,hunks:(e||[]).length}}function Xo(e,t){let n=lt(e),s=[];for(let r of t.lines)r.t!=="-"&&s.push(r.s);return Ln(n.slice(0,t.oldStart).concat(s,n.slice(t.oldStart+t.oldLines)))}function Yo(e,t){let n=lt(e),s=[];for(let r of t.lines)r.t!=="+"&&s.push(r.s);return Ln(n.slice(0,t.newStart).concat(s,n.slice(t.newStart+t.newLines)))}function zo(e,t){let n=[];for(let s of t.lines)s.t!=="+"&&n.push(s.s);return{start:t.newStart,end:t.newStart+t.newLines,lines:n}}function Qo(e){let t=[],n=[],s=e.newStart,r=-1,i=null;for(let o of e.lines)o.t==="+"?(r<0&&(r=s),s++):o.t==="-"?(r>=0&&(t.push({start:r,count:s-r}),r=-1),i||(i={at:s,lines:[]},n.push(i)),i.lines.push(o.s)):(r>=0&&(t.push({start:r,count:s-r}),r=-1),i=null,s++);return r>=0&&t.push({start:r,count:s-r}),{add:t,del:n}}ur.exports={CONTEXT:3,splitLines:lt,joinLines:Ln,computeHunks:Ko,stats:Jo,applyHunkToBaseline:Xo,revertHunkText:Yo,revertHunkEdit:zo,hunkRanges:Qo}});var fr=me((cr,ct)=>{(function(e){"use strict";let t={js:"break case catch class const continue debugger default delete do else export extends finally for function if import in instanceof let new return super switch this throw try typeof var void while with yield async await static get set of",ts:"break case catch class const continue debugger default delete do else export extends finally for function if import in instanceof let new return super switch this throw try typeof var void while with yield async await static get set of interface type enum implements private protected public readonly abstract declare namespace as satisfies keyof infer never unknown any string number boolean object symbol bigint",python:"and as assert async await break class continue def del elif else except False finally for from global if import in is lambda None nonlocal not or pass raise return True try while with yield match case",json:"true false null",go:"break case chan const continue default defer else fallthrough for func go goto if import interface map package range return select struct switch type var nil true false",rust:"as async await break const continue crate dyn else enum extern false fn for if impl in let loop match mod move mut pub ref return self Self static struct super trait true type unsafe use where while",sh:"if then else elif fi for while until do done case esac function return exit local export readonly shift",sql:"select from where insert into values update set delete create table drop alter add index join left right inner outer on group by order limit offset as and or not null primary key foreign references distinct"},n={};Object.keys(t).forEach(function(u){n[u]=new Set(t[u].split(/\s+/))});function s(u){let l=String(u||"").toLowerCase().trim();return l==="javascript"||l==="node"||l==="mjs"||l==="cjs"?"js":l==="typescript"?"ts":l==="py"||l==="python3"?"python":l==="golang"?"go":l==="rs"?"rust":l==="bash"||l==="shell"||l==="zsh"?"sh":l==="jsx"||l==="tsx"?l==="tsx"?"ts":"js":l}function r(u){let l=s(u);return n[l]?n[l]:n.js}function i(u,l){let f=r(l),d=s(l),h={kws:f,hashComment:d==="python"||d==="sh"||d==="ruby"||d==="yaml"||d==="toml",sql:d==="sql"},p=String(u??"").split(`
3
+ "use strict";var so=Object.create;var un=Object.defineProperty;var ro=Object.getOwnPropertyDescriptor;var io=Object.getOwnPropertyNames;var oo=Object.getPrototypeOf,ao=Object.prototype.hasOwnProperty;var Xe=(e,t)=>()=>(e&&(t=e(e=0)),t);var ge=(e,t)=>()=>(t||e((t={exports:{}}).exports,t),t.exports),uo=(e,t)=>{for(var n in t)un(e,n,{get:t[n],enumerable:!0})},lo=(e,t,n,s)=>{if(t&&typeof t=="object"||typeof t=="function")for(let r of io(t))!ao.call(e,r)&&r!==n&&un(e,r,{get:()=>t[r],enumerable:!(s=ro(t,r))||s.enumerable});return e};var tt=(e,t,n)=>(n=e!=null?so(oo(e)):{},lo(t||!e||!e.__esModule?un(n,"default",{value:e,enumerable:!0}):n,e));var fn=ge((Zu,js)=>{"use strict";var nt=require("fs"),ln=require("path"),xt=require("crypto"),co=require("os"),Os=new Set(["node_modules",".git",".DS_Store"]);function fo(e){return String(e??"").replace(/^~(?=$|[\\/])/,co.homedir())}function cn(e){return Array.isArray(e)?e.map(cn):e&&typeof e=="object"?Object.fromEntries(Object.keys(e).sort().map(t=>[t,cn(e[t])])):e}function Ts(e){let{signature:t,...n}=e;return JSON.stringify(cn(n))}function ho(e,t){let n=[];(function r(i,o){for(let a of nt.readdirSync(i)){if(Os.has(a))continue;let u=ln.join(i,a),l=o?o+"/"+a:a,f=nt.lstatSync(u);if(f.isSymbolicLink()){t&&t("\u8DF3\u8FC7\u7B26\u53F7\u94FE\u63A5 "+l);continue}f.isDirectory()?r(u,l):f.isFile()&&n.push(l)}})(e,""),n.sort(function(r,i){return Buffer.compare(Buffer.from(r,"utf8"),Buffer.from(i,"utf8"))});let s=xt.createHash("sha256");for(let r of n){let i=xt.createHash("sha256").update(nt.readFileSync(ln.join(e,r))).digest("hex");s.update(Buffer.from(r,"utf8")),s.update("\0"),s.update(i),s.update(`
4
+ `)}return s.digest("hex")}function po(e){return xt.createPublicKey({key:Buffer.from(e,"base64"),format:"der",type:"spki"})}function mo(e,t){if(!e||!e.signature)return{ok:!1,reason:"\u672A\u7B7E\u540D"};let{algo:n,keyId:s,sig:r}=e.signature;if(n!=="ed25519")return{ok:!1,reason:"\u4E0D\u652F\u6301\u7684\u7B7E\u540D\u7B97\u6CD5 "+n};let i=t[s];if(!i)return{ok:!1,reason:"\u627E\u4E0D\u5230\u516C\u94A5 keyId="+s};try{return xt.verify(null,Buffer.from(Ts(e)),i,Buffer.from(r||"","base64"))?{ok:!0}:{ok:!1,reason:"\u7B7E\u540D\u6821\u9A8C\u5931\u8D25\uFF1A\u6761\u76EE\u5185\u5BB9\u4E0E\u7B7E\u540D\u4E0D\u7B26\uFF08\u88AB\u7BE1\u6539\u6216\u6539\u4E86\u5B57\u6BB5\u672A\u91CD\u7B7E\uFF09"}}catch(o){return{ok:!1,reason:"\u7B7E\u540D\u89E3\u6790\u5931\u8D25\uFF1A"+o.message}}}function go(e,t){return e+"-v"+t}function Is(e){let t=/^---\r?\n([\s\S]*?)\r?\n---/.exec(String(e));if(!t)return{};let n=t[1].split(/\r?\n/),s={};for(let r=0;r<n.length;r++){let i=n[r];if(/^\s/.test(i))continue;let o=i.indexOf(":");if(o<=0)continue;let a=i.slice(0,o).trim().toLowerCase();if(!a)continue;let u=i.slice(o+1).trim(),l=/^([|>])([-+]?)$/.exec(u);if(l){let f=[];for(let d=r+1;d<n.length;d++){let h=n[d];if(!h.trim()){f.push(""),r=d;continue}if(!/^\s/.test(h))break;f.push(h.trim()),r=d}s[a]=(l[1]==="|"?f.join(`
5
+ `):f.join(" ").replace(/\s+/g," ")).trim();continue}s[a]=u}return s}var yo=2e4;function bo(e){let t=ln.join(e,"SKILL.md");if(!nt.existsSync(t))return{ok:!1,message:"\u5305\u91CC\u6CA1\u6709 SKILL.md"};let n;try{n=nt.readFileSync(t,"utf8").slice(0,yo)}catch(i){return{ok:!1,message:"SKILL.md \u8BFB\u53D6\u5931\u8D25\uFF1A"+i.message}}let s=Is(n),r=String(s.name||"").trim();return r?{ok:!0,manifest:{name:r,version:String(s.version||"").trim(),description:String(s.description||"").trim(),file:t}}:{ok:!1,message:"SKILL.md \u7684 frontmatter \u6CA1\u5199 name"}}function wo(e,t){return t?t.name!==e.name?{ok:!1,message:"name \u4E0D\u4E00\u81F4\uFF1A\u7D22\u5F15 "+e.name+"\u3001\u5305\u5185 "+t.name}:t.version&&t.version!==e.version?{ok:!1,message:"version \u4E0D\u4E00\u81F4\uFF1A\u7D22\u5F15 "+e.version+"\u3001\u5305\u5185 "+t.version}:{ok:!0}:{ok:!1,message:"\u6CA1\u6709\u6280\u80FD\u6E05\u5355"}}function $o(e,t){let n=s=>JSON.stringify((s||[]).map(r=>[r.name,r.description,r.readOnly===!0,r.parameters]));return n(e)===n(t)}js.exports={HASH_SKIP:Os,expandHome:fo,canonical:Ts,dirHash:ho,parsePublicKey:po,verifyEntry:mo,tagFor:go,sameTools:$o,parseFrontmatter:Is,readSkillManifest:bo,sameSkill:wo}});var Ps=ge((Qu,Rs)=>{"use strict";var B=require("fs"),As=require("os"),V=require("path"),st=fn(),Fs="skills-trash",dn=".installed.json",Ls={root:""};function So(e){let t=e||{};t.root&&(Ls.root=String(t.root))}function vo(){return V.resolve(Ls.root||process.cwd())}function _t(){return V.join(As.homedir(),".luban","skills")}function Et(){return V.join(As.homedir(),".luban",Fs)}function hn(e){return V.join(e||vo(),".luban","skills")}function Ns(e){return e==="project"?hn():_t()}function rt(e){let t=V.resolve(String(e||"")),n=[{scope:"global",base:_t()},{scope:"project",base:hn()}];for(let s of n){let r=V.relative(s.base,t);if(r&&r.indexOf("..")!==0&&!V.isAbsolute(r)&&r.indexOf(V.sep)<0)return{scope:s.scope,base:s.base,name:r}}return null}function Ms(){let e=new Date,t=function(n){return(n<10?"0":"")+n};return String(e.getFullYear())+t(e.getMonth()+1)+t(e.getDate())+"-"+t(e.getHours())+t(e.getMinutes())+t(e.getSeconds())}function Ot(e,t){B.mkdirSync(t,{recursive:!0});for(let n of B.readdirSync(e,{withFileTypes:!0})){if(n.name===".git"||n.isSymbolicLink())continue;let s=V.join(e,n.name),r=V.join(t,n.name);n.isDirectory()?Ot(s,r):n.isFile()&&B.copyFileSync(s,r)}}function Tt(e){try{let t=JSON.parse(B.readFileSync(V.join(e,dn),"utf8"));if(t&&typeof t=="object"&&t.skills&&typeof t.skills=="object")return t}catch{}return{version:1,skills:{}}}function pn(e,t){B.mkdirSync(e,{recursive:!0}),B.writeFileSync(V.join(e,dn),JSON.stringify(t,null,2)+`
6
+ `)}function Cs(){let e=[];for(let t of["global","project"]){let n=Ns(t),s=Tt(n),r;try{r=B.readdirSync(n,{withFileTypes:!0})}catch{continue}for(let i of r){if(!i.isDirectory()||i.name.startsWith("."))continue;let o=V.join(n,i.name),a=st.readSkillManifest(o);if(!a.ok)continue;let u=s.skills[i.name]||{};e.push({name:a.manifest.name,version:String(u.version||a.manifest.version||""),description:a.manifest.description,dir:o,scope:t,managed:!!s.skills[i.name],tag:String(u.tag||""),sourceSha256:String(u.sourceSha256||""),repo:String(u.repo||""),installedAt:String(u.installedAt||"")})}}return e}function Ds(e){let t=String(e||"").trim();if(!t)return null;let n=Cs();return n.find(function(s){return s.name===t&&s.scope==="project"})||n.find(function(s){return s.name===t})||null}function qs(e,t,n){let s=V.resolve(e),r=rt(s);if(!r)throw new Error("\u62D2\u7EDD\u64CD\u4F5C\uFF1A\u4E0D\u5728\u6280\u80FD\u76EE\u5F55\u4E0B\u7684\u4E00\u7EA7\u5B50\u76EE\u5F55\uFF1A"+s);let i=Et();B.mkdirSync(i,{recursive:!0,mode:448});let o=r.name.replace(/[^a-z0-9._-]/gi,"_"),a=o+"-"+Ms(),u=2;for(;B.existsSync(V.join(i,a))||B.existsSync(V.join(i,a+".json"));)a=o+"-"+Ms()+"-"+u,u++;let l=V.join(i,a);try{B.renameSync(s,l)}catch(f){if(f&&f.code==="EXDEV")Ot(s,l),B.rmSync(s,{recursive:!0,force:!0});else throw f}return B.writeFileSync(l+".json",JSON.stringify(Object.assign({name:r.name,from:s,scope:r.scope,at:new Date().toISOString(),why:t||""},n||{}),null,2)+`
7
+ `),a}function ko(e,t){let n=t||{},s=V.resolve(String(e||"")),r;try{r=B.statSync(s)}catch{return{ok:!1,code:"missing",message:"\u76EE\u5F55\u4E0D\u5B58\u5728\uFF1A"+s}}if(!r.isDirectory())return{ok:!1,code:"not-dir",message:"\u4E0D\u662F\u76EE\u5F55\uFF1A"+s};let i=st.readSkillManifest(s);if(i.ok&&!/^[a-z0-9][a-z0-9-]{1,39}$/.test(i.manifest.name))return{ok:!1,code:"bad-name",message:"\u6280\u80FD\u540D\u4E0D\u80FD\u4F5C\u4E3A\u76EE\u5F55\u540D\uFF1A"+i.manifest.name};if(!i.ok)return{ok:!1,code:"bad-manifest",message:"\u4E0D\u662F\u5408\u6CD5\u7684\u6280\u80FD\u76EE\u5F55\uFF1A"+i.message};let o=i.manifest.name,a=n.target==="project"?"project":"global",u=Ns(a),l=V.join(u,o);if(V.resolve(s)===l)return{ok:!1,code:"same-dir",message:"\u6E90\u76EE\u5F55\u5C31\u662F\u6280\u80FD\u76EE\u5F55\u672C\u8EAB\uFF1A"+l};let f=!1;if(B.existsSync(l)){if(!n.replace)return{ok:!1,code:"exists",name:o,dir:l,message:"\u5DF2\u5B58\u5728\u540C\u540D\u6280\u80FD\uFF1A"+o};try{qs(l,"replaced-by-install")}catch(p){return{ok:!1,code:"trash-failed",message:"\u65E7\u7248\u672C\u79FB\u8FDB\u56DE\u6536\u7AD9\u5931\u8D25\uFF1A"+p.message}}f=!0}try{Ot(s,l)}catch(p){try{B.rmSync(l,{recursive:!0,force:!0})}catch{}return{ok:!1,code:"copy-failed",message:"\u590D\u5236\u5931\u8D25\uFF1A"+p.message}}let d=st.readSkillManifest(l);if(!d.ok){try{B.rmSync(l,{recursive:!0,force:!0})}catch{}return{ok:!1,code:"bad-copy",message:"\u590D\u5236\u540E\u7684\u76EE\u5F55\u4E0D\u5B8C\u6574\uFF1A"+d.message}}let h=Tt(u);return h.skills[o]={version:String(n.version||d.manifest.version||""),tag:String(n.tag||""),sourceSha256:String(n.sourceSha256||""),repo:String(n.repo||""),installedAt:new Date().toISOString()},pn(u,h),{ok:!0,name:o,dir:l,scope:a,replaced:f,version:h.skills[o].version}}function xo(e,t){let n=t||{},s=String(e||"").trim();if(!s)return{ok:!1,message:"\u7F3A\u5C11\u6280\u80FD\u540D"};let r=s.indexOf("/")>=0||s.indexOf("\\")>=0||/^[A-Za-z]:/.test(s),i="";if(r)i=V.resolve(s);else{let f=Ds(s);if(!f)return{ok:!1,message:"\u6CA1\u6709\u8FD9\u4E2A\u6280\u80FD\uFF1A"+s};i=f.dir}let o=rt(i);if(!o)return{ok:!1,message:"\u62D2\u7EDD\u64CD\u4F5C\uFF1A\u4E0D\u5728\u6280\u80FD\u76EE\u5F55\u4E0B\u7684\u4E00\u7EA7\u5B50\u76EE\u5F55\uFF1A"+i};let a="";try{a=qs(i,n.why||"uninstall")}catch(f){return{ok:!1,message:"\u5378\u8F7D\u5931\u8D25\uFF1A"+f.message}}let u=o.base,l=Tt(u);return l.skills[o.name]&&(delete l.skills[o.name],pn(u,l)),{ok:!0,name:o.name,dir:i,trash:a}}function _o(){let e=Et(),t;try{t=B.readdirSync(e,{withFileTypes:!0})}catch{return[]}let n=[];for(let s of t){if(!s.isDirectory()||s.name.startsWith("."))continue;let r=V.join(e,s.name),i={};try{i=JSON.parse(B.readFileSync(r+".json","utf8"))||{}}catch{i={}}let o=st.readSkillManifest(r);n.push({entry:s.name,name:o.ok?o.manifest.name:String(i.name||""),description:o.ok?o.manifest.description:"",dir:r,from:String(i.from||""),scope:String(i.scope||""),why:String(i.why||""),at:String(i.at||""),valid:o.ok,error:o.ok?"":o.message})}return n.sort(function(s,r){return s.at!==r.at?s.at<r.at?1:-1:s.entry<r.entry?1:s.entry>r.entry?-1:0}),n}function Eo(e,t){let n=t||{},s=String(e||"").trim();if(!s||s.startsWith(".")||s.indexOf("/")>=0||s.indexOf("\\")>=0)return{ok:!1,message:"\u975E\u6CD5\u7684\u56DE\u6536\u7AD9\u6761\u76EE\uFF1A"+s};let r=V.join(Et(),s);if(!B.existsSync(r))return{ok:!1,message:"\u56DE\u6536\u7AD9\u91CC\u6CA1\u6709\u8FD9\u4E00\u6761\uFF1A"+s};let i={};try{i=JSON.parse(B.readFileSync(r+".json","utf8"))||{}}catch{i={}}let o=st.readSkillManifest(r),a=o.ok?o.manifest.name:String(i.name||"");if(!a)return{ok:!1,message:"\u56DE\u6536\u7AD9\u6761\u76EE\u91CC\u6CA1\u6709\u53EF\u7528\u7684 SKILL.md\uFF1A"+s};let u="",l=String(i.from||"");if(l){let d=V.resolve(l);B.existsSync(V.dirname(d))&&!B.existsSync(d)&&rt(d)&&(u=d)}if(u||(u=V.join(_t(),a)),B.existsSync(u))return{ok:!1,message:"\u76EE\u6807\u4F4D\u7F6E\u5DF2\u5B58\u5728\u540C\u540D\u6280\u80FD\uFF1A"+u};B.mkdirSync(V.dirname(u),{recursive:!0});try{B.renameSync(r,u)}catch(d){if(d&&d.code==="EXDEV")Ot(r,u),B.rmSync(r,{recursive:!0,force:!0});else return{ok:!1,message:"\u8FD8\u539F\u5931\u8D25\uFF1A"+d.message}}try{B.rmSync(r+".json",{force:!0})}catch{}let f=rt(u);if(f){let d=Tt(f.base);d.skills[f.name]||(d.skills[f.name]={version:o.ok?o.manifest.version:"",tag:"",sourceSha256:"",repo:"",installedAt:new Date().toISOString()},pn(f.base,d))}return{ok:!0,name:a,dir:u,scope:f?f.scope:""}}Rs.exports={TRASH_DIRNAME:Fs,LIST_FILENAME:dn,configure:So,globalDir:_t,projectDir:hn,trashDir:Et,scopeOf:rt,installed:Cs,find:Ds,installFromDir:ko,uninstall:xo,trashList:_o,restoreFromTrash:Eo}});var ct=ge((el,In)=>{var x=require("fs"),Ee=require("os"),k=require("path"),Ws=require("crypto"),Gs=2e3,Hs=6e4,Oo=18e4,Bs=8e3,mn=500,Mt=64,To=30,Vs=65536,Io=["bg","fg","panel","border","accent","accent-fg","muted","code-bg","surface","surface-2","hover","link","ok","warn","error"],gn={"radius-sm":[0,48],radius:[0,48],"radius-lg":[0,48],"font-size":[8,40]},jo=24,Mo=/^#[0-9a-fA-F]{3,8}$/,Ao=/^(?:rgb|rgba|hsl|hsla)\(\s*[-0-9.,%\s/]+\)$/,Fo=/^[a-zA-Z]{3,22}$/,Lo=/^(expression|url|var|env|attr|image|paint|element)$/i,No=/^(0|0?\.\d+|[1-9]\d*(?:\.\d+)?)\s*(px|em|rem|%|pt)?$/,y={root:"",version:"0",rec:function(){},confirm:null,enabled:!1,maxTools:To,timeoutMs:Hs,plugins:new Map,exposed:new Map,disabled:new Set,pending:[],trust:null,trustLoaded:!1,trustDirty:!1,dirs:[],errors:[],scannedAt:"",scannedMs:0};function Le(e){let t=e||{};if(t.root&&String(t.root)!==y.root&&(y.scannedMs=0),t.root&&(y.root=String(t.root)),typeof t.rec=="function"&&(y.rec=t.rec),typeof t.confirm=="function"&&(y.confirm=t.confirm),t.enabled!==void 0){let r=t.enabled===!0;!r&&y.enabled&&(y.plugins=new Map,y.exposed.clear(),y.dirs=[],y.errors=[],y.scannedMs=0),y.enabled=r}let n=Number(t.maxTools);if(isFinite(n)&&n>0){let r=Math.min(Math.floor(n),200);r!==y.maxTools&&(y.maxTools=r,y.scannedMs=0)}let s=Number(t.timeoutMs);isFinite(s)&&s>=1&&(y.timeoutMs=Math.min(Math.floor(s),Oo))}function ue(e,t){try{y.rec(e,t)}catch{}}function At(e,t){let n=String(e??"");return n.length>t?n.slice(0,t)+"\u2026":n}function Ne(e){return String(e??"").replace(/[^A-Za-z0-9_-]+/g,"_").replace(/^_+|_+$/g,"")||"x"}function Co(e){return Ws.createHash("sha1").update(String(e)).digest("hex").slice(0,6)}function Ks(e,t){let n="pl__"+Ne(e)+"__"+Ne(t);if(n.length>Mt){let s="_"+Co(e+"/"+t);n=n.slice(0,Mt-s.length)+s}return n}function Js(){return k.join(Ee.homedir(),".luban","plugins-trust.json")}function vn(){if(y.trustLoaded)return;y.trustLoaded=!0,y.trust=new Map;let e;try{e=JSON.parse(x.readFileSync(Js(),"utf8"))}catch{return}if(!(!e||typeof e!="object"||!e.trusted||typeof e.trusted!="object"))for(let t of Object.keys(e.trusted)){let n=e.trusted[t];typeof n=="string"&&n&&y.trust.set(t,n)}}function Xs(){if(!y.trustDirty||!y.trust)return;let e={trusted:{}};for(let[t,n]of y.trust)e.trusted[t]=n;try{let t=Js();x.mkdirSync(k.dirname(t),{recursive:!0}),x.writeFileSync(t,JSON.stringify(e,null,2)+`
8
+ `),y.trustDirty=!1}catch(t){ue("plugin_trust_save_failed",{message:t.message})}}function ot(e){let t=[];(function s(r){let i;try{i=x.readdirSync(r,{withFileTypes:!0})}catch{return}for(let o of i){if(o.name==="node_modules"||o.name===".git")continue;let a=k.join(r,o.name);o.isDirectory()?s(a):o.isFile()&&t.push(a)}})(e),t.sort();let n=Ws.createHash("sha1");for(let s of t){n.update(k.relative(e,s));try{n.update(x.readFileSync(s))}catch{}}return n.digest("hex")}function kn(e,t){return vn(),y.trust.get(e)===t}function zs(e,t){vn(),y.trust.set(e,t),y.trustDirty=!0,Xs()}function Do(e,t){let n=String(t??"").trim();if(!n||n.length>64||/[;{}<>\\"']/.test(n)||/\/\*/.test(n))return"";if(gn[e]){let s=n.match(No);if(!s)return"";let r=Number(s[1]),i=gn[e];return!isFinite(r)||r<i[0]||r>i[1]?"":s[2]?n:r+"px"}return Mo.test(n)||Ao.test(n)||Fo.test(n)&&!Lo.test(n)?n:""}function qo(e){if(!e||typeof e!="object"||Array.isArray(e))return null;let t=e.tokens&&typeof e.tokens=="object"&&!Array.isArray(e.tokens)?e.tokens:e,n=Object.create(null),s=[],r=0;for(let o of Object.keys(t)){if(r>=jo){s.push(o);continue}let a=String(o).replace(/^--/,"");if(Io.indexOf(a)<0&&!gn[a]){a!=="tokens"&&a!=="label"&&a!=="description"&&s.push(o);continue}let u=Do(a,t[o]);if(!u){s.push(o);continue}n[a]=u,r++}return r?{label:At(typeof e.label=="string"?e.label.trim():"",40)||"",tokens:n,dropped:s}:{error:"theme.tokens \u91CC\u6CA1\u6709\u5408\u6CD5 token",dropped:s}}function Oe(e){let t=k.join(e,"plugin.json"),n;try{n=x.statSync(t)}catch{return{error:"\u7F3A\u5C11 plugin.json"}}if(!n.isFile())return{error:"plugin.json \u4E0D\u662F\u6587\u4EF6"};if(n.size>Vs)return{error:"plugin.json \u8D85\u8FC7 "+Vs+" \u5B57\u8282"};let s;try{s=JSON.parse(x.readFileSync(t,"utf8"))}catch(p){return{error:"plugin.json \u89E3\u6790\u5931\u8D25\uFF1A"+p.message}}if(!s||typeof s!="object")return{error:"plugin.json \u4E0D\u662F\u5BF9\u8C61"};let r=Ne(s.name||k.basename(e));if(!s.name||typeof s.name!="string")return{error:"\u7F3A\u5C11 name"};let i=typeof s.main=="string"&&s.main.trim()?s.main.trim():"index.js",o=k.resolve(e,i),a=k.relative(e,o);if(!a||a.startsWith("..")||k.isAbsolute(a))return{error:"main \u8D8A\u754C\uFF1A"+i};if(!/\.js$/i.test(o))return{error:"main \u5FC5\u987B\u662F .js \u6587\u4EF6\uFF1A"+i};let u=s.tools,l=qo(s.theme);if(l&&l.error)return{error:l.error};if(u!=null&&!Array.isArray(u))return{error:"tools \u5FC5\u987B\u662F\u6570\u7EC4"};if(!Array.isArray(u)&&!l)return{error:"\u7F3A\u5C11 tools \u6570\u7EC4"};let f=s.readOnly===!0,d=[],h=Object.create(null);for(let p of Array.isArray(u)?u:[]){if(!p||typeof p!="object")continue;let m=Ne(p.name);if(!p.name||typeof p.name!="string"||!m||h[m])continue;h[m]=!0;let w=p.parameters&&typeof p.parameters=="object"?p.parameters:{type:"object",properties:{}};d.push({name:m,description:At(typeof p.description=="string"?p.description:"",mn),parameters:w,readOnly:p.readOnly===!0||p.readOnly!==!1&&f})}return!d.length&&!l?{error:"tools \u91CC\u6CA1\u6709\u5408\u6CD5\u5DE5\u5177"}:{name:r,version:typeof s.version=="string"?s.version:"",description:At(typeof s.description=="string"?s.description:"",mn),main:i,mainAbs:o,dir:e,tools:d,readOnly:f,theme:l?{label:l.label,tokens:l.tokens,dropped:l.dropped||[]}:null}}function Ro(e){let t=e||y.root||process.cwd(),n=Ee.homedir();return[k.join(n,".luban","plugins"),k.join(t,".luban","plugins")]}function Ys(){y.exposed.clear();let e=[];for(let t of y.plugins.values())e.push(t.name);e.sort();for(let t of e){let n=y.plugins.get(t);for(let s of n.tools){if(y.exposed.size>=y.maxTools)return;let r=Ks(n.name,s.name);if(y.exposed.has(r)){let i=2;for(;y.exposed.has(r+"_"+i);)i++;let o="_"+i;r=r.length+o.length>Mt?r.slice(0,Mt-o.length)+o:r+o}y.exposed.set(r,{plugin:n.name,tool:s.name,def:s,readOnly:s.readOnly===!0})}}}function Ze(){let e=Ro(y.root),t=[],n=new Map;for(let s of e){let r;try{r=x.readdirSync(s,{withFileTypes:!0})}catch{continue}for(let i of r){if(!i.isDirectory()||i.name.startsWith("."))continue;let o=k.join(s,i.name),a=Oe(o);if(a.error){t.push(i.name+"\uFF1A"+a.error),ue("plugin_manifest_bad",{dir:o,message:a.error});continue}n.set(a.name,{manifest:a,source:s})}}return{dirs:e,errors:t,merged:n}}async function ye(e,t){let n=t||{};if(e&&(y.root=String(e)),!y.enabled)return y.plugins=new Map,y.exposed.clear(),y.dirs=[],y.errors=[],y.pending=[],y.scannedAt=new Date().toISOString(),y.scannedMs=Date.now(),[];let s=Ze(),r=s.dirs;y.dirs=r;let i=s.errors,o=s.merged,a=new Map,u=[];for(let[l,f]of o){let d=f.manifest,h=ot(d.dir);if(kn(d.dir,h)){a.set(l,d);continue}if(y.disabled.has(d.dir)||typeof y.confirm!="function"){u.push(d),typeof y.confirm!="function"&&(i.push(l+"\uFF1A\u672A\u4FE1\u4EFB\u4E14\u65E0\u786E\u8BA4\u901A\u9053\uFF0C\u5DF2\u8DF3\u8FC7"),ue("plugin_untrusted_skip",{plugin:l,dir:d.dir}));continue}let p=!1;try{p=await y.confirm({name:d.name,version:d.version,description:d.description,dir:d.dir,source:f.source,tools:d.tools.map(function(m){return m.name}),fingerprint:h})}catch{p=!1}p===!0?(zs(d.dir,h),a.set(l,d),ue("plugin_trusted",{plugin:l,dir:d.dir})):(y.disabled.add(d.dir),u.push(d),ue("plugin_rejected",{plugin:l,dir:d.dir}))}return y.plugins=a,y.pending=u,Ys(),y.errors=i,y.scannedAt=new Date().toISOString(),y.scannedMs=Date.now(),n.quiet||ue("plugins_scanned",{count:y.plugins.size,tools:y.exposed.size,root:y.root,names:Array.from(y.plugins.keys()),errors:i}),Array.from(y.plugins.values())}function at(){if(!y.enabled||!y.root){y.exposed.size&&(y.plugins=new Map,y.exposed.clear());return}if(y.scannedMs&&Date.now()-y.scannedMs<Gs)return;let e=y.exposed.size,t=Ze().merged,n=new Map,s=[];for(let[r,i]of t){let o=i.manifest,a=ot(o.dir);kn(o.dir,a)?n.set(r,o):s.push(o)}y.plugins=n,y.pending=s,Ys(),y.scannedMs=Date.now(),y.scannedAt=new Date().toISOString(),y.exposed.size!==e&&ue("plugins_changed",{count:y.plugins.size,tools:y.exposed.size})}function Po(e){let t=e||{};y.scannedMs=0,t.keepDisabled||(y.disabled=new Set);for(let n of y.plugins.values())try{delete require.cache[En(n)]}catch{}return ye(y.root)}var Bo="plugins-trash";function ut(){return k.join(Ee.homedir(),".luban","plugins")}function lt(){return k.join(Ee.homedir(),".luban",Bo)}function Te(e){let t=k.resolve(String(e||"")),n=[{scope:"global",base:ut()},{scope:"project",base:k.join(k.resolve(y.root||process.cwd()),".luban","plugins")}];for(let s of n){let r=k.relative(s.base,t);if(r&&r.indexOf("..")!==0&&!k.isAbsolute(r)&&r.indexOf(k.sep)<0)return{scope:s.scope,base:s.base,name:r}}return null}function Us(){let e=new Date,t=function(n){return(n<10?"0":"")+n};return String(e.getFullYear())+t(e.getMonth()+1)+t(e.getDate())+"-"+t(e.getHours())+t(e.getMinutes())+t(e.getSeconds())}function Ft(e,t){x.mkdirSync(t,{recursive:!0});for(let n of x.readdirSync(e,{withFileTypes:!0})){if(n.name===".git"||n.isSymbolicLink())continue;let s=k.join(e,n.name),r=k.join(t,n.name);n.isDirectory()?Ft(s,r):n.isFile()&&x.copyFileSync(s,r)}}function Zs(e){try{let t=JSON.parse(x.readFileSync(e+".json","utf8"));return t&&typeof t=="object"?t:{}}catch{return{}}}function Vo(e,t){try{x.writeFileSync(e+".json",JSON.stringify(t,null,2)+`
9
+ `)}catch{}}function Uo(e){vn(),y.trust.delete(k.resolve(e))&&(y.trustDirty=!0,Xs())}function xn(e){let t=k.resolve(String(e||""));if(!Te(t))throw new Error("\u62D2\u7EDD\u64CD\u4F5C\uFF1A\u4E0D\u5728\u63D2\u4EF6\u76EE\u5F55\u4E0B\u7684\u4E00\u7EA7\u5B50\u76EE\u5F55\uFF1A"+t);let n=Oe(t);if(n.error)throw new Error("\u4E0D\u662F\u5408\u6CD5\u7684\u63D2\u4EF6\u76EE\u5F55\uFF1A"+n.error);return zs(t,ot(t)),y.disabled.delete(t),y.scannedMs=0,n}function Qs(e,t){let n=k.resolve(e),s=Te(n);if(!s)throw new Error("\u62D2\u7EDD\u64CD\u4F5C\uFF1A\u4E0D\u5728\u63D2\u4EF6\u76EE\u5F55\u4E0B\u7684\u4E00\u7EA7\u5B50\u76EE\u5F55\uFF1A"+n);let r=lt();x.mkdirSync(r,{recursive:!0,mode:448});let i=Ne(s.name),o=i+"-"+Us(),a=2;for(;x.existsSync(k.join(r,o))||x.existsSync(k.join(r,o+".json"));)o=i+"-"+Us()+"-"+a,a++;let u=k.join(r,o);try{x.renameSync(n,u)}catch(l){if(l&&l.code==="EXDEV")Ft(n,u),x.rmSync(n,{recursive:!0,force:!0});else throw l}return Vo(u,{name:s.name,from:n,scope:s.scope,at:new Date().toISOString(),why:t||""}),Uo(n),y.scannedMs=0,o}async function It(e,t){let n=t||{},s=k.resolve(String(e||"")),r;try{r=x.statSync(s)}catch{return{ok:!1,code:"missing",message:"\u76EE\u5F55\u4E0D\u5B58\u5728\uFF1A"+s}}if(!r.isDirectory())return{ok:!1,code:"not-dir",message:"\u4E0D\u662F\u76EE\u5F55\uFF1A"+s};let i=Oe(s);if(i.error)return{ok:!1,code:"bad-manifest",message:"\u4E0D\u662F\u5408\u6CD5\u7684\u63D2\u4EF6\u76EE\u5F55\uFF1A"+i.error};let o=n.target==="project"?"project":"global",a=o==="project"?k.join(k.resolve(y.root||process.cwd()),".luban","plugins"):ut(),u=k.join(a,i.name);if(k.resolve(s)===u)return{ok:!1,code:"same-dir",message:"\u6E90\u76EE\u5F55\u5C31\u662F\u63D2\u4EF6\u76EE\u5F55\u672C\u8EAB\uFF1A"+u};let l=!1;if(x.existsSync(u)){if(!n.replace)return{ok:!1,code:"exists",name:i.name,dir:u,message:"\u5DF2\u5B58\u5728\u540C\u540D\u63D2\u4EF6\uFF1A"+i.name};Qs(u,"replaced-by-install"),l=!0}try{Ft(s,u)}catch(d){try{x.rmSync(u,{recursive:!0,force:!0})}catch{}return{ok:!1,code:"copy-failed",message:"\u590D\u5236\u5931\u8D25\uFF1A"+d.message}}let f=Oe(u);if(f.error){try{x.rmSync(u,{recursive:!0,force:!0})}catch{}return{ok:!1,code:"bad-copy",message:"\u590D\u5236\u540E\u7684\u76EE\u5F55\u4E0D\u5B8C\u6574\uFF1A"+f.error}}if(n.trust)try{xn(u)}catch(d){ue("plugin_trust_failed",{dir:u,message:d.message})}return y.scannedMs=0,await ye(y.root,{quiet:!0}),ue("plugin_installed",{name:f.name,dir:u,replaced:l,trust:!!n.trust}),{ok:!0,name:f.name,version:f.version,dir:u,scope:o,replaced:l,tools:f.tools.map(function(d){return d.name})}}async function yn(e,t){let n=String(e||"").trim();if(!n)return{ok:!1,message:"\u7F3A\u5C11\u63D2\u4EF6\u540D"};let s=n.indexOf("/")>=0||n.indexOf("\\")>=0||/^[A-Za-z]:/.test(n),r="";if(s)r=k.resolve(n);else{let l=Ze().merged.get(n);if(!l)return{ok:!1,message:"\u6CA1\u6709\u8FD9\u4E2A\u63D2\u4EF6\uFF1A"+n};r=l.manifest.dir}let i=Te(r);if(!i)return{ok:!1,message:"\u62D2\u7EDD\u64CD\u4F5C\uFF1A\u4E0D\u5728\u63D2\u4EF6\u76EE\u5F55\u4E0B\u7684\u4E00\u7EA7\u5B50\u76EE\u5F55\uFF1A"+r};let o=Oe(r),a=o.error?i.name:o.name,u="";try{u=Qs(r,t&&t.why||"uninstall")}catch(l){return{ok:!1,message:"\u5378\u8F7D\u5931\u8D25\uFF1A"+l.message}}if(!o.error)try{delete require.cache[En(o)]}catch{}return await ye(y.root,{quiet:!0}),ue("plugin_uninstalled",{name:a,dir:r,trash:u}),{ok:!0,name:a,dir:r,trash:u}}function bn(){let e=lt(),t;try{t=x.readdirSync(e,{withFileTypes:!0})}catch{return[]}let n=[];for(let s of t){if(!s.isDirectory()||s.name.startsWith("."))continue;let r=k.join(e,s.name),i=Zs(r),o=Oe(r),a=s.name.lastIndexOf("-");n.push({entry:s.name,name:o.error?String(i.name||(a>0?s.name.slice(0,a):s.name)):o.name,version:o.error?"":o.version,description:o.error?"":o.description,dir:r,from:String(i.from||""),scope:String(i.scope||""),why:String(i.why||""),at:String(i.at||""),valid:!o.error,error:o.error||""})}return n.sort(function(s,r){return s.at!==r.at?s.at<r.at?1:-1:s.entry<r.entry?1:s.entry>r.entry?-1:0}),n}async function wn(e,t){let n=t||{},s=String(e||"").trim();if(!s||s.startsWith(".")||s.indexOf("/")>=0||s.indexOf("\\")>=0)return{ok:!1,message:"\u975E\u6CD5\u7684\u56DE\u6536\u7AD9\u6761\u76EE\uFF1A"+s};let r=k.join(lt(),s);if(!x.existsSync(r))return{ok:!1,message:"\u56DE\u6536\u7AD9\u91CC\u6CA1\u6709\u8FD9\u4E00\u6761\uFF1A"+s};let i=Zs(r),o=Oe(r),a=o.error?String(i.name||s):o.name,u="",l=String(i.from||"");if(l){let f=k.resolve(l),d=k.dirname(f);x.existsSync(d)&&!x.existsSync(f)&&Te(f)&&(u=f)}if(u||(u=k.join(ut(),Ne(a))),x.existsSync(u))return{ok:!1,message:"\u76EE\u6807\u4F4D\u7F6E\u5DF2\u5B58\u5728\u540C\u540D\u63D2\u4EF6\uFF1A"+u};x.mkdirSync(k.dirname(u),{recursive:!0});try{x.renameSync(r,u)}catch(f){if(f&&f.code==="EXDEV")Ft(r,u),x.rmSync(r,{recursive:!0,force:!0});else return{ok:!1,message:"\u8FD8\u539F\u5931\u8D25\uFF1A"+f.message}}try{x.unlinkSync(r+".json")}catch{}if(n.trust!==!1)try{xn(u)}catch(f){ue("plugin_restore_trust_failed",{dir:u,message:f.message})}return await ye(y.root,{quiet:!0}),ue("plugin_restored",{name:a,dir:u,from:s}),{ok:!0,name:a,dir:u}}function ze(e){return at(),y.exposed.has(String(e))}function _n(e){return at(),y.exposed.get(String(e))||null}function er(e){let t=_n(e);return t?t.readOnly===!0:!1}function Ye(e){at();let t=!!(e&&e.planOnly),n=[];for(let s of y.exposed){let r=s[0],i=s[1];if(t&&i.readOnly!==!0)continue;let o=i.def||{},a=o.description||"\u63D2\u4EF6\u5DE5\u5177 "+i.plugin+"/"+i.tool;if(n.push({type:"function",function:{name:r,description:At(a,mn)+"\uFF08\u6765\u81EA\u672C\u5730\u63D2\u4EF6\u300C"+i.plugin+"\u300D\uFF09",parameters:o.parameters||{type:"object",properties:{}}}}),n.length>=y.maxTools)break}return n.sort(function(s,r){return s.function.name<r.function.name?-1:s.function.name>r.function.name?1:0}),n}function En(e){let t=k.resolve(e.mainAbs);try{return x.realpathSync(t)}catch{return t}}function Wo(e){let t=y.plugins.get(e.plugin);if(!t)throw new Error("\u63D2\u4EF6\u5DF2\u5378\u8F7D: "+e.plugin);let n=En(t),s;try{require.cache[n]&&delete require.cache[n],s=require(n)}catch(o){throw new Error("\u63D2\u4EF6\u300C"+e.plugin+"\u300D\u52A0\u8F7D\u5931\u8D25\uFF1A"+o.message)}if(!s||typeof s!="object")throw new Error("\u63D2\u4EF6\u300C"+e.plugin+"\u300D\u7684 main \u6CA1\u6709\u5BFC\u51FA\u5BF9\u8C61");let r=s.tools&&typeof s.tools=="object"?s.tools:null,i=r?r[e.tool]:null;if(i&&typeof i.handler=="function")return i.handler;if(i&&typeof i=="function")return i;if(typeof s.call=="function")return function(o,a){return s.call(e.tool,o,a)};throw new Error("\u63D2\u4EF6\u300C"+e.plugin+"\u300D\u6CA1\u6709\u5DE5\u5177 "+e.tool+" \u7684 handler\uFF08\u8981 exports.tools."+e.tool+".handler \u6216 exports.call\uFF09")}function Go(e,t,n){let s,r=new Promise(function(i,o){s=setTimeout(function(){o(new Error(n+" \u8D85\u65F6\uFF08"+t+"ms\uFF09"))},t)});return Promise.race([e,r]).finally(function(){clearTimeout(s)})}async function it(e,t,n){let s=_n(e);if(!s)throw new Error("\u672A\u77E5\u63D2\u4EF6\u5DE5\u5177: "+e);let r=n||{},i=Date.now(),o=!1;try{let a=Wo(s),u={root:r.root||y.root,sessionId:r.sessionId||"",mode:r.mode||"",signal:r.signal||null,log:typeof r.log=="function"?r.log:function(){}},l=await Go(Promise.resolve().then(function(){return a(t||{},u)}),y.timeoutMs,"\u63D2\u4EF6\u5DE5\u5177 "+e);o=!0;let f;return l==null?f="(\u65E0\u8F93\u51FA)":typeof l=="string"?f=l:f=JSON.stringify(l),f=f.trim()||"(\u65E0\u8F93\u51FA)",f.length>Bs&&(f=f.slice(0,Bs)+`
10
+ \u2026[\u8F93\u51FA\u5DF2\u622A\u65AD]`),f}catch(a){let u=String(a&&a.message||a);throw ue("plugin_call_failed",{plugin:s.plugin,tool:s.tool,message:u}),new Error("\u63D2\u4EF6\u5DE5\u5177 "+e+" \u5931\u8D25\uFF1A"+u)}finally{ue("plugin_call",{plugin:s.plugin,tool:s.tool,ok:o,ms:Date.now()-i})}}function tr(){at();let e=[];for(let t of y.plugins.values()){let n=Te(t.dir);e.push({name:t.name,version:t.version,description:t.description,dir:t.dir,scope:n?n.scope:"",trusted:!0,readOnly:t.readOnly===!0,theme:On(t),tools:t.tools.map(function(s){return{name:s.name,readOnly:s.readOnly===!0}})})}return e}function Ho(){return at(),y.pending.map(function(e){let t=Te(e.dir);return{name:e.name,version:e.version,description:e.description,dir:e.dir,scope:t?t.scope:"",trusted:!1,readOnly:e.readOnly===!0,theme:On(e),tools:e.tools.map(function(n){return{name:n.name,readOnly:n.readOnly===!0}})}})}function $n(){let e=Ze(),t=[],n=[];for(let s of e.merged.values()){let r=s.manifest,i=Te(r.dir),o={name:r.name,version:r.version,description:r.description,dir:r.dir,scope:i?i.scope:"",readOnly:r.readOnly===!0,trusted:kn(r.dir,ot(r.dir)),theme:On(r),tools:r.tools.map(function(a){return{name:a.name,readOnly:a.readOnly===!0}})};(o.trusted?t:n).push(o)}return t.sort(function(s,r){return s.name<r.name?-1:s.name>r.name?1:0}),n.sort(function(s,r){return s.name<r.name?-1:s.name>r.name?1:0}),{dirs:e.dirs,errors:e.errors,plugins:t,pending:n}}function On(e){if(!e||!e.theme)return null;let t=Object.keys(e.theme.tokens);return{label:e.theme.label||e.name,tokens:t.length,names:t,dropped:(e.theme.dropped||[]).length}}function Tn(){let e=Ze(),t=[];for(let n of e.merged.values()){let s=n.manifest;s.theme&&((s.theme.dropped||[]).length&&ue("plugin_theme_token_dropped",{plugin:s.name,dropped:s.theme.dropped.slice(0,8)}),t.push({name:s.name,label:s.theme.label||s.name,description:s.description,dir:s.dir,tokens:Object.assign({},s.theme.tokens),dropped:(s.theme.dropped||[]).slice()}))}return t.sort(function(n,s){return n.name<s.name?-1:n.name>s.name?1:0}),t}function jt(e){let t=String(e??"").trim();if(!t)return null;let n=Tn();for(let s of n)if(s.name===t)return s;return null}function Sn(){return{root:y.root,enabled:y.enabled,dirs:y.dirs.slice(),globalDir:ut(),trashDir:lt(),errors:y.errors.slice(),scannedAt:y.scannedAt,plugins:tr(),pending:Ho(),tools:Array.from(y.exposed.entries()).map(function(e){return{name:e[0],plugin:e[1].plugin,tool:e[1].tool,readOnly:e[1].readOnly===!0}})}}if(require.main===In){let e=require("assert"),t=x.promises;(async function(){let n=x.mkdtempSync(k.join(Ee.tmpdir(),"luban-plugin-test-")),s=k.join(n,"proj"),r=k.join(n,"home",".luban","plugins"),i=k.join(s,".luban","plugins");x.mkdirSync(r,{recursive:!0}),x.mkdirSync(i,{recursive:!0});let o=Ee.homedir;Ee.homedir=function(){return k.join(n,"home")};let a=k.join(r,"demo");x.mkdirSync(a,{recursive:!0}),x.writeFileSync(k.join(a,"plugin.json"),JSON.stringify({name:"demo",version:"1.0.0",description:"\u6D4B\u8BD5\u63D2\u4EF6",readOnly:!0,tools:[{name:"echo",description:"\u56DE\u663E",parameters:{type:"object",properties:{text:{type:"string"}}}}]})),x.writeFileSync(k.join(a,"index.js"),'module.exports={tools:{echo:{handler:async(a)=>"echo:"+(a&&a.text||"")}}};');let u=k.join(i,"demo");x.mkdirSync(u,{recursive:!0}),x.writeFileSync(k.join(u,"plugin.json"),JSON.stringify({name:"demo",version:"2.0.0",readOnly:!1,tools:[{name:"boom",description:"\u629B\u9519",parameters:{type:"object",properties:{}}}]})),x.writeFileSync(k.join(u,"index.js"),'module.exports={tools:{boom:{handler:async()=>{throw new Error("\u70B8\u4E86")}}}};');let l=k.join(r,"bad");x.mkdirSync(l,{recursive:!0}),x.writeFileSync(k.join(l,"plugin.json"),"{ not json");let f=[],d=[];Le({root:s,enabled:!0,rec:function(W,ve){f.push([W,ve])},confirm:async function(W){return d.push(W.name),!0}}),await ye(s);let h=Sn();e.strictEqual(h.plugins.length,1,"\u5E94\u6709 1 \u4E2A\u63D2\u4EF6\uFF08demo \u9879\u76EE\u7248\u8986\u76D6\u5BB6\u76EE\u5F55\u7248\uFF0Cbad \u6E05\u5355\u574F\u88AB\u8DF3\u8FC7\uFF09");let p=h.plugins.find(function(W){return W.name==="demo"});e.strictEqual(p.version,"2.0.0","\u9879\u76EE\u63D2\u4EF6\u8986\u76D6\u5BB6\u76EE\u5F55"),e.strictEqual(p.tools.length,1),e.strictEqual(p.tools[0].name,"boom"),e.strictEqual(h.errors.some(function(W){return W.indexOf("bad")===0}),!0,"\u574F\u6E05\u5355\u8981\u8BB0 error"),e.strictEqual(ze("pl__demo__boom"),!0),e.strictEqual(ze("pl__demo__echo"),!1,"\u88AB\u9879\u76EE\u8986\u76D6\u7684 echo \u4E0D\u8BE5\u51FA\u73B0"),e.strictEqual(er("pl__demo__boom"),!1);let m=JSON.stringify(Ye({})),w=JSON.stringify(Ye({}));e.strictEqual(m,w,"\u4E24\u6B21 toolDefs \u9010\u5B57\u8282\u76F8\u540C"),e.strictEqual(Ye({planOnly:!0}).length,0,"\u975E\u53EA\u8BFB\u5DE5\u5177\u4E0D\u8FDB Plan");let b="";try{await it("pl__demo__boom",{},{root:s})}catch(W){b=W.message}e.ok(b.indexOf("\u70B8\u4E86")>=0,"\u629B\u9519\u8981\u5E26\u4E0A\u539F\u56E0\uFF0C\u5B9E\u9645: "+b);let $=k.join(r,"echo");x.mkdirSync($,{recursive:!0}),x.writeFileSync(k.join($,"plugin.json"),JSON.stringify({name:"echo",readOnly:!0,tools:[{name:"say",description:"\u56DE\u663E",parameters:{type:"object",properties:{text:{type:"string"}}}}]})),x.writeFileSync(k.join($,"index.js"),'module.exports={tools:{say:{handler:async(a)=>"say:"+(a&&a.text||"")}}}'),y.scannedMs=0,await ye(s,{quiet:!0});let _=await it("pl__echo__say",{text:"hi"},{root:s});e.strictEqual(_,"say:hi","echo \u6B63\u5E38\u8FD4\u56DE\uFF0C\u5B9E\u9645: "+_);let I=k.join(r,"slow");x.mkdirSync(I,{recursive:!0}),x.writeFileSync(k.join(I,"plugin.json"),JSON.stringify({name:"slow",readOnly:!0,tools:[{name:"hang",description:"\u6302\u4F4F",parameters:{type:"object",properties:{}}}]})),x.writeFileSync(k.join(I,"index.js"),"module.exports={tools:{hang:{handler:()=>new Promise(()=>{})}}}"),Le({timeoutMs:300}),y.scannedMs=0,await ye(s,{quiet:!0});let F="";try{await it("pl__slow__hang",{},{root:s})}catch(W){F=W.message}e.ok(F.indexOf("\u8D85\u65F6")>=0,"\u8981\u8D85\u65F6\uFF0C\u5B9E\u9645: "+F),Le({timeoutMs:Hs}),e.strictEqual(d.indexOf("demo")>=0,!0,"\u9996\u6B21\u8981\u786E\u8BA4 demo");let j=k.join(n,"home",".luban","plugins-trust.json");e.ok(x.existsSync(j),"\u4FE1\u4EFB\u8868\u8981\u843D\u76D8");let L=d.length;x.writeFileSync(k.join($,"index.js"),'module.exports={tools:{say:{handler:async()=>"changed"}}}'),y.scannedMs=0,await ye(s,{quiet:!0}),e.ok(d.length>L,"\u5185\u5BB9\u53D8\u4E86\u8981\u91CD\u65B0\u786E\u8BA4"),Le({confirm:async function(){return!1}}),y.trust=new Map,y.trustDirty=!0,y.disabled=new Set,y.scannedMs=0,await ye(s,{quiet:!0}),e.strictEqual(Ye({}).length,0,"\u5168\u62D2\u7EDD\u540E\u6E05\u5355\u4E3A\u7A7A"),e.ok(Sn().pending.length>0,"\u88AB\u62D2\u7684\u63D2\u4EF6\u8981\u8FDB pending"),Le({enabled:!0,confirm:async function(){return!0}}),y.trust=new Map,y.disabled=new Set,y.scannedMs=0,await ye(s,{quiet:!0});let M=k.join(n,"downloads","pkgs","fresh");x.mkdirSync(M,{recursive:!0}),x.writeFileSync(k.join(M,"plugin.json"),JSON.stringify({name:"fresh",version:"3.1.0",readOnly:!0,tools:[{name:"ping",description:"ping",parameters:{type:"object",properties:{}}}]})),x.writeFileSync(k.join(M,"index.js"),'module.exports={tools:{ping:{handler:async()=>"pong"}}}'),x.mkdirSync(k.join(M,".git"),{recursive:!0}),x.writeFileSync(k.join(M,".git","HEAD"),"ref: refs/heads/main");let N=await It(M,{trust:!0});e.strictEqual(N.ok,!0,"\u5B89\u88C5\u5E94\u6210\u529F\uFF1A"+JSON.stringify(N)),e.strictEqual(N.name,"fresh"),e.strictEqual(N.replaced,!1);let C=k.join(r,"fresh");e.strictEqual(x.existsSync(k.join(C,"plugin.json")),!0,"\u6587\u4EF6\u8981\u843D\u8FDB\u5168\u5C40\u63D2\u4EF6\u6839"),e.strictEqual(x.existsSync(k.join(C,".git")),!1,".git \u4E0D\u8BE5\u88AB\u590D\u5236"),e.strictEqual(ze("pl__fresh__ping"),!0,"\u88C5\u5B8C\u7ACB\u5373\u53EF\u7528\uFF08\u4FE1\u4EFB + \u91CD\u626B\uFF09"),e.strictEqual(await it("pl__fresh__ping",{},{root:s}),"pong");let U=await It(M,{trust:!0});e.strictEqual(U.ok,!1,"\u540C\u540D\u4E0D\u5E26 replace \u5E94\u62D2\u7EDD"),e.strictEqual(U.code,"exists");let q=await It(M,{trust:!0,replace:!0});e.strictEqual(q.ok,!0,"replace \u5E94\u6210\u529F"),e.strictEqual(q.replaced,!0);let ee=bn();e.ok(ee.some(function(W){return W.why==="replaced-by-install"}),"\u65E7\u7248\u8981\u8FDB\u56DE\u6536\u7AD9");let te=await yn("fresh");e.strictEqual(te.ok,!0,"\u5378\u8F7D\u5E94\u6210\u529F\uFF1A"+JSON.stringify(te)),e.strictEqual(x.existsSync(C),!1,"\u63D2\u4EF6\u76EE\u5F55\u8981\u79FB\u8D70"),e.strictEqual(ze("pl__fresh__ping"),!1,"\u5378\u8F7D\u540E\u5DE5\u5177\u6D88\u5931");let P=bn().find(function(W){return W.name==="fresh"});e.ok(P,"\u56DE\u6536\u7AD9\u91CC\u5E94\u6709 fresh"),e.strictEqual(P.valid,!0,"\u56DE\u6536\u7AD9\u6761\u76EE\u5E94\u80FD\u89E3\u6790\u6E05\u5355"),e.strictEqual(P.version,"3.1.0"),e.strictEqual(P.from,C,"\u5143\u6570\u636E\u8981\u8BB0\u4F4F\u539F\u4F4D\u7F6E");let X=await wn(P.entry);e.strictEqual(X.ok,!0,"\u8FD8\u539F\u5E94\u6210\u529F\uFF1A"+JSON.stringify(X)),e.strictEqual(X.dir,C,"\u8981\u8FD8\u539F\u56DE\u539F\u4F4D\u7F6E"),e.strictEqual(ze("pl__fresh__ping"),!0,"\u8FD8\u539F\u540E\u7ACB\u5373\u53EF\u7528");let H=k.join(n,"outside");x.mkdirSync(H,{recursive:!0}),x.writeFileSync(k.join(H,"plugin.json"),JSON.stringify({name:"evil",tools:[{name:"x",description:"x"}]}));let pe=await yn(H);e.strictEqual(pe.ok,!1,"\u63D2\u4EF6\u6839\u4E4B\u5916\u7684\u76EE\u5F55\u5FC5\u987B\u62D2\u7EDD\u5378\u8F7D"),e.strictEqual(x.existsSync(H),!0,"\u62D2\u7EDD\u540E\u76EE\u5F55\u8FD8\u5728");let ke=await wn("../outside");e.strictEqual(ke.ok,!1,"\u5E26 / \u7684\u56DE\u6536\u7AD9\u6761\u76EE\u8981\u62D2\u7EDD"),x.writeFileSync(k.join($,"index.js"),'module.exports={tools:{say:{handler:async()=>"dirty"}}}'),Le({enabled:!1}),await ye(s,{quiet:!0}),e.strictEqual(Ye({}).length,0,"\u5173\u95ED\u540E\u6E05\u5355\u4E3A\u7A7A");let Se=$n();e.ok(Se.plugins.length>0,"\u5173\u95ED\u5F00\u5173\u540E inventory \u4ECD\u5217\u51FA\u5DF2\u4FE1\u4EFB\u63D2\u4EF6\uFF0C\u5B9E\u9645 "+Se.plugins.length),e.ok(Se.pending.length>0,"\u5173\u95ED\u5F00\u5173\u540E inventory \u4ECD\u5217\u51FA\u672A\u4FE1\u4EFB\u63D2\u4EF6\uFF0C\u5B9E\u9645 "+Se.pending.length);let Ke=k.join(r,"theme-test");x.mkdirSync(Ke,{recursive:!0}),x.writeFileSync(k.join(Ke,"plugin.json"),JSON.stringify({name:"theme-test",version:"0.1.0",description:"\u53EA\u5E26\u4E3B\u9898\uFF0C\u6CA1\u6709\u5DE5\u5177",theme:{label:"\u6D4B\u8BD5\u914D\u8272",tokens:{bg:"#101014",fg:"rgb(240, 240, 245)",accent:"#ff5fa2",radius:"10","font-size":"15px",border:"red; } body { background: url(http://evil) }",surface:"url(http://evil/x.png)",width:"100px",link:"expression(alert(1))",ok:"$notacolor"}}}));let ne=Tn().find(function(W){return W.name==="theme-test"});e.ok(ne,"\u5E26 theme \u7684\u63D2\u4EF6\u8981\u51FA\u73B0\u5728 themes() \u91CC\uFF08enabled=false \u4E5F\u8981\u5728\uFF09"),e.strictEqual(ne.label,"\u6D4B\u8BD5\u914D\u8272"),e.strictEqual(ne.tokens.bg,"#101014"),e.strictEqual(ne.tokens.fg,"rgb(240, 240, 245)"),e.strictEqual(ne.tokens.radius,"10px","\u65E0\u5355\u4F4D\u5C3A\u5BF8\u8981\u8865 px"),e.strictEqual(ne.tokens["font-size"],"15px"),e.strictEqual(ne.tokens.border,void 0,"\u5E26\u5206\u53F7 / \u82B1\u62EC\u53F7\u7684\u503C\u5FC5\u987B\u4E22\u5F03"),e.strictEqual(ne.tokens.surface,void 0,"url() \u5FC5\u987B\u4E22\u5F03"),e.strictEqual(ne.tokens.width,void 0,"\u767D\u540D\u5355\u4E4B\u5916\u7684 token \u5FC5\u987B\u4E22\u5F03"),e.strictEqual(ne.tokens.link,void 0,"expression() \u5FC5\u987B\u4E22\u5F03"),e.strictEqual(ne.tokens.ok,void 0,"\u62FC\u4E0D\u6210\u989C\u8272 / \u5177\u540D\u8272\u7684\u503C\u5FC5\u987B\u4E22\u5F03"),e.ok(ne.dropped.length>=5,"\u4E22\u5F03\u8981\u6709\u7559\u75D5\uFF0C\u5B9E\u9645: "+JSON.stringify(ne.dropped)),e.strictEqual(jt("theme-test").tokens.accent,"#ff5fa2","themeOf \u6309\u540D\u53D6\u5230 tokens"),e.strictEqual(jt("nope"),null,"\u4E0D\u5B58\u5728\u7684\u63D2\u4EF6\u540D\u56DE null"),e.strictEqual(jt(""),null,"\u7A7A\u540D\u56DE null");let _e=k.join(r,"theme-broken");x.mkdirSync(_e,{recursive:!0}),x.writeFileSync(k.join(_e,"plugin.json"),JSON.stringify({name:"theme-broken",theme:{tokens:{bg:"red;}",fg:"url(x)"}}}));let Je=$n();e.ok(Je.errors.some(function(W){return W.indexOf("theme-broken")===0}),"\u5168\u975E\u6CD5 token \u7684\u4E3B\u9898\u63D2\u4EF6\u8981\u8BB0 error\uFF0C\u5B9E\u9645: "+JSON.stringify(Je.errors)),e.strictEqual(Je.plugins.concat(Je.pending).some(function(W){return W.name==="theme-broken"}),!1,"\u574F\u4E3B\u9898\u63D2\u4EF6\u4E0D\u8BE5\u51FA\u73B0\u5728\u6E05\u5355\u91CC"),Ee.homedir=o,x.rmSync(n,{recursive:!0,force:!0}),console.log("plugin.js \u81EA\u6D4B\u901A\u8FC7"),process.exit(0)})().catch(function(n){console.error("plugin.js \u81EA\u6D4B\u5931\u8D25\uFF1A",n),process.exit(1)})}In.exports={configure:Le,refresh:ye,reload:Po,list:tr,status:Sn,toolDefs:Ye,hasTool:ze,findTool:_n,readOnlyOf:er,callTool:it,installFromDir:It,uninstall:yn,trashList:bn,restoreFromTrash:wn,trustDir:xn,inventory:$n,themes:Tn,themeOf:jt,scopeOf:Te,globalDir:ut,trashDir:lt,_cleanName:Ne,_exposedBase:Ks,_parseManifest:Oe,_dirFingerprint:ot,_scanRaw:Ze,_state:y,_ttl:Gs}});var rr=ge((tl,An)=>{function Ce(e,t){let n=String(e??"").replace(/\s+/g," ").trim();return n?n.length>t?n.slice(0,t):n:""}function Ko(e,t){if(!e||typeof e!="object")return null;let n=Ce(e.id,64),s=Ce(e.label!=null?e.label:e.text,120);if(!s)return null;n||(n="o"+(t+1));let r={id:n,label:s};return(e.recommended===!0||e.recommended==="true")&&(r.recommended=!0),r}function Jo(e,t){if(!e||typeof e!="object")return null;let n=Ce(e.id,64),s=Ce(e.prompt!=null?e.prompt:e.question,240);if(!s)return null;n||(n="q"+(t+1));let r=Array.isArray(e.options)?e.options:[],i=[],o=Object.create(null);for(let a=0;a<r.length&&i.length<6;a++){let u=Ko(r[a],a);u&&(o[u.id]||(o[u.id]=1,i.push(u)))}return i.length<2?null:{id:n,prompt:s,allow_multiple:!!(e.allow_multiple||e.allowMultiple),options:i}}function Ie(e){let t=e&&typeof e=="object"?e:{},n=Ce(t.title,80),s=Array.isArray(t.questions)?t.questions:[];if(!s.length)throw new Error("ask_question \u9700\u8981\u975E\u7A7A questions \u6570\u7EC4");let r=[],i=Object.create(null);for(let o=0;o<s.length&&r.length<4;o++){let a=Jo(s[o],o);a&&(i[a.id]||(i[a.id]=1,r.push(a)))}if(!r.length)throw new Error("ask_question \u6CA1\u6709\u6709\u6548\u9898\u76EE\uFF08\u6BCF\u9898\u9700 prompt\uFF0C\u4E14 options 2~6 \u9879\uFF09");return{title:n,questions:r}}function jn(e,t){let n=e&&e.questions||[],s=t&&typeof t=="object"?t:{},r={};for(let i=0;i<n.length;i++){let o=n[i],a=Object.create(null);for(let l=0;l<o.options.length;l++)a[o.options[l].id]=o.options[l];let u=s[o.id];if(o.allow_multiple){let l=Array.isArray(u)?u:u==null||u===""?[]:[u],f=[],d=Object.create(null);for(let h=0;h<l.length;h++){let p=Ce(l[h],64);!p||!a[p]||d[p]||(d[p]=1,f.push(p))}if(!f.length)throw new Error("\u9898\u76EE\u300C"+o.id+"\u300D\u9700\u8981\u81F3\u5C11\u9009\u4E00\u9879");r[o.id]=f}else{let l=Ce(Array.isArray(u)?u[0]:u,64);if(!l||!a[l])throw new Error("\u9898\u76EE\u300C"+o.id+"\u300D\u9700\u8981\u9009\u62E9\u4E00\u4E2A\u6709\u6548\u9009\u9879");r[o.id]=l}}return r}function nr(e,t){for(let n=0;n<e.options.length;n++)if(e.options[n].id===t)return e.options[n].label;return t}function sr(e,t){let n=e&&e.questions||[],s=["\u7528\u6237\u56DE\u7B54\uFF1A"];e&&e.title&&s.unshift("\u63D0\u95EE\uFF1A"+e.title);for(let r=0;r<n.length;r++){let i=n[r],o=t[i.id],a;Array.isArray(o)?a=o.map(function(u){return u+"\uFF08"+nr(i,u)+"\uFF09"}).join("\u3001"):a=o+"\uFF08"+nr(i,o)+"\uFF09",s.push("- "+i.id+"\uFF08"+i.prompt+"\uFF09: "+a)}return s.join(`
11
+ `)}function Mn(e){let t=e&&e.questions||[];return t.length!==1?!0:!!t[0].allow_multiple}An.exports={MAX_QUESTIONS:4,MIN_OPTIONS:2,MAX_OPTIONS:6,normalize:Ie,normalizeAnswers:jn,formatAnswers:sr,needsConfirm:Mn};if(require.main===An){let e=function(s,r){if(!s)throw new Error(r||"assert failed")},t=0,n=function(s,r){try{r(),t++,console.log("ok "+s)}catch(i){console.error("FAIL "+s+": "+i.message),process.exitCode=1}};n("normalize basic",function(){let s=Ie({title:"\u65B9\u5411",questions:[{id:"q1",prompt:"\u8981\u4E0D\u8981\u8D85\u51FA\u5C04\u7A0B\u53D8\u6A59\uFF1F",options:[{id:"yes",label:"\u8981\u505A"},{id:"no",label:"\u4E0D\u505A"}]}]});e(s.title==="\u65B9\u5411","title"),e(s.questions.length===1&&s.questions[0].options.length===2,"q"),e(!Mn(s),"single select no confirm")}),n("normalize rejects empty / short options",function(){let s=!1;try{Ie({questions:[]})}catch{s=!0}e(s,"empty"),s=!1;try{Ie({questions:[{prompt:"x",options:[{id:"a",label:"A"}]}]})}catch{s=!0}e(s,"one option")}),n("normalize fills missing ids + caps",function(){let s=[];for(let i=0;i<8;i++)s.push({label:"L"+i});let r=Ie({questions:[{prompt:"P1",options:s},{prompt:"P2",options:[{label:"A"},{label:"B"}]},{prompt:"P3",options:[{label:"A"},{label:"B"}]},{prompt:"P4",options:[{label:"A"},{label:"B"}]},{prompt:"P5",options:[{label:"A"},{label:"B"}]}]});e(r.questions.length===4,"max q"),e(r.questions[0].options.length===6,"max opt"),e(r.questions[0].id==="q1","auto id")}),n("normalizeAnswers single + multi",function(){let s=Ie({questions:[{id:"a",prompt:"\u5355\u9009",options:[{id:"x",label:"X"},{id:"y",label:"Y"}]},{id:"b",prompt:"\u591A\u9009",allow_multiple:!0,options:[{id:"p",label:"P"},{id:"q",label:"Q"}]}]});e(Mn(s),"confirm");let r=jn(s,{a:"x",b:["p","q"]});e(r.a==="x"&&r.b.length===2,JSON.stringify(r));let i=sr(s,r);e(i.indexOf("\u7528\u6237\u56DE\u7B54")>=0&&i.indexOf("x\uFF08X\uFF09")>=0,i)}),n("normalizeAnswers rejects bad",function(){let s=Ie({questions:[{id:"a",prompt:"\u5355\u9009",options:[{id:"x",label:"X"},{id:"y",label:"Y"}]}]}),r=!1;try{jn(s,{a:"z"})}catch{r=!0}e(r,"bad id")}),n("normalize recommended flag",function(){let s=Ie({questions:[{id:"q1",prompt:"\u65B9\u5411",options:[{id:"yes",label:"\u8981\u505A",recommended:!0},{id:"no",label:"\u4E0D\u505A"}]}]});e(s.questions[0].options[0].recommended===!0,"rec"),e(!s.questions[0].options[1].recommended,"no rec")}),process.exitCode||console.log("ALL PASS pass="+t)}});var dr=ge((nl,fr)=>{"use strict";var Ln="\u73ED\u73ED",Nn="Banban",Cn="\u5C0F\u6728\u5320",Dn="\u5148\u91CF\u4E09\u904D\uFF0C\u518D\u4E0B\u4E00\u51FF",Xo=[" _____"," / \\"," /_______\\"],zo=" \\_______/",Yo=[" | |"," /| |\\"," \\|_____|/"," |_| |_|"],qn={idle:[" | o o |"," | . |"," | \\___/ |"],think:[" | o o |"," | . |"," | ___ |"],plan:[" | o o |"," | . |"," | --- |"],explore:[" | O o |"," | . |"," | \\_/ |"],work:[" | > < |"," | . |"," | ___ |"],done:[" | ^ ^ |"," | . |"," | \\___/ |"],tired:[" | - - |"," | . |"," | --- |"],error:[" | x x |"," | . |"," | ~~~ |"]},ir={idle:"(o o)",think:"(o.o)",plan:"[o o]",explore:"(o o)?",work:"(>_<)",done:"(^ ^)",tired:"(-_-)",error:"(x_x)"},Fn=[{mood:"idle",when:"\u7A7A\u95F2",say:"\u7B49\u4F60\u6D3E\u6D3B\uFF1B\u53EA\u8BFB\uFF0C\u5148\u91CF\u5C3A\u5BF8"},{mood:"plan",when:"plan",say:"\u53EA\u753B\u7EBF\u4E0D\u52A8\u624B\uFF1A\u5199\u5DE5\u5177\u4F1A\u88AB\u53EA\u8BFB\u95F8\u95E8\u62E6\u4E0B"},{mood:"explore",when:"explore",say:"\u53EA\u8BFB\u8C03\u7814\uFF0C\u770B\u89C1\u4EC0\u4E48\u5148\u8BB0\u4E0B\u6765"},{mood:"work",when:"agent",say:"--apply \u5F00\u4E86\u5199\u6743\u9650\uFF0C\u4E0A\u51FF\u5B50"},{mood:"think",when:"\u601D\u8003\u4E2D",say:"\u6A21\u578B\u81EA\u5DF1\u5728\u60F3\uFF08\u53EA\u663E\u793A\u7D2F\u8BA1\u5B57\u6570\uFF09"},{mood:"done",when:"final",say:"\u5E72\u5B8C\u4E86\uFF0C\u62A5\u4E00\u53E5\u8F6E\u6570 / \u5DE5\u5177\u6570 / \u8017\u65F6"},{mood:"tired",when:"maxRounds / timeout",say:"\u6536\u5DE5\uFF1A\u8F6E\u6570\u6216\u5899\u949F\u5230\u9876\uFF0C\u6216\u7528\u6237\u53D6\u6D88"},{mood:"error",when:"\u62A5\u9519",say:"\u5DE5\u5177\u8FDE\u7EED\u5931\u8D25\uFF0C\u6216\u8FD9\u4E00\u8F6E\u76F4\u63A5\u70B8\u4E86"}];function Lt(e,t){let n=String(e??"");return n.length>=t?n:n+" ".repeat(t-n.length)}function Zo(e){return e<4352?1:e<=4447||e>=11904&&e<=42191||e>=44032&&e<=55203||e>=63744&&e<=64255||e>=65072&&e<=65135||e>=65280&&e<=65376||e>=65504&&e<=65510?2:1}function or(e){let t=String(e??""),n=0;for(let s=0;s<t.length;s++)n+=Zo(t.charCodeAt(s));return n}function ar(e,t){let n=String(e??""),s=t-or(n);return s>0?n+" ".repeat(s):n}function ur(e){return Object.prototype.hasOwnProperty.call(qn,e)?e:"idle"}function Qo(e){let t=String(e||"");return t==="plan"?"plan":t==="explore"?"explore":"idle"}function ea(e){let t=String(e||"");return t==="final"?"done":"tired"}function Rn(e){return Xo.concat(qn[ur(e)],[zo])}function lr(e){return Rn(e).concat(Yo)}function cr(e){return ir[ur(e)]}function ta(e,t){let n=t||{},s=typeof e=="function"?e:function(a,u){return String(u)},r=Rn(n.mood||"plan"),i={};i[2]=" "+s("bold",Ln)+s("gray"," \xB7 "+Cn+"\uFF08"+Nn+"\uFF09"),i[3]=" "+s("gray",Dn),i[5]=" "+s("dim",String(n.tip||""));let o=[];for(let a=0;a<r.length;a++){let u=i[a];if(!u){o.push(s("cyan",r[a]));continue}o.push(s("cyan",Lt(r[a],12))+u)}return o}function na(e){let t=typeof e=="function"?e:function(o,a){return String(a)},n=lr("idle"),s=[t("bold",Ln+"\uFF08"+Nn+"\uFF09")+t("gray"," \xB7 "+Cn),t("gray",Dn),t("dim","Luban CLI \u7684\u642D\u6863\uFF1A\u53EA\u8BFB\u7684\u65F6\u5019\u753B\u7EBF\uFF0C--apply \u4E4B\u540E\u624D\u52A8\u51FF\u5B50\u3002")],r=[],i=Math.max(n.length,s.length);for(let o=0;o<i;o++){let a=n[o]||"",u=s[o]||"";if(!u){r.push(a?t("cyan",a):"");continue}r.push(t("cyan",Lt(a,14))+u)}r.push(""),r.push(t("bold"," \u8868\u60C5\uFF08\u6309 CLI \u72B6\u6001\u81EA\u52A8\u5207\u6362\uFF09"));for(let o=0;o<Fn.length;o++){let a=Fn[o];r.push(" "+t("cyan",Lt(cr(a.mood),9))+t("gray",ar(a.when,22))+a.say)}return r}fr.exports={NAME:Ln,NAME_EN:Nn,KIND:Cn,TAGLINE:Dn,MOODS:qn,FACES:ir,NOTES:Fn,padRight:Lt,padDisplay:ar,displayWidth:or,moodForMode:Qo,moodForStop:ea,portrait:Rn,full:lr,face:cr,banner:ta,sheet:na}});var pr=ge((sl,hr)=>{function ft(e){let t=String(e??"");return t===""?[]:t.split(`
12
+ `)}function Pn(e){return(e||[]).join(`
13
+ `)}function sa(e,t){let n=e.length,s=t.length,r=s+1,i=new Int32Array((n+1)*r);for(let l=n-1;l>=0;l--){let f=l*r,d=(l+1)*r;for(let h=s-1;h>=0;h--)i[f+h]=e[l]===t[h]?i[d+h+1]+1:Math.max(i[d+h],i[f+h+1])}let o=[],a=0,u=0;for(;a<n&&u<s;)e[a]===t[u]?(o.push({t:" ",s:e[a]}),a++,u++):i[(a+1)*r+u]>=i[a*r+u+1]?(o.push({t:"-",s:e[a]}),a++):(o.push({t:"+",s:t[u]}),u++);for(;a<n;)o.push({t:"-",s:e[a++]});for(;u<s;)o.push({t:"+",s:t[u++]});return o}function ra(e,t,n){let s=0,r=0;for(let f=0;f<t;f++)e[f].t!=="+"&&s++,e[f].t!=="-"&&r++;let i=e.slice(t,n).map(function(f){return{t:f.t,s:f.s}}),o=0,a=0,u=0,l=0;for(let f of i)f.t!=="+"&&o++,f.t!=="-"&&a++,f.t==="+"&&u++,f.t==="-"&&l++;return{oldStart:s,oldLines:o,newStart:r,newLines:a,add:u,del:l,header:"@@ -"+(s+1)+","+o+" +"+(r+1)+","+a+" @@",lines:i}}function ia(e){let t=[];for(let r=0;r<e.length;r++)e[r].t!==" "&&t.push(r);let n=[],s=0;for(;s<t.length;){let r=t[s],i=r,o=s+1;for(;o<t.length&&t[o]-i-1<=2*3;)i=t[o],o++;s=o;let a=Math.max(0,r-3),u=Math.min(e.length,i+3+1);n.push(ra(e,a,u))}return n.forEach(function(r,i){r.id="h"+(i+1)}),n}function oa(e,t){let n=ft(e),s=ft(t),r=n.length,i=s.length,o=0;for(;o<r&&o<i&&n[o]===s[o];)o++;let a=0;for(;a<r-o&&a<i-o&&n[r-1-a]===s[i-1-a];)a++;let u=n.slice(o,r-a),l=s.slice(o,i-a);if(!u.length&&!l.length)return[];let f;u.length*l.length>1e6?f=u.map(function(h){return{t:"-",s:h}}).concat(l.map(function(h){return{t:"+",s:h}})):f=sa(u,l);let d=[];for(let h=0;h<o;h++)d.push({t:" ",s:n[h]});for(let h of f)d.push(h);for(let h=r-a;h<r;h++)d.push({t:" ",s:n[h]});return ia(d)}function aa(e){let t=0,n=0;for(let s of e||[])t+=s.add,n+=s.del;return{add:t,del:n,hunks:(e||[]).length}}function ua(e,t){let n=ft(e),s=[];for(let r of t.lines)r.t!=="-"&&s.push(r.s);return Pn(n.slice(0,t.oldStart).concat(s,n.slice(t.oldStart+t.oldLines)))}function la(e,t){let n=ft(e),s=[];for(let r of t.lines)r.t!=="+"&&s.push(r.s);return Pn(n.slice(0,t.newStart).concat(s,n.slice(t.newStart+t.newLines)))}function ca(e,t){let n=[];for(let s of t.lines)s.t!=="+"&&n.push(s.s);return{start:t.newStart,end:t.newStart+t.newLines,lines:n}}function fa(e){let t=[],n=[],s=e.newStart,r=-1,i=null;for(let o of e.lines)o.t==="+"?(r<0&&(r=s),s++):o.t==="-"?(r>=0&&(t.push({start:r,count:s-r}),r=-1),i||(i={at:s,lines:[]},n.push(i)),i.lines.push(o.s)):(r>=0&&(t.push({start:r,count:s-r}),r=-1),i=null,s++);return r>=0&&t.push({start:r,count:s-r}),{add:t,del:n}}hr.exports={CONTEXT:3,splitLines:ft,joinLines:Pn,computeHunks:oa,stats:aa,applyHunkToBaseline:ua,revertHunkText:la,revertHunkEdit:ca,hunkRanges:fa}});var gr=ge((mr,dt)=>{(function(e){"use strict";let t={js:"break case catch class const continue debugger default delete do else export extends finally for function if import in instanceof let new return super switch this throw try typeof var void while with yield async await static get set of",ts:"break case catch class const continue debugger default delete do else export extends finally for function if import in instanceof let new return super switch this throw try typeof var void while with yield async await static get set of interface type enum implements private protected public readonly abstract declare namespace as satisfies keyof infer never unknown any string number boolean object symbol bigint",python:"and as assert async await break class continue def del elif else except False finally for from global if import in is lambda None nonlocal not or pass raise return True try while with yield match case",json:"true false null",go:"break case chan const continue default defer else fallthrough for func go goto if import interface map package range return select struct switch type var nil true false",rust:"as async await break const continue crate dyn else enum extern false fn for if impl in let loop match mod move mut pub ref return self Self static struct super trait true type unsafe use where while",sh:"if then else elif fi for while until do done case esac function return exit local export readonly shift",sql:"select from where insert into values update set delete create table drop alter add index join left right inner outer on group by order limit offset as and or not null primary key foreign references distinct"},n={};Object.keys(t).forEach(function(u){n[u]=new Set(t[u].split(/\s+/))});function s(u){let l=String(u||"").toLowerCase().trim();return l==="javascript"||l==="node"||l==="mjs"||l==="cjs"?"js":l==="typescript"?"ts":l==="py"||l==="python3"?"python":l==="golang"?"go":l==="rs"?"rust":l==="bash"||l==="shell"||l==="zsh"?"sh":l==="jsx"||l==="tsx"?l==="tsx"?"ts":"js":l}function r(u){let l=s(u);return n[l]?n[l]:n.js}function i(u,l){let f=r(l),d=s(l),h={kws:f,hashComment:d==="python"||d==="sh"||d==="ruby"||d==="yaml"||d==="toml",sql:d==="sql"},p=String(u??"").split(`
14
14
  `),m=[];for(let w=0;w<p.length;w++)w>0&&m.push({k:"plain",s:`
15
- `}),o(p[w],h,m);return m}function o(u,l,f){let d=u,h=0,p=d.length;for(;h<p;){let m=d.slice(h),w;if(l.hashComment&&m[0]==="#"){f.push({k:"com",s:m}),h=p;continue}if(!l.hashComment&&m.slice(0,2)==="//"){f.push({k:"com",s:m}),h=p;continue}if(m.slice(0,2)==="/*"){let b=d.indexOf("*/",h+2),$=b===-1?m:d.slice(h,b+2);f.push({k:"com",s:$}),h+=$.length;continue}if(l.sql&&/^--/.test(m)){f.push({k:"com",s:m}),h=p;continue}if(m[0]==='"'||m[0]==="'"||m[0]==="`"){let b=m[0],$=1;for(;$<m.length;){if(m[$]==="\\"){$+=2;continue}if(m[$]===b){$++;break}$++}let k=m.slice(0,Math.min($,m.length));f.push({k:"str",s:k}),h+=k.length;continue}if(w=/^\d+(\.\d+)?([eE][+-]?\d+)?/.exec(m),w&&/[\s\)\}\],;:=+\-*/<>!&|]|^/.test(m[w[0].length]||" ")){let b=d[h-1];if(!b||!/[A-Za-z0-9_$]/.test(b)){f.push({k:"num",s:w[0]}),h+=w[0].length;continue}}if(w=/^[A-Za-z_$][A-Za-z0-9_$]*/.exec(m),w){let b=w[0],$=m.slice(b.length);l.kws.has(b)?f.push({k:"kw",s:b}):/^\s*\(/.test($)?f.push({k:"fn",s:b}):f.push({k:"plain",s:b}),h+=b.length;continue}f.push({k:"plain",s:m[0]}),h++}}let a={highlight:i,normLang:s};typeof ct<"u"&&ct&&ct.exports&&(ct.exports=a),e&&(e.LubanHighlight=a)})(typeof globalThis<"u"?globalThis:cr)});var br=me((Gu,yr)=>{"use strict";var Zo=fr();function At(e){let t=typeof e=="function"?e:function(n,s){return s};return{bold:function(n){return t("bold",n)},dim:function(n){return t("dim",n)},italic:function(n){return t("italic",n)},underline:function(n){return t("underline",n)},heading:function(n){return t("cyan",t("bold",n))},link:function(n){return t("blue",t("underline",n))},quote:function(n){return t("dim",n)},hr:function(n){return t("dim",n)},bullet:function(n){return t("cyan",n)},code:function(n){return t("inverse",n)},codeBorder:function(n){return t("dim",n)},kw:function(n){return t("magenta",n)},str:function(n){return t("green",n)},num:function(n){return t("yellow",n)},com:function(n){return t("gray",n)},fn:function(n){return t("blue",n)},plain:function(n){return n}}}function pr(e,t,n){let s=n||At(null),r=Zo.highlight(e,t),i="";for(let o of r)o.k==="kw"?i+=s.kw(o.s):o.k==="str"?i+=s.str(o.s):o.k==="num"?i+=s.num(o.s):o.k==="com"?i+=s.com(o.s):o.k==="fn"?i+=s.fn(o.s):i+=s.plain(o.s);return i}function Ce(e,t){let n=t||At(null),s=String(e),r=[];return s=s.replace(/`([^`]+)`/g,function(i,o){return r.push(o),"\0CODE"+(r.length-1)+"\0"}),s=s.replace(/\*\*([^*]+)\*\*/g,function(i,o){return n.bold(o)}),s=s.replace(/__([^_]+)__/g,function(i,o){return n.bold(o)}),s=s.replace(/(^|[\s(])\*([^*\n]+)\*(?=$|[\s.,;:!?)])/g,function(i,o,a){return o+n.italic(a)}),s=s.replace(/\[([^\]]+)\]\(([^)]+)\)/g,function(i,o,a){return n.link(o)+" "+n.dim("("+a+")")}),s=s.replace(/\u0000CODE(\d+)\u0000/g,function(i,o){return n.code(r[Number(o)])}),s}function dr(e){let t=String(e).trim();t.charAt(0)==="|"&&(t=t.slice(1)),t.charAt(t.length-1)==="|"&&t.charAt(t.length-2)!=="\\"&&(t=t.slice(0,-1));let n="\0";return t.replace(/\\\|/g,n).split("|").map(function(s){return s.split(n).join("|").trim()})}function mr(e){return/^\s*\|?\s*:?-{1,}:?\s*(\|\s*:?-{1,}:?\s*)*\|?\s*$/.test(String(e))}function ea(e,t){return t+1>=e.length||String(e[t]).indexOf("|")===-1?!1:mr(e[t+1])}function Cn(e){let t=0;for(let n of String(e)){let s=n.codePointAt(0);s>=4352&&s<=4447||s>=11904&&s<=42191||s>=44032&&s<=55203||s>=63744&&s<=64255||s>=65072&&s<=65103||s>=65280&&s<=65376||s>=65504&&s<=65510||s>=131072&&s<=262141?t+=2:t+=1}return t}function ta(e,t){return e+" ".repeat(Math.max(0,t-Cn(e)))}function gr(e,t,n){let s=dr(e[t]),r=[],i=t+2;for(;i<e.length;){let d=String(e[i]);if(/^\s*$/.test(d)||d.indexOf("|")===-1)break;r.push(dr(d)),i++}let o=s.length;for(r.forEach(function(d){d.length>o&&(o=d.length)});s.length<o;)s.push("");r.forEach(function(d){for(;d.length<o;)d.push("")});let a=[];for(let d=0;d<o;d++){let h=Cn(s[d]);r.forEach(function(p){let m=Cn(p[d]);m>h&&(h=m)}),a.push(h)}function u(d,h,p){return n.codeBorder(d+a.map(function(m){return h.repeat(m+2)}).join(h)+p)}function l(d,h){let p=d.map(function(m,w){let b=" "+ta(m,a[w])+" ";return h?n.bold(b):Ce(b,n)});return n.codeBorder("\u2502")+p.join(n.codeBorder("\u2502"))+n.codeBorder("\u2502")}let f=[u("\u256D","\u2500","\u256E"),l(s,!0),u("\u251C","\u2500","\u2524")];return r.forEach(function(d){f.push(l(d,!1))}),f.push(u("\u2570","\u2500","\u256F")),{text:f.join(`
16
- `),next:i}}function na(e,t){let n=At(t),r=String(e??"").split(`
17
- `),i=[],o=0,a=!1,u="",l=[];for(;o<r.length;){let f=r[o],d=/^\s*(```+|~~~+)\s*([^\s]*)\s*$/.exec(f);if(d&&!a){a=!0,u=d[2]||"",l=[],o++;continue}if(a){if(/^\s*(```+|~~~+)\s*$/.exec(f)){i.push(hr(l.join(`
18
- `),u,n)),a=!1,u="",l=[],o++;continue}l.push(f),o++;continue}if(/^\s*$/.test(f)){i.push(""),o++;continue}if(ea(r,o)){let b=gr(r,o,n);i.push(b.text),o=b.next;continue}let h=/^(#{1,6})\s+(.*)$/.exec(f);if(h){let b=h[1].length,$=Ce(h[2].trim(),n);i.push(b<=2?n.heading($):n.bold($)),o++;continue}if(/^\s*([-*_])(\s*\1){2,}\s*$/.test(f)){i.push(n.hr("\u2500".repeat(40))),o++;continue}let p=/^\s*>\s?(.*)$/.exec(f);if(p){i.push(n.quote("\u2502 "+Ce(p[1],n))),o++;continue}let m=/^(\s*)[-*+]\s+(.*)$/.exec(f),w=/^(\s*)(\d+)[.)]\s+(.*)$/.exec(f);if(m||w){let b=(m||w)[1],$=" ".repeat(Math.floor(b.length/2));m?i.push($+n.bullet("\u2022")+" "+Ce(m[2],n)):i.push($+n.bullet(w[2]+".")+" "+Ce(w[3],n)),o++;continue}i.push(Ce(f,n)),o++}return a&&i.push(hr(l.join(`
15
+ `}),o(p[w],h,m);return m}function o(u,l,f){let d=u,h=0,p=d.length;for(;h<p;){let m=d.slice(h),w;if(l.hashComment&&m[0]==="#"){f.push({k:"com",s:m}),h=p;continue}if(!l.hashComment&&m.slice(0,2)==="//"){f.push({k:"com",s:m}),h=p;continue}if(m.slice(0,2)==="/*"){let b=d.indexOf("*/",h+2),$=b===-1?m:d.slice(h,b+2);f.push({k:"com",s:$}),h+=$.length;continue}if(l.sql&&/^--/.test(m)){f.push({k:"com",s:m}),h=p;continue}if(m[0]==='"'||m[0]==="'"||m[0]==="`"){let b=m[0],$=1;for(;$<m.length;){if(m[$]==="\\"){$+=2;continue}if(m[$]===b){$++;break}$++}let _=m.slice(0,Math.min($,m.length));f.push({k:"str",s:_}),h+=_.length;continue}if(w=/^\d+(\.\d+)?([eE][+-]?\d+)?/.exec(m),w&&/[\s\)\}\],;:=+\-*/<>!&|]|^/.test(m[w[0].length]||" ")){let b=d[h-1];if(!b||!/[A-Za-z0-9_$]/.test(b)){f.push({k:"num",s:w[0]}),h+=w[0].length;continue}}if(w=/^[A-Za-z_$][A-Za-z0-9_$]*/.exec(m),w){let b=w[0],$=m.slice(b.length);l.kws.has(b)?f.push({k:"kw",s:b}):/^\s*\(/.test($)?f.push({k:"fn",s:b}):f.push({k:"plain",s:b}),h+=b.length;continue}f.push({k:"plain",s:m[0]}),h++}}let a={highlight:i,normLang:s};typeof dt<"u"&&dt&&dt.exports&&(dt.exports=a),e&&(e.LubanHighlight=a)})(typeof globalThis<"u"?globalThis:mr)});var kr=ge((rl,vr)=>{"use strict";var da=gr();function Nt(e){let t=typeof e=="function"?e:function(n,s){return s};return{bold:function(n){return t("bold",n)},dim:function(n){return t("dim",n)},italic:function(n){return t("italic",n)},underline:function(n){return t("underline",n)},heading:function(n){return t("cyan",t("bold",n))},link:function(n){return t("blue",t("underline",n))},quote:function(n){return t("dim",n)},hr:function(n){return t("dim",n)},bullet:function(n){return t("cyan",n)},code:function(n){return t("inverse",n)},codeBorder:function(n){return t("dim",n)},kw:function(n){return t("magenta",n)},str:function(n){return t("green",n)},num:function(n){return t("yellow",n)},com:function(n){return t("gray",n)},fn:function(n){return t("blue",n)},plain:function(n){return n}}}function wr(e,t,n){let s=n||Nt(null),r=da.highlight(e,t),i="";for(let o of r)o.k==="kw"?i+=s.kw(o.s):o.k==="str"?i+=s.str(o.s):o.k==="num"?i+=s.num(o.s):o.k==="com"?i+=s.com(o.s):o.k==="fn"?i+=s.fn(o.s):i+=s.plain(o.s);return i}function De(e,t){let n=t||Nt(null),s=String(e),r=[];return s=s.replace(/`([^`]+)`/g,function(i,o){return r.push(o),"\0CODE"+(r.length-1)+"\0"}),s=s.replace(/\*\*([^*]+)\*\*/g,function(i,o){return n.bold(o)}),s=s.replace(/__([^_]+)__/g,function(i,o){return n.bold(o)}),s=s.replace(/(^|[\s(])\*([^*\n]+)\*(?=$|[\s.,;:!?)])/g,function(i,o,a){return o+n.italic(a)}),s=s.replace(/\[([^\]]+)\]\(([^)]+)\)/g,function(i,o,a){return n.link(o)+" "+n.dim("("+a+")")}),s=s.replace(/\u0000CODE(\d+)\u0000/g,function(i,o){return n.code(r[Number(o)])}),s}function yr(e){let t=String(e).trim();t.charAt(0)==="|"&&(t=t.slice(1)),t.charAt(t.length-1)==="|"&&t.charAt(t.length-2)!=="\\"&&(t=t.slice(0,-1));let n="\0";return t.replace(/\\\|/g,n).split("|").map(function(s){return s.split(n).join("|").trim()})}function $r(e){return/^\s*\|?\s*:?-{1,}:?\s*(\|\s*:?-{1,}:?\s*)*\|?\s*$/.test(String(e))}function ha(e,t){return t+1>=e.length||String(e[t]).indexOf("|")===-1?!1:$r(e[t+1])}function Bn(e){let t=0;for(let n of String(e)){let s=n.codePointAt(0);s>=4352&&s<=4447||s>=11904&&s<=42191||s>=44032&&s<=55203||s>=63744&&s<=64255||s>=65072&&s<=65103||s>=65280&&s<=65376||s>=65504&&s<=65510||s>=131072&&s<=262141?t+=2:t+=1}return t}function pa(e,t){return e+" ".repeat(Math.max(0,t-Bn(e)))}function Sr(e,t,n){let s=yr(e[t]),r=[],i=t+2;for(;i<e.length;){let d=String(e[i]);if(/^\s*$/.test(d)||d.indexOf("|")===-1)break;r.push(yr(d)),i++}let o=s.length;for(r.forEach(function(d){d.length>o&&(o=d.length)});s.length<o;)s.push("");r.forEach(function(d){for(;d.length<o;)d.push("")});let a=[];for(let d=0;d<o;d++){let h=Bn(s[d]);r.forEach(function(p){let m=Bn(p[d]);m>h&&(h=m)}),a.push(h)}function u(d,h,p){return n.codeBorder(d+a.map(function(m){return h.repeat(m+2)}).join(h)+p)}function l(d,h){let p=d.map(function(m,w){let b=" "+pa(m,a[w])+" ";return h?n.bold(b):De(b,n)});return n.codeBorder("\u2502")+p.join(n.codeBorder("\u2502"))+n.codeBorder("\u2502")}let f=[u("\u256D","\u2500","\u256E"),l(s,!0),u("\u251C","\u2500","\u2524")];return r.forEach(function(d){f.push(l(d,!1))}),f.push(u("\u2570","\u2500","\u256F")),{text:f.join(`
16
+ `),next:i}}function ma(e,t){let n=Nt(t),r=String(e??"").split(`
17
+ `),i=[],o=0,a=!1,u="",l=[];for(;o<r.length;){let f=r[o],d=/^\s*(```+|~~~+)\s*([^\s]*)\s*$/.exec(f);if(d&&!a){a=!0,u=d[2]||"",l=[],o++;continue}if(a){if(/^\s*(```+|~~~+)\s*$/.exec(f)){i.push(br(l.join(`
18
+ `),u,n)),a=!1,u="",l=[],o++;continue}l.push(f),o++;continue}if(/^\s*$/.test(f)){i.push(""),o++;continue}if(ha(r,o)){let b=Sr(r,o,n);i.push(b.text),o=b.next;continue}let h=/^(#{1,6})\s+(.*)$/.exec(f);if(h){let b=h[1].length,$=De(h[2].trim(),n);i.push(b<=2?n.heading($):n.bold($)),o++;continue}if(/^\s*([-*_])(\s*\1){2,}\s*$/.test(f)){i.push(n.hr("\u2500".repeat(40))),o++;continue}let p=/^\s*>\s?(.*)$/.exec(f);if(p){i.push(n.quote("\u2502 "+De(p[1],n))),o++;continue}let m=/^(\s*)[-*+]\s+(.*)$/.exec(f),w=/^(\s*)(\d+)[.)]\s+(.*)$/.exec(f);if(m||w){let b=(m||w)[1],$=" ".repeat(Math.floor(b.length/2));m?i.push($+n.bullet("\u2022")+" "+De(m[2],n)):i.push($+n.bullet(w[2]+".")+" "+De(w[3],n)),o++;continue}i.push(De(f,n)),o++}return a&&i.push(br(l.join(`
19
19
  `),u,n)),i.join(`
20
- `)}function hr(e,t,n){let r=pr(e,t,n).split(`
20
+ `)}function br(e,t,n){let r=wr(e,t,n).split(`
21
21
  `),i=t?n.codeBorder(" "+t+" "):"",o=n.codeBorder("\u256D"+"\u2500".repeat(2)+i+"\u2500".repeat(4)),a=n.codeBorder("\u2570"+"\u2500".repeat(40)),u=r.map(function(l){return n.codeBorder("\u2502 ")+l});return[o].concat(u,[a]).join(`
22
- `)}yr.exports={renderBlock:na,highlightCode:pr,renderInline:Ce,isSepRow:mr,renderTable:gr,mk:At}});var Sr=me((Hu,Nn)=>{var Lt=process||{},wr=Lt.argv||[],Ft=Lt.env||{},sa=!(Ft.NO_COLOR||wr.includes("--no-color"))&&(!!Ft.FORCE_COLOR||wr.includes("--color")||Lt.platform==="win32"||(Lt.stdout||{}).isTTY&&Ft.TERM!=="dumb"||!!Ft.CI),ra=(e,t,n=e)=>s=>{let r=""+s,i=r.indexOf(t,e.length);return~i?e+ia(r,t,n,i)+t:e+r+t},ia=(e,t,n,s)=>{let r="",i=0;do r+=e.substring(i,s)+n,i=s+t.length,s=e.indexOf(t,i);while(~s);return r+e.substring(i)},$r=(e=sa)=>{let t=e?ra:()=>String;return{isColorSupported:e,reset:t("\x1B[0m","\x1B[0m"),bold:t("\x1B[1m","\x1B[22m","\x1B[22m\x1B[1m"),dim:t("\x1B[2m","\x1B[22m","\x1B[22m\x1B[2m"),italic:t("\x1B[3m","\x1B[23m"),underline:t("\x1B[4m","\x1B[24m"),inverse:t("\x1B[7m","\x1B[27m"),hidden:t("\x1B[8m","\x1B[28m"),strikethrough:t("\x1B[9m","\x1B[29m"),black:t("\x1B[30m","\x1B[39m"),red:t("\x1B[31m","\x1B[39m"),green:t("\x1B[32m","\x1B[39m"),yellow:t("\x1B[33m","\x1B[39m"),blue:t("\x1B[34m","\x1B[39m"),magenta:t("\x1B[35m","\x1B[39m"),cyan:t("\x1B[36m","\x1B[39m"),white:t("\x1B[37m","\x1B[39m"),gray:t("\x1B[90m","\x1B[39m"),bgBlack:t("\x1B[40m","\x1B[49m"),bgRed:t("\x1B[41m","\x1B[49m"),bgGreen:t("\x1B[42m","\x1B[49m"),bgYellow:t("\x1B[43m","\x1B[49m"),bgBlue:t("\x1B[44m","\x1B[49m"),bgMagenta:t("\x1B[45m","\x1B[49m"),bgCyan:t("\x1B[46m","\x1B[49m"),bgWhite:t("\x1B[47m","\x1B[49m"),blackBright:t("\x1B[90m","\x1B[39m"),redBright:t("\x1B[91m","\x1B[39m"),greenBright:t("\x1B[92m","\x1B[39m"),yellowBright:t("\x1B[93m","\x1B[39m"),blueBright:t("\x1B[94m","\x1B[39m"),magentaBright:t("\x1B[95m","\x1B[39m"),cyanBright:t("\x1B[96m","\x1B[39m"),whiteBright:t("\x1B[97m","\x1B[39m"),bgBlackBright:t("\x1B[100m","\x1B[49m"),bgRedBright:t("\x1B[101m","\x1B[49m"),bgGreenBright:t("\x1B[102m","\x1B[49m"),bgYellowBright:t("\x1B[103m","\x1B[49m"),bgBlueBright:t("\x1B[104m","\x1B[49m"),bgMagentaBright:t("\x1B[105m","\x1B[49m"),bgCyanBright:t("\x1B[106m","\x1B[49m"),bgWhiteBright:t("\x1B[107m","\x1B[49m")}};Nn.exports=$r();Nn.exports.createColors=$r});var vr,xr,_r,kr=Ge(()=>{vr=(()=>{let e=/[\uD800-\uDBFF][\uDC00-\uDFFF]/g;return t=>{let n=0;for(e.lastIndex=0;e.test(t);)n+=1;return t.length-n}})(),xr=e=>e===12288||e>=65281&&e<=65376||e>=65504&&e<=65510,_r=e=>e===8987||e===9001||e>=12272&&e<=12287||e>=12289&&e<=12350||e>=12441&&e<=12543||e>=12549&&e<=12591||e>=12593&&e<=12686||e>=12688&&e<=12771||e>=12783&&e<=12830||e>=12832&&e<=12871||e>=12880&&e<=19903||e>=65040&&e<=65049||e>=65072&&e<=65106||e>=65108&&e<=65126||e>=65128&&e<=65131||e>=127488&&e<=127490||e>=127504&&e<=127547||e>=127552&&e<=127560||e>=131072&&e<=196605||e>=196608&&e<=262141});var oa,aa,Er,ua,Ir,la,ca,fa,Or,Tr,jr=Ge(()=>{kr();oa=/[\u001b\u009b][[()#;?]*(?:[0-9]{1,4}(?:;[0-9]{0,4})*)?[0-9A-ORZcf-nqry=><]|\u001b\]8;[^;]*;.*?(?:\u0007|\u001b\u005c)/y,aa=/[\x00-\x08\x0A-\x1F\x7F-\x9F]{1,1000}/y,Er=/(?:(?![\uFF61-\uFF9F\uFF00-\uFFEF])[\p{Script=Han}\p{Script=Hiragana}\p{Script=Katakana}\p{Script=Hangul}\p{Script=Tangut}]){1,1000}/yu,ua=/\t{1,1000}/y,Ir=new RegExp("[\\u{1F1E6}-\\u{1F1FF}]{2}|\\u{1F3F4}[\\u{E0061}-\\u{E007A}]{2}[\\u{E0030}-\\u{E0039}\\u{E0061}-\\u{E007A}]{1,3}\\u{E007F}|(?:\\p{Emoji}\\uFE0F\\u20E3?|\\p{Emoji_Modifier_Base}\\p{Emoji_Modifier}?|\\p{Emoji_Presentation})(?:\\u200D(?:\\p{Emoji_Modifier_Base}\\p{Emoji_Modifier}?|\\p{Emoji_Presentation}|\\p{Emoji}\\uFE0F\\u20E3?))*","yu"),la=/(?:[\x20-\x7E\xA0-\xFF](?!\uFE0F)){1,1000}/y,ca=new RegExp("\\p{M}+","gu"),fa={limit:1/0,ellipsis:""},Or=(e,t={},n={})=>{let s=t.limit??1/0,r=t.ellipsis??"",i=t?.ellipsisWidth??(r?Or(r,fa,n).width:0),o=0,a=n.controlWidth??0,u=n.tabWidth??8,l=n.emojiWidth??2,f=2,d=n.regularWidth??1,h=n.wideWidth??f,p=[[la,d],[oa,o],[aa,a],[ua,u],[Ir,l],[Er,h]],m=0,w=0,b=e.length,$=0,k=!1,T=b,F=Math.max(0,s-i),j=0,L=0,M=0,C=0;e:for(;;){if(L>j||w>=b&&w>m){let N=e.slice(j,L)||e.slice(m,w);$=0;for(let U of N.replaceAll(ca,"")){let R=U.codePointAt(0)||0;if(xr(R)?C=f:_r(R)?C=h:C=d,M+C>F&&(T=Math.min(T,Math.max(j,m)+$)),M+C>s){k=!0;break e}$+=U.length,M+=C}j=L=0}if(w>=b)break e;for(let N=0,U=p.length;N<U;N++){let[R,Z]=p[N];if(R.lastIndex=w,R.test(e)){if($=R===Er?vr(e.slice(w,R.lastIndex)):R===Ir?1:R.lastIndex-w,C=$*Z,M+C>F&&(T=Math.min(T,w+Math.floor((F-M)/Z))),M+C>s){k=!0;break e}M+=C,j=m,L=w,w=m=R.lastIndex;continue e}}w+=1}return{width:k?F:M,index:k?T:b,truncated:k,ellipsed:k&&s>=i}},Tr=Or});var da,ha,Q,Dn=Ge(()=>{jr();da={limit:1/0,ellipsis:"",ellipsisWidth:0},ha=(e,t={})=>Tr(e,da,t).width,Q=ha});function we(e,t,n){return String(e).normalize().split(ba).map(s=>ya(s,t,n)).join(`
23
- `)}var Ct,Cr,pa,qn,Nr,ma,Dr,Pn,Mr,Ar,Fr,Lr,Rn,ga,ya,ba,Bn=Ge(()=>{Dn();Ct="\x1B",Cr="\x9B",pa=39,qn="\x07",Nr="[",ma="]",Dr="m",Pn=`${ma}8;;`,Mr=new RegExp(`(?:\\${Nr}(?<code>\\d+)m|\\${Pn}(?<uri>.*)${qn})`,"y"),Ar=e=>{if(e>=30&&e<=37||e>=90&&e<=97)return 39;if(e>=40&&e<=47||e>=100&&e<=107)return 49;if(e===1||e===2)return 22;if(e===3)return 23;if(e===4)return 24;if(e===7)return 27;if(e===8)return 28;if(e===9)return 29;if(e===0)return 0},Fr=e=>`${Ct}${Nr}${e}${Dr}`,Lr=e=>`${Ct}${Pn}${e}${qn}`,Rn=(e,t,n)=>{let s=t[Symbol.iterator](),r=!1,i=!1,o=e.at(-1),a=o===void 0?0:Q(o),u=s.next(),l=s.next(),f=0;for(;!u.done;){let d=u.value,h=Q(d);a+h<=n?e[e.length-1]+=d:(e.push(d),a=0),(d===Ct||d===Cr)&&(r=!0,i=t.startsWith(Pn,f+1)),r?i?d===qn&&(r=!1,i=!1):d===Dr&&(r=!1):(a+=h,a===n&&!l.done&&(e.push(""),a=0)),u=l,l=s.next(),f+=d.length}o=e.at(-1),!a&&o!==void 0&&o.length&&e.length>1&&(e[e.length-2]+=e.pop())},ga=e=>{let t=e.split(" "),n=t.length;for(;n&&!Q(t[n-1]);)n--;return n===t.length?e:t.slice(0,n).join(" ")+t.slice(n).join("")},ya=(e,t,n={})=>{if(n.trim!==!1&&e.trim()==="")return"";let s="",r,i,o=e.split(" "),a=[""],u=0;for(let d=0;d<o.length;d++){let h=o[d];if(n.trim!==!1){let m=a.at(-1)??"",w=m.trimStart();m.length!==w.length&&(a[a.length-1]=w,u=Q(w))}d!==0&&(u>=t&&(n.wordWrap===!1||n.trim===!1)&&(a.push(""),u=0),(u||n.trim===!1)&&(a[a.length-1]+=" ",u++));let p=Q(h);if(n.hard&&p>t){let m=t-u,w=1+Math.floor((p-m-1)/t);Math.floor((p-1)/t)<w&&a.push(""),Rn(a,h,t),u=Q(a.at(-1)??"");continue}if(u+p>t&&u&&p){if(n.wordWrap===!1&&u<t){Rn(a,h,t),u=Q(a.at(-1)??"");continue}a.push(""),u=0}if(u+p>t&&n.wordWrap===!1){Rn(a,h,t),u=Q(a.at(-1)??"");continue}a[a.length-1]+=h,u+=p}n.trim!==!1&&(a=a.map(d=>ga(d)));let l=a.join(`
24
- `),f=!1;for(let d=0;d<l.length;d++){let h=l[d];if(s+=h,f)f=!1;else if(f=h>="\uD800"&&h<="\uDBFF",f)continue;if(h===Ct||h===Cr){Mr.lastIndex=d+1;let m=Mr.exec(l)?.groups;if(m?.code!==void 0){let w=Number.parseFloat(m.code);r=w===pa?void 0:w}else m?.uri!==void 0&&(i=m.uri.length===0?void 0:m.uri)}if(l[d+1]===`
25
- `){i&&(s+=Lr(""));let p=r?Ar(r):void 0;r&&p&&(s+=Fr(p))}else h===`
26
- `&&(r&&Ar(r)&&(s+=Fr(r)),i&&(s+=Lr(i)))}return s},ba=/\r?\n/});var Wn=me((el,Rr)=>{"use strict";var Vn="\x1B",K=`${Vn}[`,wa="\x07",Un={to(e,t){return t?`${K}${t+1};${e+1}H`:`${K}${e+1}G`},move(e,t){let n="";return e<0?n+=`${K}${-e}D`:e>0&&(n+=`${K}${e}C`),t<0?n+=`${K}${-t}A`:t>0&&(n+=`${K}${t}B`),n},up:(e=1)=>`${K}${e}A`,down:(e=1)=>`${K}${e}B`,forward:(e=1)=>`${K}${e}C`,backward:(e=1)=>`${K}${e}D`,nextLine:(e=1)=>`${K}E`.repeat(e),prevLine:(e=1)=>`${K}F`.repeat(e),left:`${K}G`,hide:`${K}?25l`,show:`${K}?25h`,save:`${Vn}7`,restore:`${Vn}8`},$a={up:(e=1)=>`${K}S`.repeat(e),down:(e=1)=>`${K}T`.repeat(e)},Sa={screen:`${K}2J`,up:(e=1)=>`${K}1J`.repeat(e),down:(e=1)=>`${K}J`.repeat(e),line:`${K}2K`,lineEnd:`${K}K`,lineStart:`${K}1K`,lines(e){let t="";for(let n=0;n<e;n++)t+=this.line+(n<e-1?Un.up():"");return e&&(t+=Un.left),t}};Rr.exports={cursor:Un,scroll:$a,erase:Sa,beep:wa}});function ve(e,t,n){if(!n.some(o=>!o.disabled))return e;let s=e+t,r=Math.max(n.length-1,0),i=s<0?r:s>r?0:s;return n[i]?.disabled?ve(i,t<0?-1:1,n):i}function Nt(e,t,n,s){let r=s.split(`
27
- `),i=0,o=e;for(let u of r){if(o<=u.length)break;o-=u.length+1,i++}for(i=Math.max(0,Math.min(r.length-1,i+n)),o=Math.min(o,r[i].length)+t;o<0&&i>0;)i--,o+=r[i].length+1;for(;o>r[i].length&&i<r.length-1;)o-=r[i].length+1,i++;o=Math.max(0,Math.min(r[i].length,o));let a=0;for(let u=0;u<i;u++)a+=r[u].length+1;return a+o}function Vr(e){if(e.aliases!==void 0){let t=e.aliases;for(let n in t){if(!Object.hasOwn(t,n))continue;let s=t[n];s===void 0||!I.actions.has(s)||I.aliases.has(n)||I.aliases.set(n,s)}}if(e.messages!==void 0){let t=e.messages;t.cancel!==void 0&&(I.messages.cancel=t.cancel),t.error!==void 0&&(I.messages.error=t.error)}if(e.withGuide!==void 0&&(I.withGuide=e.withGuide!==!1),e.accessible!==void 0&&(I.accessible=e.accessible===!0),e.date!==void 0){let t=e.date;t.monthNames!==void 0&&(I.date.monthNames=[...t.monthNames]),t.messages!==void 0&&(t.messages.required!==void 0&&(I.date.messages.required=t.messages.required),t.messages.invalidMonth!==void 0&&(I.date.messages.invalidMonth=t.messages.invalidMonth),t.messages.invalidDay!==void 0&&(I.date.messages.invalidDay=t.messages.invalidDay),t.messages.afterMin!==void 0&&(I.date.messages.afterMin=t.messages.afterMin),t.messages.beforeMax!==void 0&&(I.date.messages.beforeMax=t.messages.beforeMax))}}function _a(e){if(e!==void 0)return e;if(I.accessible!==void 0)return I.accessible;let t=process.env.ACCESSIBLE;return t!==void 0&&t!==""&&t!=="0"&&t!=="false"}function Jn(e,t){if(typeof e=="string")return I.aliases.get(e)===t;for(let n of e)if(n!==void 0&&Jn(n,t))return!0;return!1}function ka(e,t){if(e===t)return;let n=e.split(`
22
+ `)}vr.exports={renderBlock:ma,highlightCode:wr,renderInline:De,isSepRow:$r,renderTable:Sr,mk:Nt}});var Er=ge((il,Vn)=>{var Dt=process||{},xr=Dt.argv||[],Ct=Dt.env||{},ga=!(Ct.NO_COLOR||xr.includes("--no-color"))&&(!!Ct.FORCE_COLOR||xr.includes("--color")||Dt.platform==="win32"||(Dt.stdout||{}).isTTY&&Ct.TERM!=="dumb"||!!Ct.CI),ya=(e,t,n=e)=>s=>{let r=""+s,i=r.indexOf(t,e.length);return~i?e+ba(r,t,n,i)+t:e+r+t},ba=(e,t,n,s)=>{let r="",i=0;do r+=e.substring(i,s)+n,i=s+t.length,s=e.indexOf(t,i);while(~s);return r+e.substring(i)},_r=(e=ga)=>{let t=e?ya:()=>String;return{isColorSupported:e,reset:t("\x1B[0m","\x1B[0m"),bold:t("\x1B[1m","\x1B[22m","\x1B[22m\x1B[1m"),dim:t("\x1B[2m","\x1B[22m","\x1B[22m\x1B[2m"),italic:t("\x1B[3m","\x1B[23m"),underline:t("\x1B[4m","\x1B[24m"),inverse:t("\x1B[7m","\x1B[27m"),hidden:t("\x1B[8m","\x1B[28m"),strikethrough:t("\x1B[9m","\x1B[29m"),black:t("\x1B[30m","\x1B[39m"),red:t("\x1B[31m","\x1B[39m"),green:t("\x1B[32m","\x1B[39m"),yellow:t("\x1B[33m","\x1B[39m"),blue:t("\x1B[34m","\x1B[39m"),magenta:t("\x1B[35m","\x1B[39m"),cyan:t("\x1B[36m","\x1B[39m"),white:t("\x1B[37m","\x1B[39m"),gray:t("\x1B[90m","\x1B[39m"),bgBlack:t("\x1B[40m","\x1B[49m"),bgRed:t("\x1B[41m","\x1B[49m"),bgGreen:t("\x1B[42m","\x1B[49m"),bgYellow:t("\x1B[43m","\x1B[49m"),bgBlue:t("\x1B[44m","\x1B[49m"),bgMagenta:t("\x1B[45m","\x1B[49m"),bgCyan:t("\x1B[46m","\x1B[49m"),bgWhite:t("\x1B[47m","\x1B[49m"),blackBright:t("\x1B[90m","\x1B[39m"),redBright:t("\x1B[91m","\x1B[39m"),greenBright:t("\x1B[92m","\x1B[39m"),yellowBright:t("\x1B[93m","\x1B[39m"),blueBright:t("\x1B[94m","\x1B[39m"),magentaBright:t("\x1B[95m","\x1B[39m"),cyanBright:t("\x1B[96m","\x1B[39m"),whiteBright:t("\x1B[97m","\x1B[39m"),bgBlackBright:t("\x1B[100m","\x1B[49m"),bgRedBright:t("\x1B[101m","\x1B[49m"),bgGreenBright:t("\x1B[102m","\x1B[49m"),bgYellowBright:t("\x1B[103m","\x1B[49m"),bgBlueBright:t("\x1B[104m","\x1B[49m"),bgMagentaBright:t("\x1B[105m","\x1B[49m"),bgCyanBright:t("\x1B[106m","\x1B[49m"),bgWhiteBright:t("\x1B[107m","\x1B[49m")}};Vn.exports=_r();Vn.exports.createColors=_r});var Or,Tr,Ir,jr=Xe(()=>{Or=(()=>{let e=/[\uD800-\uDBFF][\uDC00-\uDFFF]/g;return t=>{let n=0;for(e.lastIndex=0;e.test(t);)n+=1;return t.length-n}})(),Tr=e=>e===12288||e>=65281&&e<=65376||e>=65504&&e<=65510,Ir=e=>e===8987||e===9001||e>=12272&&e<=12287||e>=12289&&e<=12350||e>=12441&&e<=12543||e>=12549&&e<=12591||e>=12593&&e<=12686||e>=12688&&e<=12771||e>=12783&&e<=12830||e>=12832&&e<=12871||e>=12880&&e<=19903||e>=65040&&e<=65049||e>=65072&&e<=65106||e>=65108&&e<=65126||e>=65128&&e<=65131||e>=127488&&e<=127490||e>=127504&&e<=127547||e>=127552&&e<=127560||e>=131072&&e<=196605||e>=196608&&e<=262141});var wa,$a,Mr,Sa,Ar,va,ka,xa,Fr,Lr,Nr=Xe(()=>{jr();wa=/[\u001b\u009b][[()#;?]*(?:[0-9]{1,4}(?:;[0-9]{0,4})*)?[0-9A-ORZcf-nqry=><]|\u001b\]8;[^;]*;.*?(?:\u0007|\u001b\u005c)/y,$a=/[\x00-\x08\x0A-\x1F\x7F-\x9F]{1,1000}/y,Mr=/(?:(?![\uFF61-\uFF9F\uFF00-\uFFEF])[\p{Script=Han}\p{Script=Hiragana}\p{Script=Katakana}\p{Script=Hangul}\p{Script=Tangut}]){1,1000}/yu,Sa=/\t{1,1000}/y,Ar=new RegExp("[\\u{1F1E6}-\\u{1F1FF}]{2}|\\u{1F3F4}[\\u{E0061}-\\u{E007A}]{2}[\\u{E0030}-\\u{E0039}\\u{E0061}-\\u{E007A}]{1,3}\\u{E007F}|(?:\\p{Emoji}\\uFE0F\\u20E3?|\\p{Emoji_Modifier_Base}\\p{Emoji_Modifier}?|\\p{Emoji_Presentation})(?:\\u200D(?:\\p{Emoji_Modifier_Base}\\p{Emoji_Modifier}?|\\p{Emoji_Presentation}|\\p{Emoji}\\uFE0F\\u20E3?))*","yu"),va=/(?:[\x20-\x7E\xA0-\xFF](?!\uFE0F)){1,1000}/y,ka=new RegExp("\\p{M}+","gu"),xa={limit:1/0,ellipsis:""},Fr=(e,t={},n={})=>{let s=t.limit??1/0,r=t.ellipsis??"",i=t?.ellipsisWidth??(r?Fr(r,xa,n).width:0),o=0,a=n.controlWidth??0,u=n.tabWidth??8,l=n.emojiWidth??2,f=2,d=n.regularWidth??1,h=n.wideWidth??f,p=[[va,d],[wa,o],[$a,a],[Sa,u],[Ar,l],[Mr,h]],m=0,w=0,b=e.length,$=0,_=!1,I=b,F=Math.max(0,s-i),j=0,L=0,M=0,N=0;e:for(;;){if(L>j||w>=b&&w>m){let C=e.slice(j,L)||e.slice(m,w);$=0;for(let U of C.replaceAll(ka,"")){let q=U.codePointAt(0)||0;if(Tr(q)?N=f:Ir(q)?N=h:N=d,M+N>F&&(I=Math.min(I,Math.max(j,m)+$)),M+N>s){_=!0;break e}$+=U.length,M+=N}j=L=0}if(w>=b)break e;for(let C=0,U=p.length;C<U;C++){let[q,ee]=p[C];if(q.lastIndex=w,q.test(e)){if($=q===Mr?Or(e.slice(w,q.lastIndex)):q===Ar?1:q.lastIndex-w,N=$*ee,M+N>F&&(I=Math.min(I,w+Math.floor((F-M)/ee))),M+N>s){_=!0;break e}M+=N,j=m,L=w,w=m=q.lastIndex;continue e}}w+=1}return{width:_?F:M,index:_?I:b,truncated:_,ellipsed:_&&s>=i}},Lr=Fr});var _a,Ea,Q,Un=Xe(()=>{Nr();_a={limit:1/0,ellipsis:"",ellipsisWidth:0},Ea=(e,t={})=>Lr(e,_a,t).width,Q=Ea});function $e(e,t,n){return String(e).normalize().split(Ma).map(s=>ja(s,t,n)).join(`
23
+ `)}var qt,Pr,Oa,Gn,Br,Ta,Vr,Hn,Cr,Dr,qr,Rr,Wn,Ia,ja,Ma,Kn=Xe(()=>{Un();qt="\x1B",Pr="\x9B",Oa=39,Gn="\x07",Br="[",Ta="]",Vr="m",Hn=`${Ta}8;;`,Cr=new RegExp(`(?:\\${Br}(?<code>\\d+)m|\\${Hn}(?<uri>.*)${Gn})`,"y"),Dr=e=>{if(e>=30&&e<=37||e>=90&&e<=97)return 39;if(e>=40&&e<=47||e>=100&&e<=107)return 49;if(e===1||e===2)return 22;if(e===3)return 23;if(e===4)return 24;if(e===7)return 27;if(e===8)return 28;if(e===9)return 29;if(e===0)return 0},qr=e=>`${qt}${Br}${e}${Vr}`,Rr=e=>`${qt}${Hn}${e}${Gn}`,Wn=(e,t,n)=>{let s=t[Symbol.iterator](),r=!1,i=!1,o=e.at(-1),a=o===void 0?0:Q(o),u=s.next(),l=s.next(),f=0;for(;!u.done;){let d=u.value,h=Q(d);a+h<=n?e[e.length-1]+=d:(e.push(d),a=0),(d===qt||d===Pr)&&(r=!0,i=t.startsWith(Hn,f+1)),r?i?d===Gn&&(r=!1,i=!1):d===Vr&&(r=!1):(a+=h,a===n&&!l.done&&(e.push(""),a=0)),u=l,l=s.next(),f+=d.length}o=e.at(-1),!a&&o!==void 0&&o.length&&e.length>1&&(e[e.length-2]+=e.pop())},Ia=e=>{let t=e.split(" "),n=t.length;for(;n&&!Q(t[n-1]);)n--;return n===t.length?e:t.slice(0,n).join(" ")+t.slice(n).join("")},ja=(e,t,n={})=>{if(n.trim!==!1&&e.trim()==="")return"";let s="",r,i,o=e.split(" "),a=[""],u=0;for(let d=0;d<o.length;d++){let h=o[d];if(n.trim!==!1){let m=a.at(-1)??"",w=m.trimStart();m.length!==w.length&&(a[a.length-1]=w,u=Q(w))}d!==0&&(u>=t&&(n.wordWrap===!1||n.trim===!1)&&(a.push(""),u=0),(u||n.trim===!1)&&(a[a.length-1]+=" ",u++));let p=Q(h);if(n.hard&&p>t){let m=t-u,w=1+Math.floor((p-m-1)/t);Math.floor((p-1)/t)<w&&a.push(""),Wn(a,h,t),u=Q(a.at(-1)??"");continue}if(u+p>t&&u&&p){if(n.wordWrap===!1&&u<t){Wn(a,h,t),u=Q(a.at(-1)??"");continue}a.push(""),u=0}if(u+p>t&&n.wordWrap===!1){Wn(a,h,t),u=Q(a.at(-1)??"");continue}a[a.length-1]+=h,u+=p}n.trim!==!1&&(a=a.map(d=>Ia(d)));let l=a.join(`
24
+ `),f=!1;for(let d=0;d<l.length;d++){let h=l[d];if(s+=h,f)f=!1;else if(f=h>="\uD800"&&h<="\uDBFF",f)continue;if(h===qt||h===Pr){Cr.lastIndex=d+1;let m=Cr.exec(l)?.groups;if(m?.code!==void 0){let w=Number.parseFloat(m.code);r=w===Oa?void 0:w}else m?.uri!==void 0&&(i=m.uri.length===0?void 0:m.uri)}if(l[d+1]===`
25
+ `){i&&(s+=Rr(""));let p=r?Dr(r):void 0;r&&p&&(s+=qr(p))}else h===`
26
+ `&&(r&&Dr(r)&&(s+=qr(r)),i&&(s+=Rr(i)))}return s},Ma=/\r?\n/});var zn=ge((hl,Ur)=>{"use strict";var Jn="\x1B",J=`${Jn}[`,Aa="\x07",Xn={to(e,t){return t?`${J}${t+1};${e+1}H`:`${J}${e+1}G`},move(e,t){let n="";return e<0?n+=`${J}${-e}D`:e>0&&(n+=`${J}${e}C`),t<0?n+=`${J}${-t}A`:t>0&&(n+=`${J}${t}B`),n},up:(e=1)=>`${J}${e}A`,down:(e=1)=>`${J}${e}B`,forward:(e=1)=>`${J}${e}C`,backward:(e=1)=>`${J}${e}D`,nextLine:(e=1)=>`${J}E`.repeat(e),prevLine:(e=1)=>`${J}F`.repeat(e),left:`${J}G`,hide:`${J}?25l`,show:`${J}?25h`,save:`${Jn}7`,restore:`${Jn}8`},Fa={up:(e=1)=>`${J}S`.repeat(e),down:(e=1)=>`${J}T`.repeat(e)},La={screen:`${J}2J`,up:(e=1)=>`${J}1J`.repeat(e),down:(e=1)=>`${J}J`.repeat(e),line:`${J}2K`,lineEnd:`${J}K`,lineStart:`${J}1K`,lines(e){let t="";for(let n=0;n<e;n++)t+=this.line+(n<e-1?Xn.up():"");return e&&(t+=Xn.left),t}};Ur.exports={cursor:Xn,scroll:Fa,erase:La,beep:Aa}});function xe(e,t,n){if(!n.some(o=>!o.disabled))return e;let s=e+t,r=Math.max(n.length-1,0),i=s<0?r:s>r?0:s;return n[i]?.disabled?xe(i,t<0?-1:1,n):i}function Rt(e,t,n,s){let r=s.split(`
27
+ `),i=0,o=e;for(let u of r){if(o<=u.length)break;o-=u.length+1,i++}for(i=Math.max(0,Math.min(r.length-1,i+n)),o=Math.min(o,r[i].length)+t;o<0&&i>0;)i--,o+=r[i].length+1;for(;o>r[i].length&&i<r.length-1;)o-=r[i].length+1,i++;o=Math.max(0,Math.min(r[i].length,o));let a=0;for(let u=0;u<i;u++)a+=r[u].length+1;return a+o}function Kr(e){if(e.aliases!==void 0){let t=e.aliases;for(let n in t){if(!Object.hasOwn(t,n))continue;let s=t[n];s===void 0||!O.actions.has(s)||O.aliases.has(n)||O.aliases.set(n,s)}}if(e.messages!==void 0){let t=e.messages;t.cancel!==void 0&&(O.messages.cancel=t.cancel),t.error!==void 0&&(O.messages.error=t.error)}if(e.withGuide!==void 0&&(O.withGuide=e.withGuide!==!1),e.accessible!==void 0&&(O.accessible=e.accessible===!0),e.date!==void 0){let t=e.date;t.monthNames!==void 0&&(O.date.monthNames=[...t.monthNames]),t.messages!==void 0&&(t.messages.required!==void 0&&(O.date.messages.required=t.messages.required),t.messages.invalidMonth!==void 0&&(O.date.messages.invalidMonth=t.messages.invalidMonth),t.messages.invalidDay!==void 0&&(O.date.messages.invalidDay=t.messages.invalidDay),t.messages.afterMin!==void 0&&(O.date.messages.afterMin=t.messages.afterMin),t.messages.beforeMax!==void 0&&(O.date.messages.beforeMax=t.messages.beforeMax))}}function Da(e){if(e!==void 0)return e;if(O.accessible!==void 0)return O.accessible;let t=process.env.ACCESSIBLE;return t!==void 0&&t!==""&&t!=="0"&&t!=="false"}function es(e,t){if(typeof e=="string")return O.aliases.get(e)===t;for(let n of e)if(n!==void 0&&es(n,t))return!0;return!1}function qa(e,t){if(e===t)return;let n=e.split(`
28
28
  `),s=t.split(`
29
- `),r=Math.max(n.length,s.length),i=[];for(let o=0;o<r;o++)n[o]!==s[o]&&i.push(o);return{lines:i,numLinesBefore:n.length,numLinesAfter:s.length,numLines:r}}function Gt(e){return e===ft}function Dt(e,t){let n=e;n.isTTY&&n.setRawMode(t)}function Ur({input:e=De.stdin,output:t=De.stdout,overwrite:n=!0,hideCursor:s=!0}={}){let r=Oe.createInterface({input:e,output:t,prompt:"",tabSize:1});Oe.emitKeypressEvents(e,r),e instanceof Hn.ReadStream&&e.isTTY&&e.setRawMode(!0);let i=(o,{name:a,sequence:u})=>{let l=String(o);if(Jn([l,a,u],"cancel")){s&&t.write(re.cursor.show),process.exit(0);return}if(!n)return;Oe.moveCursor(t,a==="return"?0:-1,a==="return"?-1:0,()=>{Oe.clearLine(t,1,()=>{e.once("keypress",i)})})};return s&&t.write(re.cursor.hide),e.once("keypress",i),()=>{e.off("keypress",i),s&&t.write(re.cursor.show),e instanceof Hn.ReadStream&&e.isTTY&&!Ea&&e.setRawMode(!1),r.terminal=!1,r.close()}}function X(e,t,n,s=n,r=n,i){let o=Re(e??De.stdout);return we(t,o-n.length,{hard:!0,trim:!1}).split(`
29
+ `),r=Math.max(n.length,s.length),i=[];for(let o=0;o<r;o++)n[o]!==s[o]&&i.push(o);return{lines:i,numLinesBefore:n.length,numLinesAfter:s.length,numLines:r}}function Jt(e){return e===ht}function Pt(e,t){let n=e;n.isTTY&&n.setRawMode(t)}function Jr({input:e=Re.stdin,output:t=Re.stdout,overwrite:n=!0,hideCursor:s=!0}={}){let r=je.createInterface({input:e,output:t,prompt:"",tabSize:1});je.emitKeypressEvents(e,r),e instanceof Zn.ReadStream&&e.isTTY&&e.setRawMode(!0);let i=(o,{name:a,sequence:u})=>{let l=String(o);if(es([l,a,u],"cancel")){s&&t.write(ie.cursor.show),process.exit(0);return}if(!n)return;je.moveCursor(t,a==="return"?0:-1,a==="return"?-1:0,()=>{je.clearLine(t,1,()=>{e.once("keypress",i)})})};return s&&t.write(ie.cursor.hide),e.once("keypress",i),()=>{e.off("keypress",i),s&&t.write(ie.cursor.show),e instanceof Zn.ReadStream&&e.isTTY&&!Ra&&e.setRawMode(!1),r.terminal=!1,r.close()}}function z(e,t,n,s=n,r=n,i){let o=Pe(e??Re.stdout);return $e(t,o-n.length,{hard:!0,trim:!1}).split(`
30
30
  `).map((a,u,l)=>{let f=i?i(a,u):a;return u===0?`${s}${f}`:u===l.length-1?`${r}${f}`:`${n}${f}`}).join(`
31
- `)}function dt(e,t){if("~standard"in e){let n=e["~standard"].validate(t);return n instanceof Promise?n.then(s=>s.issues?.at(0)?.message):n.issues?.at(0)?.message}return e(t)}function Ia(e,t){if(e===void 0||t.length===0)return 0;let n=t.findIndex(s=>s.value===e);return n!==-1?n:0}function Oa(e,t){return(t.label??String(t.value)).toLowerCase().includes(e.toLowerCase())}function Ta(e,t){if(t)return e?t:t[0]}function qr(e){return[...e].map(t=>ja[t])}function Ma(e){let t=new Intl.DateTimeFormat(e,{year:"numeric",month:"2-digit",day:"2-digit"}).formatToParts(new Date(2e3,0,15)),n=[],s="/";for(let r of t)r.type==="literal"?s=r.value.trim()||r.value:(r.type==="year"||r.type==="month"||r.type==="day")&&n.push({type:r.type,len:r.type==="year"?4:2});return{segments:n,separator:s}}function Gn(e){return Number.parseInt((e||"0").replace(/_/g,"0"),10)||0}function Rt(e){return{year:Gn(e.year),month:Gn(e.month),day:Gn(e.day)}}function Kn(e,t){return new Date(e||2001,t||1,0).getDate()}function Wr(e){let{year:t,month:n,day:s}=Rt(e);if(!t||t<0||t>9999||!n||n<1||n>12||!s||s<1)return;let r=new Date(Date.UTC(t,n-1,s));if(!(r.getUTCFullYear()!==t||r.getUTCMonth()!==n-1||r.getUTCDate()!==s))return{year:t,month:n,day:s}}function Pr(e){let t=Wr(e);return t?new Date(Date.UTC(t.year,t.month-1,t.day)):void 0}function Aa(e,t,n,s){let r=n?{year:n.getUTCFullYear(),month:n.getUTCMonth()+1,day:n.getUTCDate()}:null,i=s?{year:s.getUTCFullYear(),month:s.getUTCMonth()+1,day:s.getUTCDate()}:null;return e==="year"?{min:r?.year??1,max:i?.year??9999}:e==="month"?{min:r&&t.year===r.year?r.month:1,max:i&&t.year===i.year?i.month:12}:{min:r&&t.year===r.year&&t.month===r.month?r.day:1,max:i&&t.year===i.year&&t.month===i.month?i.day:Kn(t.year,t.month)}}var Ne,De,Oe,Br,re,Hn,va,xa,I,Ea,ft,Re,Xn,ye,Yn,qt,ja,Pt,Gr,Fa,Bt,Vt,Hr,Kr,Ut,Wt,zn=Ge(()=>{Ne=require("node:util"),De=require("node:process"),Oe=Qe(require("node:readline"),1),Br=Qe(require("node:readline"),1);Bn();re=Qe(Wn(),1),Hn=require("node:tty");va=["up","down","left","right","space","enter","cancel"],xa=["January","February","March","April","May","June","July","August","September","October","November","December"],I={actions:new Set(va),aliases:new Map([["k","up"],["j","down"],["h","left"],["l","right"],["","cancel"],["escape","cancel"]]),messages:{cancel:"Canceled",error:"Something went wrong"},withGuide:!0,accessible:void 0,date:{monthNames:[...xa],messages:{required:"Please enter a valid date",invalidMonth:"There are only 12 months in a year",invalidDay:(e,t)=>`There are only ${e} days in ${t}`,afterMin:e=>`Date must be on or after ${e.toISOString().slice(0,10)}`,beforeMax:e=>`Date must be on or before ${e.toISOString().slice(0,10)}`}}};Ea=globalThis.process.platform.startsWith("win"),ft=Symbol("clack:cancel");Re=e=>"columns"in e&&typeof e.columns=="number"?e.columns:80,Xn=e=>"rows"in e&&typeof e.rows=="number"?e.rows:20;ye=class{input;output;_abortSignal;rl;opts;_render;_track=!1;_prevFrame="";_subscribers=new Map;_cursor=0;state="initial";error="";value;userInput="";get accessible(){return _a(this.opts.accessible)}constructor(t,n=!0){let{input:s=De.stdin,output:r=De.stdout,render:i,signal:o,...a}=t;this.opts=a,this.onKeypress=this.onKeypress.bind(this),this.close=this.close.bind(this),this.render=this.render.bind(this),this._render=i.bind(this),this._track=n,this._abortSignal=o,this.input=s,this.output=r}unsubscribe(){this._subscribers.clear()}setSubscriber(t,n){let s=this._subscribers.get(t)??[];s.push(n),this._subscribers.set(t,s)}on(t,n){this.setSubscriber(t,{cb:n})}once(t,n){this.setSubscriber(t,{cb:n,once:!0})}emit(t,...n){let s=this._subscribers.get(t)??[],r=[];for(let i of s)i.cb(...n),i.once&&r.push(()=>s.splice(s.indexOf(i),1));for(let i of r)i()}prompt(){return new Promise(t=>{if(this._abortSignal){if(this._abortSignal.aborted)return this.state="cancel",this.close(),t(ft);this._abortSignal.addEventListener("abort",()=>{this.state="cancel",this.close()},{once:!0})}this.rl=Br.default.createInterface({input:this.input,tabSize:2,prompt:"",escapeCodeTimeout:50,terminal:!0}),this.rl.prompt(),this.opts.initialUserInput!==void 0&&this._setUserInput(this.opts.initialUserInput,!0),this.input.on("keypress",this.onKeypress),Dt(this.input,!0),this.output.on("resize",this.render),this.render(),this.once("submit",()=>{this.output.write(re.cursor.show),this.output.off("resize",this.render),Dt(this.input,!1),t(this.value)}),this.once("cancel",()=>{this.output.write(re.cursor.show),this.output.off("resize",this.render),Dt(this.input,!1),t(ft)})})}_isActionKey(t,n){return t===" "}_shouldSubmit(t,n){return!0}_setValue(t){this.value=t,this.emit("value",this.value)}_setUserInput(t,n){this.userInput=t??"",this.emit("userInput",this.userInput),n&&this._track&&this.rl&&(this.rl.write(this.userInput),this._cursor=this.rl.cursor)}_clearUserInput(){this.rl?.write(null,{ctrl:!0,name:"u"}),this._setUserInput("")}async onKeypress(t,n){if(this.state!=="validating"){if(this._track&&n.name!=="return"&&(n.name&&this._isActionKey(t,n)&&this.rl?.write(null,{ctrl:!0,name:"h"}),this._cursor=this.rl?.cursor??0,this._setUserInput(this.rl?.line)),this.state==="error"&&(this.state="active"),n?.name&&(!this._track&&I.aliases.has(n.name)&&this.emit("cursor",I.aliases.get(n.name)),I.actions.has(n.name)&&this.emit("cursor",n.name)),t&&(t.toLowerCase()==="y"||t.toLowerCase()==="n")&&this.emit("confirm",t.toLowerCase()==="y"),this.emit("key",t,n),n?.name==="return"&&this._shouldSubmit(t,n)){if(this.opts.validate){let s=dt(this.opts.validate,this.value),r;s instanceof Promise?(this.state="validating",this.render(),r=await s):r=s,r&&(this.error=r instanceof Error?r.message:r,this.state="error",this.rl?.write(this.userInput))}this.state!=="error"&&(this.state="submit")}Jn([t,n?.name,n?.sequence],"cancel")&&(this.state="cancel"),(this.state==="submit"||this.state==="cancel")&&this.emit("finalize"),this.render(),(this.state==="submit"||this.state==="cancel")&&this.close()}}close(){this.input.unpipe(),this.input.removeListener("keypress",this.onKeypress),this.output.write(`
32
- `),Dt(this.input,!1),this.rl?.close(),this.rl=void 0,this.emit(`${this.state}`,this.value),this.unsubscribe()}restoreCursor(){let t=we(this._prevFrame,process.stdout.columns,{hard:!0,trim:!1}).split(`
33
- `).length-1;this.output.write(re.cursor.move(-999,t*-1))}render(){let t=we(this._render(this)??"",process.stdout.columns,{hard:!0,trim:!1});if(t!==this._prevFrame){if(this.state==="initial")this.output.write(re.cursor.hide);else{let n=ka(this._prevFrame,t),s=Xn(this.output);if(this.restoreCursor(),n){let r=Math.max(0,n.numLinesAfter-s),i=Math.max(0,n.numLinesBefore-s),o=n.lines.find(a=>a>=r);if(o===void 0){this._prevFrame=t;return}if(n.lines.length===1){this.output.write(re.cursor.move(0,o-i)),this.output.write(re.erase.lines(1));let a=t.split(`
34
- `);this.output.write(a[o]),this._prevFrame=t,this.output.write(re.cursor.move(0,a.length-o-1));return}else if(n.lines.length>1){if(r<i)o=r;else{let u=o-i;u>0&&this.output.write(re.cursor.move(0,u))}this.output.write(re.erase.down());let a=t.split(`
31
+ `)}function pt(e,t){if("~standard"in e){let n=e["~standard"].validate(t);return n instanceof Promise?n.then(s=>s.issues?.at(0)?.message):n.issues?.at(0)?.message}return e(t)}function Pa(e,t){if(e===void 0||t.length===0)return 0;let n=t.findIndex(s=>s.value===e);return n!==-1?n:0}function Ba(e,t){return(t.label??String(t.value)).toLowerCase().includes(e.toLowerCase())}function Va(e,t){if(t)return e?t:t[0]}function Wr(e){return[...e].map(t=>Ua[t])}function Wa(e){let t=new Intl.DateTimeFormat(e,{year:"numeric",month:"2-digit",day:"2-digit"}).formatToParts(new Date(2e3,0,15)),n=[],s="/";for(let r of t)r.type==="literal"?s=r.value.trim()||r.value:(r.type==="year"||r.type==="month"||r.type==="day")&&n.push({type:r.type,len:r.type==="year"?4:2});return{segments:n,separator:s}}function Yn(e){return Number.parseInt((e||"0").replace(/_/g,"0"),10)||0}function Bt(e){return{year:Yn(e.year),month:Yn(e.month),day:Yn(e.day)}}function Qn(e,t){return new Date(e||2001,t||1,0).getDate()}function Xr(e){let{year:t,month:n,day:s}=Bt(e);if(!t||t<0||t>9999||!n||n<1||n>12||!s||s<1)return;let r=new Date(Date.UTC(t,n-1,s));if(!(r.getUTCFullYear()!==t||r.getUTCMonth()!==n-1||r.getUTCDate()!==s))return{year:t,month:n,day:s}}function Gr(e){let t=Xr(e);return t?new Date(Date.UTC(t.year,t.month-1,t.day)):void 0}function Ga(e,t,n,s){let r=n?{year:n.getUTCFullYear(),month:n.getUTCMonth()+1,day:n.getUTCDate()}:null,i=s?{year:s.getUTCFullYear(),month:s.getUTCMonth()+1,day:s.getUTCDate()}:null;return e==="year"?{min:r?.year??1,max:i?.year??9999}:e==="month"?{min:r&&t.year===r.year?r.month:1,max:i&&t.year===i.year?i.month:12}:{min:r&&t.year===r.year&&t.month===r.month?r.day:1,max:i&&t.year===i.year&&t.month===i.month?i.day:Qn(t.year,t.month)}}var qe,Re,je,Hr,ie,Zn,Na,Ca,O,Ra,ht,Pe,ts,be,ns,Vt,Ua,Ut,zr,Ha,Wt,Gt,Yr,Zr,Ht,Kt,ss=Xe(()=>{qe=require("node:util"),Re=require("node:process"),je=tt(require("node:readline"),1),Hr=tt(require("node:readline"),1);Kn();ie=tt(zn(),1),Zn=require("node:tty");Na=["up","down","left","right","space","enter","cancel"],Ca=["January","February","March","April","May","June","July","August","September","October","November","December"],O={actions:new Set(Na),aliases:new Map([["k","up"],["j","down"],["h","left"],["l","right"],["","cancel"],["escape","cancel"]]),messages:{cancel:"Canceled",error:"Something went wrong"},withGuide:!0,accessible:void 0,date:{monthNames:[...Ca],messages:{required:"Please enter a valid date",invalidMonth:"There are only 12 months in a year",invalidDay:(e,t)=>`There are only ${e} days in ${t}`,afterMin:e=>`Date must be on or after ${e.toISOString().slice(0,10)}`,beforeMax:e=>`Date must be on or before ${e.toISOString().slice(0,10)}`}}};Ra=globalThis.process.platform.startsWith("win"),ht=Symbol("clack:cancel");Pe=e=>"columns"in e&&typeof e.columns=="number"?e.columns:80,ts=e=>"rows"in e&&typeof e.rows=="number"?e.rows:20;be=class{input;output;_abortSignal;rl;opts;_render;_track=!1;_prevFrame="";_subscribers=new Map;_cursor=0;state="initial";error="";value;userInput="";get accessible(){return Da(this.opts.accessible)}constructor(t,n=!0){let{input:s=Re.stdin,output:r=Re.stdout,render:i,signal:o,...a}=t;this.opts=a,this.onKeypress=this.onKeypress.bind(this),this.close=this.close.bind(this),this.render=this.render.bind(this),this._render=i.bind(this),this._track=n,this._abortSignal=o,this.input=s,this.output=r}unsubscribe(){this._subscribers.clear()}setSubscriber(t,n){let s=this._subscribers.get(t)??[];s.push(n),this._subscribers.set(t,s)}on(t,n){this.setSubscriber(t,{cb:n})}once(t,n){this.setSubscriber(t,{cb:n,once:!0})}emit(t,...n){let s=this._subscribers.get(t)??[],r=[];for(let i of s)i.cb(...n),i.once&&r.push(()=>s.splice(s.indexOf(i),1));for(let i of r)i()}prompt(){return new Promise(t=>{if(this._abortSignal){if(this._abortSignal.aborted)return this.state="cancel",this.close(),t(ht);this._abortSignal.addEventListener("abort",()=>{this.state="cancel",this.close()},{once:!0})}this.rl=Hr.default.createInterface({input:this.input,tabSize:2,prompt:"",escapeCodeTimeout:50,terminal:!0}),this.rl.prompt(),this.opts.initialUserInput!==void 0&&this._setUserInput(this.opts.initialUserInput,!0),this.input.on("keypress",this.onKeypress),Pt(this.input,!0),this.output.on("resize",this.render),this.render(),this.once("submit",()=>{this.output.write(ie.cursor.show),this.output.off("resize",this.render),Pt(this.input,!1),t(this.value)}),this.once("cancel",()=>{this.output.write(ie.cursor.show),this.output.off("resize",this.render),Pt(this.input,!1),t(ht)})})}_isActionKey(t,n){return t===" "}_shouldSubmit(t,n){return!0}_setValue(t){this.value=t,this.emit("value",this.value)}_setUserInput(t,n){this.userInput=t??"",this.emit("userInput",this.userInput),n&&this._track&&this.rl&&(this.rl.write(this.userInput),this._cursor=this.rl.cursor)}_clearUserInput(){this.rl?.write(null,{ctrl:!0,name:"u"}),this._setUserInput("")}async onKeypress(t,n){if(this.state!=="validating"){if(this._track&&n.name!=="return"&&(n.name&&this._isActionKey(t,n)&&this.rl?.write(null,{ctrl:!0,name:"h"}),this._cursor=this.rl?.cursor??0,this._setUserInput(this.rl?.line)),this.state==="error"&&(this.state="active"),n?.name&&(!this._track&&O.aliases.has(n.name)&&this.emit("cursor",O.aliases.get(n.name)),O.actions.has(n.name)&&this.emit("cursor",n.name)),t&&(t.toLowerCase()==="y"||t.toLowerCase()==="n")&&this.emit("confirm",t.toLowerCase()==="y"),this.emit("key",t,n),n?.name==="return"&&this._shouldSubmit(t,n)){if(this.opts.validate){let s=pt(this.opts.validate,this.value),r;s instanceof Promise?(this.state="validating",this.render(),r=await s):r=s,r&&(this.error=r instanceof Error?r.message:r,this.state="error",this.rl?.write(this.userInput))}this.state!=="error"&&(this.state="submit")}es([t,n?.name,n?.sequence],"cancel")&&(this.state="cancel"),(this.state==="submit"||this.state==="cancel")&&this.emit("finalize"),this.render(),(this.state==="submit"||this.state==="cancel")&&this.close()}}close(){this.input.unpipe(),this.input.removeListener("keypress",this.onKeypress),this.output.write(`
32
+ `),Pt(this.input,!1),this.rl?.close(),this.rl=void 0,this.emit(`${this.state}`,this.value),this.unsubscribe()}restoreCursor(){let t=$e(this._prevFrame,process.stdout.columns,{hard:!0,trim:!1}).split(`
33
+ `).length-1;this.output.write(ie.cursor.move(-999,t*-1))}render(){let t=$e(this._render(this)??"",process.stdout.columns,{hard:!0,trim:!1});if(t!==this._prevFrame){if(this.state==="initial")this.output.write(ie.cursor.hide);else{let n=qa(this._prevFrame,t),s=ts(this.output);if(this.restoreCursor(),n){let r=Math.max(0,n.numLinesAfter-s),i=Math.max(0,n.numLinesBefore-s),o=n.lines.find(a=>a>=r);if(o===void 0){this._prevFrame=t;return}if(n.lines.length===1){this.output.write(ie.cursor.move(0,o-i)),this.output.write(ie.erase.lines(1));let a=t.split(`
34
+ `);this.output.write(a[o]),this._prevFrame=t,this.output.write(ie.cursor.move(0,a.length-o-1));return}else if(n.lines.length>1){if(r<i)o=r;else{let u=o-i;u>0&&this.output.write(ie.cursor.move(0,u))}this.output.write(ie.erase.down());let a=t.split(`
35
35
  `).slice(o);this.output.write(a.join(`
36
- `)),this._prevFrame=t;return}}this.output.write(re.erase.down())}this.output.write(t),this.state==="initial"&&(this.state="active"),this._prevFrame=t}}};Yn=class extends ye{filteredOptions;multiple;isNavigating=!1;selectedValues=[];focusedValue;#t=0;#r="";#e;#o;#a;#n;get cursor(){return this.#t}get userInputWithCursor(){if(!this.userInput)return(0,Ne.styleText)(["inverse","hidden"],"_");if(this._cursor>=this.userInput.length)return`${this.userInput}\u2588`;let t=this.userInput.slice(0,this.cursor),n=this.userInput.slice(this.cursor,this.cursor+1),s=this.userInput.slice(this.cursor+1);return`${t}${(0,Ne.styleText)("inverse",n)}${s}`}get options(){return typeof this.#o=="function"?this.#o():this.#o}constructor(t){super(t),this.#o=t.options,this.#a=t.placeholder,this.#n=t.completeOnTab===!0;let n=this.options;this.filteredOptions=[...n],this.multiple=t.multiple===!0,this.#e=typeof t.options=="function"?t.filter:t.filter??Oa;let s;if(t.initialValue&&Array.isArray(t.initialValue)?this.multiple?s=t.initialValue:s=t.initialValue.slice(0,1):!this.multiple&&this.options.length>0&&(s=[this.options[0]?.value]),s)for(let r of s){let i=n.findIndex(o=>o.value===r);i!==-1&&(this.toggleSelected(r),this.#t=i)}this.focusedValue=this.options[this.#t]?.value,this.on("key",(r,i)=>this.#s(r,i)),this.on("userInput",r=>this.#i(r))}_isActionKey(t,n){return t===" "||this.multiple&&this.isNavigating&&n.name==="space"&&t!==void 0&&t!==""}#s(t,n){let s=n.name==="up",r=n.name==="down",i=n.name==="return",o=this.userInput===""||this.userInput===" ",a=this.#a,u=this.options,l=a!==void 0&&a!==""&&u.some(f=>!f.disabled&&(this.#e?this.#e(a,f):!0));if(n.name==="tab"&&o&&l){this.userInput===" "&&this._clearUserInput(),this._setUserInput(a,!0),this.isNavigating=!1;return}if(n.name==="tab"&&this.#n&&!this.multiple&&this.focusedValue!==void 0){let f=String(this.focusedValue);this._clearUserInput(),this._setUserInput(f,!0),this.isNavigating=!1;return}s||r?(this.#t=ve(this.#t,s?-1:1,this.filteredOptions),this.focusedValue=this.filteredOptions[this.#t]?.value,this.multiple||(this.selectedValues=[this.focusedValue]),this.isNavigating=!0):i?this.value=Ta(this.multiple,this.selectedValues):this.multiple?this.focusedValue!==void 0&&(n.name==="tab"||this.isNavigating&&n.name==="space")?this.toggleSelected(this.focusedValue):this.isNavigating=!1:(this.focusedValue&&(this.selectedValues=[this.focusedValue]),this.isNavigating=!1)}deselectAll(){this.selectedValues=[]}toggleSelected(t){this.filteredOptions.length!==0&&(this.multiple?this.selectedValues.includes(t)?this.selectedValues=this.selectedValues.filter(n=>n!==t):this.selectedValues=[...this.selectedValues,t]:this.selectedValues=[t])}#i(t){if(t!==this.#r){this.#r=t;let n=this.options;t&&this.#e?this.filteredOptions=n.filter(i=>this.#e?.(t,i)):this.filteredOptions=[...n];let s=Ia(this.focusedValue,this.filteredOptions);this.#t=ve(s,0,this.filteredOptions);let r=this.filteredOptions[this.#t];r&&!r.disabled?this.focusedValue=r.value:this.focusedValue=void 0,this.multiple||(this.focusedValue!==void 0?this.toggleSelected(this.focusedValue):this.deselectAll())}}},qt=class extends ye{get cursor(){return this.value?0:1}get _value(){return this.cursor===0}constructor(t){super(t,!1),this.value=!!t.initialValue,this.on("userInput",()=>{this.value=this._value}),this.on("confirm",n=>{this.output.write(re.cursor.move(0,-1)),this.value=n,this.state="submit",this.close()}),this.on("cursor",()=>{this.value=!this.value})}},ja={Y:{type:"year",len:4},M:{type:"month",len:2},D:{type:"day",len:2}};Pt=class extends ye{#t;#r;#e;#o;#a;#n={segmentIndex:0,positionInSegment:0};#s=!0;#i=null;inlineError="";get segmentCursor(){return{...this.#n}}get segmentValues(){return{...this.#e}}get segments(){return this.#t}get separator(){return this.#r}get formattedValue(){return this.#f(this.#e)}#f(t){return this.#t.map(n=>t[n.type]).join(this.#r)}#u(){this._setUserInput(this.#f(this.#e)),this._setValue(Pr(this.#e)??void 0)}constructor(t){let n=t.format?{segments:qr(t.format),separator:t.separator??"/"}:Ma(t.locale),s=t.separator??n.separator,r=t.format?qr(t.format):n.segments,i=t.initialValue??t.defaultValue,o=i?{year:String(i.getUTCFullYear()).padStart(4,"0"),month:String(i.getUTCMonth()+1).padStart(2,"0"),day:String(i.getUTCDate()).padStart(2,"0")}:{year:"____",month:"__",day:"__"},a=r.map(u=>o[u.type]).join(s);super({...t,initialUserInput:a},!1),this.#t=r,this.#r=s,this.#e=o,this.#o=t.minDate,this.#a=t.maxDate,this.#u(),this.on("cursor",u=>this.#p(u)),this.on("key",(u,l)=>this.#m(u,l)),this.on("finalize",()=>this.#g(t))}#l(){let t=Math.max(0,Math.min(this.#n.segmentIndex,this.#t.length-1)),n=this.#t[t];if(n)return this.#n.positionInSegment=Math.max(0,Math.min(this.#n.positionInSegment,n.len-1)),{segment:n,index:t}}#c(t){this.inlineError="",this.#i=null;let n=this.#l();n&&(this.#n.segmentIndex=Math.max(0,Math.min(this.#t.length-1,n.index+t)),this.#n.positionInSegment=0,this.#s=!0)}#d(t){let n=this.#l();if(!n)return;let{segment:s}=n,r=this.#e[s.type],i=!r||r.replace(/_/g,"")==="",o=Number.parseInt((r||"0").replace(/_/g,"0"),10)||0,a=Aa(s.type,Rt(this.#e),this.#o,this.#a),u;i?u=t===1?a.min:a.max:u=Math.max(Math.min(a.max,o+t),a.min),this.#e={...this.#e,[s.type]:u.toString().padStart(s.len,"0")},this.#s=!0,this.#i=null,this.#u()}#p(t){if(t)switch(t){case"right":return this.#c(1);case"left":return this.#c(-1);case"up":return this.#d(1);case"down":return this.#d(-1)}}#m(t,n){if(n?.name==="backspace"||n?.sequence==="\x7F"||n?.sequence==="\b"||t==="\x7F"||t==="\b"){this.inlineError="";let s=this.#l();if(!s)return;if(!this.#e[s.segment.type].replace(/_/g,"")){this.#c(-1);return}this.#e[s.segment.type]="_".repeat(s.segment.len),this.#s=!0,this.#n.positionInSegment=0,this.#u();return}if(n?.name==="tab"){this.inlineError="";let s=this.#l();if(!s)return;let r=n.shift?-1:1,i=s.index+r;i>=0&&i<this.#t.length&&(this.#n.segmentIndex=i,this.#n.positionInSegment=0,this.#s=!0);return}if(t&&/^[0-9]$/.test(t)){let s=this.#l();if(!s)return;let{segment:r}=s,i=!this.#e[r.type].replace(/_/g,"");if(this.#s&&this.#i!==null&&!i){let p=this.#i+t,m={...this.#e,[r.type]:p},w=this.#h(m,r);if(w){this.inlineError=w,this.#i=null,this.#s=!1;return}this.inlineError="",this.#e[r.type]=p,this.#i=null,this.#s=!1,this.#u(),s.index<this.#t.length-1&&(this.#n.segmentIndex=s.index+1,this.#n.positionInSegment=0,this.#s=!0);return}this.#s&&!i&&(this.#e[r.type]="_".repeat(r.len),this.#n.positionInSegment=0),this.#s=!1,this.#i=null;let o=this.#e[r.type],a=o.indexOf("_"),u=a>=0?a:Math.min(this.#n.positionInSegment,r.len-1);if(u<0||u>=r.len)return;let l=o.slice(0,u)+t+o.slice(u+1),f=!1;if(u===0&&o==="__"&&(r.type==="month"||r.type==="day")){let p=Number.parseInt(t,10);l=`0${t}`,f=p<=(r.type==="month"?1:2)}if(r.type==="year"&&(l=(o.replace(/_/g,"")+t).padStart(r.len,"_")),!l.includes("_")){let p={...this.#e,[r.type]:l},m=this.#h(p,r);if(m){this.inlineError=m;return}}this.inlineError="",this.#e[r.type]=l;let d=l.includes("_")?void 0:Wr(this.#e);if(d){let{year:p,month:m}=d,w=Kn(p,m);this.#e={year:String(Math.max(0,Math.min(9999,p))).padStart(4,"0"),month:String(Math.max(1,Math.min(12,m))).padStart(2,"0"),day:String(Math.max(1,Math.min(w,d.day))).padStart(2,"0")}}this.#u();let h=l.indexOf("_");f?(this.#s=!0,this.#i=t):h>=0?this.#n.positionInSegment=h:a>=0&&s.index<this.#t.length-1?(this.#n.segmentIndex=s.index+1,this.#n.positionInSegment=0,this.#s=!0):this.#n.positionInSegment=Math.min(u+1,r.len-1)}}#h(t,n){let{month:s,day:r}=Rt(t);if(n.type==="month"&&(s<0||s>12))return I.date.messages.invalidMonth;if(n.type==="day"&&(r<0||r>31))return I.date.messages.invalidDay(31,"any month")}#g(t){let{year:n,month:s,day:r}=Rt(this.#e);if(n&&s&&r){let i=Kn(n,s);this.#e={...this.#e,day:String(Math.min(r,i)).padStart(2,"0")}}this.value=Pr(this.#e)??t.defaultValue??void 0}},Gr=class extends ye{options;cursor=0;#t;getGroupItems(t){return this.options.filter(n=>n.group===t)}isGroupSelected(t){let n=this.getGroupItems(t),s=this.value;return s===void 0?!1:n.every(r=>s.includes(r.value))}toggleValue(){let t=this.options[this.cursor];if(t!==void 0)if(this.value===void 0&&(this.value=[]),t.group===!0){let n=t.value,s=this.getGroupItems(n);this.isGroupSelected(n)?this.value=this.value.filter(r=>s.findIndex(i=>i.value===r)===-1):this.value=[...this.value,...s.map(r=>r.value)],this.value=Array.from(new Set(this.value))}else{let n=this.value.includes(t.value);this.value=n?this.value.filter(s=>s!==t.value):[...this.value,t.value]}}constructor(t){super(t,!1);let{options:n}=t;this.#t=t.selectableGroups!==!1,this.options=Object.entries(n).flatMap(([s,r])=>[{value:s,group:!0,label:s},...r.map(i=>({...i,group:s}))]),this.value=[...t.initialValues??[]],this.cursor=Math.max(this.options.findIndex(({value:s})=>s===t.cursorAt),this.#t?0:1),this.on("cursor",s=>{switch(s){case"left":case"up":{this.cursor=this.cursor===0?this.options.length-1:this.cursor-1;let r=this.options[this.cursor]?.group===!0;!this.#t&&r&&(this.cursor=this.cursor===0?this.options.length-1:this.cursor-1);break}case"down":case"right":{this.cursor=this.cursor===this.options.length-1?0:this.cursor+1;let r=this.options[this.cursor]?.group===!0;!this.#t&&r&&(this.cursor=this.cursor===this.options.length-1?0:this.cursor+1);break}case"space":this.toggleValue();break}})}},Fa=new Set(["up","down","left","right"]),Bt=class extends ye{#t=!1;#r;focused="editor";get userInputWithCursor(){if(this.state==="submit")return this.userInput;let t=this.userInput;if(this.cursor>=t.length)return`${t}\u2588`;let n=t.slice(0,this.cursor),s=t.slice(this.cursor,this.cursor+1),r=t.slice(this.cursor+1);return s===`
36
+ `)),this._prevFrame=t;return}}this.output.write(ie.erase.down())}this.output.write(t),this.state==="initial"&&(this.state="active"),this._prevFrame=t}}};ns=class extends be{filteredOptions;multiple;isNavigating=!1;selectedValues=[];focusedValue;#t=0;#r="";#e;#o;#a;#n;get cursor(){return this.#t}get userInputWithCursor(){if(!this.userInput)return(0,qe.styleText)(["inverse","hidden"],"_");if(this._cursor>=this.userInput.length)return`${this.userInput}\u2588`;let t=this.userInput.slice(0,this.cursor),n=this.userInput.slice(this.cursor,this.cursor+1),s=this.userInput.slice(this.cursor+1);return`${t}${(0,qe.styleText)("inverse",n)}${s}`}get options(){return typeof this.#o=="function"?this.#o():this.#o}constructor(t){super(t),this.#o=t.options,this.#a=t.placeholder,this.#n=t.completeOnTab===!0;let n=this.options;this.filteredOptions=[...n],this.multiple=t.multiple===!0,this.#e=typeof t.options=="function"?t.filter:t.filter??Ba;let s;if(t.initialValue&&Array.isArray(t.initialValue)?this.multiple?s=t.initialValue:s=t.initialValue.slice(0,1):!this.multiple&&this.options.length>0&&(s=[this.options[0]?.value]),s)for(let r of s){let i=n.findIndex(o=>o.value===r);i!==-1&&(this.toggleSelected(r),this.#t=i)}this.focusedValue=this.options[this.#t]?.value,this.on("key",(r,i)=>this.#s(r,i)),this.on("userInput",r=>this.#i(r))}_isActionKey(t,n){return t===" "||this.multiple&&this.isNavigating&&n.name==="space"&&t!==void 0&&t!==""}#s(t,n){let s=n.name==="up",r=n.name==="down",i=n.name==="return",o=this.userInput===""||this.userInput===" ",a=this.#a,u=this.options,l=a!==void 0&&a!==""&&u.some(f=>!f.disabled&&(this.#e?this.#e(a,f):!0));if(n.name==="tab"&&o&&l){this.userInput===" "&&this._clearUserInput(),this._setUserInput(a,!0),this.isNavigating=!1;return}if(n.name==="tab"&&this.#n&&!this.multiple&&this.focusedValue!==void 0){let f=String(this.focusedValue);this._clearUserInput(),this._setUserInput(f,!0),this.isNavigating=!1;return}s||r?(this.#t=xe(this.#t,s?-1:1,this.filteredOptions),this.focusedValue=this.filteredOptions[this.#t]?.value,this.multiple||(this.selectedValues=[this.focusedValue]),this.isNavigating=!0):i?this.value=Va(this.multiple,this.selectedValues):this.multiple?this.focusedValue!==void 0&&(n.name==="tab"||this.isNavigating&&n.name==="space")?this.toggleSelected(this.focusedValue):this.isNavigating=!1:(this.focusedValue&&(this.selectedValues=[this.focusedValue]),this.isNavigating=!1)}deselectAll(){this.selectedValues=[]}toggleSelected(t){this.filteredOptions.length!==0&&(this.multiple?this.selectedValues.includes(t)?this.selectedValues=this.selectedValues.filter(n=>n!==t):this.selectedValues=[...this.selectedValues,t]:this.selectedValues=[t])}#i(t){if(t!==this.#r){this.#r=t;let n=this.options;t&&this.#e?this.filteredOptions=n.filter(i=>this.#e?.(t,i)):this.filteredOptions=[...n];let s=Pa(this.focusedValue,this.filteredOptions);this.#t=xe(s,0,this.filteredOptions);let r=this.filteredOptions[this.#t];r&&!r.disabled?this.focusedValue=r.value:this.focusedValue=void 0,this.multiple||(this.focusedValue!==void 0?this.toggleSelected(this.focusedValue):this.deselectAll())}}},Vt=class extends be{get cursor(){return this.value?0:1}get _value(){return this.cursor===0}constructor(t){super(t,!1),this.value=!!t.initialValue,this.on("userInput",()=>{this.value=this._value}),this.on("confirm",n=>{this.output.write(ie.cursor.move(0,-1)),this.value=n,this.state="submit",this.close()}),this.on("cursor",()=>{this.value=!this.value})}},Ua={Y:{type:"year",len:4},M:{type:"month",len:2},D:{type:"day",len:2}};Ut=class extends be{#t;#r;#e;#o;#a;#n={segmentIndex:0,positionInSegment:0};#s=!0;#i=null;inlineError="";get segmentCursor(){return{...this.#n}}get segmentValues(){return{...this.#e}}get segments(){return this.#t}get separator(){return this.#r}get formattedValue(){return this.#f(this.#e)}#f(t){return this.#t.map(n=>t[n.type]).join(this.#r)}#u(){this._setUserInput(this.#f(this.#e)),this._setValue(Gr(this.#e)??void 0)}constructor(t){let n=t.format?{segments:Wr(t.format),separator:t.separator??"/"}:Wa(t.locale),s=t.separator??n.separator,r=t.format?Wr(t.format):n.segments,i=t.initialValue??t.defaultValue,o=i?{year:String(i.getUTCFullYear()).padStart(4,"0"),month:String(i.getUTCMonth()+1).padStart(2,"0"),day:String(i.getUTCDate()).padStart(2,"0")}:{year:"____",month:"__",day:"__"},a=r.map(u=>o[u.type]).join(s);super({...t,initialUserInput:a},!1),this.#t=r,this.#r=s,this.#e=o,this.#o=t.minDate,this.#a=t.maxDate,this.#u(),this.on("cursor",u=>this.#p(u)),this.on("key",(u,l)=>this.#m(u,l)),this.on("finalize",()=>this.#g(t))}#l(){let t=Math.max(0,Math.min(this.#n.segmentIndex,this.#t.length-1)),n=this.#t[t];if(n)return this.#n.positionInSegment=Math.max(0,Math.min(this.#n.positionInSegment,n.len-1)),{segment:n,index:t}}#c(t){this.inlineError="",this.#i=null;let n=this.#l();n&&(this.#n.segmentIndex=Math.max(0,Math.min(this.#t.length-1,n.index+t)),this.#n.positionInSegment=0,this.#s=!0)}#d(t){let n=this.#l();if(!n)return;let{segment:s}=n,r=this.#e[s.type],i=!r||r.replace(/_/g,"")==="",o=Number.parseInt((r||"0").replace(/_/g,"0"),10)||0,a=Ga(s.type,Bt(this.#e),this.#o,this.#a),u;i?u=t===1?a.min:a.max:u=Math.max(Math.min(a.max,o+t),a.min),this.#e={...this.#e,[s.type]:u.toString().padStart(s.len,"0")},this.#s=!0,this.#i=null,this.#u()}#p(t){if(t)switch(t){case"right":return this.#c(1);case"left":return this.#c(-1);case"up":return this.#d(1);case"down":return this.#d(-1)}}#m(t,n){if(n?.name==="backspace"||n?.sequence==="\x7F"||n?.sequence==="\b"||t==="\x7F"||t==="\b"){this.inlineError="";let s=this.#l();if(!s)return;if(!this.#e[s.segment.type].replace(/_/g,"")){this.#c(-1);return}this.#e[s.segment.type]="_".repeat(s.segment.len),this.#s=!0,this.#n.positionInSegment=0,this.#u();return}if(n?.name==="tab"){this.inlineError="";let s=this.#l();if(!s)return;let r=n.shift?-1:1,i=s.index+r;i>=0&&i<this.#t.length&&(this.#n.segmentIndex=i,this.#n.positionInSegment=0,this.#s=!0);return}if(t&&/^[0-9]$/.test(t)){let s=this.#l();if(!s)return;let{segment:r}=s,i=!this.#e[r.type].replace(/_/g,"");if(this.#s&&this.#i!==null&&!i){let p=this.#i+t,m={...this.#e,[r.type]:p},w=this.#h(m,r);if(w){this.inlineError=w,this.#i=null,this.#s=!1;return}this.inlineError="",this.#e[r.type]=p,this.#i=null,this.#s=!1,this.#u(),s.index<this.#t.length-1&&(this.#n.segmentIndex=s.index+1,this.#n.positionInSegment=0,this.#s=!0);return}this.#s&&!i&&(this.#e[r.type]="_".repeat(r.len),this.#n.positionInSegment=0),this.#s=!1,this.#i=null;let o=this.#e[r.type],a=o.indexOf("_"),u=a>=0?a:Math.min(this.#n.positionInSegment,r.len-1);if(u<0||u>=r.len)return;let l=o.slice(0,u)+t+o.slice(u+1),f=!1;if(u===0&&o==="__"&&(r.type==="month"||r.type==="day")){let p=Number.parseInt(t,10);l=`0${t}`,f=p<=(r.type==="month"?1:2)}if(r.type==="year"&&(l=(o.replace(/_/g,"")+t).padStart(r.len,"_")),!l.includes("_")){let p={...this.#e,[r.type]:l},m=this.#h(p,r);if(m){this.inlineError=m;return}}this.inlineError="",this.#e[r.type]=l;let d=l.includes("_")?void 0:Xr(this.#e);if(d){let{year:p,month:m}=d,w=Qn(p,m);this.#e={year:String(Math.max(0,Math.min(9999,p))).padStart(4,"0"),month:String(Math.max(1,Math.min(12,m))).padStart(2,"0"),day:String(Math.max(1,Math.min(w,d.day))).padStart(2,"0")}}this.#u();let h=l.indexOf("_");f?(this.#s=!0,this.#i=t):h>=0?this.#n.positionInSegment=h:a>=0&&s.index<this.#t.length-1?(this.#n.segmentIndex=s.index+1,this.#n.positionInSegment=0,this.#s=!0):this.#n.positionInSegment=Math.min(u+1,r.len-1)}}#h(t,n){let{month:s,day:r}=Bt(t);if(n.type==="month"&&(s<0||s>12))return O.date.messages.invalidMonth;if(n.type==="day"&&(r<0||r>31))return O.date.messages.invalidDay(31,"any month")}#g(t){let{year:n,month:s,day:r}=Bt(this.#e);if(n&&s&&r){let i=Qn(n,s);this.#e={...this.#e,day:String(Math.min(r,i)).padStart(2,"0")}}this.value=Gr(this.#e)??t.defaultValue??void 0}},zr=class extends be{options;cursor=0;#t;getGroupItems(t){return this.options.filter(n=>n.group===t)}isGroupSelected(t){let n=this.getGroupItems(t),s=this.value;return s===void 0?!1:n.every(r=>s.includes(r.value))}toggleValue(){let t=this.options[this.cursor];if(t!==void 0)if(this.value===void 0&&(this.value=[]),t.group===!0){let n=t.value,s=this.getGroupItems(n);this.isGroupSelected(n)?this.value=this.value.filter(r=>s.findIndex(i=>i.value===r)===-1):this.value=[...this.value,...s.map(r=>r.value)],this.value=Array.from(new Set(this.value))}else{let n=this.value.includes(t.value);this.value=n?this.value.filter(s=>s!==t.value):[...this.value,t.value]}}constructor(t){super(t,!1);let{options:n}=t;this.#t=t.selectableGroups!==!1,this.options=Object.entries(n).flatMap(([s,r])=>[{value:s,group:!0,label:s},...r.map(i=>({...i,group:s}))]),this.value=[...t.initialValues??[]],this.cursor=Math.max(this.options.findIndex(({value:s})=>s===t.cursorAt),this.#t?0:1),this.on("cursor",s=>{switch(s){case"left":case"up":{this.cursor=this.cursor===0?this.options.length-1:this.cursor-1;let r=this.options[this.cursor]?.group===!0;!this.#t&&r&&(this.cursor=this.cursor===0?this.options.length-1:this.cursor-1);break}case"down":case"right":{this.cursor=this.cursor===this.options.length-1?0:this.cursor+1;let r=this.options[this.cursor]?.group===!0;!this.#t&&r&&(this.cursor=this.cursor===this.options.length-1?0:this.cursor+1);break}case"space":this.toggleValue();break}})}},Ha=new Set(["up","down","left","right"]),Wt=class extends be{#t=!1;#r;focused="editor";get userInputWithCursor(){if(this.state==="submit")return this.userInput;let t=this.userInput;if(this.cursor>=t.length)return`${t}\u2588`;let n=t.slice(0,this.cursor),s=t.slice(this.cursor,this.cursor+1),r=t.slice(this.cursor+1);return s===`
37
37
  `?`${n}\u2588
38
- ${r}`:`${n}${(0,Ne.styleText)("inverse",s)}${r}`}get cursor(){return this._cursor}#e(t){if(this.userInput.length===0){this._setUserInput(t);return}this._setUserInput(this.userInput.slice(0,this.cursor)+t+this.userInput.slice(this.cursor))}#o(t){let n=this.value??"";switch(t){case"up":this._cursor=Nt(this._cursor,0,-1,n);return;case"down":this._cursor=Nt(this._cursor,0,1,n);return;case"left":this._cursor=Nt(this._cursor,-1,0,n);return;case"right":this._cursor=Nt(this._cursor,1,0,n);return}}_shouldSubmit(t,n){if(this.#r)return this.focused==="submit"?!0:(this.#e(`
38
+ ${r}`:`${n}${(0,qe.styleText)("inverse",s)}${r}`}get cursor(){return this._cursor}#e(t){if(this.userInput.length===0){this._setUserInput(t);return}this._setUserInput(this.userInput.slice(0,this.cursor)+t+this.userInput.slice(this.cursor))}#o(t){let n=this.value??"";switch(t){case"up":this._cursor=Rt(this._cursor,0,-1,n);return;case"down":this._cursor=Rt(this._cursor,0,1,n);return;case"left":this._cursor=Rt(this._cursor,-1,0,n);return;case"right":this._cursor=Rt(this._cursor,1,0,n);return}}_shouldSubmit(t,n){if(this.#r)return this.focused==="submit"?!0:(this.#e(`
39
39
  `),this._cursor++,!1);let s=this.#t;return this.#t=!0,s&&this.cursor===this.userInput.length?(this.userInput[this.cursor-1]===`
40
40
  `&&(this._setUserInput(this.userInput.slice(0,this.cursor-1)+this.userInput.slice(this.cursor)),this._cursor--),!0):(this.#e(`
41
- `),this._cursor++,!1)}constructor(t){let n=t.initialUserInput??t.initialValue;super({...t,initialUserInput:n},!1),n!==void 0&&(this._cursor=n.length),this.#r=t.showSubmit??!1,this.on("key",(s,r)=>{if(r?.name&&Fa.has(r.name)){this.#t=!1,this.#o(r.name);return}if(s===" "&&this.#r){this.focused=this.focused==="editor"?"submit":"editor";return}if(r?.name!=="return"){if(this.#t=!1,r?.name==="backspace"&&this.cursor>0){this._setUserInput(this.userInput.slice(0,this.cursor-1)+this.userInput.slice(this.cursor)),this._cursor--;return}if(r?.name==="delete"&&this.cursor<this.userInput.length){this._setUserInput(this.userInput.slice(0,this.cursor)+this.userInput.slice(this.cursor+1));return}s&&(this.#r&&this.focused==="submit"&&(this.focused="editor"),this.#e(s??""),this._cursor++)}}),this.on("userInput",s=>{this._setValue(s)}),this.on("finalize",()=>{this.value||(this.value=t.defaultValue),this.value===void 0&&(this.value="")})}},Vt=class extends ye{options;cursor=0;get _value(){return this.options[this.cursor]?.value}get _enabledOptions(){return this.options.filter(t=>t.disabled!==!0)}toggleAll(){let t=this._enabledOptions,n=this.value!==void 0&&this.value.length===t.length;this.value=n?[]:t.map(s=>s.value)}toggleInvert(){let t=this.value;if(!t)return;let n=this._enabledOptions.filter(s=>!t.includes(s.value));this.value=n.map(s=>s.value)}toggleValue(){this.value===void 0&&(this.value=[]);let t=this.value.includes(this._value);this.value=t?this.value.filter(n=>n!==this._value):[...this.value,this._value]}constructor(t){super(t,!1),this.options=t.options,this.value=[...t.initialValues??[]];let n=Math.max(this.options.findIndex(({value:s})=>s===t.cursorAt),0);this.cursor=this.options[n]?.disabled?ve(n,1,this.options):n,this.on("key",(s,r)=>{r.name==="a"&&this.toggleAll(),r.name==="i"&&this.toggleInvert()}),this.on("cursor",s=>{switch(s){case"left":case"up":this.cursor=ve(this.cursor,-1,this.options);break;case"down":case"right":this.cursor=ve(this.cursor,1,this.options);break;case"space":this.toggleValue();break}})}},Hr=class extends ye{_mask="\u2022";get cursor(){return this._cursor}get masked(){return this.userInput.replaceAll(/./g,this._mask)}get userInputWithCursor(){if(this.state==="submit"||this.state==="cancel")return this.masked;let t=this.userInput;if(this.cursor>=t.length)return`${this.masked}${(0,Ne.styleText)(["inverse","hidden"],"_")}`;let n=this.masked,s=n.slice(0,this.cursor),r=n.slice(this.cursor,this.cursor+1),i=n.slice(this.cursor+1);return`${s}${(0,Ne.styleText)("inverse",r)}${i}`}clear(){this._clearUserInput()}constructor({mask:t,...n}){super(n),this._mask=t??"\u2022",this.on("userInput",s=>{this._setValue(s)}),this.on("finalize",()=>{this.value===void 0&&(this.value="")})}},Kr=class extends ye{options;cursor=0;get _selectedValue(){return this.options[this.cursor]}changeValue(){let t=this._selectedValue;this.value=t===void 0?void 0:t.value}constructor(t){super(t,!1),this.options=t.options;let n=this.options.findIndex(({value:r})=>r===t.initialValue),s=n===-1?0:n;this.cursor=this.options[s]?.disabled?ve(s,1,this.options):s,this.changeValue(),this.on("cursor",r=>{switch(r){case"left":case"up":this.cursor=ve(this.cursor,-1,this.options);break;case"down":case"right":this.cursor=ve(this.cursor,1,this.options);break}this.changeValue()})}},Ut=class extends ye{options;cursor=0;constructor(t){super(t,!1),this.options=t.options;let n=t.caseSensitive===!0,s=this.options.map(({value:[r]})=>n?r:r?.toLowerCase());this.cursor=Math.max(s.indexOf(t.initialValue),0),this.on("key",r=>{if(!r)return;let i=n?r:r.toLowerCase();if(!s.includes(i))return;let o=this.options.find(({value:[a]})=>n?a===i:a?.toLowerCase()===i);o&&(this.value=o.value,this.state="submit",this.emit("submit"))})}},Wt=class extends ye{get userInputWithCursor(){if(this.state==="submit")return this.userInput;let t=this.userInput;if(this.cursor>=t.length)return`${this.userInput}\u2588`;let n=t.slice(0,this.cursor),s=t.slice(this.cursor,this.cursor+1),r=t.slice(this.cursor+1);return`${n}${(0,Ne.styleText)("inverse",s)}${r}`}get cursor(){return this._cursor}constructor(t){super({...t,initialUserInput:t.initialUserInput??t.initialValue}),this.on("userInput",n=>{this._setValue(n)}),this.on("finalize",()=>{this.value||(this.value=t.defaultValue),this.value===void 0&&(this.value="")})}}});var ui={};ro(ui,{CANCEL_SYMBOL:()=>ft,MULTISELECT_INSTRUCTIONS:()=>fs,SELECT_INSTRUCTIONS:()=>ai,S_BAR:()=>v,S_BAR_END:()=>H,S_BAR_END_RIGHT:()=>ti,S_BAR_H:()=>Xt,S_BAR_START:()=>ns,S_BAR_START_RIGHT:()=>ei,S_CHECKBOX_ACTIVE:()=>Jt,S_CHECKBOX_INACTIVE:()=>Xe,S_CHECKBOX_SELECTED:()=>Pe,S_CONNECT_LEFT:()=>si,S_CORNER_BOTTOM_LEFT:()=>is,S_CORNER_BOTTOM_RIGHT:()=>rs,S_CORNER_TOP_LEFT:()=>ri,S_CORNER_TOP_RIGHT:()=>ss,S_ERROR:()=>ls,S_INFO:()=>os,S_PASSWORD_MASK:()=>ni,S_RADIO_ACTIVE:()=>mt,S_RADIO_INACTIVE:()=>Ve,S_STEP_ACTIVE:()=>Qn,S_STEP_CANCEL:()=>es,S_STEP_ERROR:()=>ts,S_STEP_SUBMIT:()=>Ue,S_SUCCESS:()=>as,S_WARN:()=>us,autocomplete:()=>oi,autocompleteMultiselect:()=>Na,box:()=>Pa,cancel:()=>Xa,confirm:()=>Ba,date:()=>Va,formatInstructionFooter:()=>Yt,group:()=>Ha,groupMultiselect:()=>Ja,intro:()=>Ya,isCI:()=>Zn,isCancel:()=>Gt,isTTY:()=>Zr,limitOptions:()=>Te,log:()=>de,multiline:()=>Qa,multiselect:()=>Ka,note:()=>tu,outro:()=>za,password:()=>nu,path:()=>su,progress:()=>iu,select:()=>ou,selectKey:()=>au,settings:()=>I,spinner:()=>ds,stream:()=>qe,symbol:()=>he,symbolBar:()=>cs,taskLog:()=>cu,tasks:()=>uu,text:()=>fu,unicode:()=>Kt,unicodeOr:()=>q,updateSettings:()=>Vr});function La(){return fe.default.platform!=="win32"?fe.default.env.TERM!=="linux":!!fe.default.env.CI||!!fe.default.env.WT_SESSION||!!fe.default.env.TERMINUS_SUBLIME||fe.default.env.ConEmuTask==="{cmd::Cmder}"||fe.default.env.TERM_PROGRAM==="Terminus-Sublime"||fe.default.env.TERM_PROGRAM==="vscode"||fe.default.env.TERM==="xterm-256color"||fe.default.env.TERM==="alacritty"||fe.default.env.TERMINAL_EMULATOR==="JetBrains-JediTerm"}function Yt(e,t){let n=[`${t?`${(0,c.styleText)("cyan",v)} `:""}${e.join(" \u2022 ")}`];return t&&n.push((0,c.styleText)("cyan",H)),n}function Xr(e){return e.label??String(e.value??"")}function ii(e,t){if(!e)return!0;let n=(t.label??String(t.value??"")).toLowerCase(),s=(t.hint??"").toLowerCase(),r=String(t.value).toLowerCase(),i=e.toLowerCase();return n.includes(i)||s.includes(i)||r.includes(i)}function Ca(e,t){let n=[];for(let s of t)e.includes(s.value)&&n.push(s);return n}function Yr(e,t,n,s){let r=n,i=n;return s==="center"?r=Math.floor((t-e)/2):s==="right"&&(r=t-e-n),i=t-r-e,[r,i]}function Ua(e,t){let n=e.segmentValues,s=e.segmentCursor;if(t==="submit"||t==="cancel")return e.formattedValue;let r=(0,c.styleText)("gray",e.separator);return e.segments.map((i,o)=>{let a=o===s.segmentIndex&&!["submit","cancel"].includes(t),u=Ga[i.type];return Wa(n[i.type],{isActive:a,label:u})}).join(r)}function Wa(e,t){let n=!e||e.replace(/_/g,"")==="";return t.isActive?(0,c.styleText)("inverse",n?t.label:e.replace(/_/g," ")):n?(0,c.styleText)("dim",t.label):e.replace(/_/g,(0,c.styleText)("dim"," "))}function iu({style:e="heavy",max:t=100,size:n=40,...s}={}){let r=ds(s),i=0,o="",a=Math.max(1,t),u=Math.max(1,n),l=p=>{switch(p){case"initial":case"active":return m=>(0,c.styleText)("magenta",m);case"error":case"cancel":return m=>(0,c.styleText)("red",m);case"submit":return m=>(0,c.styleText)("green",m);default:return m=>(0,c.styleText)("magenta",m)}},f=(p,m)=>{let w=Math.floor(i/a*u);return`${l(p)(zr[e].repeat(w))}${(0,c.styleText)("dim",zr[e].repeat(u-w))} ${m}`},d=(p="")=>{o=p,r.start(f("initial",p))},h=(p=1,m)=>{i=Math.min(a,p+i),r.message(f("active",m??o)),o=m??o};return{start:d,stop:r.stop,cancel:r.cancel,error:r.error,clear:r.clear,advance:h,isCancelled:r.isCancelled,message:p=>h(0,p)}}var c,fe,Be,pt,Je,Kt,Zn,Zr,q,Qn,es,ts,Ue,ns,v,H,ei,ti,mt,Ve,Jt,Pe,Xe,ni,Xt,ss,si,rs,is,ri,os,as,us,ls,he,cs,Jr,Te,oi,Na,Da,Ra,qa,Pa,Ba,Va,Ga,Ha,fs,ht,Ka,Ja,de,Xa,Ya,za,Qa,Za,eu,tu,nu,su,ru,ds,zr,ai,Ht,ou,au,Qr,qe,uu,lu,cu,fu,li=Ge(()=>{zn();zn();c=require("node:util"),fe=Qe(require("node:process"),1);Bn();Dn();Be=require("node:fs"),pt=require("node:path"),Je=Qe(Wn(),1);Kt=La(),Zn=()=>process.env.CI==="true",Zr=e=>e.isTTY===!0,q=(e,t)=>Kt?e:t,Qn=q("\u25C6","*"),es=q("\u25A0","x"),ts=q("\u25B2","x"),Ue=q("\u25C7","o"),ns=q("\u250C","T"),v=q("\u2502","|"),H=q("\u2514","\u2014"),ei=q("\u2510","T"),ti=q("\u2518","\u2014"),mt=q("\u25CF",">"),Ve=q("\u25CB"," "),Jt=q("\u25FB","[\u2022]"),Pe=q("\u25FC","[+]"),Xe=q("\u25FB","[ ]"),ni=q("\u25AA","\u2022"),Xt=q("\u2500","-"),ss=q("\u256E","+"),si=q("\u251C","+"),rs=q("\u256F","+"),is=q("\u2570","+"),ri=q("\u256D","+"),os=q("\u25CF","\u2022"),as=q("\u25C6","*"),us=q("\u25B2","!"),ls=q("\u25A0","x"),he=e=>{switch(e){case"initial":case"active":return(0,c.styleText)("cyan",Qn);case"cancel":return(0,c.styleText)("red",es);case"error":return(0,c.styleText)("yellow",ts);case"submit":return(0,c.styleText)("green",Ue);case"validating":return(0,c.styleText)("dim",Qn)}},cs=e=>{switch(e){case"initial":case"active":return(0,c.styleText)("cyan",v);case"cancel":return(0,c.styleText)("red",v);case"error":return(0,c.styleText)("yellow",v);case"submit":return(0,c.styleText)("green",v)}};Jr=(e,t,n,s,r,i=!1)=>{let o=t,a=0;if(i)for(let u=s-1;u>=n;u--){let l=e[u];if(l&&(o-=l.length),a++,o<=r)break}else for(let u=n;u<s;u++){let l=e[u];if(l&&(o-=l.length),a++,o<=r)break}return{lineCount:o,removals:a}},Te=({cursor:e,options:t,style:n,output:s=process.stdout,maxItems:r=Number.POSITIVE_INFINITY,columnPadding:i=0,rowPadding:o=4})=>{let a=Re(s)-i,u=Xn(s),l=(0,c.styleText)("dim","..."),f=Math.max(u-o,0),d=Math.max(Math.min(r,f),5),h=0;e>=d-3&&(h=Math.max(Math.min(e-d+3,t.length-d),0));let p=d<t.length&&h>0,m=d<t.length&&h+d<t.length,w=Math.min(h+d,t.length),b=[],$=0;p&&$++,m&&$++;let k=h+(p?1:0),T=w-(m?1:0);for(let j=k;j<T;j++){let L=t[j],M=L?n(L,j===e):"",C=we(M,a,{hard:!0,trim:!1}).split(`
42
- `);b.push(C),$+=C.length}if($>f){let j=0,L=0,M=$,C=e-k,N=f,U=()=>Jr(b,M,0,C,N),R=()=>Jr(b,M,C+1,b.length,N,!0);p?({lineCount:M,removals:j}=U(),M>N&&(m||(N-=1),{lineCount:M,removals:L}=R())):(m||(N-=1),{lineCount:M,removals:L}=R(),M>N&&(N-=1,{lineCount:M,removals:j}=U())),j>0&&(p=!0,b.splice(0,j)),L>0&&(m=!0,b.splice(b.length-L,L))}let F=[];p&&F.push(l);for(let j of b)for(let L of j)F.push(L);return m&&F.push(l),F};oi=e=>new Yn({options:e.options,initialValue:e.initialValue?[e.initialValue]:void 0,initialUserInput:e.initialUserInput,placeholder:e.placeholder,completeOnTab:e.completeOnTab,filter:e.filter??((t,n)=>ii(t,n)),signal:e.signal,input:e.input,output:e.output,validate:e.validate,render(){let t=e.withGuide??I.withGuide,n=t?[`${(0,c.styleText)("gray",v)}`,`${he(this.state)} ${e.message}`]:[`${he(this.state)} ${e.message}`],s=this.userInput,r=this.options,i=e.placeholder,o=s===""&&i!==void 0,a=(u,l)=>{let f=Xr(u),d=u.hint&&u.value===this.focusedValue?(0,c.styleText)("dim",` (${u.hint})`):"";switch(l){case"active":return`${(0,c.styleText)("green",mt)} ${f}${d}`;case"inactive":return`${(0,c.styleText)("dim",Ve)} ${(0,c.styleText)("dim",f)}`;case"disabled":return`${(0,c.styleText)("gray",Ve)} ${(0,c.styleText)(["strikethrough","gray"],f)}`}};switch(this.state){case"submit":{let u=Ca(this.selectedValues,r),l=u.length>0?` ${(0,c.styleText)("dim",u.map(Xr).join(", "))}`:"",f=t?(0,c.styleText)("gray",v):"";return`${n.join(`
41
+ `),this._cursor++,!1)}constructor(t){let n=t.initialUserInput??t.initialValue;super({...t,initialUserInput:n},!1),n!==void 0&&(this._cursor=n.length),this.#r=t.showSubmit??!1,this.on("key",(s,r)=>{if(r?.name&&Ha.has(r.name)){this.#t=!1,this.#o(r.name);return}if(s===" "&&this.#r){this.focused=this.focused==="editor"?"submit":"editor";return}if(r?.name!=="return"){if(this.#t=!1,r?.name==="backspace"&&this.cursor>0){this._setUserInput(this.userInput.slice(0,this.cursor-1)+this.userInput.slice(this.cursor)),this._cursor--;return}if(r?.name==="delete"&&this.cursor<this.userInput.length){this._setUserInput(this.userInput.slice(0,this.cursor)+this.userInput.slice(this.cursor+1));return}s&&(this.#r&&this.focused==="submit"&&(this.focused="editor"),this.#e(s??""),this._cursor++)}}),this.on("userInput",s=>{this._setValue(s)}),this.on("finalize",()=>{this.value||(this.value=t.defaultValue),this.value===void 0&&(this.value="")})}},Gt=class extends be{options;cursor=0;get _value(){return this.options[this.cursor]?.value}get _enabledOptions(){return this.options.filter(t=>t.disabled!==!0)}toggleAll(){let t=this._enabledOptions,n=this.value!==void 0&&this.value.length===t.length;this.value=n?[]:t.map(s=>s.value)}toggleInvert(){let t=this.value;if(!t)return;let n=this._enabledOptions.filter(s=>!t.includes(s.value));this.value=n.map(s=>s.value)}toggleValue(){this.value===void 0&&(this.value=[]);let t=this.value.includes(this._value);this.value=t?this.value.filter(n=>n!==this._value):[...this.value,this._value]}constructor(t){super(t,!1),this.options=t.options,this.value=[...t.initialValues??[]];let n=Math.max(this.options.findIndex(({value:s})=>s===t.cursorAt),0);this.cursor=this.options[n]?.disabled?xe(n,1,this.options):n,this.on("key",(s,r)=>{r.name==="a"&&this.toggleAll(),r.name==="i"&&this.toggleInvert()}),this.on("cursor",s=>{switch(s){case"left":case"up":this.cursor=xe(this.cursor,-1,this.options);break;case"down":case"right":this.cursor=xe(this.cursor,1,this.options);break;case"space":this.toggleValue();break}})}},Yr=class extends be{_mask="\u2022";get cursor(){return this._cursor}get masked(){return this.userInput.replaceAll(/./g,this._mask)}get userInputWithCursor(){if(this.state==="submit"||this.state==="cancel")return this.masked;let t=this.userInput;if(this.cursor>=t.length)return`${this.masked}${(0,qe.styleText)(["inverse","hidden"],"_")}`;let n=this.masked,s=n.slice(0,this.cursor),r=n.slice(this.cursor,this.cursor+1),i=n.slice(this.cursor+1);return`${s}${(0,qe.styleText)("inverse",r)}${i}`}clear(){this._clearUserInput()}constructor({mask:t,...n}){super(n),this._mask=t??"\u2022",this.on("userInput",s=>{this._setValue(s)}),this.on("finalize",()=>{this.value===void 0&&(this.value="")})}},Zr=class extends be{options;cursor=0;get _selectedValue(){return this.options[this.cursor]}changeValue(){let t=this._selectedValue;this.value=t===void 0?void 0:t.value}constructor(t){super(t,!1),this.options=t.options;let n=this.options.findIndex(({value:r})=>r===t.initialValue),s=n===-1?0:n;this.cursor=this.options[s]?.disabled?xe(s,1,this.options):s,this.changeValue(),this.on("cursor",r=>{switch(r){case"left":case"up":this.cursor=xe(this.cursor,-1,this.options);break;case"down":case"right":this.cursor=xe(this.cursor,1,this.options);break}this.changeValue()})}},Ht=class extends be{options;cursor=0;constructor(t){super(t,!1),this.options=t.options;let n=t.caseSensitive===!0,s=this.options.map(({value:[r]})=>n?r:r?.toLowerCase());this.cursor=Math.max(s.indexOf(t.initialValue),0),this.on("key",r=>{if(!r)return;let i=n?r:r.toLowerCase();if(!s.includes(i))return;let o=this.options.find(({value:[a]})=>n?a===i:a?.toLowerCase()===i);o&&(this.value=o.value,this.state="submit",this.emit("submit"))})}},Kt=class extends be{get userInputWithCursor(){if(this.state==="submit")return this.userInput;let t=this.userInput;if(this.cursor>=t.length)return`${this.userInput}\u2588`;let n=t.slice(0,this.cursor),s=t.slice(this.cursor,this.cursor+1),r=t.slice(this.cursor+1);return`${n}${(0,qe.styleText)("inverse",s)}${r}`}get cursor(){return this._cursor}constructor(t){super({...t,initialUserInput:t.initialUserInput??t.initialValue}),this.on("userInput",n=>{this._setValue(n)}),this.on("finalize",()=>{this.value||(this.value=t.defaultValue),this.value===void 0&&(this.value="")})}}});var hi={};uo(hi,{CANCEL_SYMBOL:()=>ht,MULTISELECT_INSTRUCTIONS:()=>ys,SELECT_INSTRUCTIONS:()=>di,S_BAR:()=>v,S_BAR_END:()=>K,S_BAR_END_RIGHT:()=>oi,S_BAR_H:()=>Zt,S_BAR_START:()=>us,S_BAR_START_RIGHT:()=>ii,S_CHECKBOX_ACTIVE:()=>Yt,S_CHECKBOX_INACTIVE:()=>et,S_CHECKBOX_SELECTED:()=>Ve,S_CONNECT_LEFT:()=>ui,S_CORNER_BOTTOM_LEFT:()=>fs,S_CORNER_BOTTOM_RIGHT:()=>cs,S_CORNER_TOP_LEFT:()=>li,S_CORNER_TOP_RIGHT:()=>ls,S_ERROR:()=>ms,S_INFO:()=>ds,S_PASSWORD_MASK:()=>ai,S_RADIO_ACTIVE:()=>yt,S_RADIO_INACTIVE:()=>We,S_STEP_ACTIVE:()=>rs,S_STEP_CANCEL:()=>os,S_STEP_ERROR:()=>as,S_STEP_SUBMIT:()=>Ge,S_SUCCESS:()=>hs,S_WARN:()=>ps,autocomplete:()=>fi,autocompleteMultiselect:()=>Xa,box:()=>Qa,cancel:()=>uu,confirm:()=>eu,date:()=>tu,formatInstructionFooter:()=>Qt,group:()=>iu,groupMultiselect:()=>au,intro:()=>lu,isCI:()=>is,isCancel:()=>Jt,isTTY:()=>ri,limitOptions:()=>Me,log:()=>de,multiline:()=>fu,multiselect:()=>ou,note:()=>pu,outro:()=>cu,password:()=>mu,path:()=>gu,progress:()=>bu,select:()=>wu,selectKey:()=>$u,settings:()=>O,spinner:()=>bs,stream:()=>Be,symbol:()=>he,symbolBar:()=>gs,taskLog:()=>ku,tasks:()=>Su,text:()=>xu,unicode:()=>zt,unicodeOr:()=>R,updateSettings:()=>Kr});function Ka(){return fe.default.platform!=="win32"?fe.default.env.TERM!=="linux":!!fe.default.env.CI||!!fe.default.env.WT_SESSION||!!fe.default.env.TERMINUS_SUBLIME||fe.default.env.ConEmuTask==="{cmd::Cmder}"||fe.default.env.TERM_PROGRAM==="Terminus-Sublime"||fe.default.env.TERM_PROGRAM==="vscode"||fe.default.env.TERM==="xterm-256color"||fe.default.env.TERM==="alacritty"||fe.default.env.TERMINAL_EMULATOR==="JetBrains-JediTerm"}function Qt(e,t){let n=[`${t?`${(0,c.styleText)("cyan",v)} `:""}${e.join(" \u2022 ")}`];return t&&n.push((0,c.styleText)("cyan",K)),n}function ei(e){return e.label??String(e.value??"")}function ci(e,t){if(!e)return!0;let n=(t.label??String(t.value??"")).toLowerCase(),s=(t.hint??"").toLowerCase(),r=String(t.value).toLowerCase(),i=e.toLowerCase();return n.includes(i)||s.includes(i)||r.includes(i)}function Ja(e,t){let n=[];for(let s of t)e.includes(s.value)&&n.push(s);return n}function ti(e,t,n,s){let r=n,i=n;return s==="center"?r=Math.floor((t-e)/2):s==="right"&&(r=t-e-n),i=t-r-e,[r,i]}function nu(e,t){let n=e.segmentValues,s=e.segmentCursor;if(t==="submit"||t==="cancel")return e.formattedValue;let r=(0,c.styleText)("gray",e.separator);return e.segments.map((i,o)=>{let a=o===s.segmentIndex&&!["submit","cancel"].includes(t),u=ru[i.type];return su(n[i.type],{isActive:a,label:u})}).join(r)}function su(e,t){let n=!e||e.replace(/_/g,"")==="";return t.isActive?(0,c.styleText)("inverse",n?t.label:e.replace(/_/g," ")):n?(0,c.styleText)("dim",t.label):e.replace(/_/g,(0,c.styleText)("dim"," "))}function bu({style:e="heavy",max:t=100,size:n=40,...s}={}){let r=bs(s),i=0,o="",a=Math.max(1,t),u=Math.max(1,n),l=p=>{switch(p){case"initial":case"active":return m=>(0,c.styleText)("magenta",m);case"error":case"cancel":return m=>(0,c.styleText)("red",m);case"submit":return m=>(0,c.styleText)("green",m);default:return m=>(0,c.styleText)("magenta",m)}},f=(p,m)=>{let w=Math.floor(i/a*u);return`${l(p)(ni[e].repeat(w))}${(0,c.styleText)("dim",ni[e].repeat(u-w))} ${m}`},d=(p="")=>{o=p,r.start(f("initial",p))},h=(p=1,m)=>{i=Math.min(a,p+i),r.message(f("active",m??o)),o=m??o};return{start:d,stop:r.stop,cancel:r.cancel,error:r.error,clear:r.clear,advance:h,isCancelled:r.isCancelled,message:p=>h(0,p)}}var c,fe,Ue,gt,Qe,zt,is,ri,R,rs,os,as,Ge,us,v,K,ii,oi,yt,We,Yt,Ve,et,ai,Zt,ls,ui,cs,fs,li,ds,hs,ps,ms,he,gs,Qr,Me,fi,Xa,za,Ya,Za,Qa,eu,tu,ru,iu,ys,mt,ou,au,de,uu,lu,cu,fu,du,hu,pu,mu,gu,yu,bs,ni,di,Xt,wu,$u,si,Be,Su,vu,ku,xu,pi=Xe(()=>{ss();ss();c=require("node:util"),fe=tt(require("node:process"),1);Kn();Un();Ue=require("node:fs"),gt=require("node:path"),Qe=tt(zn(),1);zt=Ka(),is=()=>process.env.CI==="true",ri=e=>e.isTTY===!0,R=(e,t)=>zt?e:t,rs=R("\u25C6","*"),os=R("\u25A0","x"),as=R("\u25B2","x"),Ge=R("\u25C7","o"),us=R("\u250C","T"),v=R("\u2502","|"),K=R("\u2514","\u2014"),ii=R("\u2510","T"),oi=R("\u2518","\u2014"),yt=R("\u25CF",">"),We=R("\u25CB"," "),Yt=R("\u25FB","[\u2022]"),Ve=R("\u25FC","[+]"),et=R("\u25FB","[ ]"),ai=R("\u25AA","\u2022"),Zt=R("\u2500","-"),ls=R("\u256E","+"),ui=R("\u251C","+"),cs=R("\u256F","+"),fs=R("\u2570","+"),li=R("\u256D","+"),ds=R("\u25CF","\u2022"),hs=R("\u25C6","*"),ps=R("\u25B2","!"),ms=R("\u25A0","x"),he=e=>{switch(e){case"initial":case"active":return(0,c.styleText)("cyan",rs);case"cancel":return(0,c.styleText)("red",os);case"error":return(0,c.styleText)("yellow",as);case"submit":return(0,c.styleText)("green",Ge);case"validating":return(0,c.styleText)("dim",rs)}},gs=e=>{switch(e){case"initial":case"active":return(0,c.styleText)("cyan",v);case"cancel":return(0,c.styleText)("red",v);case"error":return(0,c.styleText)("yellow",v);case"submit":return(0,c.styleText)("green",v)}};Qr=(e,t,n,s,r,i=!1)=>{let o=t,a=0;if(i)for(let u=s-1;u>=n;u--){let l=e[u];if(l&&(o-=l.length),a++,o<=r)break}else for(let u=n;u<s;u++){let l=e[u];if(l&&(o-=l.length),a++,o<=r)break}return{lineCount:o,removals:a}},Me=({cursor:e,options:t,style:n,output:s=process.stdout,maxItems:r=Number.POSITIVE_INFINITY,columnPadding:i=0,rowPadding:o=4})=>{let a=Pe(s)-i,u=ts(s),l=(0,c.styleText)("dim","..."),f=Math.max(u-o,0),d=Math.max(Math.min(r,f),5),h=0;e>=d-3&&(h=Math.max(Math.min(e-d+3,t.length-d),0));let p=d<t.length&&h>0,m=d<t.length&&h+d<t.length,w=Math.min(h+d,t.length),b=[],$=0;p&&$++,m&&$++;let _=h+(p?1:0),I=w-(m?1:0);for(let j=_;j<I;j++){let L=t[j],M=L?n(L,j===e):"",N=$e(M,a,{hard:!0,trim:!1}).split(`
42
+ `);b.push(N),$+=N.length}if($>f){let j=0,L=0,M=$,N=e-_,C=f,U=()=>Qr(b,M,0,N,C),q=()=>Qr(b,M,N+1,b.length,C,!0);p?({lineCount:M,removals:j}=U(),M>C&&(m||(C-=1),{lineCount:M,removals:L}=q())):(m||(C-=1),{lineCount:M,removals:L}=q(),M>C&&(C-=1,{lineCount:M,removals:j}=U())),j>0&&(p=!0,b.splice(0,j)),L>0&&(m=!0,b.splice(b.length-L,L))}let F=[];p&&F.push(l);for(let j of b)for(let L of j)F.push(L);return m&&F.push(l),F};fi=e=>new ns({options:e.options,initialValue:e.initialValue?[e.initialValue]:void 0,initialUserInput:e.initialUserInput,placeholder:e.placeholder,completeOnTab:e.completeOnTab,filter:e.filter??((t,n)=>ci(t,n)),signal:e.signal,input:e.input,output:e.output,validate:e.validate,render(){let t=e.withGuide??O.withGuide,n=t?[`${(0,c.styleText)("gray",v)}`,`${he(this.state)} ${e.message}`]:[`${he(this.state)} ${e.message}`],s=this.userInput,r=this.options,i=e.placeholder,o=s===""&&i!==void 0,a=(u,l)=>{let f=ei(u),d=u.hint&&u.value===this.focusedValue?(0,c.styleText)("dim",` (${u.hint})`):"";switch(l){case"active":return`${(0,c.styleText)("green",yt)} ${f}${d}`;case"inactive":return`${(0,c.styleText)("dim",We)} ${(0,c.styleText)("dim",f)}`;case"disabled":return`${(0,c.styleText)("gray",We)} ${(0,c.styleText)(["strikethrough","gray"],f)}`}};switch(this.state){case"submit":{let u=Ja(this.selectedValues,r),l=u.length>0?` ${(0,c.styleText)("dim",u.map(ei).join(", "))}`:"",f=t?(0,c.styleText)("gray",v):"";return`${n.join(`
43
43
  `)}
44
44
  ${f}${l}`}case"cancel":{let u=s?` ${(0,c.styleText)(["strikethrough","dim"],s)}`:"",l=t?(0,c.styleText)("gray",v):"";return`${n.join(`
45
45
  `)}
46
- ${l}${u}`}default:{let u=this.state==="error"?"yellow":"cyan",l=t?`${(0,c.styleText)(u,v)} `:"",f=t?(0,c.styleText)(u,H):"",d="";if(this.isNavigating||o){let k=o?i:s;d=k!==""?` ${(0,c.styleText)("dim",k)}`:""}else d=` ${this.userInputWithCursor}`;let h=this.filteredOptions.length!==r.length?(0,c.styleText)("dim",` (${this.filteredOptions.length} match${this.filteredOptions.length===1?"":"es"})`):"",p=this.filteredOptions.length===0&&s?[`${l}${(0,c.styleText)("yellow","No matches found")}`]:[],m=this.state==="error"?[`${l}${(0,c.styleText)("yellow",this.error)}`]:[];t&&n.push(`${l.trimEnd()}`),n.push(`${l}${(0,c.styleText)("dim","Search:")}${d}${h}`,...p,...m);let w=[`${(0,c.styleText)("dim","\u2191/\u2193")} to select`,...e.completeOnTab?[`${(0,c.styleText)("dim","Tab:")} complete`]:[],`${(0,c.styleText)("dim","Enter:")} confirm`,`${(0,c.styleText)("dim","Type:")} to search`],b=[`${l}${w.join(" \u2022 ")}`,f],$=this.filteredOptions.length===0?[]:Te({cursor:this.cursor,options:this.filteredOptions,columnPadding:t?3:0,rowPadding:n.length+b.length,style:(k,T)=>a(k,k.disabled?"disabled":T?"active":"inactive"),maxItems:e.maxItems,output:e.output});return[...n,...$.map(k=>`${l}${k}`),...b].join(`
47
- `)}}}}).prompt(),Na=e=>{let t=(s,r,i,o)=>{let a=i.includes(s.value),u=s.label??String(s.value??""),l=s.hint&&o!==void 0&&s.value===o?(0,c.styleText)("dim",` (${s.hint})`):"",f=a?(0,c.styleText)("green",Pe):(0,c.styleText)("dim",Xe);return s.disabled?`${(0,c.styleText)("gray",Xe)} ${(0,c.styleText)(["strikethrough","gray"],u)}`:r?`${f} ${u}${l}`:`${f} ${(0,c.styleText)("dim",u)}`},n=new Yn({options:e.options,multiple:!0,placeholder:e.placeholder,filter:e.filter??((s,r)=>ii(s,r)),validate:()=>{if(e.required&&n.selectedValues.length===0)return"Please select at least one item"},initialValue:e.initialValues,signal:e.signal,input:e.input,output:e.output,render(){let s=e.withGuide??I.withGuide,r=`${s?`${(0,c.styleText)("gray",v)}
46
+ ${l}${u}`}default:{let u=this.state==="error"?"yellow":"cyan",l=t?`${(0,c.styleText)(u,v)} `:"",f=t?(0,c.styleText)(u,K):"",d="";if(this.isNavigating||o){let _=o?i:s;d=_!==""?` ${(0,c.styleText)("dim",_)}`:""}else d=` ${this.userInputWithCursor}`;let h=this.filteredOptions.length!==r.length?(0,c.styleText)("dim",` (${this.filteredOptions.length} match${this.filteredOptions.length===1?"":"es"})`):"",p=this.filteredOptions.length===0&&s?[`${l}${(0,c.styleText)("yellow","No matches found")}`]:[],m=this.state==="error"?[`${l}${(0,c.styleText)("yellow",this.error)}`]:[];t&&n.push(`${l.trimEnd()}`),n.push(`${l}${(0,c.styleText)("dim","Search:")}${d}${h}`,...p,...m);let w=[`${(0,c.styleText)("dim","\u2191/\u2193")} to select`,...e.completeOnTab?[`${(0,c.styleText)("dim","Tab:")} complete`]:[],`${(0,c.styleText)("dim","Enter:")} confirm`,`${(0,c.styleText)("dim","Type:")} to search`],b=[`${l}${w.join(" \u2022 ")}`,f],$=this.filteredOptions.length===0?[]:Me({cursor:this.cursor,options:this.filteredOptions,columnPadding:t?3:0,rowPadding:n.length+b.length,style:(_,I)=>a(_,_.disabled?"disabled":I?"active":"inactive"),maxItems:e.maxItems,output:e.output});return[...n,...$.map(_=>`${l}${_}`),...b].join(`
47
+ `)}}}}).prompt(),Xa=e=>{let t=(s,r,i,o)=>{let a=i.includes(s.value),u=s.label??String(s.value??""),l=s.hint&&o!==void 0&&s.value===o?(0,c.styleText)("dim",` (${s.hint})`):"",f=a?(0,c.styleText)("green",Ve):(0,c.styleText)("dim",et);return s.disabled?`${(0,c.styleText)("gray",et)} ${(0,c.styleText)(["strikethrough","gray"],u)}`:r?`${f} ${u}${l}`:`${f} ${(0,c.styleText)("dim",u)}`},n=new ns({options:e.options,multiple:!0,placeholder:e.placeholder,filter:e.filter??((s,r)=>ci(s,r)),validate:()=>{if(e.required&&n.selectedValues.length===0)return"Please select at least one item"},initialValue:e.initialValues,signal:e.signal,input:e.input,output:e.output,render(){let s=e.withGuide??O.withGuide,r=`${s?`${(0,c.styleText)("gray",v)}
48
48
  `:""}${he(this.state)} ${e.message}
49
- `,i=this.userInput,o=e.placeholder,a=i===""&&o!==void 0,u=this.isNavigating||a?(0,c.styleText)("dim",a?o:i):this.userInputWithCursor,l=this.options,f=this.filteredOptions.length!==l.length?(0,c.styleText)("dim",` (${this.filteredOptions.length} match${this.filteredOptions.length===1?"":"es"})`):"";switch(this.state){case"submit":return`${r}${s?`${(0,c.styleText)("gray",v)} `:""}${(0,c.styleText)("dim",`${this.selectedValues.length} items selected`)}`;case"cancel":return`${r}${s?`${(0,c.styleText)("gray",v)} `:""}${(0,c.styleText)(["strikethrough","dim"],i)}`;default:{let d=this.state==="error"?"yellow":"cyan",h=s?`${(0,c.styleText)(d,v)} `:"",p=s?(0,c.styleText)(d,H):"",m=[`${(0,c.styleText)("dim","\u2191/\u2193")} to navigate`,`${(0,c.styleText)("dim",this.isNavigating?"Space/Tab:":"Tab:")} select`,`${(0,c.styleText)("dim","Enter:")} confirm`,`${(0,c.styleText)("dim","Type:")} to search`],w=this.filteredOptions.length===0&&i?[`${h}${(0,c.styleText)("yellow","No matches found")}`]:[],b=this.state==="error"?[`${h}${(0,c.styleText)("yellow",this.error)}`]:[],$=[...`${r}${s?(0,c.styleText)(d,v):""}`.split(`
50
- `),`${h}${(0,c.styleText)("dim","Search:")} ${u}${f}`,...w,...b],k=[`${h}${m.join(" \u2022 ")}`,p],T=Te({cursor:this.cursor,options:this.filteredOptions,style:(F,j)=>t(F,j,this.selectedValues,this.focusedValue),maxItems:e.maxItems,output:e.output,rowPadding:$.length+k.length});return[...$,...T.map(F=>`${h}${F}`),...k].join(`
51
- `)}}}});return n.prompt()},Da=[ri,ss,is,rs],Ra=[ns,ei,H,ti];qa=e=>e,Pa=(e="",t="",n)=>{let s=n?.output??process.stdout,r=Re(s),i=1*2,o=n?.titlePadding??1,a=n?.contentPadding??2,u=n?.width===void 0||n.width==="auto"?1:Math.min(1,n.width),l=n?.withGuide??I.withGuide?`${(0,c.styleText)("gray",v)} `:"",f=n?.formatBorder??qa,d=(n?.rounded?Da:Ra).map(f),h=f(Xt),p=f(v),m=Q(l),w=Q(t),b=r-m,$=Math.floor(r*u)-m;if(n?.width==="auto"){let N=e.split(`
52
- `),U=w+o*2;for(let Z of N){let ee=Q(Z)+a*2;ee>U&&(U=ee)}let R=U+i;R<$&&($=R)}$%2!==0&&($<b?$++:$--);let k=$-i,T=k-o*2,F=w>T?`${t.slice(0,T-3)}...`:t,[j,L]=Yr(Q(F),k,o,n?.titleAlign),M=we(e,k-a*2,{hard:!0,trim:!1});s.write(`${l}${d[0]}${h.repeat(j)}${F}${h.repeat(L)}${d[1]}
53
- `);let C=M.split(`
54
- `);for(let N of C){let[U,R]=Yr(Q(N),k,a,n?.contentAlign);s.write(`${l}${p}${" ".repeat(U)}${N}${" ".repeat(R)}${p}
55
- `)}s.write(`${l}${d[2]}${h.repeat(k)}${d[3]}
56
- `)},Ba=e=>{let t=e.active??"Yes",n=e.inactive??"No";return new qt({active:t,inactive:n,signal:e.signal,input:e.input,output:e.output,initialValue:e.initialValue??!0,render(){let s=e.withGuide??I.withGuide,r=`${he(this.state)} `,i=s?`${(0,c.styleText)("gray",v)} `:"",o=X(e.output,e.message,i,r),a=`${s?`${(0,c.styleText)("gray",v)}
49
+ `,i=this.userInput,o=e.placeholder,a=i===""&&o!==void 0,u=this.isNavigating||a?(0,c.styleText)("dim",a?o:i):this.userInputWithCursor,l=this.options,f=this.filteredOptions.length!==l.length?(0,c.styleText)("dim",` (${this.filteredOptions.length} match${this.filteredOptions.length===1?"":"es"})`):"";switch(this.state){case"submit":return`${r}${s?`${(0,c.styleText)("gray",v)} `:""}${(0,c.styleText)("dim",`${this.selectedValues.length} items selected`)}`;case"cancel":return`${r}${s?`${(0,c.styleText)("gray",v)} `:""}${(0,c.styleText)(["strikethrough","dim"],i)}`;default:{let d=this.state==="error"?"yellow":"cyan",h=s?`${(0,c.styleText)(d,v)} `:"",p=s?(0,c.styleText)(d,K):"",m=[`${(0,c.styleText)("dim","\u2191/\u2193")} to navigate`,`${(0,c.styleText)("dim",this.isNavigating?"Space/Tab:":"Tab:")} select`,`${(0,c.styleText)("dim","Enter:")} confirm`,`${(0,c.styleText)("dim","Type:")} to search`],w=this.filteredOptions.length===0&&i?[`${h}${(0,c.styleText)("yellow","No matches found")}`]:[],b=this.state==="error"?[`${h}${(0,c.styleText)("yellow",this.error)}`]:[],$=[...`${r}${s?(0,c.styleText)(d,v):""}`.split(`
50
+ `),`${h}${(0,c.styleText)("dim","Search:")} ${u}${f}`,...w,...b],_=[`${h}${m.join(" \u2022 ")}`,p],I=Me({cursor:this.cursor,options:this.filteredOptions,style:(F,j)=>t(F,j,this.selectedValues,this.focusedValue),maxItems:e.maxItems,output:e.output,rowPadding:$.length+_.length});return[...$,...I.map(F=>`${h}${F}`),..._].join(`
51
+ `)}}}});return n.prompt()},za=[li,ls,fs,cs],Ya=[us,ii,K,oi];Za=e=>e,Qa=(e="",t="",n)=>{let s=n?.output??process.stdout,r=Pe(s),i=1*2,o=n?.titlePadding??1,a=n?.contentPadding??2,u=n?.width===void 0||n.width==="auto"?1:Math.min(1,n.width),l=n?.withGuide??O.withGuide?`${(0,c.styleText)("gray",v)} `:"",f=n?.formatBorder??Za,d=(n?.rounded?za:Ya).map(f),h=f(Zt),p=f(v),m=Q(l),w=Q(t),b=r-m,$=Math.floor(r*u)-m;if(n?.width==="auto"){let C=e.split(`
52
+ `),U=w+o*2;for(let ee of C){let te=Q(ee)+a*2;te>U&&(U=te)}let q=U+i;q<$&&($=q)}$%2!==0&&($<b?$++:$--);let _=$-i,I=_-o*2,F=w>I?`${t.slice(0,I-3)}...`:t,[j,L]=ti(Q(F),_,o,n?.titleAlign),M=$e(e,_-a*2,{hard:!0,trim:!1});s.write(`${l}${d[0]}${h.repeat(j)}${F}${h.repeat(L)}${d[1]}
53
+ `);let N=M.split(`
54
+ `);for(let C of N){let[U,q]=ti(Q(C),_,a,n?.contentAlign);s.write(`${l}${p}${" ".repeat(U)}${C}${" ".repeat(q)}${p}
55
+ `)}s.write(`${l}${d[2]}${h.repeat(_)}${d[3]}
56
+ `)},eu=e=>{let t=e.active??"Yes",n=e.inactive??"No";return new Vt({active:t,inactive:n,signal:e.signal,input:e.input,output:e.output,initialValue:e.initialValue??!0,render(){let s=e.withGuide??O.withGuide,r=`${he(this.state)} `,i=s?`${(0,c.styleText)("gray",v)} `:"",o=z(e.output,e.message,i,r),a=`${s?`${(0,c.styleText)("gray",v)}
57
57
  `:""}${o}
58
58
  `,u=this.value?t:n;switch(this.state){case"submit":{let l=s?`${(0,c.styleText)("gray",v)} `:"";return`${a}${l}${(0,c.styleText)("dim",u)}`}case"cancel":{let l=s?`${(0,c.styleText)("gray",v)} `:"";return`${a}${l}${(0,c.styleText)(["strikethrough","dim"],u)}${s?`
59
- ${(0,c.styleText)("gray",v)}`:""}`}default:{let l=s?`${(0,c.styleText)("cyan",v)} `:"",f=s?(0,c.styleText)("cyan",H):"";return`${a}${l}${this.value?`${(0,c.styleText)("green",mt)} ${t}`:`${(0,c.styleText)("dim",Ve)} ${(0,c.styleText)("dim",t)}`}${e.vertical?s?`
59
+ ${(0,c.styleText)("gray",v)}`:""}`}default:{let l=s?`${(0,c.styleText)("cyan",v)} `:"",f=s?(0,c.styleText)("cyan",K):"";return`${a}${l}${this.value?`${(0,c.styleText)("green",yt)} ${t}`:`${(0,c.styleText)("dim",We)} ${(0,c.styleText)("dim",t)}`}${e.vertical?s?`
60
60
  ${(0,c.styleText)("cyan",v)} `:`
61
- `:` ${(0,c.styleText)("dim","/")} `}${this.value?`${(0,c.styleText)("dim",Ve)} ${(0,c.styleText)("dim",n)}`:`${(0,c.styleText)("green",mt)} ${n}`}
61
+ `:` ${(0,c.styleText)("dim","/")} `}${this.value?`${(0,c.styleText)("dim",We)} ${(0,c.styleText)("dim",n)}`:`${(0,c.styleText)("green",yt)} ${n}`}
62
62
  ${f}
63
- `}}}}).prompt()},Va=e=>{let t=e.validate;return new Pt({...e,validate(n){if(n===void 0)return e.defaultValue!==void 0?void 0:t?dt(t,n):I.date.messages.required;let s=r=>r.toISOString().slice(0,10);if(e.minDate&&s(n)<s(e.minDate))return I.date.messages.afterMin(e.minDate);if(e.maxDate&&s(n)>s(e.maxDate))return I.date.messages.beforeMax(e.maxDate);if(t)return dt(t,n)},render(){let n=(e?.withGuide??I.withGuide)!==!1,s=`${`${n?`${(0,c.styleText)("gray",v)}
63
+ `}}}}).prompt()},tu=e=>{let t=e.validate;return new Ut({...e,validate(n){if(n===void 0)return e.defaultValue!==void 0?void 0:t?pt(t,n):O.date.messages.required;let s=r=>r.toISOString().slice(0,10);if(e.minDate&&s(n)<s(e.minDate))return O.date.messages.afterMin(e.minDate);if(e.maxDate&&s(n)>s(e.maxDate))return O.date.messages.beforeMax(e.maxDate);if(t)return pt(t,n)},render(){let n=(e?.withGuide??O.withGuide)!==!1,s=`${`${n?`${(0,c.styleText)("gray",v)}
64
64
  `:""}${he(this.state)} `}${e.message}
65
- `,r=this.state!=="initial"?this.state:"active",i=Ua(this,r),o=this.value instanceof Date?this.formattedValue:"";switch(this.state){case"error":{let a=this.error?` ${(0,c.styleText)("yellow",this.error)}`:"",u=n?`${(0,c.styleText)("yellow",v)} `:"",l=n?(0,c.styleText)("yellow",H):"";return`${s.trim()}
65
+ `,r=this.state!=="initial"?this.state:"active",i=nu(this,r),o=this.value instanceof Date?this.formattedValue:"";switch(this.state){case"error":{let a=this.error?` ${(0,c.styleText)("yellow",this.error)}`:"",u=n?`${(0,c.styleText)("yellow",v)} `:"",l=n?(0,c.styleText)("yellow",K):"";return`${s.trim()}
66
66
  ${u}${i}
67
67
  ${l}${a}
68
68
  `}case"submit":{let a=o?` ${(0,c.styleText)("dim",o)}`:"",u=n?(0,c.styleText)("gray",v):"";return`${s}${u}${a}`}case"cancel":{let a=o?` ${(0,c.styleText)(["strikethrough","dim"],o)}`:"",u=n?(0,c.styleText)("gray",v):"";return`${s}${u}${a}${o.trim()?`
69
- ${u}`:""}`}default:{let a=n?`${(0,c.styleText)("cyan",v)} `:"",u=n?(0,c.styleText)("cyan",H):"",l=n?`${(0,c.styleText)("cyan",v)} `:"",f=this.inlineError?`
69
+ ${u}`:""}`}default:{let a=n?`${(0,c.styleText)("cyan",v)} `:"",u=n?(0,c.styleText)("cyan",K):"",l=n?`${(0,c.styleText)("cyan",v)} `:"",f=this.inlineError?`
70
70
  ${l}${(0,c.styleText)("yellow",this.inlineError)}`:"";return`${s}${a}${i}${f}
71
71
  ${u}
72
- `}}}}).prompt()};Ga={year:"yyyy",month:"mm",day:"dd"},Ha=async(e,t)=>{let n={},s=Object.keys(e);for(let r of s){let i=e[r],o=await i({results:n})?.catch(a=>{throw a});if(typeof t?.onCancel=="function"&&Gt(o)){n[r]="canceled",t.onCancel({results:n});continue}n[r]=o}return n},fs=[`${(0,c.styleText)("dim","\u2191/\u2193")} to navigate`,`${(0,c.styleText)("dim","Space:")} select`,`${(0,c.styleText)("dim","Enter:")} confirm`],ht=(e,t)=>e.split(`
72
+ `}}}}).prompt()};ru={year:"yyyy",month:"mm",day:"dd"},iu=async(e,t)=>{let n={},s=Object.keys(e);for(let r of s){let i=e[r],o=await i({results:n})?.catch(a=>{throw a});if(typeof t?.onCancel=="function"&&Jt(o)){n[r]="canceled",t.onCancel({results:n});continue}n[r]=o}return n},ys=[`${(0,c.styleText)("dim","\u2191/\u2193")} to navigate`,`${(0,c.styleText)("dim","Space:")} select`,`${(0,c.styleText)("dim","Enter:")} confirm`],mt=(e,t)=>e.split(`
73
73
  `).map(n=>t(n)).join(`
74
- `),Ka=e=>{let t=(r,i)=>{let o=r.label??String(r.value);return i==="disabled"?`${(0,c.styleText)("gray",Xe)} ${ht(o,a=>(0,c.styleText)(["strikethrough","gray"],a))}${r.hint?` ${(0,c.styleText)("dim",`(${r.hint??"disabled"})`)}`:""}`:i==="active"?`${(0,c.styleText)("cyan",Jt)} ${o}${r.hint?` ${(0,c.styleText)("dim",`(${r.hint})`)}`:""}`:i==="selected"?`${(0,c.styleText)("green",Pe)} ${ht(o,a=>(0,c.styleText)("dim",a))}${r.hint?` ${(0,c.styleText)("dim",`(${r.hint})`)}`:""}`:i==="cancelled"?`${ht(o,a=>(0,c.styleText)(["strikethrough","dim"],a))}`:i==="active-selected"?`${(0,c.styleText)("green",Pe)} ${o}${r.hint?` ${(0,c.styleText)("dim",`(${r.hint})`)}`:""}`:i==="submitted"?`${ht(o,a=>(0,c.styleText)("dim",a))}`:`${(0,c.styleText)("dim",Xe)} ${ht(o,a=>(0,c.styleText)("dim",a))}`},n=e.required??!0,s=e.showInstructions??!0;return new Vt({options:e.options,signal:e.signal,input:e.input,output:e.output,initialValues:e.initialValues,required:n,cursorAt:e.cursorAt,validate(r){if(n&&(r===void 0||r.length===0))return`Please select at least one option.
75
- ${(0,c.styleText)("reset",(0,c.styleText)("dim",`Press ${(0,c.styleText)(["gray","bgWhite","inverse"]," space ")} to select, ${(0,c.styleText)("gray",(0,c.styleText)("bgWhite",(0,c.styleText)("inverse"," enter ")))} to submit`))}`},render(){let r=e.withGuide??I.withGuide,i=X(e.output,e.message,r?`${cs(this.state)} `:"",`${he(this.state)} `),o=`${r?`${(0,c.styleText)("gray",v)}
74
+ `),ou=e=>{let t=(r,i)=>{let o=r.label??String(r.value);return i==="disabled"?`${(0,c.styleText)("gray",et)} ${mt(o,a=>(0,c.styleText)(["strikethrough","gray"],a))}${r.hint?` ${(0,c.styleText)("dim",`(${r.hint??"disabled"})`)}`:""}`:i==="active"?`${(0,c.styleText)("cyan",Yt)} ${o}${r.hint?` ${(0,c.styleText)("dim",`(${r.hint})`)}`:""}`:i==="selected"?`${(0,c.styleText)("green",Ve)} ${mt(o,a=>(0,c.styleText)("dim",a))}${r.hint?` ${(0,c.styleText)("dim",`(${r.hint})`)}`:""}`:i==="cancelled"?`${mt(o,a=>(0,c.styleText)(["strikethrough","dim"],a))}`:i==="active-selected"?`${(0,c.styleText)("green",Ve)} ${o}${r.hint?` ${(0,c.styleText)("dim",`(${r.hint})`)}`:""}`:i==="submitted"?`${mt(o,a=>(0,c.styleText)("dim",a))}`:`${(0,c.styleText)("dim",et)} ${mt(o,a=>(0,c.styleText)("dim",a))}`},n=e.required??!0,s=e.showInstructions??!0;return new Gt({options:e.options,signal:e.signal,input:e.input,output:e.output,initialValues:e.initialValues,required:n,cursorAt:e.cursorAt,validate(r){if(n&&(r===void 0||r.length===0))return`Please select at least one option.
75
+ ${(0,c.styleText)("reset",(0,c.styleText)("dim",`Press ${(0,c.styleText)(["gray","bgWhite","inverse"]," space ")} to select, ${(0,c.styleText)("gray",(0,c.styleText)("bgWhite",(0,c.styleText)("inverse"," enter ")))} to submit`))}`},render(){let r=e.withGuide??O.withGuide,i=z(e.output,e.message,r?`${gs(this.state)} `:"",`${he(this.state)} `),o=`${r?`${(0,c.styleText)("gray",v)}
76
76
  `:""}${i}
77
- `,a=this.value??[],u=(l,f)=>{if(l.disabled)return t(l,"disabled");let d=a.includes(l.value);return f&&d?t(l,"active-selected"):d?t(l,"selected"):t(l,f?"active":"inactive")};switch(this.state){case"submit":{let l=this.options.filter(({value:d})=>a.includes(d)).map(d=>t(d,"submitted")).join((0,c.styleText)("dim",", "))||(0,c.styleText)("dim","none"),f=X(e.output,l,r?`${(0,c.styleText)("gray",v)} `:"");return`${o}${f}`}case"cancel":{let l=this.options.filter(({value:d})=>a.includes(d)).map(d=>t(d,"cancelled")).join((0,c.styleText)("dim",", "));if(l.trim()==="")return`${o}${(0,c.styleText)("gray",v)}`;let f=X(e.output,l,r?`${(0,c.styleText)("gray",v)} `:"");return`${o}${f}${r?`
77
+ `,a=this.value??[],u=(l,f)=>{if(l.disabled)return t(l,"disabled");let d=a.includes(l.value);return f&&d?t(l,"active-selected"):d?t(l,"selected"):t(l,f?"active":"inactive")};switch(this.state){case"submit":{let l=this.options.filter(({value:d})=>a.includes(d)).map(d=>t(d,"submitted")).join((0,c.styleText)("dim",", "))||(0,c.styleText)("dim","none"),f=z(e.output,l,r?`${(0,c.styleText)("gray",v)} `:"");return`${o}${f}`}case"cancel":{let l=this.options.filter(({value:d})=>a.includes(d)).map(d=>t(d,"cancelled")).join((0,c.styleText)("dim",", "));if(l.trim()==="")return`${o}${(0,c.styleText)("gray",v)}`;let f=z(e.output,l,r?`${(0,c.styleText)("gray",v)} `:"");return`${o}${f}${r?`
78
78
  ${(0,c.styleText)("gray",v)}`:""}`}case"error":{let l=r?`${(0,c.styleText)("yellow",v)} `:"",f=this.error.split(`
79
- `).map((p,m)=>m===0?`${r?`${(0,c.styleText)("yellow",H)} `:""}${(0,c.styleText)("yellow",p)}`:` ${p}`).join(`
79
+ `).map((p,m)=>m===0?`${r?`${(0,c.styleText)("yellow",K)} `:""}${(0,c.styleText)("yellow",p)}`:` ${p}`).join(`
80
80
  `),d=o.split(`
81
81
  `).length,h=f.split(`
82
- `).length+1;return`${o}${l}${Te({output:e.output,options:this.options,cursor:this.cursor,maxItems:e.maxItems,columnPadding:l.length,rowPadding:d+h,style:u}).join(`
82
+ `).length+1;return`${o}${l}${Me({output:e.output,options:this.options,cursor:this.cursor,maxItems:e.maxItems,columnPadding:l.length,rowPadding:d+h,style:u}).join(`
83
83
  ${l}`)}
84
84
  ${f}
85
85
  `}default:{let l=r?`${(0,c.styleText)("cyan",v)} `:"",f=o.split(`
86
- `).length,d=s?Yt(fs,r):r?[(0,c.styleText)("cyan",H)]:[],h=d.join(`
87
- `),p=d.length+1;return`${o}${l}${Te({output:e.output,options:this.options,cursor:this.cursor,maxItems:e.maxItems,columnPadding:l.length,rowPadding:f+p,style:u}).join(`
86
+ `).length,d=s?Qt(ys,r):r?[(0,c.styleText)("cyan",K)]:[],h=d.join(`
87
+ `),p=d.length+1;return`${o}${l}${Me({output:e.output,options:this.options,cursor:this.cursor,maxItems:e.maxItems,columnPadding:l.length,rowPadding:f+p,style:u}).join(`
88
88
  ${l}`)}
89
89
  ${h}
90
- `}}}}).prompt()},Ja=e=>{let{selectableGroups:t=!0,groupSpacing:n=0}=e,s=(o,a,u=[])=>{let l=o.label??String(o.value),f=typeof o.group=="string",d=f&&(u[u.indexOf(o)+1]??{group:!0}),h=f&&d&&d.group===!0,p="",m="";f&&(t?(p=h?`${H} `:`${v} `,m=h?" ":`${v} `):p=" ");let w="";if(n>0&&!f&&(w=`
91
- `.repeat(n)),a==="active")return X(e.output,`${l}${o.hint?` ${(0,c.styleText)("dim",`(${o.hint})`)}`:""}`,`${w}${(0,c.styleText)("dim",p)} `,`${w}${(0,c.styleText)("dim",p)}${(0,c.styleText)("cyan",Jt)} `,`${w}${(0,c.styleText)("dim",m)} `);if(a==="group-active")return X(e.output,l,`${w}${p} `,`${w}${p}${(0,c.styleText)("cyan",Jt)} `,`${w}${m} `,$=>(0,c.styleText)("dim",$));if(a==="group-active-selected")return X(e.output,l,`${w}${p} `,`${w}${p}${(0,c.styleText)("green",Pe)} `,`${w}${m} `,$=>(0,c.styleText)("dim",$));if(a==="selected"){let $=f||t?(0,c.styleText)("green",Pe):"";return X(e.output,`${l}${o.hint?` (${o.hint})`:""}`,`${w}${(0,c.styleText)("dim",p)} `,`${w}${(0,c.styleText)("dim",p)}${$} `,`${w}${(0,c.styleText)("dim",m)} `,k=>(0,c.styleText)("dim",k))}if(a==="cancelled")return`${(0,c.styleText)(["strikethrough","dim"],l)}`;if(a==="active-selected")return X(e.output,`${l}${o.hint?` ${(0,c.styleText)("dim",`(${o.hint})`)}`:""}`,`${w}${(0,c.styleText)("dim",p)} `,`${w}${(0,c.styleText)("dim",p)}${(0,c.styleText)("green",Pe)} `,`${w}${(0,c.styleText)("dim",m)} `);if(a==="submitted")return`${(0,c.styleText)("dim",l)}`;let b=f||t?(0,c.styleText)("dim",Xe):"";return X(e.output,l,`${w}${(0,c.styleText)("dim",p)} `,`${w}${(0,c.styleText)("dim",p)}${b} `,`${w}${(0,c.styleText)("dim",m)} `,$=>(0,c.styleText)("dim",$))},r=e.required??!0,i=e.showInstructions??!0;return new Gr({options:e.options,signal:e.signal,input:e.input,output:e.output,initialValues:e.initialValues,required:r,cursorAt:e.cursorAt,selectableGroups:t,validate(o){if(r&&(o===void 0||o.length===0))return`Please select at least one option.
92
- ${(0,c.styleText)("reset",(0,c.styleText)("dim",`Press ${(0,c.styleText)(["gray","bgWhite","inverse"]," space ")} to select, ${(0,c.styleText)("gray",(0,c.styleText)(["bgWhite","inverse"]," enter "))} to submit`))}`},render(){let o=e.withGuide??I.withGuide,a=`${o?`${(0,c.styleText)("gray",v)}
90
+ `}}}}).prompt()},au=e=>{let{selectableGroups:t=!0,groupSpacing:n=0}=e,s=(o,a,u=[])=>{let l=o.label??String(o.value),f=typeof o.group=="string",d=f&&(u[u.indexOf(o)+1]??{group:!0}),h=f&&d&&d.group===!0,p="",m="";f&&(t?(p=h?`${K} `:`${v} `,m=h?" ":`${v} `):p=" ");let w="";if(n>0&&!f&&(w=`
91
+ `.repeat(n)),a==="active")return z(e.output,`${l}${o.hint?` ${(0,c.styleText)("dim",`(${o.hint})`)}`:""}`,`${w}${(0,c.styleText)("dim",p)} `,`${w}${(0,c.styleText)("dim",p)}${(0,c.styleText)("cyan",Yt)} `,`${w}${(0,c.styleText)("dim",m)} `);if(a==="group-active")return z(e.output,l,`${w}${p} `,`${w}${p}${(0,c.styleText)("cyan",Yt)} `,`${w}${m} `,$=>(0,c.styleText)("dim",$));if(a==="group-active-selected")return z(e.output,l,`${w}${p} `,`${w}${p}${(0,c.styleText)("green",Ve)} `,`${w}${m} `,$=>(0,c.styleText)("dim",$));if(a==="selected"){let $=f||t?(0,c.styleText)("green",Ve):"";return z(e.output,`${l}${o.hint?` (${o.hint})`:""}`,`${w}${(0,c.styleText)("dim",p)} `,`${w}${(0,c.styleText)("dim",p)}${$} `,`${w}${(0,c.styleText)("dim",m)} `,_=>(0,c.styleText)("dim",_))}if(a==="cancelled")return`${(0,c.styleText)(["strikethrough","dim"],l)}`;if(a==="active-selected")return z(e.output,`${l}${o.hint?` ${(0,c.styleText)("dim",`(${o.hint})`)}`:""}`,`${w}${(0,c.styleText)("dim",p)} `,`${w}${(0,c.styleText)("dim",p)}${(0,c.styleText)("green",Ve)} `,`${w}${(0,c.styleText)("dim",m)} `);if(a==="submitted")return`${(0,c.styleText)("dim",l)}`;let b=f||t?(0,c.styleText)("dim",et):"";return z(e.output,l,`${w}${(0,c.styleText)("dim",p)} `,`${w}${(0,c.styleText)("dim",p)}${b} `,`${w}${(0,c.styleText)("dim",m)} `,$=>(0,c.styleText)("dim",$))},r=e.required??!0,i=e.showInstructions??!0;return new zr({options:e.options,signal:e.signal,input:e.input,output:e.output,initialValues:e.initialValues,required:r,cursorAt:e.cursorAt,selectableGroups:t,validate(o){if(r&&(o===void 0||o.length===0))return`Please select at least one option.
92
+ ${(0,c.styleText)("reset",(0,c.styleText)("dim",`Press ${(0,c.styleText)(["gray","bgWhite","inverse"]," space ")} to select, ${(0,c.styleText)("gray",(0,c.styleText)(["bgWhite","inverse"]," enter "))} to submit`))}`},render(){let o=e.withGuide??O.withGuide,a=`${o?`${(0,c.styleText)("gray",v)}
93
93
  `:""}${he(this.state)} ${e.message}
94
94
  `,u=this.value??[],l=(f,d)=>{let h=this.options,p=u.includes(f.value)||f.group===!0&&this.isGroupSelected(`${f.value}`);return!d&&typeof f.group=="string"&&this.options[this.cursor]?.value===f.group?s(f,p?"group-active-selected":"group-active",h):d&&p?s(f,"active-selected",h):p?s(f,"selected",h):s(f,d?"active":"inactive",h)};switch(this.state){case"submit":{let f=this.options.filter(({value:h})=>u.includes(h)).map(h=>s(h,"submitted")),d=f.length===0?"":` ${f.join((0,c.styleText)("dim",", "))}`;return`${a}${o?(0,c.styleText)("gray",v):""}${d}`}case"cancel":{let f=this.options.filter(({value:d})=>u.includes(d)).map(d=>s(d,"cancelled")).join((0,c.styleText)("dim",", "));return`${a}${o?`${(0,c.styleText)("gray",v)} `:""}${f.trim()?`${f}${o?`
95
95
  ${(0,c.styleText)("gray",v)}`:""}`:""}`}case"error":{let f=o?`${(0,c.styleText)("yellow",v)} `:"",d=this.error.split(`
96
- `).map((w,b)=>b===0?`${o?`${(0,c.styleText)("yellow",H)} `:""}${(0,c.styleText)("yellow",w)}`:` ${w}`).join(`
96
+ `).map((w,b)=>b===0?`${o?`${(0,c.styleText)("yellow",K)} `:""}${(0,c.styleText)("yellow",w)}`:` ${w}`).join(`
97
97
  `),h=a.split(`
98
98
  `).length,p=d.split(`
99
- `).length+1,m=Te({output:e.output,options:this.options,cursor:this.cursor,maxItems:e.maxItems,columnPadding:f.length,rowPadding:h+p,style:l}).join(`
99
+ `).length+1,m=Me({output:e.output,options:this.options,cursor:this.cursor,maxItems:e.maxItems,columnPadding:f.length,rowPadding:h+p,style:l}).join(`
100
100
  ${f}`);return`${a}${f}${m}
101
101
  ${d}
102
102
  `}default:{let f=o?`${(0,c.styleText)("cyan",v)} `:"",d=a.split(`
103
- `).length,h=i?Yt(fs,o):o?[(0,c.styleText)("cyan",H)]:[],p=h.join(`
104
- `),m=h.length+1,w=Te({output:e.output,options:this.options,cursor:this.cursor,maxItems:e.maxItems,columnPadding:f.length,rowPadding:d+m,style:l}).join(`
103
+ `).length,h=i?Qt(ys,o):o?[(0,c.styleText)("cyan",K)]:[],p=h.join(`
104
+ `),m=h.length+1,w=Me({output:e.output,options:this.options,cursor:this.cursor,maxItems:e.maxItems,columnPadding:f.length,rowPadding:d+m,style:l}).join(`
105
105
  ${f}`);return`${a}${f}${w}
106
106
  ${p}
107
- `}}}}).prompt()},de={message:(e=[],{symbol:t=(0,c.styleText)("gray",v),secondarySymbol:n=(0,c.styleText)("gray",v),output:s=process.stdout,spacing:r=1,withGuide:i}={})=>{let o=[],a=i??I.withGuide,u=a?n:"",l=a?`${t} `:"",f=a?`${n} `:"";for(let h=0;h<r;h++)o.push(u);let d=Array.isArray(e)?e:e.split(`
107
+ `}}}}).prompt()},de={message:(e=[],{symbol:t=(0,c.styleText)("gray",v),secondarySymbol:n=(0,c.styleText)("gray",v),output:s=process.stdout,spacing:r=1,withGuide:i}={})=>{let o=[],a=i??O.withGuide,u=a?n:"",l=a?`${t} `:"",f=a?`${n} `:"";for(let h=0;h<r;h++)o.push(u);let d=Array.isArray(e)?e:e.split(`
108
108
  `);if(d.length>0){let[h,...p]=d;h.length>0?o.push(`${l}${h}`):o.push(a?t:"");for(let m of p)m.length>0?o.push(`${f}${m}`):o.push(a?n:"")}s.write(`${o.join(`
109
109
  `)}
110
- `)},info:(e,t)=>{de.message(e,{...t,symbol:(0,c.styleText)("blue",os)})},success:(e,t)=>{de.message(e,{...t,symbol:(0,c.styleText)("green",as)})},step:(e,t)=>{de.message(e,{...t,symbol:(0,c.styleText)("green",Ue)})},warn:(e,t)=>{de.message(e,{...t,symbol:(0,c.styleText)("yellow",us)})},warning:(e,t)=>{de.warn(e,t)},error:(e,t)=>{de.message(e,{...t,symbol:(0,c.styleText)("red",ls)})}},Xa=(e="",t)=>{let n=t?.output??process.stdout,s=t?.withGuide??I.withGuide?`${(0,c.styleText)("gray",H)} `:"";n.write(`${s}${(0,c.styleText)("red",e)}
110
+ `)},info:(e,t)=>{de.message(e,{...t,symbol:(0,c.styleText)("blue",ds)})},success:(e,t)=>{de.message(e,{...t,symbol:(0,c.styleText)("green",hs)})},step:(e,t)=>{de.message(e,{...t,symbol:(0,c.styleText)("green",Ge)})},warn:(e,t)=>{de.message(e,{...t,symbol:(0,c.styleText)("yellow",ps)})},warning:(e,t)=>{de.warn(e,t)},error:(e,t)=>{de.message(e,{...t,symbol:(0,c.styleText)("red",ms)})}},uu=(e="",t)=>{let n=t?.output??process.stdout,s=t?.withGuide??O.withGuide?`${(0,c.styleText)("gray",K)} `:"";n.write(`${s}${(0,c.styleText)("red",e)}
111
111
 
112
- `)},Ya=(e="",t)=>{let n=t?.output??process.stdout,s=t?.withGuide??I.withGuide?`${(0,c.styleText)("gray",ns)} `:"";n.write(`${s}${e}
113
- `)},za=(e="",t)=>{let n=t?.output??process.stdout,s=t?.withGuide??I.withGuide?`${(0,c.styleText)("gray",v)}
114
- ${(0,c.styleText)("gray",H)} `:"";n.write(`${s}${e}
112
+ `)},lu=(e="",t)=>{let n=t?.output??process.stdout,s=t?.withGuide??O.withGuide?`${(0,c.styleText)("gray",us)} `:"";n.write(`${s}${e}
113
+ `)},cu=(e="",t)=>{let n=t?.output??process.stdout,s=t?.withGuide??O.withGuide?`${(0,c.styleText)("gray",v)}
114
+ ${(0,c.styleText)("gray",K)} `:"";n.write(`${s}${e}
115
115
 
116
- `)},Qa=e=>new Bt({validate:e.validate,placeholder:e.placeholder,defaultValue:e.defaultValue,initialValue:e.initialValue,showSubmit:e.showSubmit,output:e.output,signal:e.signal,input:e.input,render(){let t=e?.withGuide??I.withGuide,n=`${`${t?`${(0,c.styleText)("gray",v)}
116
+ `)},fu=e=>new Wt({validate:e.validate,placeholder:e.placeholder,defaultValue:e.defaultValue,initialValue:e.initialValue,showSubmit:e.showSubmit,output:e.output,signal:e.signal,input:e.input,render(){let t=e?.withGuide??O.withGuide,n=`${`${t?`${(0,c.styleText)("gray",v)}
117
117
  `:""}${he(this.state)} `}${e.message}
118
118
  `,s=e.placeholder&&e.placeholder.length>0?(0,c.styleText)("inverse",e.placeholder[0])+(0,c.styleText)("dim",e.placeholder.slice(1)):(0,c.styleText)(["inverse","hidden"],"_"),r=this.userInput?this.userInputWithCursor:s,i=this.value??"",o=e.showSubmit?`
119
- ${(0,c.styleText)(this.focused==="submit"?"cyan":"dim","[ submit ]")}`:"";switch(this.state){case"error":{let a=`${(0,c.styleText)("yellow",v)} `,u=t?X(e.output,r,a,void 0):r,l=(0,c.styleText)("yellow",H);return`${n}${u}
119
+ ${(0,c.styleText)(this.focused==="submit"?"cyan":"dim","[ submit ]")}`:"";switch(this.state){case"error":{let a=`${(0,c.styleText)("yellow",v)} `,u=t?z(e.output,r,a,void 0):r,l=(0,c.styleText)("yellow",K);return`${n}${u}
120
120
  ${l} ${(0,c.styleText)("yellow",this.error)}${o}
121
- `}case"submit":{let a=`${(0,c.styleText)("gray",v)} `,u=t?X(e.output,i,a,void 0,void 0,l=>(0,c.styleText)("dim",l)):i?(0,c.styleText)("dim",i):"";return`${n}${u}`}case"cancel":{let a=`${(0,c.styleText)("gray",v)} `,u=t?X(e.output,i,a,void 0,void 0,l=>(0,c.styleText)(["strikethrough","dim"],l)):i?(0,c.styleText)(["strikethrough","dim"],i):"";return`${n}${u}`}default:{let a=t?`${(0,c.styleText)("cyan",v)} `:"",u=t?(0,c.styleText)("cyan",H):"",l=t?X(e.output,r,a):r;return`${n}${l}
121
+ `}case"submit":{let a=`${(0,c.styleText)("gray",v)} `,u=t?z(e.output,i,a,void 0,void 0,l=>(0,c.styleText)("dim",l)):i?(0,c.styleText)("dim",i):"";return`${n}${u}`}case"cancel":{let a=`${(0,c.styleText)("gray",v)} `,u=t?z(e.output,i,a,void 0,void 0,l=>(0,c.styleText)(["strikethrough","dim"],l)):i?(0,c.styleText)(["strikethrough","dim"],i):"";return`${n}${u}`}default:{let a=t?`${(0,c.styleText)("cyan",v)} `:"",u=t?(0,c.styleText)("cyan",K):"",l=t?z(e.output,r,a):r;return`${n}${l}
122
122
  ${u}${o}
123
- `}}}}).prompt(),Za=e=>e,eu=(e,t,n)=>{let s={hard:!0,trim:!1},r=we(e,t,s).split(`
124
- `),i=r.reduce((u,l)=>Math.max(Q(l),u),0),o=r.map(n).reduce((u,l)=>Math.max(Q(l),u),0),a=t-(o-i);return we(e,a,s)},tu=(e="",t="",n)=>{let s=n?.output??fe.default.stdout,r=n?.withGuide??I.withGuide,i=n?.format??Za,o=["",...eu(e,Re(s)-6,i).split(`
123
+ `}}}}).prompt(),du=e=>e,hu=(e,t,n)=>{let s={hard:!0,trim:!1},r=$e(e,t,s).split(`
124
+ `),i=r.reduce((u,l)=>Math.max(Q(l),u),0),o=r.map(n).reduce((u,l)=>Math.max(Q(l),u),0),a=t-(o-i);return $e(e,a,s)},pu=(e="",t="",n)=>{let s=n?.output??fe.default.stdout,r=n?.withGuide??O.withGuide,i=n?.format??du,o=["",...hu(e,Pe(s)-6,i).split(`
125
125
  `).map(i),""],a=Q(t),u=Math.max(o.reduce((h,p)=>{let m=Q(p);return m>h?m:h},0),a)+2,l=o.map(h=>`${(0,c.styleText)("gray",v)} ${h}${" ".repeat(u-Q(h))}${(0,c.styleText)("gray",v)}`).join(`
126
126
  `),f=r?`${(0,c.styleText)("gray",v)}
127
- `:"",d=r?si:is;s.write(`${f}${(0,c.styleText)("green",Ue)} ${(0,c.styleText)("reset",t)} ${(0,c.styleText)("gray",Xt.repeat(Math.max(u-a-1,1))+ss)}
127
+ `:"",d=r?ui:fs;s.write(`${f}${(0,c.styleText)("green",Ge)} ${(0,c.styleText)("reset",t)} ${(0,c.styleText)("gray",Zt.repeat(Math.max(u-a-1,1))+ls)}
128
128
  ${l}
129
- ${(0,c.styleText)("gray",d+Xt.repeat(u+2)+rs)}
130
- `)},nu=e=>new Hr({validate:e.validate,mask:e.mask??ni,signal:e.signal,input:e.input,output:e.output,render(){let t=e.withGuide??I.withGuide,n=`${t?`${(0,c.styleText)("gray",v)}
129
+ ${(0,c.styleText)("gray",d+Zt.repeat(u+2)+cs)}
130
+ `)},mu=e=>new Yr({validate:e.validate,mask:e.mask??ai,signal:e.signal,input:e.input,output:e.output,render(){let t=e.withGuide??O.withGuide,n=`${t?`${(0,c.styleText)("gray",v)}
131
131
  `:""}${he(this.state)} ${e.message}
132
- `,s=this.userInputWithCursor,r=this.masked;switch(this.state){case"error":{let i=t?`${(0,c.styleText)("yellow",v)} `:"",o=t?`${(0,c.styleText)("yellow",H)} `:"",a=r??"";return e.clearOnError&&this.clear(),`${n.trim()}
132
+ `,s=this.userInputWithCursor,r=this.masked;switch(this.state){case"error":{let i=t?`${(0,c.styleText)("yellow",v)} `:"",o=t?`${(0,c.styleText)("yellow",K)} `:"",a=r??"";return e.clearOnError&&this.clear(),`${n.trim()}
133
133
  ${i}${a}
134
134
  ${o}${(0,c.styleText)("yellow",this.error)}
135
135
  `}case"submit":{let i=t?`${(0,c.styleText)("gray",v)} `:"",o=r?(0,c.styleText)("dim",r):"";return`${n}${i}${o}`}case"cancel":{let i=t?`${(0,c.styleText)("gray",v)} `:"",o=r?(0,c.styleText)(["strikethrough","dim"],r):"";return`${n}${i}${o}${r&&t?`
136
- ${(0,c.styleText)("gray",v)}`:""}`}default:{let i=t?`${(0,c.styleText)("cyan",v)} `:"",o=t?(0,c.styleText)("cyan",H):"";return`${n}${i}${s}
136
+ ${(0,c.styleText)("gray",v)}`:""}`}default:{let i=t?`${(0,c.styleText)("cyan",v)} `:"",o=t?(0,c.styleText)("cyan",K):"";return`${n}${i}${s}
137
137
  ${o}
138
- `}}}}).prompt(),su=e=>{let t=e.validate;return oi({...e,initialUserInput:e.initialValue??e.root??process.cwd(),maxItems:5,completeOnTab:!0,validate(n){if(!Array.isArray(n)){if(!n)return"Please select a path";if(t)return dt(t,n)}},options(){let n=this.userInput;if(n==="")return[];try{let s;(0,Be.existsSync)(n)?(0,Be.lstatSync)(n).isDirectory()&&(!e.directory||n.endsWith("/"))?s=n:s=(0,pt.dirname)(n):s=(0,pt.dirname)(n);let r=n.length>1&&n.endsWith("/")?n.slice(0,-1):n;return(0,Be.readdirSync)(s).map(i=>{let o=(0,pt.join)(s,i),a=(0,Be.lstatSync)(o);return{name:i,path:o,isDirectory:a.isDirectory()}}).filter(({path:i,isDirectory:o})=>i.startsWith(r)&&(o||!e.directory)).map(i=>({value:i.path}))}catch{return[]}}})},ru=e=>(0,c.styleText)("magenta",e),ds=({indicator:e="dots",onCancel:t,output:n=process.stdout,cancelMessage:s,errorMessage:r,frames:i=Kt?["\u25D2","\u25D0","\u25D3","\u25D1"]:["\u2022","o","O","0"],delay:o=Kt?80:120,signal:a,...u}={})=>{let l=Zn(),f,d,h=!1,p=!1,m="",w,b=performance.now(),$=Re(n),k=u?.styleFrame??ru,T=D=>{let P=D>1?r??I.messages.error:s??I.messages.cancel;p=D===1,h&&(ee(P,D),p&&typeof t=="function"&&t())},F=()=>T(2),j=()=>T(1),L=()=>{process.on("uncaughtExceptionMonitor",F),process.on("unhandledRejection",F),process.on("SIGINT",j),process.on("SIGTERM",j),process.on("exit",T),a&&a.addEventListener("abort",j)},M=()=>{process.removeListener("uncaughtExceptionMonitor",F),process.removeListener("unhandledRejection",F),process.removeListener("SIGINT",j),process.removeListener("SIGTERM",j),process.removeListener("exit",T),a&&a.removeEventListener("abort",j)},C=()=>{if(w===void 0)return;l&&n.write(`
139
- `);let D=we(w,$,{hard:!0,trim:!1}).split(`
140
- `);D.length>1&&n.write(Je.cursor.up(D.length-1)),n.write(Je.cursor.to(0)),n.write(Je.erase.down())},N=D=>D.replace(/\.+$/,""),U=D=>{let P=(performance.now()-D)/1e3,J=Math.floor(P/60),G=Math.floor(P%60);return J>0?`[${J}m ${G}s]`:`[${G}s]`},R=u.withGuide??I.withGuide,Z=(D="")=>{h=!0,f=Ur({output:n}),m=N(D),b=performance.now(),R&&n.write(`${(0,c.styleText)("gray",v)}
141
- `);let P=0,J=0;L(),d=setInterval(()=>{if(l&&m===w)return;C(),w=m;let G=k(i[P]),pe;if(l)pe=`${G} ${m}...`;else if(e==="timer")pe=`${G} ${m} ${U(b)}`;else{let $e=".".repeat(Math.floor(J)).slice(0,3);pe=`${G} ${m}${$e}`}let Se=we(pe,$,{hard:!0,trim:!1});n.write(Se),P=P+1<i.length?P+1:0,J=J<4?J+.125:0},o)},ee=(D="",P=0,J=!1)=>{if(!h)return;h=!1,clearInterval(d),C();let G=P===0?(0,c.styleText)("green",Ue):P===1?(0,c.styleText)("red",es):(0,c.styleText)("red",ts);m=D??m,J||(e==="timer"?n.write(`${G} ${m} ${U(b)}
142
- `):n.write(`${G} ${m}
143
- `)),M(),f()};return{start:Z,stop:(D="")=>ee(D,0),message:(D="")=>{m=N(D??m)},cancel:(D="")=>ee(D,1),error:(D="")=>ee(D,2),clear:()=>ee("",0,!0),get isCancelled(){return p}}},zr={light:q("\u2500","-"),heavy:q("\u2501","="),block:q("\u2588","#")};ai=[`${(0,c.styleText)("dim","\u2191/\u2193")} to navigate`,`${(0,c.styleText)("dim","Enter:")} confirm`],Ht=(e,t)=>e.includes(`
138
+ `}}}}).prompt(),gu=e=>{let t=e.validate;return fi({...e,initialUserInput:e.initialValue??e.root??process.cwd(),maxItems:5,completeOnTab:!0,validate(n){if(!Array.isArray(n)){if(!n)return"Please select a path";if(t)return pt(t,n)}},options(){let n=this.userInput;if(n==="")return[];try{let s;(0,Ue.existsSync)(n)?(0,Ue.lstatSync)(n).isDirectory()&&(!e.directory||n.endsWith("/"))?s=n:s=(0,gt.dirname)(n):s=(0,gt.dirname)(n);let r=n.length>1&&n.endsWith("/")?n.slice(0,-1):n;return(0,Ue.readdirSync)(s).map(i=>{let o=(0,gt.join)(s,i),a=(0,Ue.lstatSync)(o);return{name:i,path:o,isDirectory:a.isDirectory()}}).filter(({path:i,isDirectory:o})=>i.startsWith(r)&&(o||!e.directory)).map(i=>({value:i.path}))}catch{return[]}}})},yu=e=>(0,c.styleText)("magenta",e),bs=({indicator:e="dots",onCancel:t,output:n=process.stdout,cancelMessage:s,errorMessage:r,frames:i=zt?["\u25D2","\u25D0","\u25D3","\u25D1"]:["\u2022","o","O","0"],delay:o=zt?80:120,signal:a,...u}={})=>{let l=is(),f,d,h=!1,p=!1,m="",w,b=performance.now(),$=Pe(n),_=u?.styleFrame??yu,I=D=>{let P=D>1?r??O.messages.error:s??O.messages.cancel;p=D===1,h&&(te(P,D),p&&typeof t=="function"&&t())},F=()=>I(2),j=()=>I(1),L=()=>{process.on("uncaughtExceptionMonitor",F),process.on("unhandledRejection",F),process.on("SIGINT",j),process.on("SIGTERM",j),process.on("exit",I),a&&a.addEventListener("abort",j)},M=()=>{process.removeListener("uncaughtExceptionMonitor",F),process.removeListener("unhandledRejection",F),process.removeListener("SIGINT",j),process.removeListener("SIGTERM",j),process.removeListener("exit",I),a&&a.removeEventListener("abort",j)},N=()=>{if(w===void 0)return;l&&n.write(`
139
+ `);let D=$e(w,$,{hard:!0,trim:!1}).split(`
140
+ `);D.length>1&&n.write(Qe.cursor.up(D.length-1)),n.write(Qe.cursor.to(0)),n.write(Qe.erase.down())},C=D=>D.replace(/\.+$/,""),U=D=>{let P=(performance.now()-D)/1e3,X=Math.floor(P/60),H=Math.floor(P%60);return X>0?`[${X}m ${H}s]`:`[${H}s]`},q=u.withGuide??O.withGuide,ee=(D="")=>{h=!0,f=Jr({output:n}),m=C(D),b=performance.now(),q&&n.write(`${(0,c.styleText)("gray",v)}
141
+ `);let P=0,X=0;L(),d=setInterval(()=>{if(l&&m===w)return;N(),w=m;let H=_(i[P]),pe;if(l)pe=`${H} ${m}...`;else if(e==="timer")pe=`${H} ${m} ${U(b)}`;else{let Se=".".repeat(Math.floor(X)).slice(0,3);pe=`${H} ${m}${Se}`}let ke=$e(pe,$,{hard:!0,trim:!1});n.write(ke),P=P+1<i.length?P+1:0,X=X<4?X+.125:0},o)},te=(D="",P=0,X=!1)=>{if(!h)return;h=!1,clearInterval(d),N();let H=P===0?(0,c.styleText)("green",Ge):P===1?(0,c.styleText)("red",os):(0,c.styleText)("red",as);m=D??m,X||(e==="timer"?n.write(`${H} ${m} ${U(b)}
142
+ `):n.write(`${H} ${m}
143
+ `)),M(),f()};return{start:ee,stop:(D="")=>te(D,0),message:(D="")=>{m=C(D??m)},cancel:(D="")=>te(D,1),error:(D="")=>te(D,2),clear:()=>te("",0,!0),get isCancelled(){return p}}},ni={light:R("\u2500","-"),heavy:R("\u2501","="),block:R("\u2588","#")};di=[`${(0,c.styleText)("dim","\u2191/\u2193")} to navigate`,`${(0,c.styleText)("dim","Enter:")} confirm`],Xt=(e,t)=>e.includes(`
144
144
  `)?e.split(`
145
145
  `).map(n=>t(n)).join(`
146
- `):t(e),ou=e=>{let t=(s,r)=>{if(s===void 0)return"";let i=s.label??String(s.value);switch(r){case"disabled":return`${(0,c.styleText)("gray",Ve)} ${Ht(i,o=>(0,c.styleText)("gray",o))}${s.hint?` ${(0,c.styleText)("dim",`(${s.hint??"disabled"})`)}`:""}`;case"selected":return`${Ht(i,o=>(0,c.styleText)("dim",o))}`;case"active":return`${(0,c.styleText)("green",mt)} ${i}${s.hint?` ${(0,c.styleText)("dim",`(${s.hint})`)}`:""}`;case"cancelled":return`${Ht(i,o=>(0,c.styleText)(["strikethrough","dim"],o))}`;default:return`${(0,c.styleText)("dim",Ve)} ${Ht(i,o=>(0,c.styleText)("dim",o))}`}},n=e.showInstructions??!0;return new Kr({options:e.options,signal:e.signal,input:e.input,output:e.output,initialValue:e.initialValue,render(){let s=e.withGuide??I.withGuide,r=`${he(this.state)} `,i=`${cs(this.state)} `,o=X(e.output,e.message,i,r),a=`${s?`${(0,c.styleText)("gray",v)}
146
+ `):t(e),wu=e=>{let t=(s,r)=>{if(s===void 0)return"";let i=s.label??String(s.value);switch(r){case"disabled":return`${(0,c.styleText)("gray",We)} ${Xt(i,o=>(0,c.styleText)("gray",o))}${s.hint?` ${(0,c.styleText)("dim",`(${s.hint??"disabled"})`)}`:""}`;case"selected":return`${Xt(i,o=>(0,c.styleText)("dim",o))}`;case"active":return`${(0,c.styleText)("green",yt)} ${i}${s.hint?` ${(0,c.styleText)("dim",`(${s.hint})`)}`:""}`;case"cancelled":return`${Xt(i,o=>(0,c.styleText)(["strikethrough","dim"],o))}`;default:return`${(0,c.styleText)("dim",We)} ${Xt(i,o=>(0,c.styleText)("dim",o))}`}},n=e.showInstructions??!0;return new Zr({options:e.options,signal:e.signal,input:e.input,output:e.output,initialValue:e.initialValue,render(){let s=e.withGuide??O.withGuide,r=`${he(this.state)} `,i=`${gs(this.state)} `,o=z(e.output,e.message,i,r),a=`${s?`${(0,c.styleText)("gray",v)}
147
147
  `:""}${o}
148
- `;switch(this.state){case"submit":{let u=s?`${(0,c.styleText)("gray",v)} `:"",l=X(e.output,t(this.options[this.cursor],"selected"),u);return`${a}${l}`}case"cancel":{let u=s?`${(0,c.styleText)("gray",v)} `:"",l=X(e.output,t(this.options[this.cursor],"cancelled"),u);return`${a}${l}${s?`
148
+ `;switch(this.state){case"submit":{let u=s?`${(0,c.styleText)("gray",v)} `:"",l=z(e.output,t(this.options[this.cursor],"selected"),u);return`${a}${l}`}case"cancel":{let u=s?`${(0,c.styleText)("gray",v)} `:"",l=z(e.output,t(this.options[this.cursor],"cancelled"),u);return`${a}${l}${s?`
149
149
  ${(0,c.styleText)("gray",v)}`:""}`}default:{let u=s?`${(0,c.styleText)("cyan",v)} `:"",l=a.split(`
150
- `).length,f=n?Yt(ai,s):s?[(0,c.styleText)("cyan",H)]:[],d=f.join(`
151
- `),h=f.length+1;return`${a}${u}${Te({output:e.output,cursor:this.cursor,options:this.options,maxItems:e.maxItems,columnPadding:u.length,rowPadding:l+h,style:(p,m)=>t(p,p.disabled?"disabled":m?"active":"inactive")}).join(`
150
+ `).length,f=n?Qt(di,s):s?[(0,c.styleText)("cyan",K)]:[],d=f.join(`
151
+ `),h=f.length+1;return`${a}${u}${Me({output:e.output,cursor:this.cursor,options:this.options,maxItems:e.maxItems,columnPadding:u.length,rowPadding:l+h,style:(p,m)=>t(p,p.disabled?"disabled":m?"active":"inactive")}).join(`
152
152
  ${u}`)}
153
153
  ${d}
154
- `}}}}).prompt()},au=e=>{let t=(n,s="inactive")=>{if(n===void 0)return"";let r=n.label??String(n.value);return s==="selected"?`${(0,c.styleText)("dim",r)}`:s==="cancelled"?`${(0,c.styleText)(["strikethrough","dim"],r)}`:s==="active"?`${(0,c.styleText)(["bgCyan","gray"],` ${n.value} `)} ${r}${n.hint?` ${(0,c.styleText)("dim",`(${n.hint})`)}`:""}`:`${(0,c.styleText)(["gray","bgWhite","inverse"],` ${n.value} `)} ${r}${n.hint?` ${(0,c.styleText)("dim",`(${n.hint})`)}`:""}`};return new Ut({options:e.options,signal:e.signal,input:e.input,output:e.output,initialValue:e.initialValue,caseSensitive:e.caseSensitive,render(){let n=e.withGuide??I.withGuide,s=`${n?`${(0,c.styleText)("gray",v)}
154
+ `}}}}).prompt()},$u=e=>{let t=(n,s="inactive")=>{if(n===void 0)return"";let r=n.label??String(n.value);return s==="selected"?`${(0,c.styleText)("dim",r)}`:s==="cancelled"?`${(0,c.styleText)(["strikethrough","dim"],r)}`:s==="active"?`${(0,c.styleText)(["bgCyan","gray"],` ${n.value} `)} ${r}${n.hint?` ${(0,c.styleText)("dim",`(${n.hint})`)}`:""}`:`${(0,c.styleText)(["gray","bgWhite","inverse"],` ${n.value} `)} ${r}${n.hint?` ${(0,c.styleText)("dim",`(${n.hint})`)}`:""}`};return new Ht({options:e.options,signal:e.signal,input:e.input,output:e.output,initialValue:e.initialValue,caseSensitive:e.caseSensitive,render(){let n=e.withGuide??O.withGuide,s=`${n?`${(0,c.styleText)("gray",v)}
155
155
  `:""}${he(this.state)} ${e.message}
156
- `;switch(this.state){case"submit":{let r=n?`${(0,c.styleText)("gray",v)} `:"",i=this.options.find(a=>a.value===this.value)??e.options[0],o=X(e.output,t(i,"selected"),r);return`${s}${o}`}case"cancel":{let r=n?`${(0,c.styleText)("gray",v)} `:"",i=X(e.output,t(this.options[0],"cancelled"),r);return`${s}${i}${n?`
157
- ${(0,c.styleText)("gray",v)}`:""}`}default:{let r=n?`${(0,c.styleText)("cyan",v)} `:"",i=n?(0,c.styleText)("cyan",H):"",o=this.options.map((a,u)=>X(e.output,t(a,u===this.cursor?"active":"inactive"),r)).join(`
156
+ `;switch(this.state){case"submit":{let r=n?`${(0,c.styleText)("gray",v)} `:"",i=this.options.find(a=>a.value===this.value)??e.options[0],o=z(e.output,t(i,"selected"),r);return`${s}${o}`}case"cancel":{let r=n?`${(0,c.styleText)("gray",v)} `:"",i=z(e.output,t(this.options[0],"cancelled"),r);return`${s}${i}${n?`
157
+ ${(0,c.styleText)("gray",v)}`:""}`}default:{let r=n?`${(0,c.styleText)("cyan",v)} `:"",i=n?(0,c.styleText)("cyan",K):"",o=this.options.map((a,u)=>z(e.output,t(a,u===this.cursor?"active":"inactive"),r)).join(`
158
158
  `);return`${s}${o}
159
159
  ${i}
160
- `}}}}).prompt()},Qr=`${(0,c.styleText)("gray",v)} `,qe={message:async(e,{symbol:t=(0,c.styleText)("gray",v)}={})=>{process.stdout.write(`${(0,c.styleText)("gray",v)}
160
+ `}}}}).prompt()},si=`${(0,c.styleText)("gray",v)} `,Be={message:async(e,{symbol:t=(0,c.styleText)("gray",v)}={})=>{process.stdout.write(`${(0,c.styleText)("gray",v)}
161
161
  ${t} `);let n=3;for await(let s of e){s=s.replace(/\n/g,`
162
- ${Qr}`),s.includes(`
162
+ ${si}`),s.includes(`
163
163
  `)&&(n=3+(0,c.stripVTControlCharacters)(s.slice(s.lastIndexOf(`
164
164
  `))).length);let r=(0,c.stripVTControlCharacters)(s).length;n+r<process.stdout.columns?(n+=r,process.stdout.write(s)):(process.stdout.write(`
165
- ${Qr}${s.trimStart()}`),n=3+(0,c.stripVTControlCharacters)(s.trimStart()).length)}process.stdout.write(`
166
- `)},info:e=>qe.message(e,{symbol:(0,c.styleText)("blue",os)}),success:e=>qe.message(e,{symbol:(0,c.styleText)("green",as)}),step:e=>qe.message(e,{symbol:(0,c.styleText)("green",Ue)}),warn:e=>qe.message(e,{symbol:(0,c.styleText)("yellow",us)}),warning:e=>qe.warn(e),error:e=>qe.message(e,{symbol:(0,c.styleText)("red",ls)})},uu=async(e,t)=>{for(let n of e){if(n.enabled===!1)continue;let s=ds(t);s.start(n.title);let r=await n.task(s.message);s.stop(r||n.title)}},lu=e=>e.replace(/\x1b\[(?:\d+;)*\d*[ABCDEFGHfJKSTsu]|\x1b\[(s|u)/g,""),cu=e=>{let t=e.output??process.stdout,n=Re(t),s=(0,c.styleText)("gray",v),r=e.spacing??1,i=3,o=e.retainLog===!0,a=!Zn()&&Zr(t);t.write(`${s}
167
- `),t.write(`${(0,c.styleText)("green",Ue)} ${e.title}
165
+ ${si}${s.trimStart()}`),n=3+(0,c.stripVTControlCharacters)(s.trimStart()).length)}process.stdout.write(`
166
+ `)},info:e=>Be.message(e,{symbol:(0,c.styleText)("blue",ds)}),success:e=>Be.message(e,{symbol:(0,c.styleText)("green",hs)}),step:e=>Be.message(e,{symbol:(0,c.styleText)("green",Ge)}),warn:e=>Be.message(e,{symbol:(0,c.styleText)("yellow",ps)}),warning:e=>Be.warn(e),error:e=>Be.message(e,{symbol:(0,c.styleText)("red",ms)})},Su=async(e,t)=>{for(let n of e){if(n.enabled===!1)continue;let s=bs(t);s.start(n.title);let r=await n.task(s.message);s.stop(r||n.title)}},vu=e=>e.replace(/\x1b\[(?:\d+;)*\d*[ABCDEFGHfJKSTsu]|\x1b\[(s|u)/g,""),ku=e=>{let t=e.output??process.stdout,n=Pe(t),s=(0,c.styleText)("gray",v),r=e.spacing??1,i=3,o=e.retainLog===!0,a=!is()&&ri(t);t.write(`${s}
167
+ `),t.write(`${(0,c.styleText)("green",Ge)} ${e.title}
168
168
  `);for(let b=0;b<r;b++)t.write(`${s}
169
- `);let u=[{value:"",full:""}],l=!1,f=b=>{if(u.length===0)return;let $=0;b&&($+=r+2);for(let k of u){let{value:T,result:F}=k,j=F?.message??T;if(j.length===0)continue;F===void 0&&k.header!==void 0&&k.header!==""&&(j+=`
170
- ${k.header}`);let L=j.split(`
171
- `).reduce((M,C)=>C===""?M+1:M+Math.ceil((C.length+i)/n),0);$+=L}$>0&&($+=1,t.write(Je.erase.lines($)))},d=(b,$,k)=>{let T=k?`${b.full}
169
+ `);let u=[{value:"",full:""}],l=!1,f=b=>{if(u.length===0)return;let $=0;b&&($+=r+2);for(let _ of u){let{value:I,result:F}=_,j=F?.message??I;if(j.length===0)continue;F===void 0&&_.header!==void 0&&_.header!==""&&(j+=`
170
+ ${_.header}`);let L=j.split(`
171
+ `).reduce((M,N)=>N===""?M+1:M+Math.ceil((N.length+i)/n),0);$+=L}$>0&&($+=1,t.write(Qe.erase.lines($)))},d=(b,$,_)=>{let I=_?`${b.full}
172
172
  ${b.value}`:b.value;b.header!==void 0&&b.header!==""&&de.message(b.header.split(`
173
- `).map(F=>(0,c.styleText)("bold",F)),{output:t,secondarySymbol:s,symbol:s,spacing:0}),de.message(T.split(`
174
- `).map(F=>(0,c.styleText)("dim",F)),{output:t,secondarySymbol:s,symbol:s,spacing:$??r})},h=()=>{for(let b of u){let{header:$,value:k,full:T}=b;($===void 0||$.length===0)&&k.length===0||d(b,void 0,o===!0&&T.length>0)}},p=(b,$,k)=>{if(f(!1),(k?.raw!==!0||!l)&&b.value!==""&&(b.value+=`
175
- `),b.value+=lu($),l=k?.raw===!0,e.limit!==void 0){let T=b.value.split(`
176
- `),F=T.length-e.limit;if(F>0){let j=T.splice(0,F);o&&(b.full+=(b.full===""?"":`
173
+ `).map(F=>(0,c.styleText)("bold",F)),{output:t,secondarySymbol:s,symbol:s,spacing:0}),de.message(I.split(`
174
+ `).map(F=>(0,c.styleText)("dim",F)),{output:t,secondarySymbol:s,symbol:s,spacing:$??r})},h=()=>{for(let b of u){let{header:$,value:_,full:I}=b;($===void 0||$.length===0)&&_.length===0||d(b,void 0,o===!0&&I.length>0)}},p=(b,$,_)=>{if(f(!1),(_?.raw!==!0||!l)&&b.value!==""&&(b.value+=`
175
+ `),b.value+=vu($),l=_?.raw===!0,e.limit!==void 0){let I=b.value.split(`
176
+ `),F=I.length-e.limit;if(F>0){let j=I.splice(0,F);o&&(b.full+=(b.full===""?"":`
177
177
  `)+j.join(`
178
- `))}b.value=T.join(`
179
- `)}a&&m()},m=()=>{for(let b of u)b.result?b.result.status==="error"?de.error(b.result.message,{output:t,secondarySymbol:s,spacing:0}):de.success(b.result.message,{output:t,secondarySymbol:s,spacing:0}):b.value!==""&&d(b,0)},w=(b,$)=>{f(!1),b.result=$,a&&m()};return{message(b,$){p(u[0],b,$)},group(b){let $={header:b,value:"",full:""};return u.push($),{message(k,T){p($,k,T)},error(k){w($,{status:"error",message:k})},success(k){w($,{status:"success",message:k})}}},error(b,$){f(!0),de.error(b,{output:t,secondarySymbol:s,spacing:1}),$?.showLog!==!1&&h(),u.splice(1,u.length-1),u[0].value="",u[0].full=""},success(b,$){f(!0),de.success(b,{output:t,secondarySymbol:s,spacing:1}),$?.showLog===!0&&h(),u.splice(1,u.length-1),u[0].value="",u[0].full=""}}},fu=e=>new Wt({validate:e.validate,placeholder:e.placeholder,defaultValue:e.defaultValue,initialValue:e.initialValue,output:e.output,signal:e.signal,input:e.input,render(){let t=e?.withGuide??I.withGuide,n=`${`${t?`${(0,c.styleText)("gray",v)}
178
+ `))}b.value=I.join(`
179
+ `)}a&&m()},m=()=>{for(let b of u)b.result?b.result.status==="error"?de.error(b.result.message,{output:t,secondarySymbol:s,spacing:0}):de.success(b.result.message,{output:t,secondarySymbol:s,spacing:0}):b.value!==""&&d(b,0)},w=(b,$)=>{f(!1),b.result=$,a&&m()};return{message(b,$){p(u[0],b,$)},group(b){let $={header:b,value:"",full:""};return u.push($),{message(_,I){p($,_,I)},error(_){w($,{status:"error",message:_})},success(_){w($,{status:"success",message:_})}}},error(b,$){f(!0),de.error(b,{output:t,secondarySymbol:s,spacing:1}),$?.showLog!==!1&&h(),u.splice(1,u.length-1),u[0].value="",u[0].full=""},success(b,$){f(!0),de.success(b,{output:t,secondarySymbol:s,spacing:1}),$?.showLog===!0&&h(),u.splice(1,u.length-1),u[0].value="",u[0].full=""}}},xu=e=>new Kt({validate:e.validate,placeholder:e.placeholder,defaultValue:e.defaultValue,initialValue:e.initialValue,output:e.output,signal:e.signal,input:e.input,render(){let t=e?.withGuide??O.withGuide,n=`${`${t?`${(0,c.styleText)("gray",v)}
180
180
  `:""}${he(this.state)} `}${e.message}
181
- `,s=e.placeholder&&e.placeholder.length>0?(0,c.styleText)("inverse",e.placeholder[0])+(0,c.styleText)("dim",e.placeholder.slice(1)):(0,c.styleText)(["inverse","hidden"],"_"),r=this.userInput?this.userInputWithCursor:s,i=this.value??"";switch(this.state){case"validating":{let o=t?`${(0,c.styleText)("cyan",v)} `:"",a=t?(0,c.styleText)("cyan",H):"",u=(0,c.styleText)("dim",r),l=(0,c.styleText)("dim","Validating...");return`${n}${o}${u}
181
+ `,s=e.placeholder&&e.placeholder.length>0?(0,c.styleText)("inverse",e.placeholder[0])+(0,c.styleText)("dim",e.placeholder.slice(1)):(0,c.styleText)(["inverse","hidden"],"_"),r=this.userInput?this.userInputWithCursor:s,i=this.value??"";switch(this.state){case"validating":{let o=t?`${(0,c.styleText)("cyan",v)} `:"",a=t?(0,c.styleText)("cyan",K):"",u=(0,c.styleText)("dim",r),l=(0,c.styleText)("dim","Validating...");return`${n}${o}${u}
182
182
  ${a} ${l}
183
- `}case"error":{let o=this.error?` ${(0,c.styleText)("yellow",this.error)}`:"",a=t?`${(0,c.styleText)("yellow",v)} `:"",u=t?(0,c.styleText)("yellow",H):"";return`${n.trim()}
183
+ `}case"error":{let o=this.error?` ${(0,c.styleText)("yellow",this.error)}`:"",a=t?`${(0,c.styleText)("yellow",v)} `:"",u=t?(0,c.styleText)("yellow",K):"";return`${n.trim()}
184
184
  ${a}${r}
185
185
  ${u}${o}
186
186
  `}case"submit":{let o=i?`${t?" ":""}${(0,c.styleText)("dim",i)}`:"",a=t?(0,c.styleText)("gray",v):"";return`${n}${a}${o}`}case"cancel":{let o=i?` ${(0,c.styleText)(["strikethrough","dim"],i)}`:"",a=t?(0,c.styleText)("gray",v):"";return`${n}${a}${o}${i.trim()?`
187
- ${a}`:""}`}default:{let o=t?`${(0,c.styleText)("cyan",v)} `:"",a=t?(0,c.styleText)("cyan",H):"";return`${n}${o}${r}
187
+ ${a}`:""}`}default:{let o=t?`${(0,c.styleText)("cyan",v)} `:"",a=t?(0,c.styleText)("cyan",K):"";return`${n}${o}${r}
188
188
  ${a}
189
- `}}}}).prompt()});var yi=me((fl,gi)=>{"use strict";var du=require("readline"),ci=Zs(),zt=ar(),fi=lr(),je=null;try{je=br()}catch{je=null}var hu=["write_file","replace_in_file","apply_patch","delete_file","move_file"],pu=60,mu=160,ps={pending:"\xB7",in_progress:"\u25B6",completed:"\u2713",cancelled:"\u2298"},gu={pending:"gray",in_progress:"cyan",completed:"green",cancelled:"gray"},Me=null;try{let e=Sr();e&&typeof e.createColors=="function"?Me=e.createColors(!process.env.NO_COLOR&&!!process.stderr.isTTY):e&&(Me=e)}catch{Me=null}var We=!!(Me&&Me.isColorSupported===!0);function O(e,t){let n=String(t??""),s=Me&&Me[e];return typeof s=="function"?s(n):n}function yu(e,t){let n=String(e??"").replace(/\s+/g," ").trim();return n?n.length>t?n.slice(0,t-1)+"\u2026":n:""}function hi(e){let t=Math.max(0,Number(e)||0);return t<1e3?String(t):t<1e4?(t/1e3).toFixed(1)+"k":Math.round(t/1e3)+"k"}function di(e){let t=Math.max(0,Number(e)||0)/1e3;return t<10?t.toFixed(2)+"s":t<60?t.toFixed(1)+"s":Math.floor(t/60)+"m"+Math.round(t%60)+"s"}function pi(e){let t=String((e&&e.result)==null?"":e.result);if(!t)return"";if(e&&e.ok===!1){let r=t.split(`
190
- `);for(let i=0;i<r.length;i++){let o=r[i].trim();if(o)return yu(o.replace(/^ERROR:\s*/i,""),60)}return""}let n=0,s=t.split(`
191
- `);for(let r=0;r<s.length;r++)s[r].trim()&&n++;return n>=2?n+" \u884C":""}function bu(e,t,n){let s=e&&e.name||"?",r=e&&e.path?" "+String(e.path):"",i=!(e&&e.ok===!1),o=[];n&&n.detail&&o.push(n.detail),n&&n.sec&&o.push(n.sec);let a=o.length?" \xB7 "+o.join(" \xB7 "):"";return t?(i?O("green","\u25C7"):O("red","\u2717"))+" "+O("bold",s)+O("gray",r)+(a?O("dim",a):""):"[tool] "+s+r+a+(i?"":" \u2717")}function wu(e,t,n){let s=Number(e)||0,r=Number(t)||0;if(r<=0)return hi(s);let i=Math.max(0,Math.min(1,s/r)),o=Math.round(i*8),a="\u2588".repeat(o)+"\u2591".repeat(8-o),u=Math.round(i*100)+"%",l=i>.95?"red":i>.8?"yellow":"cyan";return n("dim","[")+n(l,a)+n("dim","] ")+u}function $u(e,t){let n=e.map(function(s){return s&&s.path}).join(", ");return t?O("gray","\xB7 \u5F15\u7528 ")+O("dim",n):"[refs] "+n}function Su(e,t){let n=(e&&e.description||"")+(e&&e.line||"");return t?O("gray","\xB7 \u5B50\u4EE3\u7406 ")+O("dim",n):"[\u5B50\u4EE3\u7406] "+n}function hs(e,t,n){let s="+"+(Number(e)||0),r="-"+(Number(t)||0);return n?O("green",s)+" "+O("red",r):s+" "+r}function vu(e,t){let n=String(e.s==null?"":e.s);return e.t==="@"?t?O("cyan",n):n:e.t==="+"?t?O("green","+ "+n):"+ "+n:e.t==="-"?t?O("red","- "+n):"- "+n:t?O("dim"," "+n):" "+n}function mi(e,t){let n=e||{},s=Array.isArray(n.files)?n.files:[],r=[],i=function(f){r.push(f)};if(n.name==="move_file"&&s.length===2){let f=s[0].path,d=s[1].path,h=t?O("cyan","\u25CF")+" "+O("bold","move_file")+O("gray"," \xB7 \u79FB\u52A8 "+f+" \u2192 "+d):"\u25CF move_file \xB7 \u79FB\u52A8 "+f+" \u2192 "+d;return i(h+(t?O("dim","\uFF08\u5185\u5BB9\u4E0D\u53D8\uFF09"):"\uFF08\u5185\u5BB9\u4E0D\u53D8\uFF09")),r}let o=s.map(function(f){let d=fi.computeHunks(f.before||"",f.after||"");return{f,hunks:d,st:fi.stats(d)}}),a=0,u=0;for(let f of o)a+=f.st.add,u+=f.st.del;o.length>1&&i((t?O("cyan","\u25CF")+" "+O("bold",n.name||"\u5199\u5165"):"\u25CF "+(n.name||"\u5199\u5165"))+" "+o.length+" \u4E2A\u6587\u4EF6 "+hs(a,u,t));let l=mu;for(let f of o){let d=f.f,h=f.st,p=d.kind==="add"?"\u65B0\u589E":d.kind==="delete"?"\u5220\u9664":"\u4FEE\u6539";o.length===1?i((t?O("cyan","\u25CF")+" "+O("bold",n.name||"\u5199\u5165")+O("gray"," \xB7 "+p+" "+d.path):"\u25CF "+(n.name||"\u5199\u5165")+" \xB7 "+p+" "+d.path)+" "+hs(h.add,h.del,t)):i((t?O("gray"," \u25B8 "):" \u25B8 ")+(t?O("bold",p+" "+d.path):p+" "+d.path)+" "+hs(h.add,h.del,t));let m=[];for(let k of f.hunks){m.push({t:"@",s:k.header});for(let T of k.lines)m.push({t:T.t,s:T.s})}let w=Math.max(0,Math.min(pu,l)),b=m.slice(0,w);l-=b.length;for(let k of b)i(" "+vu(k,t));let $=m.length-b.length;$>0&&i(" "+(t?O("dim","\u2026 \u8FD8\u6709 "+$+" \u884C\u672A\u663E\u793A"):"\u2026 \u8FD8\u6709 "+$+" \u884C\u672A\u663E\u793A"))}return r}function xu(e,t){let n=e&&ps[e.status]?e.status:"pending",s=ps[n],r=String(e&&e.content||"");return t?O(gu[n]||"gray",s)+" "+(n==="completed"||n==="cancelled"?O("dim",r):r):"[todo] "+s+" "+r}function _u(e){let t=e||{},n=t.output||process.stderr,s=t.stdout||process.stdout,r=t.colors!==void 0?t.colors:Me,i=!!t.enabled,o=t.stream!==!1,a=!!t.showThinking,u=null,l=!1,f=["\u25D2","\u25D0","\u25D3","\u25D1"],d=null,h=0,p=!1,m="idle",w="idle",b="\u601D\u8003\u4E2D",$=b,k="",T=0,F=0,j=0,L="",M=!1,C=!1,N="",U=0,R=!1,Z=!1,ee=0,D="",P="",J=!1,G="",pe=!1,Se=[],$e="",te=0;function ce(g){if(!M){ze();try{n.write(String(g)+`
192
- `)}catch{}}}function Ye(g){if(g)try{s.write(g)}catch{}}function ze(){Z&&(Ye(`
193
- `),ee++,Z=!1)}function Oi(){let g=[$];return k&&g.push(k),j>0&&g.push(hi(j)+" \u5B57\u601D\u8003"),T>0&&g.push("ctx "+wu(T,F,O)),g.join(" \xB7 ")}function $t(){if(!i||M)return;let g=f[h%f.length];h++;try{n.write("\r\x1B[K"+O("cyan",zt.face(w))+" "+O("magenta",g)+" "+Oi())}catch{}p=!0}function xe(g){if(g&&($=String(g)),!(!i||M)){if(d){$t();return}$t(),d=setInterval($t,100)}}function tn(){d&&$t()}function oe(){if(d&&(clearInterval(d),d=null),p){try{n.write("\r\x1B[K")}catch{}p=!1}}function Ti(){if(!s.isTTY)return!1;let g="\r\x1B[J";return ee>0&&(g+="\x1B["+ee+"A\x1B[J"),Ye(g),ee=0,Z=!1,!0}async function ji(){if(!i)return!1;try{u=await Promise.resolve().then(()=>(li(),ui))}catch{return u=null,C||(C=!0,ce(O("yellow","[luban] ")+"\u9009\u62E9\u9898\u7EC4\u4EF6\u4E0D\u53EF\u7528\uFF08\u5148 npm install\uFF0C\u6216 Node \u7248\u672C\u8FC7\u4F4E\uFF09\uFF1Aask_question \u4F1A\u76F4\u63A5\u62A5\u9519")),!1}return l=!0,!0}function bs(){return!!(je&&r&&s.isTTY&&r.isColorSupported===!0)}function Mi(g){P+=g;let S;for(;(S=P.indexOf(`
194
- `))>=0;){let E=P.slice(0,S+1);P=P.slice(S+1),Ai(E)}}function Ai(g){if(g.match(/^\s*(```+|~~~+)\s*([\w+#.-]*)\s*$/)){if(!J){nn(),J=!0,G=g;return}G+=g,ws(G),G="",J=!1;return}if(J){G+=g;return}let E=g.trim(),A=E.indexOf("|")!==-1;if(pe){if(!A||/^\s*$/.test(E)){nn(),St(g);return}Se.push(g);return}if(A&&!/^\s*$/.test(E)){pe=!0,Se=[g];return}St(g)}function nn(){if(!pe)return;let g=Se;if(pe=!1,Se=[],g.length>=2&&je.isSepRow(g[1])){let S=g.map(function(A){return A.replace(/\n$/,"")}),E=je.renderTable(S,0,je.mk(O));sn(E.text+`
195
- `)}else g.forEach(St)}function St(g){let S=je.renderBlock(g,O);sn(S)}function ws(g){sn(je.renderBlock(g,O))}function sn(g){if(g){ze();try{n.write(g)}catch{return}for(let S=0;S<g.length;S++)g.charCodeAt(S)===10&&ee++;Z=g.charCodeAt(g.length-1)!==10}}function $s(){if(bs()&&(J&&G&&(ws(G),G="",J=!1),nn(),P)){let g=P;P="",St(g.endsWith(`
189
+ `}}}}).prompt()});var vi=ge((xl,Si)=>{"use strict";var _u=require("readline"),mi=rr(),en=dr(),gi=pr(),Ae=null;try{Ae=kr()}catch{Ae=null}var Eu=["write_file","replace_in_file","apply_patch","delete_file","move_file"],Ou=60,Tu=160,$s={pending:"\xB7",in_progress:"\u25B6",completed:"\u2713",cancelled:"\u2298"},Iu={pending:"gray",in_progress:"cyan",completed:"green",cancelled:"gray"},Fe=null;try{let e=Er();e&&typeof e.createColors=="function"?Fe=e.createColors(!process.env.NO_COLOR&&!!process.stderr.isTTY):e&&(Fe=e)}catch{Fe=null}var He=!!(Fe&&Fe.isColorSupported===!0);function T(e,t){let n=String(t??""),s=Fe&&Fe[e];return typeof s=="function"?s(n):n}function ju(e,t){let n=String(e??"").replace(/\s+/g," ").trim();return n?n.length>t?n.slice(0,t-1)+"\u2026":n:""}function bi(e){let t=Math.max(0,Number(e)||0);return t<1e3?String(t):t<1e4?(t/1e3).toFixed(1)+"k":Math.round(t/1e3)+"k"}function yi(e){let t=Math.max(0,Number(e)||0)/1e3;return t<10?t.toFixed(2)+"s":t<60?t.toFixed(1)+"s":Math.floor(t/60)+"m"+Math.round(t%60)+"s"}function wi(e){let t=String((e&&e.result)==null?"":e.result);if(!t)return"";if(e&&e.ok===!1){let r=t.split(`
190
+ `);for(let i=0;i<r.length;i++){let o=r[i].trim();if(o)return ju(o.replace(/^ERROR:\s*/i,""),60)}return""}let n=0,s=t.split(`
191
+ `);for(let r=0;r<s.length;r++)s[r].trim()&&n++;return n>=2?n+" \u884C":""}function Mu(e,t,n){let s=e&&e.name||"?",r=e&&e.path?" "+String(e.path):"",i=!(e&&e.ok===!1),o=[];n&&n.detail&&o.push(n.detail),n&&n.sec&&o.push(n.sec);let a=o.length?" \xB7 "+o.join(" \xB7 "):"";return t?(i?T("green","\u25C7"):T("red","\u2717"))+" "+T("bold",s)+T("gray",r)+(a?T("dim",a):""):"[tool] "+s+r+a+(i?"":" \u2717")}function Au(e,t,n){let s=Number(e)||0,r=Number(t)||0;if(r<=0)return bi(s);let i=Math.max(0,Math.min(1,s/r)),o=Math.round(i*8),a="\u2588".repeat(o)+"\u2591".repeat(8-o),u=Math.round(i*100)+"%",l=i>.95?"red":i>.8?"yellow":"cyan";return n("dim","[")+n(l,a)+n("dim","] ")+u}function Fu(e,t){let n=e.map(function(s){return s&&s.path}).join(", ");return t?T("gray","\xB7 \u5F15\u7528 ")+T("dim",n):"[refs] "+n}function Lu(e,t){let n=(e&&e.description||"")+(e&&e.line||"");return t?T("gray","\xB7 \u5B50\u4EE3\u7406 ")+T("dim",n):"[\u5B50\u4EE3\u7406] "+n}function ws(e,t,n){let s="+"+(Number(e)||0),r="-"+(Number(t)||0);return n?T("green",s)+" "+T("red",r):s+" "+r}function Nu(e,t){let n=String(e.s==null?"":e.s);return e.t==="@"?t?T("cyan",n):n:e.t==="+"?t?T("green","+ "+n):"+ "+n:e.t==="-"?t?T("red","- "+n):"- "+n:t?T("dim"," "+n):" "+n}function $i(e,t){let n=e||{},s=Array.isArray(n.files)?n.files:[],r=[],i=function(f){r.push(f)};if(n.name==="move_file"&&s.length===2){let f=s[0].path,d=s[1].path,h=t?T("cyan","\u25CF")+" "+T("bold","move_file")+T("gray"," \xB7 \u79FB\u52A8 "+f+" \u2192 "+d):"\u25CF move_file \xB7 \u79FB\u52A8 "+f+" \u2192 "+d;return i(h+(t?T("dim","\uFF08\u5185\u5BB9\u4E0D\u53D8\uFF09"):"\uFF08\u5185\u5BB9\u4E0D\u53D8\uFF09")),r}let o=s.map(function(f){let d=gi.computeHunks(f.before||"",f.after||"");return{f,hunks:d,st:gi.stats(d)}}),a=0,u=0;for(let f of o)a+=f.st.add,u+=f.st.del;o.length>1&&i((t?T("cyan","\u25CF")+" "+T("bold",n.name||"\u5199\u5165"):"\u25CF "+(n.name||"\u5199\u5165"))+" "+o.length+" \u4E2A\u6587\u4EF6 "+ws(a,u,t));let l=Tu;for(let f of o){let d=f.f,h=f.st,p=d.kind==="add"?"\u65B0\u589E":d.kind==="delete"?"\u5220\u9664":"\u4FEE\u6539";o.length===1?i((t?T("cyan","\u25CF")+" "+T("bold",n.name||"\u5199\u5165")+T("gray"," \xB7 "+p+" "+d.path):"\u25CF "+(n.name||"\u5199\u5165")+" \xB7 "+p+" "+d.path)+" "+ws(h.add,h.del,t)):i((t?T("gray"," \u25B8 "):" \u25B8 ")+(t?T("bold",p+" "+d.path):p+" "+d.path)+" "+ws(h.add,h.del,t));let m=[];for(let _ of f.hunks){m.push({t:"@",s:_.header});for(let I of _.lines)m.push({t:I.t,s:I.s})}let w=Math.max(0,Math.min(Ou,l)),b=m.slice(0,w);l-=b.length;for(let _ of b)i(" "+Nu(_,t));let $=m.length-b.length;$>0&&i(" "+(t?T("dim","\u2026 \u8FD8\u6709 "+$+" \u884C\u672A\u663E\u793A"):"\u2026 \u8FD8\u6709 "+$+" \u884C\u672A\u663E\u793A"))}return r}function Cu(e,t){let n=e&&$s[e.status]?e.status:"pending",s=$s[n],r=String(e&&e.content||"");return t?T(Iu[n]||"gray",s)+" "+(n==="completed"||n==="cancelled"?T("dim",r):r):"[todo] "+s+" "+r}function Du(e){let t=e||{},n=t.output||process.stderr,s=t.stdout||process.stdout,r=t.colors!==void 0?t.colors:Fe,i=!!t.enabled,o=t.stream!==!1,a=!!t.showThinking,u=null,l=!1,f=["\u25D2","\u25D0","\u25D3","\u25D1"],d=null,h=0,p=!1,m="idle",w="idle",b="\u601D\u8003\u4E2D",$=b,_="",I=0,F=0,j=0,L="",M=!1,N=!1,C="",U=0,q=!1,ee=!1,te=0,D="",P="",X=!1,H="",pe=!1,ke=[],Se="",Ke=0;function me(g){if(!M){_e();try{n.write(String(g)+`
192
+ `)}catch{}}}function ne(g){if(g)try{s.write(g)}catch{}}function _e(){ee&&(ne(`
193
+ `),te++,ee=!1)}function Je(){let g=[$];return _&&g.push(_),j>0&&g.push(bi(j)+" \u5B57\u601D\u8003"),I>0&&g.push("ctx "+Au(I,F,T)),g.join(" \xB7 ")}function W(){if(!i||M)return;let g=f[h%f.length];h++;try{n.write("\r\x1B[K"+T("cyan",en.face(w))+" "+T("magenta",g)+" "+Je())}catch{}p=!0}function ve(g){if(g&&($=String(g)),!(!i||M)){if(d){W();return}W(),d=setInterval(W,100)}}function rn(){d&&W()}function ae(){if(d&&(clearInterval(d),d=null),p){try{n.write("\r\x1B[K")}catch{}p=!1}}function Fi(){if(!s.isTTY)return!1;let g="\r\x1B[J";return te>0&&(g+="\x1B["+te+"A\x1B[J"),ne(g),te=0,ee=!1,!0}async function Li(){if(!i)return!1;try{u=await Promise.resolve().then(()=>(pi(),hi))}catch{return u=null,N||(N=!0,me(T("yellow","[luban] ")+"\u9009\u62E9\u9898\u7EC4\u4EF6\u4E0D\u53EF\u7528\uFF08\u5148 npm install\uFF0C\u6216 Node \u7248\u672C\u8FC7\u4F4E\uFF09\uFF1Aask_question \u4F1A\u76F4\u63A5\u62A5\u9519")),!1}return l=!0,!0}function xs(){return!!(Ae&&r&&s.isTTY&&r.isColorSupported===!0)}function Ni(g){P+=g;let S;for(;(S=P.indexOf(`
194
+ `))>=0;){let E=P.slice(0,S+1);P=P.slice(S+1),Ci(E)}}function Ci(g){if(g.match(/^\s*(```+|~~~+)\s*([\w+#.-]*)\s*$/)){if(!X){on(),X=!0,H=g;return}H+=g,_s(H),H="",X=!1;return}if(X){H+=g;return}let E=g.trim(),A=E.indexOf("|")!==-1;if(pe){if(!A||/^\s*$/.test(E)){on(),vt(g);return}ke.push(g);return}if(A&&!/^\s*$/.test(E)){pe=!0,ke=[g];return}vt(g)}function on(){if(!pe)return;let g=ke;if(pe=!1,ke=[],g.length>=2&&Ae.isSepRow(g[1])){let S=g.map(function(A){return A.replace(/\n$/,"")}),E=Ae.renderTable(S,0,Ae.mk(T));an(E.text+`
195
+ `)}else g.forEach(vt)}function vt(g){let S=Ae.renderBlock(g,T);an(S)}function _s(g){an(Ae.renderBlock(g,T))}function an(g){if(g){_e();try{n.write(g)}catch{return}for(let S=0;S<g.length;S++)g.charCodeAt(S)===10&&te++;ee=g.charCodeAt(g.length-1)!==10}}function Es(){if(xs()&&(X&&H&&(_s(H),H="",X=!1),on(),P)){let g=P;P="",vt(g.endsWith(`
196
196
  `)?g:g+`
197
- `)}}function Fi(g){let S=String(g??"");if(!(!S||!o||M)){if(Z||oe(),R=!0,bs())Mi(S);else{Ye(S);for(let E=0;E<S.length;E++)S.charCodeAt(E)===10&&ee++;Z=S.charCodeAt(S.length-1)!==10}D+=S}}function Li(g){let S=String(g??"");if(!S)return;if(j+=S.length,!a){tn();return}L+=S;let E=L.lastIndexOf(`
198
- `);if(E<0)return;let A=L.slice(0,E);if(L=L.slice(E+1),!!A.trim()){oe(),ze();try{n.write(O("gray",A)+`
199
- `)}catch{}}}function Ci(g){let S=String(g??"");if(j+=S.length,R&&(Ti(),D="",R=!1),a&&S.trim()){oe();try{n.write(O("gray",S.replace(/\s+$/,""))+`
200
- `)}catch{}}tn()}function Ni(g){let S=String(g??"");if(N=S,U=Date.now(),w="work",!i){ze(),ce("[..] "+S);return}ze(),xe(S)}function Di(g){if(g&&g.phase==="start")return;oe(),w=m;let S=g&&g.name||"",E={detail:pi(g),sec:""};U>0&&S&&N.indexOf(S)===0&&(E.sec=di(Date.now()-U),U=0,N=""),ce(bu(g,We,E)),i&&xe(b)}function Ri(g){g&&(w=m,T=Number(g.contextTokens)||0,F=Number(g.window)||0,D&&($e=D,D=""))}function qi(g){!Array.isArray(g)||!g.length||(w=m,oe(),ce($u(g,We)),i&&xe(b))}function Pi(g){w=m,oe(),ce(Su(g,We)),i&&xe(b)}let vt=Object.create(null);function Bi(g){let S=Array.isArray(g)?g:[];if(!S.length)return;let E=[];for(let A=0;A<S.length;A++){let Y=S[A];if(!Y||!Y.id)continue;let ne=ps[Y.status]?Y.status:"pending";vt[Y.id]!==ne&&(vt[Y.id]=ne,E.push(xu(Y,We)))}if(E.length){w=m,oe();for(let A=0;A<E.length;A++)ce(E[A]);i&&xe(b)}}function Vi(g){let S=g||{};S.mode&&(k=String(S.mode)),m=zt.moodForMode(k),w=m,tn()}async function Ui(g,S){if(!i)throw new Error("ask_question \u9700\u8981\u4EA4\u4E92\u7EC8\u7AEF\uFF08--json / --no-tui / \u975E TTY \u4E0B\u4E0D\u53EF\u7528\uFF09");if(!l||!u)throw new Error("ask_question \u9700\u8981 @clack/prompts\uFF08\u5148 npm install \u518D\u8BD5\uFF09");oe();try{g&&g.title&&u.note(g.title,"\u63D0\u95EE",{output:n});let E={},A=g&&g.questions||[];for(let Y=0;Y<A.length;Y++){let ne=A[Y],z=ne.options.map(function(be){return{value:be.id,label:be.recommended?be.label+"\uFF08\u63A8\u8350\uFF09":be.label}}),se;if(ne.allow_multiple?se=await u.multiselect({message:ne.prompt,options:z,required:!0,output:n,signal:S}):se=await u.select({message:ne.prompt,options:z,output:n,signal:S}),u.isCancel(se)){if(typeof t.onCancel=="function")try{t.onCancel("\u7528\u6237\u53D6\u6D88\u4E86\u63D0\u95EE")}catch{}throw new Error("ask_question \u5DF2\u53D6\u6D88\uFF1A\u7528\u6237\u53D6\u6D88\u4E86\u63D0\u95EE")}E[ne.id]=se}return ci.formatAnswers(g,ci.normalizeAnswers(g,E))}finally{i&&!(S&&S.aborted)&&xe(b)}}function Wi(g){return new Promise(function(S){let E=null,A=!1,Y=function(z){if(!A){A=!0;try{E&&E.close()}catch{}S(z)}};try{E=du.createInterface({input:process.stdin,output:n,terminal:!!(process.stdin.isTTY&&n.isTTY)})}catch{S(null);return}let ne=function(){Y(null)};if(g&&typeof g.addEventListener=="function"){if(g.aborted){Y(null);return}g.addEventListener("abort",ne,{once:!0})}E.question("\u5141\u8BB8\u8FD9\u6B21\u5199\u5165\uFF1F[y] \u5141\u8BB8 / [a] \u672C\u6B21\u4F1A\u8BDD\u90FD\u5141\u8BB8 / [N] \u62D2\u7EDD ",function(z){g&&typeof g.removeEventListener=="function"&&g.removeEventListener("abort",ne);let se=String(z||"").trim().toLowerCase();Y(se==="a"||se==="all"?"all":se==="y"||se==="yes"?"yes":null)})})}async function Gi(g,S){if(!i)return!0;let E=mi(g,We);E.length&&(oe(),w="work",ce(E.join(`
201
- `)));let A=null;if(l&&u){try{A=await u.select({message:"\u5141\u8BB8\u8FD9\u6B21\u5199\u5165\u5417\uFF1F",options:[{value:"yes",label:"\u5141\u8BB8\u672C\u6B21"},{value:"all",label:"\u5141\u8BB8\uFF0C\u672C\u6B21\u4F1A\u8BDD\u4E0D\u518D\u8BE2\u95EE"},{value:"no",label:"\u62D2\u7EDD"}],output:n,signal:S})}catch{A=null}u.isCancel(A)&&(A=null)}else A=await Wi(S);return U=Date.now(),i&&!(S&&S.aborted)&&xe(b),A==="all"?"all":A==="yes"?"yes":!1}function Hi(g){let S=String(g??"");if(!S.trim())return"";if(!R)return S;let E=D.trim()?D:$e||"";return E.trim()?E.trimEnd()===S.trimEnd()?"":S.startsWith(E)?S.slice(E.length):S:S}function Ki(g){let S=String(g??"");if($s(),!R){Ye(S+`
202
- `),Z=!1;return}let E=Hi(S),A="";Z?(A+=`
203
- `,Z=!1):E&&E.charAt(0)===`
197
+ `)}}function Di(g){let S=String(g??"");if(!(!S||!o||M)){if(ee||ae(),q=!0,xs())Ni(S);else{ne(S);for(let E=0;E<S.length;E++)S.charCodeAt(E)===10&&te++;ee=S.charCodeAt(S.length-1)!==10}D+=S}}function qi(g){let S=String(g??"");if(!S)return;if(j+=S.length,!a){rn();return}L+=S;let E=L.lastIndexOf(`
198
+ `);if(E<0)return;let A=L.slice(0,E);if(L=L.slice(E+1),!!A.trim()){ae(),_e();try{n.write(T("gray",A)+`
199
+ `)}catch{}}}function Ri(g){let S=String(g??"");if(j+=S.length,q&&(Fi(),D="",q=!1),a&&S.trim()){ae();try{n.write(T("gray",S.replace(/\s+$/,""))+`
200
+ `)}catch{}}rn()}function Pi(g){let S=String(g??"");if(C=S,U=Date.now(),w="work",!i){_e(),me("[..] "+S);return}_e(),ve(S)}function Bi(g){if(g&&g.phase==="start")return;ae(),w=m;let S=g&&g.name||"",E={detail:wi(g),sec:""};U>0&&S&&C.indexOf(S)===0&&(E.sec=yi(Date.now()-U),U=0,C=""),me(Mu(g,He,E)),i&&ve(b)}function Vi(g){g&&(w=m,I=Number(g.contextTokens)||0,F=Number(g.window)||0,D&&(Se=D,D=""))}function Ui(g){!Array.isArray(g)||!g.length||(w=m,ae(),me(Fu(g,He)),i&&ve(b))}function Wi(g){w=m,ae(),me(Lu(g,He)),i&&ve(b)}let kt=Object.create(null);function Gi(g){let S=Array.isArray(g)?g:[];if(!S.length)return;let E=[];for(let A=0;A<S.length;A++){let Y=S[A];if(!Y||!Y.id)continue;let se=$s[Y.status]?Y.status:"pending";kt[Y.id]!==se&&(kt[Y.id]=se,E.push(Cu(Y,He)))}if(E.length){w=m,ae();for(let A=0;A<E.length;A++)me(E[A]);i&&ve(b)}}function Hi(g){let S=g||{};S.mode&&(_=String(S.mode)),m=en.moodForMode(_),w=m,rn()}async function Ki(g,S){if(!i)throw new Error("ask_question \u9700\u8981\u4EA4\u4E92\u7EC8\u7AEF\uFF08--json / --no-tui / \u975E TTY \u4E0B\u4E0D\u53EF\u7528\uFF09");if(!l||!u)throw new Error("ask_question \u9700\u8981 @clack/prompts\uFF08\u5148 npm install \u518D\u8BD5\uFF09");ae();try{g&&g.title&&u.note(g.title,"\u63D0\u95EE",{output:n});let E={},A=g&&g.questions||[];for(let Y=0;Y<A.length;Y++){let se=A[Y],Z=se.options.map(function(we){return{value:we.id,label:we.recommended?we.label+"\uFF08\u63A8\u8350\uFF09":we.label}}),re;if(se.allow_multiple?re=await u.multiselect({message:se.prompt,options:Z,required:!0,output:n,signal:S}):re=await u.select({message:se.prompt,options:Z,output:n,signal:S}),u.isCancel(re)){if(typeof t.onCancel=="function")try{t.onCancel("\u7528\u6237\u53D6\u6D88\u4E86\u63D0\u95EE")}catch{}throw new Error("ask_question \u5DF2\u53D6\u6D88\uFF1A\u7528\u6237\u53D6\u6D88\u4E86\u63D0\u95EE")}E[se.id]=re}return mi.formatAnswers(g,mi.normalizeAnswers(g,E))}finally{i&&!(S&&S.aborted)&&ve(b)}}function Ji(g){return new Promise(function(S){let E=null,A=!1,Y=function(Z){if(!A){A=!0;try{E&&E.close()}catch{}S(Z)}};try{E=_u.createInterface({input:process.stdin,output:n,terminal:!!(process.stdin.isTTY&&n.isTTY)})}catch{S(null);return}let se=function(){Y(null)};if(g&&typeof g.addEventListener=="function"){if(g.aborted){Y(null);return}g.addEventListener("abort",se,{once:!0})}E.question("\u5141\u8BB8\u8FD9\u6B21\u5199\u5165\uFF1F[y] \u5141\u8BB8 / [a] \u672C\u6B21\u4F1A\u8BDD\u90FD\u5141\u8BB8 / [N] \u62D2\u7EDD ",function(Z){g&&typeof g.removeEventListener=="function"&&g.removeEventListener("abort",se);let re=String(Z||"").trim().toLowerCase();Y(re==="a"||re==="all"?"all":re==="y"||re==="yes"?"yes":null)})})}async function Xi(g,S){if(!i)return!0;let E=$i(g,He);E.length&&(ae(),w="work",me(E.join(`
201
+ `)));let A=null;if(l&&u){try{A=await u.select({message:"\u5141\u8BB8\u8FD9\u6B21\u5199\u5165\u5417\uFF1F",options:[{value:"yes",label:"\u5141\u8BB8\u672C\u6B21"},{value:"all",label:"\u5141\u8BB8\uFF0C\u672C\u6B21\u4F1A\u8BDD\u4E0D\u518D\u8BE2\u95EE"},{value:"no",label:"\u62D2\u7EDD"}],output:n,signal:S})}catch{A=null}u.isCancel(A)&&(A=null)}else A=await Ji(S);return U=Date.now(),i&&!(S&&S.aborted)&&ve(b),A==="all"?"all":A==="yes"?"yes":!1}function zi(g){let S=String(g??"");if(!S.trim())return"";if(!q)return S;let E=D.trim()?D:Se||"";return E.trim()?E.trimEnd()===S.trimEnd()?"":S.startsWith(E)?S.slice(E.length):S:S}function Yi(g){let S=String(g??"");if(Es(),!q){ne(S+`
202
+ `),ee=!1;return}let E=zi(S),A="";ee?(A+=`
203
+ `,ee=!1):E&&E.charAt(0)===`
204
204
  `&&(E=E.slice(1)),E&&(A+=E),A&&A.charCodeAt(A.length-1)!==10&&(A+=`
205
- `),Ye(A)}function Ji(g){let S=g||{};if(oe(),a&&L.trim())try{n.write(O("gray",L.replace(/\s+$/,""))+`
206
- `)}catch{}L="";let E=i?O("cyan",zt.face(zt.moodForStop(S.stop)))+" ":"";if(S.compact){let z=[String(S.stop||"unknown")];z.push((S.iters==null?0:S.iters)+" \u8F6E"),z.push((S.tools||0)+" \u5DE5\u5177"),te>0&&z.push(di(Date.now()-te)),ce(i?E+O("gray",z.join(" \xB7 ")):"[luban] "+z.join(" "))}else{let z="\u6A21\u5F0F="+S.mode+" \u8F6E\u6570="+S.iters+" \u5DE5\u5177\u8C03\u7528="+S.tools+" \u505C\u6B62="+S.stop+" \u6A21\u578B="+(S.model||"");ce(E+(We?O("cyan","[luban] "):"[luban] ")+z)}let A=Array.isArray(S.log)?S.log:[],Y=Object.create(null),ne=[];for(let z=0;z<A.length;z++){let se=A[z];if(!se||se.ok===!1||hu.indexOf(se.name)<0)continue;let be=se.path?String(se.path):"";!be||Y[be]||/^\d+ 个文件$/.test(be)||(Y[be]=1,ne.push(be))}ne.length&&ce((We?O("gray","\xB7 \u6539\u52A8 "):"[files] ")+ne.length+" \u4E2A\u6587\u4EF6: "+ne.join(", "))}function Xi(){oe(),$=b,w=m,R=!1,Z=!1,ee=0,D="",P="",J=!1,G="",pe=!1,Se=[],$e="",j=0,L="",N="",U=0,T=0,F=0,te=Date.now();for(let g in vt)delete vt[g];xe(b)}function Yi(){if(oe(),a&&L.trim())try{n.write(O("gray",L.replace(/\s+$/,""))+`
207
- `)}catch{}L="",$s()}function zi(g){return g!==void 0&&(a=!!g),a}function Qi(){oe(),M=!0}return process.once("exit",function(){try{oe()}catch{}}),{enabled:i,init:ji,stream:Fi,thinking:Li,split:Ci,progress:Ni,tool:Di,usage:Ri,refs:qi,sub:Pi,todos:Bi,setStatus:Vi,setThinking:zi,beginTurn:Xi,endTurn:Yi,ask:Ui,confirmWrite:Gi,outputFinal:Ki,finish:Ji,close:Qi,line:function(g){oe(),ce(g)}}}gi.exports={createUI:_u,paint:O,resultDetail:pi,previewLines:mi}});var Ii=me((dl,Ei)=>{"use strict";var ue=require("fs"),ku=require("os"),ie=require("path"),{execFile:Eu}=require("child_process"),le=un(),Zt=Ls(),wi="https://raw.githubusercontent.com/eppen/luban-plugins/main/registry/registry.json",$i=6e4,Iu=3e4,Ou={fsRead:"\u8BFB\u53D6\u5DE5\u4F5C\u533A\u6587\u4EF6",fsWrite:"\u5199\u5165 / \u5220\u9664\u6587\u4EF6",shell:"\u6267\u884C shell \u547D\u4EE4",net:"\u53D1\u8D77\u7F51\u7EDC\u8BF7\u6C42",env:"\u8BFB\u53D6\u73AF\u5883\u53D8\u91CF"};function gt(e){return/^https?:\/\//i.test(String(e||""))}function gs(e){let t=e||process.cwd();try{ut().configure({root:t})}catch{}Zt.configure({root:t})}function yt(e){let t=e||{};if(t.registry)return t.registry;if(process.env.LUBAN_REGISTRY)return process.env.LUBAN_REGISTRY;let n=[ie.join(__dirname,"registry","registry.json"),ie.join(__dirname,"..","registry","registry.json")];for(let s of n)if(ue.existsSync(s))return s;return wi}function Tu(){let e=[ie.join(__dirname,"registry","registry.json"),ie.join(__dirname,"..","registry","registry.json")];for(let t of e)if(ue.existsSync(t))return t;return""}async function ju(e,t){let n=new AbortController,s=setTimeout(function(){n.abort()},t||Iu);try{let r=await fetch(e,{headers:{"user-agent":"luban-plugin-client"},signal:n.signal});if(!r.ok)throw new Error("HTTP "+r.status);return await r.text()}finally{clearTimeout(s)}}async function bt(e,t){return gt(e)?ju(e,t):ue.readFileSync(le.expandHome(e),"utf8")}async function wt(e,t){let n={},s=gt(t)?t:ie.resolve(le.expandHome(t));for(let r of e.signingKeys||[]){if(!r||!r.keyId)continue;if(r.publicKey&&!/\.pub$/i.test(String(r.publicKey))&&String(r.publicKey).length>64){try{n[r.keyId]=le.parsePublicKey(r.publicKey)}catch{}continue}let i=String(r.publicKey||"keys/"+r.keyId+".pub"),o=gt(s)?new URL(i,s).toString():ie.join(ie.dirname(s),i);try{let a=JSON.parse(await bt(o));n[r.keyId]=le.parsePublicKey(a.publicKey)}catch{}}return n}function bi(e,t,n){return new Promise(function(s,r){Eu(e,t,{timeout:n||$i,maxBuffer:4*1024*1024},function(i,o,a){if(i){let u=String(a||i.message||"").trim().split(`
208
- `).slice(-3).join(" / "),l=new Error(e+" \u5931\u8D25\uFF1A"+u);return l.code=i.code,l.stderr=String(a||""),r(l)}s({stdout:String(o||""),stderr:String(a||"")})})})}function Mu(e){let t=ie.join(ku.tmpdir(),"luban-plugin-"+String(e||"x").replace(/[^a-z0-9-]/gi,"_")+"-"+process.pid+"-"+Date.now());return ue.mkdirSync(t,{recursive:!0,mode:448}),t}async function Si(e,t){let n=t||{},s=e.install||{},r=e.name,i=e.version;if(s.type==="local"){let u=le.expandHome(s.path||"");if(!u||!ue.existsSync(u))throw new Error("\u672C\u5730\u6765\u6E90\u4E0D\u5B58\u5728\uFF1A"+(s.path||"(\u7A7A)"));return{dir:ie.resolve(u),cleanup:function(){},kind:"local"}}let o=Mu(r),a=function(){try{ue.rmSync(o,{recursive:!0,force:!0})}catch{}};if(s.type==="git"){if(!gt(s.url)&&!/^git@/.test(String(s.url||"")))throw new Error("install.url \u4E0D\u662F\u53EF\u7528\u7684 git \u5730\u5740\uFF1A"+(s.url||"(\u7A7A)"));let u=n.tag||le.tagFor(r,i),l=ie.join(o,"repo"),f=[s.url];/^git@github\.com:/.test(s.url)?f.push("https://github.com/"+s.url.slice(15)):/^https:\/\/github\.com\//.test(s.url)&&f.push("git@github.com:"+s.url.slice(19));let d=null;for(let p=0;p<f.length;p++)try{await bi("git",["clone","--depth","1","--branch",u,"--single-branch",f[p],l]),d=null;break}catch(m){if(d=m,m.code==="ENOENT")throw new Error("\u672C\u673A\u6CA1\u6709 git\uFF0C\u65E0\u6CD5\u4ECE git \u6765\u6E90\u5B89\u88C5");if(p===f.length-1)break;a(),ue.mkdirSync(o,{recursive:!0})}if(d)throw a(),new Error("\u62C9\u53D6 "+s.url+" \u7684 "+u+" \u5931\u8D25\uFF1A"+d.message);let h=s.subdir?ie.join(l,s.subdir):l;if(!ue.existsSync(h))throw a(),new Error("\u4ED3\u5E93\u91CC\u6CA1\u6709 subdir\uFF1A"+s.subdir);return{dir:h,cleanup:a,kind:"git",tag:u}}if(s.type==="tarball"){if(!gt(s.url))throw a(),new Error("tarball \u6765\u6E90\u9700\u8981 http(s) \u5730\u5740");let u=ie.join(o,"pkg.tgz"),l=Buffer.from(await async function(){let p=new AbortController,m=setTimeout(function(){p.abort()},$i);try{let w=await fetch(s.url,{signal:p.signal});if(!w.ok)throw new Error("HTTP "+w.status);return await w.arrayBuffer()}finally{clearTimeout(m)}}());ue.writeFileSync(u,l);let f=ie.join(o,"x");ue.mkdirSync(f,{recursive:!0});try{await bi("tar",["-xzf",u,"-C",f],6e4)}catch(p){throw a(),new Error("\u89E3\u5305\u5931\u8D25\uFF08\u9700\u8981\u7CFB\u7EDF tar\uFF09\uFF1A"+p.message)}let d=ue.readdirSync(f).filter(function(p){return!p.startsWith(".")});if(d.length!==1)throw a(),new Error("\u538B\u7F29\u5305\u9876\u5C42\u5E94\u5F53\u53EA\u6709\u4E00\u4E2A\u76EE\u5F55\uFF0C\u5B9E\u9645 "+d.length+" \u4E2A");let h=s.subdir?ie.join(f,d[0],s.subdir):ie.join(f,d[0]);if(!ue.existsSync(h))throw a(),new Error("\u538B\u7F29\u5305\u91CC\u6CA1\u6709 subdir\uFF1A"+s.subdir);return{dir:h,cleanup:a,kind:"tarball"}}throw a(),new Error("\u4E0D\u652F\u6301\u7684 install.type\uFF1A"+s.type)}function vi(e,t){if(e&&e.type==="skill"){let r=le.readSkillManifest(t);if(!r.ok)return{ok:!1,message:r.message};let i=le.sameSkill(e,r.manifest);return i.ok?{ok:!0,manifest:r.manifest}:{ok:!1,message:i.message}}let n=ie.join(t,"plugin.json");if(!ue.existsSync(n))return{ok:!1,message:"\u5305\u91CC\u6CA1\u6709 plugin.json"};let s;try{s=JSON.parse(ue.readFileSync(n,"utf8"))}catch(r){return{ok:!1,message:"plugin.json \u89E3\u6790\u5931\u8D25\uFF1A"+r.message}}return s.name!==e.name?{ok:!1,message:"name \u4E0D\u4E00\u81F4\uFF1A\u7D22\u5F15 "+e.name+"\u3001\u5305\u5185 "+s.name}:s.version!==e.version?{ok:!1,message:"version \u4E0D\u4E00\u81F4\uFF1A\u7D22\u5F15 "+e.version+"\u3001\u5305\u5185 "+s.version}:le.sameTools(e.tools,s.tools)?{ok:!0,manifest:s}:{ok:!1,message:"tools \u4E0E\u7D22\u5F15\u4E0D\u4E00\u81F4\uFF08\u63CF\u8FF0 / readOnly / \u53C2\u6570 schema \u4EFB\u4E00\u4E0D\u540C\u90FD\u7B97\uFF09"}}async function xi(e,t){let n=t||{},s=e.type==="skill"?"skill":e.type==="plugin"?"plugin":"";if(!s)return{ok:!1,code:"bad-type",message:e.name+" \u7684 type \u4E0D\u53EF\u7528\uFF1A"+e.type};let r=e.review&&e.review.status||"pending";if(r==="revoked")return{ok:!1,code:"revoked",message:"\u8BE5"+en(s)+"\u5DF2\u88AB\u64A4\u9500\uFF08revoked\uFF09\uFF0C\u5BBF\u4E3B\u5E94\u963B\u6B62\u5B89\u88C5"};if(r==="flagged")return{ok:!1,code:"flagged",message:"\u8BE5"+en(s)+"\u88AB\u5BA1\u6838\u6807\u8BB0\u4E3A\u6709\u95EE\u9898\uFF08flagged\uFF09\uFF0C\u62D2\u7EDD\u5B89\u88C5"};let i=[];r==="pending"&&i.push("\u5BA1\u6838\u72B6\u6001 pending\uFF1A\u7B7E\u540D\u53EA\u80FD\u8BC1\u660E\u300C\u662F\u4F5C\u8005\u53D1\u7684\u300D\uFF0C\u5B89\u5168\u7ED3\u8BBA\u8FD8\u6CA1\u4EBA\u6838\u5BF9\u8FC7");let o;try{o=await Si(e,n)}catch(a){return{ok:!1,code:"source",message:a.message}}try{let a=vi(e,o.dir);if(!a.ok)return{ok:!1,code:"manifest",message:"\u6E05\u5355\u6821\u9A8C\u5931\u8D25\uFF1A"+a.message};let u=le.dirHash(o.dir);if(e.sourceSha256&&u!==e.sourceSha256)return{ok:!1,code:"hash",message:"sourceSha256 \u4E0D\u7B26\uFF1A\u7D22\u5F15 "+e.sourceSha256+"\u3001\u5B9E\u9645 "+u+"\uFF08\u53EF\u80FD\u662F\u4ED3\u5E93\u5185\u5BB9\u53D8\u4E86\u6CA1\u91CD\u7B97\u7D22\u5F15\uFF0C\u6216\u5305\u88AB\u66FF\u6362\uFF09"};e.sourceSha256||i.push("\u7D22\u5F15\u6CA1\u7ED9 sourceSha256\uFF0C\u672C\u6B21\u5B89\u88C5\u4E0D\u53EF\u590D\u73B0");let l=n.target==="project"||n.target==="global"?n.target:e.install&&e.install.target||"global",f={name:e.name,type:s,version:e.version,review:r,permissions:e.permissions||{},sourceSha256:u,tag:o.tag||"",target:l,warnings:i.slice()};if(n.dryRun)return Object.assign({ok:!0,code:"dry-run",dir:o.dir,tools:s==="skill"?[]:(e.tools||[]).map(function(p){return p.name})},f);if(s==="skill"){gs(n.root);let p=Zt.installFromDir(o.dir,{replace:n.replace===!0,target:l,version:e.version,sourceSha256:u,tag:o.tag||"",repo:e.repo||""});return p.ok?Object.assign({ok:!0,code:"installed",dir:p.dir,replaced:p.replaced,tools:[]},f):{ok:!1,code:p.code||"install",message:p.message}}let d=ut();gs(n.root);let h=await d.installFromDir(o.dir,{replace:n.replace===!0,target:l,trust:!1});return h.ok?Object.assign({ok:!0,code:"installed",dir:h.dir,replaced:h.replaced,tools:h.tools},f):{ok:!1,code:h.code||"install",message:h.message}}finally{o.cleanup()}}async function _i(e,t){let n=t||{},s=String(e||"").trim();if(!s)return{ok:!1,code:"bad-arg",message:"\u7F3A\u5C11\u63D2\u4EF6\u540D"};let r=yt(n),i;try{i=JSON.parse(await bt(r))}catch(p){return{ok:!1,code:"registry",message:"\u8BFB\u53D6\u7D22\u5F15\u5931\u8D25\uFF08"+r+"\uFF09\uFF1A"+p.message+`
209
- \u6362\u4E00\u4EFD\u7D22\u5F15\uFF1A--registry <\u672C\u5730\u8DEF\u5F84|URL> \u6216\u73AF\u5883\u53D8\u91CF LUBAN_REGISTRY`}}let o=i.entries||[],a=o.find(function(p){return p&&p.name===s});if(!a)return{ok:!1,code:"not-found",message:"\u7D22\u5F15\u91CC\u6CA1\u6709 "+s,names:o.map(function(p){return p.name})};let u=a.type==="skill"?"skill":a.type==="plugin"?"plugin":"";if(!u)return{ok:!1,code:"bad-type",message:s+" \u7684 type \u4E0D\u53EF\u7528\uFF1A"+a.type};if(n.type&&n.type!==u){let p=n.type==="skill"?"\u6280\u80FD":"\u63D2\u4EF6",m=u==="skill"?"\u6280\u80FD":"\u63D2\u4EF6";return{ok:!1,code:"wrong-type",message:s+" \u662F"+m+"\uFF0C\u4E0D\u662F"+p+"\uFF08\u7528 luban "+(u==="skill"?"skill":"plugin")+" add "+s+"\uFF09"}}let l=await wt(i,r),f=le.verifyEntry(a,l);if(!f.ok&&!n.allowUnsigned)return{ok:!1,code:"untrusted",message:f.reason.indexOf("\u672A\u7B7E\u540D")>=0?"\u8BE5\u6761\u76EE\u672A\u7B7E\u540D\uFF0C\u65E0\u6CD5\u786E\u8BA4\u662F\u4F5C\u8005\u53D1\u5E03\u7684\uFF08\u786E\u5B9E\u8981\u88C5\u53EF\u52A0 --allow-unsigned\uFF09":"\u7D22\u5F15\u6761\u76EE\u9A8C\u7B7E\u5931\u8D25\uFF1A"+f.reason};let d=a.review&&a.review.status||"pending";if(d==="revoked")return{ok:!1,code:"revoked",message:"\u8BE5"+en(u)+"\u5DF2\u88AB\u64A4\u9500\uFF08revoked\uFF09\uFF0C\u5BBF\u4E3B\u5E94\u963B\u6B62\u5B89\u88C5"};if(d==="flagged")return{ok:!1,code:"flagged",message:"\u8BE5"+en(u)+"\u88AB\u5BA1\u6838\u6807\u8BB0\u4E3A\u6709\u95EE\u9898\uFF08flagged\uFF09\uFF0C\u62D2\u7EDD\u5B89\u88C5"};let h=await xi(a,n);return h.ok&&h.warnings&&!f.ok&&h.warnings.push("\u6761\u76EE\u672A\u7B7E\u540D\uFF08--allow-unsigned\uFF09"),h}function en(e){return e==="skill"?"\u6280\u80FD":"\u63D2\u4EF6"}async function ki(e,t){let n=t||{},s=n.root||process.cwd(),r=ut();gs(s);let i=n.type==="skill"||n.type==="plugin"?n.type:"",o=r.inventory(),a=o.plugins.concat(o.pending).some(function(f){return f.name===e}),u=!!Zt.find(e);if(i==="skill"||!i&&!a&&u){if(!u)return{ok:!1,code:"not-found",message:"\u6CA1\u6709\u8FD9\u4E2A\u6280\u80FD\uFF1A"+e};let f=Zt.uninstall(e,{why:"cli-plugin-remove"});return Object.assign({type:"skill"},f)}if(!a)return{ok:!1,code:"not-found",message:"\u6CA1\u6709\u8FD9\u4E2A\u63D2\u4EF6\uFF1A"+e};let l=await r.uninstall(e,{why:"cli-plugin-remove"});return Object.assign({type:"plugin"},l)}async function ys(e){let t=e||{},n=yt(t),s=JSON.parse(await bt(n)),r=await wt(s,n),i=t.type==="skill"||t.type==="plugin"?t.type:"";return{source:n,updatedAt:s.updatedAt||"",entries:(s.entries||[]).filter(function(o){return!i||o.type===i}).map(function(o){let a=le.verifyEntry(o,r);return{name:o.name,displayName:o.displayName,version:o.version,type:o.type,description:o.description,review:o.review&&o.review.status||"pending",signed:a.ok,unsignedReason:a.ok?"":a.reason,permissions:o.permissions||{},repo:o.repo||""}})}}async function Au(e){let t=e||{},n=t.registry||yt(t),s;try{s=JSON.parse(await bt(n,t.timeoutMs))}catch(o){return{ok:!1,source:n,error:String(o&&o.message||o),entries:[]}}let r=await wt(s,n),i=(s.entries||[]).map(function(o){let a=le.verifyEntry(o,r);return{name:o.name,displayName:o.displayName||"",version:o.version||"",type:o.type==="skill"?"skill":"plugin",description:o.description||"",review:o.review&&o.review.status||"pending",reviewNotes:o.review&&o.review.notes||"",signed:a.ok,unsignedReason:a.ok?"":a.reason,permissions:o.permissions||{},tools:(o.tools||[]).map(function(u){return{name:u.name,readOnly:u.readOnly===!0}}),repo:o.repo||"",tags:o.tags||[],sourceSha256:o.sourceSha256||""}});return{ok:!0,source:n,updatedAt:s.updatedAt||"",entries:i,error:""}}async function Fu(e){let t=e||{},n=t.registry||yt(t),s;try{s=JSON.parse(await bt(n,t.timeoutMs))}catch(i){return{ok:!1,source:n,error:String(i&&i.message||i),registry:null}}let r=await wt(s,n);return{ok:!0,source:n,registry:s,keys:r,error:""}}function Qt(e,t){try{return yi().paint(e,t)}catch{return t}}function ms(e){let t=Object.keys(e||{}).filter(function(n){return e[n]===!0});return t.length?t.map(function(n){return Ou[n]||n}).join("\u3001"):"\u65E0\uFF08\u7EAF\u8BA1\u7B97\uFF09"}function Lu(){let e=["luban plugin \u2014\u2014 \u7D22\u5F15\u5BA2\u6237\u7AEF\uFF08\u63D2\u4EF6\u4E0E\u6280\u80FD\uFF09","luban skill \u2014\u2014 \u540C\u4E0A\uFF0C\u4F46\u53EA\u5904\u7406\u6280\u80FD\uFF08\u7B49\u4EF7\u4E8E luban plugin --type skill \u2026\uFF09","","\u7528\u6CD5\uFF1A"," luban plugin list [--type plugin|skill] [--registry <\u8DEF\u5F84|URL>] [--json]"," luban plugin info <name> [--type plugin|skill] [--registry <\u8DEF\u5F84|URL>]"," luban plugin add <name> [--type plugin|skill] [--registry <\u8DEF\u5F84|URL>] [--target global|project]"," [--replace] [--allow-unsigned] [--dry-run] [--json]"," luban plugin remove <name> [--type plugin|skill] [--json]","","add \u7684\u6D41\u7A0B\uFF1A\u9A8C\u7B7E \u2192 \u67E5\u5BA1\u6838\u72B6\u6001 \u2192 \u6309 install \u62C9\u5305\uFF08git tag <name>-v<version> / tarball / local\uFF09"," \u2192 \u6821\u5BF9 sourceSha256 \u4E0E\u5305\u5185\u6E05\u5355\uFF08plugin.json / SKILL.md\uFF09\u2192 \u62F7\u8FDB\u63D2\u4EF6 / \u6280\u80FD\u76EE\u5F55\u3002","\u63D2\u4EF6\u88C5\u5B8C\u4E0D\u4F1A\u81EA\u52A8\u4FE1\u4EFB\uFF1ALuban \u91CC\u9996\u6B21\u52A0\u8F7D\u4F1A\u5217\u51FA\u5DE5\u5177\u6E05\u5355\u518D\u95EE\u4E00\u6B21\uFF08\u65E0\u5934\u573A\u666F\u4E00\u5F8B\u4E0D\u6267\u884C\u672A\u4FE1\u4EFB\u63D2\u4EF6\uFF09\u3002","\u6280\u80FD\u662F\u7EAF Markdown\uFF08\u65E0\u6267\u884C\u80FD\u529B\uFF09\uFF0C\u88C5\u8FDB ~/.luban/skills/<name> \u540E\u76EE\u5F55\u5185\u5373\u53EF\u89C1\uFF0C\u4E0D\u9700\u8981\u4FE1\u4EFB\u786E\u8BA4\u3002","","\u7D22\u5F15\u6765\u6E90\u4F18\u5148\u7EA7\uFF1A--registry > LUBAN_REGISTRY > \u4ED3\u5E93\u5185 registry/registry.json > GitHub main\u3002","--target \u9ED8\u8BA4\u53D6\u7D22\u5F15\u6761\u76EE\u7684 install.target\uFF08\u901A\u5E38\u662F global\uFF09\uFF1Bproject \u843D <repo>/.luban/\u3002"];process.stdout.write(e.join(`
205
+ `),ne(A)}function Zi(g){let S=g||{};if(ae(),a&&L.trim())try{n.write(T("gray",L.replace(/\s+$/,""))+`
206
+ `)}catch{}L="";let E=i?T("cyan",en.face(en.moodForStop(S.stop)))+" ":"";if(S.compact){let Z=[String(S.stop||"unknown")];Z.push((S.iters==null?0:S.iters)+" \u8F6E"),Z.push((S.tools||0)+" \u5DE5\u5177"),Ke>0&&Z.push(yi(Date.now()-Ke)),me(i?E+T("gray",Z.join(" \xB7 ")):"[luban] "+Z.join(" "))}else{let Z="\u6A21\u5F0F="+S.mode+" \u8F6E\u6570="+S.iters+" \u5DE5\u5177\u8C03\u7528="+S.tools+" \u505C\u6B62="+S.stop+" \u6A21\u578B="+(S.model||"");me(E+(He?T("cyan","[luban] "):"[luban] ")+Z)}let A=Array.isArray(S.log)?S.log:[],Y=Object.create(null),se=[];for(let Z=0;Z<A.length;Z++){let re=A[Z];if(!re||re.ok===!1||Eu.indexOf(re.name)<0)continue;let we=re.path?String(re.path):"";!we||Y[we]||/^\d+ 个文件$/.test(we)||(Y[we]=1,se.push(we))}se.length&&me((He?T("gray","\xB7 \u6539\u52A8 "):"[files] ")+se.length+" \u4E2A\u6587\u4EF6: "+se.join(", "))}function Qi(){ae(),$=b,w=m,q=!1,ee=!1,te=0,D="",P="",X=!1,H="",pe=!1,ke=[],Se="",j=0,L="",C="",U=0,I=0,F=0,Ke=Date.now();for(let g in kt)delete kt[g];ve(b)}function eo(){if(ae(),a&&L.trim())try{n.write(T("gray",L.replace(/\s+$/,""))+`
207
+ `)}catch{}L="",Es()}function to(g){return g!==void 0&&(a=!!g),a}function no(){ae(),M=!0}return process.once("exit",function(){try{ae()}catch{}}),{enabled:i,init:Li,stream:Di,thinking:qi,split:Ri,progress:Pi,tool:Bi,usage:Vi,refs:Ui,sub:Wi,todos:Gi,setStatus:Hi,setThinking:to,beginTurn:Qi,endTurn:eo,ask:Ki,confirmWrite:Xi,outputFinal:Yi,finish:Zi,close:no,line:function(g){ae(),me(g)}}}Si.exports={createUI:Du,paint:T,resultDetail:wi,previewLines:$i}});var Ai=ge((_l,Mi)=>{"use strict";var le=require("fs"),qu=require("os"),oe=require("path"),{execFile:Ru}=require("child_process"),ce=fn(),nn=Ps(),xi="https://raw.githubusercontent.com/eppen/luban-plugins/main/registry/registry.json",_i=6e4,Pu=3e4,Bu={fsRead:"\u8BFB\u53D6\u5DE5\u4F5C\u533A\u6587\u4EF6",fsWrite:"\u5199\u5165 / \u5220\u9664\u6587\u4EF6",shell:"\u6267\u884C shell \u547D\u4EE4",net:"\u53D1\u8D77\u7F51\u7EDC\u8BF7\u6C42",env:"\u8BFB\u53D6\u73AF\u5883\u53D8\u91CF"};function bt(e){return/^https?:\/\//i.test(String(e||""))}function vs(e){let t=e||process.cwd();try{ct().configure({root:t})}catch{}nn.configure({root:t})}function wt(e){let t=e||{};if(t.registry)return t.registry;if(process.env.LUBAN_REGISTRY)return process.env.LUBAN_REGISTRY;let n=[oe.join(__dirname,"registry","registry.json"),oe.join(__dirname,"..","registry","registry.json")];for(let s of n)if(le.existsSync(s))return s;return xi}function Vu(){let e=[oe.join(__dirname,"registry","registry.json"),oe.join(__dirname,"..","registry","registry.json")];for(let t of e)if(le.existsSync(t))return t;return""}async function Uu(e,t){let n=new AbortController,s=setTimeout(function(){n.abort()},t||Pu);try{let r=await fetch(e,{headers:{"user-agent":"luban-plugin-client"},signal:n.signal});if(!r.ok)throw new Error("HTTP "+r.status);return await r.text()}finally{clearTimeout(s)}}async function $t(e,t){return bt(e)?Uu(e,t):le.readFileSync(ce.expandHome(e),"utf8")}async function St(e,t){let n={},s=bt(t)?t:oe.resolve(ce.expandHome(t));for(let r of e.signingKeys||[]){if(!r||!r.keyId)continue;if(r.publicKey&&!/\.pub$/i.test(String(r.publicKey))&&String(r.publicKey).length>64){try{n[r.keyId]=ce.parsePublicKey(r.publicKey)}catch{}continue}let i=String(r.publicKey||"keys/"+r.keyId+".pub"),o=bt(s)?new URL(i,s).toString():oe.join(oe.dirname(s),i);try{let a=JSON.parse(await $t(o));n[r.keyId]=ce.parsePublicKey(a.publicKey)}catch{}}return n}function ki(e,t,n){return new Promise(function(s,r){Ru(e,t,{timeout:n||_i,maxBuffer:4*1024*1024},function(i,o,a){if(i){let u=String(a||i.message||"").trim().split(`
208
+ `).slice(-3).join(" / "),l=new Error(e+" \u5931\u8D25\uFF1A"+u);return l.code=i.code,l.stderr=String(a||""),r(l)}s({stdout:String(o||""),stderr:String(a||"")})})})}function Wu(e){let t=oe.join(qu.tmpdir(),"luban-plugin-"+String(e||"x").replace(/[^a-z0-9-]/gi,"_")+"-"+process.pid+"-"+Date.now());return le.mkdirSync(t,{recursive:!0,mode:448}),t}async function Ei(e,t){let n=t||{},s=e.install||{},r=e.name,i=e.version;if(s.type==="local"){let u=ce.expandHome(s.path||"");if(!u||!le.existsSync(u))throw new Error("\u672C\u5730\u6765\u6E90\u4E0D\u5B58\u5728\uFF1A"+(s.path||"(\u7A7A)"));return{dir:oe.resolve(u),cleanup:function(){},kind:"local"}}let o=Wu(r),a=function(){try{le.rmSync(o,{recursive:!0,force:!0})}catch{}};if(s.type==="git"){if(!bt(s.url)&&!/^git@/.test(String(s.url||"")))throw new Error("install.url \u4E0D\u662F\u53EF\u7528\u7684 git \u5730\u5740\uFF1A"+(s.url||"(\u7A7A)"));let u=n.tag||ce.tagFor(r,i),l=oe.join(o,"repo"),f=[s.url];/^git@github\.com:/.test(s.url)?f.push("https://github.com/"+s.url.slice(15)):/^https:\/\/github\.com\//.test(s.url)&&f.push("git@github.com:"+s.url.slice(19));let d=null;for(let p=0;p<f.length;p++)try{await ki("git",["clone","--depth","1","--branch",u,"--single-branch",f[p],l]),d=null;break}catch(m){if(d=m,m.code==="ENOENT")throw new Error("\u672C\u673A\u6CA1\u6709 git\uFF0C\u65E0\u6CD5\u4ECE git \u6765\u6E90\u5B89\u88C5");if(p===f.length-1)break;a(),le.mkdirSync(o,{recursive:!0})}if(d)throw a(),new Error("\u62C9\u53D6 "+s.url+" \u7684 "+u+" \u5931\u8D25\uFF1A"+d.message);let h=s.subdir?oe.join(l,s.subdir):l;if(!le.existsSync(h))throw a(),new Error("\u4ED3\u5E93\u91CC\u6CA1\u6709 subdir\uFF1A"+s.subdir);return{dir:h,cleanup:a,kind:"git",tag:u}}if(s.type==="tarball"){if(!bt(s.url))throw a(),new Error("tarball \u6765\u6E90\u9700\u8981 http(s) \u5730\u5740");let u=oe.join(o,"pkg.tgz"),l=Buffer.from(await async function(){let p=new AbortController,m=setTimeout(function(){p.abort()},_i);try{let w=await fetch(s.url,{signal:p.signal});if(!w.ok)throw new Error("HTTP "+w.status);return await w.arrayBuffer()}finally{clearTimeout(m)}}());le.writeFileSync(u,l);let f=oe.join(o,"x");le.mkdirSync(f,{recursive:!0});try{await ki("tar",["-xzf",u,"-C",f],6e4)}catch(p){throw a(),new Error("\u89E3\u5305\u5931\u8D25\uFF08\u9700\u8981\u7CFB\u7EDF tar\uFF09\uFF1A"+p.message)}let d=le.readdirSync(f).filter(function(p){return!p.startsWith(".")});if(d.length!==1)throw a(),new Error("\u538B\u7F29\u5305\u9876\u5C42\u5E94\u5F53\u53EA\u6709\u4E00\u4E2A\u76EE\u5F55\uFF0C\u5B9E\u9645 "+d.length+" \u4E2A");let h=s.subdir?oe.join(f,d[0],s.subdir):oe.join(f,d[0]);if(!le.existsSync(h))throw a(),new Error("\u538B\u7F29\u5305\u91CC\u6CA1\u6709 subdir\uFF1A"+s.subdir);return{dir:h,cleanup:a,kind:"tarball"}}throw a(),new Error("\u4E0D\u652F\u6301\u7684 install.type\uFF1A"+s.type)}function Oi(e,t){if(e&&e.type==="skill"){let r=ce.readSkillManifest(t);if(!r.ok)return{ok:!1,message:r.message};let i=ce.sameSkill(e,r.manifest);return i.ok?{ok:!0,manifest:r.manifest}:{ok:!1,message:i.message}}let n=oe.join(t,"plugin.json");if(!le.existsSync(n))return{ok:!1,message:"\u5305\u91CC\u6CA1\u6709 plugin.json"};let s;try{s=JSON.parse(le.readFileSync(n,"utf8"))}catch(r){return{ok:!1,message:"plugin.json \u89E3\u6790\u5931\u8D25\uFF1A"+r.message}}return s.name!==e.name?{ok:!1,message:"name \u4E0D\u4E00\u81F4\uFF1A\u7D22\u5F15 "+e.name+"\u3001\u5305\u5185 "+s.name}:s.version!==e.version?{ok:!1,message:"version \u4E0D\u4E00\u81F4\uFF1A\u7D22\u5F15 "+e.version+"\u3001\u5305\u5185 "+s.version}:ce.sameTools(e.tools,s.tools)?{ok:!0,manifest:s}:{ok:!1,message:"tools \u4E0E\u7D22\u5F15\u4E0D\u4E00\u81F4\uFF08\u63CF\u8FF0 / readOnly / \u53C2\u6570 schema \u4EFB\u4E00\u4E0D\u540C\u90FD\u7B97\uFF09"}}async function Ti(e,t){let n=t||{},s=e.type==="skill"?"skill":e.type==="plugin"?"plugin":"";if(!s)return{ok:!1,code:"bad-type",message:e.name+" \u7684 type \u4E0D\u53EF\u7528\uFF1A"+e.type};let r=e.review&&e.review.status||"pending";if(r==="revoked")return{ok:!1,code:"revoked",message:"\u8BE5"+sn(s)+"\u5DF2\u88AB\u64A4\u9500\uFF08revoked\uFF09\uFF0C\u5BBF\u4E3B\u5E94\u963B\u6B62\u5B89\u88C5"};if(r==="flagged")return{ok:!1,code:"flagged",message:"\u8BE5"+sn(s)+"\u88AB\u5BA1\u6838\u6807\u8BB0\u4E3A\u6709\u95EE\u9898\uFF08flagged\uFF09\uFF0C\u62D2\u7EDD\u5B89\u88C5"};let i=[];r==="pending"&&i.push("\u5BA1\u6838\u72B6\u6001 pending\uFF1A\u7B7E\u540D\u53EA\u80FD\u8BC1\u660E\u300C\u662F\u4F5C\u8005\u53D1\u7684\u300D\uFF0C\u5B89\u5168\u7ED3\u8BBA\u8FD8\u6CA1\u4EBA\u6838\u5BF9\u8FC7");let o;try{o=await Ei(e,n)}catch(a){return{ok:!1,code:"source",message:a.message}}try{let a=Oi(e,o.dir);if(!a.ok)return{ok:!1,code:"manifest",message:"\u6E05\u5355\u6821\u9A8C\u5931\u8D25\uFF1A"+a.message};let u=ce.dirHash(o.dir);if(e.sourceSha256&&u!==e.sourceSha256)return{ok:!1,code:"hash",message:"sourceSha256 \u4E0D\u7B26\uFF1A\u7D22\u5F15 "+e.sourceSha256+"\u3001\u5B9E\u9645 "+u+"\uFF08\u53EF\u80FD\u662F\u4ED3\u5E93\u5185\u5BB9\u53D8\u4E86\u6CA1\u91CD\u7B97\u7D22\u5F15\uFF0C\u6216\u5305\u88AB\u66FF\u6362\uFF09"};e.sourceSha256||i.push("\u7D22\u5F15\u6CA1\u7ED9 sourceSha256\uFF0C\u672C\u6B21\u5B89\u88C5\u4E0D\u53EF\u590D\u73B0");let l=n.target==="project"||n.target==="global"?n.target:e.install&&e.install.target||"global",f={name:e.name,type:s,version:e.version,review:r,permissions:e.permissions||{},sourceSha256:u,tag:o.tag||"",target:l,warnings:i.slice()};if(n.dryRun)return Object.assign({ok:!0,code:"dry-run",dir:o.dir,tools:s==="skill"?[]:(e.tools||[]).map(function(p){return p.name})},f);if(s==="skill"){vs(n.root);let p=nn.installFromDir(o.dir,{replace:n.replace===!0,target:l,version:e.version,sourceSha256:u,tag:o.tag||"",repo:e.repo||""});return p.ok?Object.assign({ok:!0,code:"installed",dir:p.dir,replaced:p.replaced,tools:[]},f):{ok:!1,code:p.code||"install",message:p.message}}let d=ct();vs(n.root);let h=await d.installFromDir(o.dir,{replace:n.replace===!0,target:l,trust:!1});return h.ok?Object.assign({ok:!0,code:"installed",dir:h.dir,replaced:h.replaced,tools:h.tools},f):{ok:!1,code:h.code||"install",message:h.message}}finally{o.cleanup()}}async function Ii(e,t){let n=t||{},s=String(e||"").trim();if(!s)return{ok:!1,code:"bad-arg",message:"\u7F3A\u5C11\u63D2\u4EF6\u540D"};let r=wt(n),i;try{i=JSON.parse(await $t(r))}catch(p){return{ok:!1,code:"registry",message:"\u8BFB\u53D6\u7D22\u5F15\u5931\u8D25\uFF08"+r+"\uFF09\uFF1A"+p.message+`
209
+ \u6362\u4E00\u4EFD\u7D22\u5F15\uFF1A--registry <\u672C\u5730\u8DEF\u5F84|URL> \u6216\u73AF\u5883\u53D8\u91CF LUBAN_REGISTRY`}}let o=i.entries||[],a=o.find(function(p){return p&&p.name===s});if(!a)return{ok:!1,code:"not-found",message:"\u7D22\u5F15\u91CC\u6CA1\u6709 "+s,names:o.map(function(p){return p.name})};let u=a.type==="skill"?"skill":a.type==="plugin"?"plugin":"";if(!u)return{ok:!1,code:"bad-type",message:s+" \u7684 type \u4E0D\u53EF\u7528\uFF1A"+a.type};if(n.type&&n.type!==u){let p=n.type==="skill"?"\u6280\u80FD":"\u63D2\u4EF6",m=u==="skill"?"\u6280\u80FD":"\u63D2\u4EF6";return{ok:!1,code:"wrong-type",message:s+" \u662F"+m+"\uFF0C\u4E0D\u662F"+p+"\uFF08\u7528 luban "+(u==="skill"?"skill":"plugin")+" add "+s+"\uFF09"}}let l=await St(i,r),f=ce.verifyEntry(a,l);if(!f.ok&&!n.allowUnsigned)return{ok:!1,code:"untrusted",message:f.reason.indexOf("\u672A\u7B7E\u540D")>=0?"\u8BE5\u6761\u76EE\u672A\u7B7E\u540D\uFF0C\u65E0\u6CD5\u786E\u8BA4\u662F\u4F5C\u8005\u53D1\u5E03\u7684\uFF08\u786E\u5B9E\u8981\u88C5\u53EF\u52A0 --allow-unsigned\uFF09":"\u7D22\u5F15\u6761\u76EE\u9A8C\u7B7E\u5931\u8D25\uFF1A"+f.reason};let d=a.review&&a.review.status||"pending";if(d==="revoked")return{ok:!1,code:"revoked",message:"\u8BE5"+sn(u)+"\u5DF2\u88AB\u64A4\u9500\uFF08revoked\uFF09\uFF0C\u5BBF\u4E3B\u5E94\u963B\u6B62\u5B89\u88C5"};if(d==="flagged")return{ok:!1,code:"flagged",message:"\u8BE5"+sn(u)+"\u88AB\u5BA1\u6838\u6807\u8BB0\u4E3A\u6709\u95EE\u9898\uFF08flagged\uFF09\uFF0C\u62D2\u7EDD\u5B89\u88C5"};let h=await Ti(a,n);return h.ok&&h.warnings&&!f.ok&&h.warnings.push("\u6761\u76EE\u672A\u7B7E\u540D\uFF08--allow-unsigned\uFF09"),h}function sn(e){return e==="skill"?"\u6280\u80FD":"\u63D2\u4EF6"}async function ji(e,t){let n=t||{},s=n.root||process.cwd(),r=ct();vs(s);let i=n.type==="skill"||n.type==="plugin"?n.type:"",o=r.inventory(),a=o.plugins.concat(o.pending).some(function(f){return f.name===e}),u=!!nn.find(e);if(i==="skill"||!i&&!a&&u){if(!u)return{ok:!1,code:"not-found",message:"\u6CA1\u6709\u8FD9\u4E2A\u6280\u80FD\uFF1A"+e};let f=nn.uninstall(e,{why:"cli-plugin-remove"});return Object.assign({type:"skill"},f)}if(!a)return{ok:!1,code:"not-found",message:"\u6CA1\u6709\u8FD9\u4E2A\u63D2\u4EF6\uFF1A"+e};let l=await r.uninstall(e,{why:"cli-plugin-remove"});return Object.assign({type:"plugin"},l)}async function ks(e){let t=e||{},n=wt(t),s=JSON.parse(await $t(n)),r=await St(s,n),i=t.type==="skill"||t.type==="plugin"?t.type:"";return{source:n,updatedAt:s.updatedAt||"",entries:(s.entries||[]).filter(function(o){return!i||o.type===i}).map(function(o){let a=ce.verifyEntry(o,r);return{name:o.name,displayName:o.displayName,version:o.version,type:o.type,description:o.description,review:o.review&&o.review.status||"pending",signed:a.ok,unsignedReason:a.ok?"":a.reason,permissions:o.permissions||{},repo:o.repo||""}})}}async function Gu(e){let t=e||{},n=t.registry||wt(t),s;try{s=JSON.parse(await $t(n,t.timeoutMs))}catch(o){return{ok:!1,source:n,error:String(o&&o.message||o),entries:[]}}let r=await St(s,n),i=(s.entries||[]).map(function(o){let a=ce.verifyEntry(o,r);return{name:o.name,displayName:o.displayName||"",version:o.version||"",type:o.type==="skill"?"skill":"plugin",description:o.description||"",review:o.review&&o.review.status||"pending",reviewNotes:o.review&&o.review.notes||"",signed:a.ok,unsignedReason:a.ok?"":a.reason,permissions:o.permissions||{},tools:(o.tools||[]).map(function(u){return{name:u.name,readOnly:u.readOnly===!0}}),repo:o.repo||"",tags:o.tags||[],sourceSha256:o.sourceSha256||""}});return{ok:!0,source:n,updatedAt:s.updatedAt||"",entries:i,error:""}}async function Hu(e){let t=e||{},n=t.registry||wt(t),s;try{s=JSON.parse(await $t(n,t.timeoutMs))}catch(i){return{ok:!1,source:n,error:String(i&&i.message||i),registry:null}}let r=await St(s,n);return{ok:!0,source:n,registry:s,keys:r,error:""}}function tn(e,t){try{return vi().paint(e,t)}catch{return t}}function Ss(e){let t=Object.keys(e||{}).filter(function(n){return e[n]===!0});return t.length?t.map(function(n){return Bu[n]||n}).join("\u3001"):"\u65E0\uFF08\u7EAF\u8BA1\u7B97\uFF09"}function Ku(){let e=["luban plugin \u2014\u2014 \u7D22\u5F15\u5BA2\u6237\u7AEF\uFF08\u63D2\u4EF6\u4E0E\u6280\u80FD\uFF09","luban skill \u2014\u2014 \u540C\u4E0A\uFF0C\u4F46\u53EA\u5904\u7406\u6280\u80FD\uFF08\u7B49\u4EF7\u4E8E luban plugin --type skill \u2026\uFF09","","\u7528\u6CD5\uFF1A"," luban plugin list [--type plugin|skill] [--registry <\u8DEF\u5F84|URL>] [--json]"," luban plugin info <name> [--type plugin|skill] [--registry <\u8DEF\u5F84|URL>]"," luban plugin add <name> [--type plugin|skill] [--registry <\u8DEF\u5F84|URL>] [--target global|project]"," [--replace] [--allow-unsigned] [--dry-run] [--json]"," luban plugin remove <name> [--type plugin|skill] [--json]","","add \u7684\u6D41\u7A0B\uFF1A\u9A8C\u7B7E \u2192 \u67E5\u5BA1\u6838\u72B6\u6001 \u2192 \u6309 install \u62C9\u5305\uFF08git tag <name>-v<version> / tarball / local\uFF09"," \u2192 \u6821\u5BF9 sourceSha256 \u4E0E\u5305\u5185\u6E05\u5355\uFF08plugin.json / SKILL.md\uFF09\u2192 \u62F7\u8FDB\u63D2\u4EF6 / \u6280\u80FD\u76EE\u5F55\u3002","\u63D2\u4EF6\u88C5\u5B8C\u4E0D\u4F1A\u81EA\u52A8\u4FE1\u4EFB\uFF1ALuban \u91CC\u9996\u6B21\u52A0\u8F7D\u4F1A\u5217\u51FA\u5DE5\u5177\u6E05\u5355\u518D\u95EE\u4E00\u6B21\uFF08\u65E0\u5934\u573A\u666F\u4E00\u5F8B\u4E0D\u6267\u884C\u672A\u4FE1\u4EFB\u63D2\u4EF6\uFF09\u3002","\u6280\u80FD\u662F\u7EAF Markdown\uFF08\u65E0\u6267\u884C\u80FD\u529B\uFF09\uFF0C\u88C5\u8FDB ~/.luban/skills/<name> \u540E\u76EE\u5F55\u5185\u5373\u53EF\u89C1\uFF0C\u4E0D\u9700\u8981\u4FE1\u4EFB\u786E\u8BA4\u3002","","\u7D22\u5F15\u6765\u6E90\u4F18\u5148\u7EA7\uFF1A--registry > LUBAN_REGISTRY > \u4ED3\u5E93\u5185 registry/registry.json > GitHub main\u3002","--target \u9ED8\u8BA4\u53D6\u7D22\u5F15\u6761\u76EE\u7684 install.target\uFF08\u901A\u5E38\u662F global\uFF09\uFF1Bproject \u843D <repo>/.luban/\u3002"];process.stdout.write(e.join(`
210
210
  `)+`
211
- `)}function Cu(e){let t={_:[]};for(let n=0;n<e.length;n++){let s=e[n],r=function(){return n++,n<e.length?e[n]:""};s==="--json"?t.json=!0:s==="--replace"?t.replace=!0:s==="--allow-unsigned"?t.allowUnsigned=!0:s==="--dry-run"?t.dryRun=!0:s==="--registry"?t.registry=r():s==="--target"?t.target=r():s==="--type"?t.type=r():s==="--root"?t.root=r():s==="--tag"?t.tag=r():s==="--help"||s==="-h"?t.help=!0:s.charAt(0)==="-"&&s.length>1?t.error="\u672A\u77E5\u9009\u9879 "+s:t._.push(s)}return t}function W(e){process.stdout.write(e+`
212
- `)}async function Nu(e){let t=Cu(e);try{ut().configure({root:t.root||process.cwd(),enabled:!1})}catch{}let n=String(t._[0]||"").toLowerCase(),s=t._[1]||"";if(!n||n==="help"||t.help)return Lu(),!n||t.help?0:2;if(t.error)return process.stderr.write("luban plugin: "+t.error+`
211
+ `)}function Ju(e){let t={_:[]};for(let n=0;n<e.length;n++){let s=e[n],r=function(){return n++,n<e.length?e[n]:""};s==="--json"?t.json=!0:s==="--replace"?t.replace=!0:s==="--allow-unsigned"?t.allowUnsigned=!0:s==="--dry-run"?t.dryRun=!0:s==="--registry"?t.registry=r():s==="--target"?t.target=r():s==="--type"?t.type=r():s==="--root"?t.root=r():s==="--tag"?t.tag=r():s==="--help"||s==="-h"?t.help=!0:s.charAt(0)==="-"&&s.length>1?t.error="\u672A\u77E5\u9009\u9879 "+s:t._.push(s)}return t}function G(e){process.stdout.write(e+`
212
+ `)}async function Xu(e){let t=Ju(e);try{ct().configure({root:t.root||process.cwd(),enabled:!1})}catch{}let n=String(t._[0]||"").toLowerCase(),s=t._[1]||"";if(!n||n==="help"||t.help)return Ku(),!n||t.help?0:2;if(t.error)return process.stderr.write("luban plugin: "+t.error+`
213
213
  `),2;if(t.type&&t.type!=="plugin"&&t.type!=="skill")return process.stderr.write(`luban plugin: --type \u53EA\u80FD\u662F plugin \u6216 skill
214
- `),2;if(n==="list"){let r;try{r=await ys(t)}catch(i){return process.stderr.write("luban plugin: "+i.message+`
215
- `),1}if(t.json)return W(JSON.stringify(r,null,2)),0;if(W("\u7D22\u5F15\uFF1A"+r.source+(r.updatedAt?" (updated "+r.updatedAt+")":"")),!r.entries.length)return W("\uFF08\u7A7A\uFF09"),0;for(let i of r.entries){let o=i.signed?Qt("green","\u2713\u7B7E\u540D"):Qt("yellow","\u672A\u7B7E\u540D"),a=i.review==="reviewed"?Qt("green","reviewed"):Qt("yellow",i.review);W(" "+i.name.padEnd(16)+(i.version||"").padEnd(10)+a.padEnd(10)+o+" "+i.description),W(" "+i.type+" \xB7 "+(i.type==="skill"?"\u7EAF\u8BF4\u660E\u6587\u6863\uFF08\u65E0\u6267\u884C\u6743\u9650\uFF09":ms(i.permissions))+(i.repo?" \xB7 "+i.repo:""))}return 0}if(n==="info"){if(!s)return process.stderr.write(`luban plugin: \u7528\u6CD5 luban plugin info <name>
216
- `),2;let r;try{r=await ys(t)}catch(o){return process.stderr.write("luban plugin: "+o.message+`
217
- `),1}let i=r.entries.find(function(o){return o.name===s});return i?t.json?(W(JSON.stringify(i,null,2)),0):(W(i.name+" "+i.version+(i.displayName?" "+i.displayName:"")+" ["+i.type+"]"),W(" "+i.description),W(" \u5BA1\u6838\uFF1A"+i.review+" \u7B7E\u540D\uFF1A"+(i.signed?"\u901A\u8FC7":i.unsignedReason)),W(" \u6743\u9650\uFF1A"+(i.type==="skill"?"\u65E0\uFF08\u6280\u80FD\u662F\u7EAF Markdown \u8BF4\u660E\u4E66\uFF0C\u4E0D\u7ED9\u6A21\u578B\u65B0\u589E\u4EFB\u4F55\u6267\u884C\u80FD\u529B\uFF09":ms(i.permissions))),i.repo&&W(" \u6E90\u7801\uFF1A"+i.repo),0):(process.stderr.write("luban plugin: \u7D22\u5F15\u91CC\u6CA1\u6709 "+s+`
214
+ `),2;if(n==="list"){let r;try{r=await ks(t)}catch(i){return process.stderr.write("luban plugin: "+i.message+`
215
+ `),1}if(t.json)return G(JSON.stringify(r,null,2)),0;if(G("\u7D22\u5F15\uFF1A"+r.source+(r.updatedAt?" (updated "+r.updatedAt+")":"")),!r.entries.length)return G("\uFF08\u7A7A\uFF09"),0;for(let i of r.entries){let o=i.signed?tn("green","\u2713\u7B7E\u540D"):tn("yellow","\u672A\u7B7E\u540D"),a=i.review==="reviewed"?tn("green","reviewed"):tn("yellow",i.review);G(" "+i.name.padEnd(16)+(i.version||"").padEnd(10)+a.padEnd(10)+o+" "+i.description),G(" "+i.type+" \xB7 "+(i.type==="skill"?"\u7EAF\u8BF4\u660E\u6587\u6863\uFF08\u65E0\u6267\u884C\u6743\u9650\uFF09":Ss(i.permissions))+(i.repo?" \xB7 "+i.repo:""))}return 0}if(n==="info"){if(!s)return process.stderr.write(`luban plugin: \u7528\u6CD5 luban plugin info <name>
216
+ `),2;let r;try{r=await ks(t)}catch(o){return process.stderr.write("luban plugin: "+o.message+`
217
+ `),1}let i=r.entries.find(function(o){return o.name===s});return i?t.json?(G(JSON.stringify(i,null,2)),0):(G(i.name+" "+i.version+(i.displayName?" "+i.displayName:"")+" ["+i.type+"]"),G(" "+i.description),G(" \u5BA1\u6838\uFF1A"+i.review+" \u7B7E\u540D\uFF1A"+(i.signed?"\u901A\u8FC7":i.unsignedReason)),G(" \u6743\u9650\uFF1A"+(i.type==="skill"?"\u65E0\uFF08\u6280\u80FD\u662F\u7EAF Markdown \u8BF4\u660E\u4E66\uFF0C\u4E0D\u7ED9\u6A21\u578B\u65B0\u589E\u4EFB\u4F55\u6267\u884C\u80FD\u529B\uFF09":Ss(i.permissions))),i.repo&&G(" \u6E90\u7801\uFF1A"+i.repo),0):(process.stderr.write("luban plugin: \u7D22\u5F15\u91CC\u6CA1\u6709 "+s+`
218
218
  `),1)}if(n==="add"){if(!s)return process.stderr.write(`luban plugin: \u7528\u6CD5 luban plugin add <name>
219
- `),2;let r=await _i(s,t);if(t.json)return W(JSON.stringify(r,null,2)),r.ok?0:1;if(!r.ok)return process.stderr.write("luban plugin: "+r.message+`
219
+ `),2;let r=await Ii(s,t);if(t.json)return G(JSON.stringify(r,null,2)),r.ok?0:1;if(!r.ok)return process.stderr.write("luban plugin: "+r.message+`
220
220
  `),r.names&&r.names.length&&process.stderr.write(" \u7D22\u5F15\u91CC\u53EF\u7528\uFF1A"+r.names.join("\u3001")+`
221
- `),1;if(r.code==="dry-run"?W("[dry-run] "+(r.type==="skill"?"\u6280\u80FD ":"")+r.name+" "+r.version+" \u6821\u9A8C\u901A\u8FC7\uFF0C\u672A\u843D\u76D8"):W("\u5DF2\u5B89\u88C5"+(r.type==="skill"?"\u6280\u80FD ":" ")+r.name+" "+r.version+" \u2192 "+r.dir+(r.replaced?"\uFF08\u8986\u76D6\u4E86\u65E7\u7248\u672C\uFF0C\u65E7\u7684\u5DF2\u8FDB\u56DE\u6536\u7AD9\uFF09":"")),r.type==="skill"){W(" sourceSha256\uFF1A"+r.sourceSha256+" \u5BA1\u6838\uFF1A"+r.review);for(let i of r.warnings)W(" ! "+i);return r.code==="dry-run"?W(" \u5C06\u4F1A\u88C5\u5230 "+(r.target==="project"?"<repo>/.luban/skills/":"~/.luban/skills/")+r.name):W(" \u6280\u80FD\u662F\u7EAF Markdown\uFF0C\u5DF2\u5728\u6280\u80FD\u76EE\u5F55\u5185\u53EF\u89C1\uFF08read_skill "+r.name+"\uFF09\uFF1B\u4E0D\u9700\u8981\u4FE1\u4EFB\u786E\u8BA4\u3002"),0}W(" \u5DE5\u5177\uFF1A"+(r.tools||[]).map(function(i){return"pl__"+r.name+"__"+i}).join("\u3001")),W(" \u6743\u9650\uFF1A"+ms(r.permissions)),W(" \u5BA1\u6838\uFF1A"+r.review+" sourceSha256\uFF1A"+r.sourceSha256);for(let i of r.warnings)W(" ! "+i);return W(" \u6CE8\u610F\uFF1A\u8FD8\u6CA1\u6709\u5199\u4FE1\u4EFB\u8868\u3002Luban \u91CC\u6253\u5F00\u63D2\u4EF6\u5F00\u5173\u540E\uFF0C\u9996\u6B21\u52A0\u8F7D\u4F1A\u5217\u51FA\u5DE5\u5177\u6E05\u5355\u8BA9\u4F60\u786E\u8BA4\u3002"),0}if(n==="remove"){if(!s)return process.stderr.write(`luban plugin: \u7528\u6CD5 luban plugin remove <name>
222
- `),2;let r=await ki(s,t);return t.json?(W(JSON.stringify(r,null,2)),r.ok?0:1):r.ok?(W("\u5DF2\u5378\u8F7D"+(r.type==="skill"?"\u6280\u80FD ":" ")+r.name+"\uFF08\u79FB\u8FDB\u56DE\u6536\u7AD9 "+r.trash+"\uFF0C\u53EF\u8FD8\u539F\uFF09"),0):(process.stderr.write("luban plugin: "+r.message+`
221
+ `),1;if(r.code==="dry-run"?G("[dry-run] "+(r.type==="skill"?"\u6280\u80FD ":"")+r.name+" "+r.version+" \u6821\u9A8C\u901A\u8FC7\uFF0C\u672A\u843D\u76D8"):G("\u5DF2\u5B89\u88C5"+(r.type==="skill"?"\u6280\u80FD ":" ")+r.name+" "+r.version+" \u2192 "+r.dir+(r.replaced?"\uFF08\u8986\u76D6\u4E86\u65E7\u7248\u672C\uFF0C\u65E7\u7684\u5DF2\u8FDB\u56DE\u6536\u7AD9\uFF09":"")),r.type==="skill"){G(" sourceSha256\uFF1A"+r.sourceSha256+" \u5BA1\u6838\uFF1A"+r.review);for(let i of r.warnings)G(" ! "+i);return r.code==="dry-run"?G(" \u5C06\u4F1A\u88C5\u5230 "+(r.target==="project"?"<repo>/.luban/skills/":"~/.luban/skills/")+r.name):G(" \u6280\u80FD\u662F\u7EAF Markdown\uFF0C\u5DF2\u5728\u6280\u80FD\u76EE\u5F55\u5185\u53EF\u89C1\uFF08read_skill "+r.name+"\uFF09\uFF1B\u4E0D\u9700\u8981\u4FE1\u4EFB\u786E\u8BA4\u3002"),0}G(" \u5DE5\u5177\uFF1A"+(r.tools||[]).map(function(i){return"pl__"+r.name+"__"+i}).join("\u3001")),G(" \u6743\u9650\uFF1A"+Ss(r.permissions)),G(" \u5BA1\u6838\uFF1A"+r.review+" sourceSha256\uFF1A"+r.sourceSha256);for(let i of r.warnings)G(" ! "+i);return G(" \u6CE8\u610F\uFF1A\u8FD8\u6CA1\u6709\u5199\u4FE1\u4EFB\u8868\u3002Luban \u91CC\u6253\u5F00\u63D2\u4EF6\u5F00\u5173\u540E\uFF0C\u9996\u6B21\u52A0\u8F7D\u4F1A\u5217\u51FA\u5DE5\u5177\u6E05\u5355\u8BA9\u4F60\u786E\u8BA4\u3002"),0}if(n==="remove"){if(!s)return process.stderr.write(`luban plugin: \u7528\u6CD5 luban plugin remove <name>
222
+ `),2;let r=await ji(s,t);return t.json?(G(JSON.stringify(r,null,2)),r.ok?0:1):r.ok?(G("\u5DF2\u5378\u8F7D"+(r.type==="skill"?"\u6280\u80FD ":" ")+r.name+"\uFF08\u79FB\u8FDB\u56DE\u6536\u7AD9 "+r.trash+"\uFF0C\u53EF\u8FD8\u539F\uFF09"),0):(process.stderr.write("luban plugin: "+r.message+`
223
223
  `),1)}return process.stderr.write("luban plugin: \u672A\u77E5\u5B50\u547D\u4EE4 "+n+`\uFF08--help \u770B\u7528\u6CD5\uFF09
224
- `),2}Ei.exports={DEFAULT_REGISTRY_URL:wi,registrySource:yt,bundledRegistryPath:Tu,loadKeys:wt,readRegistry:Au,readRegistryRaw:Fu,fetchSource:Si,checkManifest:vi,install:_i,installEntry:xi,remove:ki,list:ys,dirHash:le.dirHash,runCli:Nu}});var Du=Ii();Du.runCli(process.argv.slice(2)).then(function(e){process.exit(e||0)},function(e){process.stderr.write("luban plugin: "+(e&&e.message||e)+`
224
+ `),2}Mi.exports={DEFAULT_REGISTRY_URL:xi,registrySource:wt,bundledRegistryPath:Vu,loadKeys:St,readRegistry:Gu,readRegistryRaw:Hu,fetchSource:Ei,checkManifest:Oi,install:Ii,installEntry:Ti,remove:ji,list:ks,dirHash:ce.dirHash,runCli:Xu}});var zu=Ai();zu.runCli(process.argv.slice(2)).then(function(e){process.exit(e||0)},function(e){process.stderr.write("luban plugin: "+(e&&e.message||e)+`
225
225
  `),process.exit(2)});