@lark-apaas/openclaw-extension-miaoda-coding 1.0.16 → 1.0.17-alpha.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.mjs
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import{createRequire as e}from"node:module";import{execFile as t,spawn as n}from"node:child_process";import{randomUUID as r}from"node:crypto";import i,{readFileSync as a}from"node:fs";import o,{dirname as s,join as c,resolve as l}from"node:path";import{appendFile as u,mkdir as d,readFile as f,readdir as p,rm as m,writeFile as h}from"node:fs/promises";import*as g from"fs";import{readdir as _,readdirSync as v,realpath as y,realpathSync as b,stat as x,statSync as S}from"fs";import{basename as C,dirname as w,isAbsolute as T,normalize as E,posix as D,relative as O,resolve as k,sep as A}from"path";import{fileURLToPath as j}from"url";import{createRequire as M}from"module";import{fileURLToPath as N}from"node:url";var P=Object.create,F=Object.defineProperty,I=Object.getOwnPropertyDescriptor,L=Object.getOwnPropertyNames,R=Object.getPrototypeOf,z=Object.prototype.hasOwnProperty,B=(e,t)=>()=>(t||e((t={exports:{}}).exports,t),t.exports),V=(e,t,n,r)=>{if(t&&typeof t==`object`||typeof t==`function`)for(var i=L(t),a=0,o=i.length,s;a<o;a++)s=i[a],!z.call(e,s)&&s!==n&&F(e,s,{get:(e=>t[e]).bind(null,s),enumerable:!(r=I(t,s))||r.enumerable});return e},H=(e,t,n)=>(n=e==null?{}:P(R(e)),V(t||!e||!e.__esModule?F(n,`default`,{value:e,enumerable:!0}):n,e)),U=e(import.meta.url);function W(){return l(process.env.OPENCLAW_STATE_DIR||process.cwd())}function G(e){return c(e,`.agent`)}function K(e,t){return c(e,`app`,t)}function q(e,t){return c(e,t)}function J(e){let t=typeof e.workspaceDir==`string`&&e.workspaceDir!==``,n=typeof e.agentDir==`string`&&e.agentDir!==``;if(!t||!n)throw Error(`resolveToolPaths: workspaceDir and agentDir are required in tool factory context`);return{workspaceDir:e.workspaceDir,agentDir:e.agentDir,agentId:e.agentId,sessionKey:e.sessionKey}}var ee=M(import.meta.url);function Y(e){let t=E(e);return t.length>1&&t[t.length-1]===A&&(t=t.substring(0,t.length-1)),t}const X=/[\\/]/g;function Z(e,t){return e.replace(X,t)}const te=/^[a-z]:[\\/]$/i;function ne(e){return e===`/`||te.test(e)}function re(e,t){let{resolvePaths:n,normalizePath:r,pathSeparator:i}=t,a=process.platform===`win32`&&e.includes(`/`)||e.startsWith(`.`);return n&&(e=k(e)),(r||a)&&(e=Y(e)),e===`.`?``:Z(e[e.length-1]===i?e:e+i,i)}function ie(e,t){return t+e}function ae(e,t){return function(n,r){return r.startsWith(e)?r.slice(e.length)+n:Z(O(e,r),t.pathSeparator)+t.pathSeparator+n}}function oe(e){return e}function se(e,t,n){return t+e+n}function ce(e,t){let{relativePaths:n,includeBasePath:r}=t;return n&&e?ae(e,t):r?ie:oe}function le(e){return function(t,n){n.push(t.substring(e.length)||`.`)}}function ue(e){return function(t,n,r){let i=t.substring(e.length)||`.`;r.every(e=>e(i,!0))&&n.push(i)}}const de=(e,t)=>{t.push(e||`.`)},fe=(e,t,n)=>{let r=e||`.`;n.every(e=>e(r,!0))&&t.push(r)},pe=()=>{};function me(e,t){let{includeDirs:n,filters:r,relativePaths:i}=t;return n?i?r&&r.length?ue(e):le(e):r&&r.length?fe:de:pe}const he=(e,t,n,r)=>{r.every(t=>t(e,!1))&&n.files++},ge=(e,t,n,r)=>{r.every(t=>t(e,!1))&&t.push(e)},_e=(e,t,n,r)=>{n.files++},ve=(e,t)=>{t.push(e)},ye=()=>{};function be(e){let{excludeFiles:t,filters:n,onlyCounts:r}=e;return t?ye:n&&n.length?r?he:ge:r?_e:ve}const xe=e=>e,Se=()=>[``].slice(0,0);function Ce(e){return e.group?Se:xe}const we=(e,t,n)=>{e.push({directory:t,files:n,dir:t})},Te=()=>{};function Ee(e){return e.group?we:Te}const De=function(e,t,n){let{queue:r,fs:i,options:{suppressErrors:a}}=t;r.enqueue(),i.realpath(e,(o,s)=>{if(o)return r.dequeue(a?null:o,t);i.stat(s,(i,o)=>{if(i)return r.dequeue(a?null:i,t);if(o.isDirectory()&&Ae(e,s,t))return r.dequeue(null,t);n(o,s),r.dequeue(null,t)})})},Oe=function(e,t,n){let{queue:r,fs:i,options:{suppressErrors:a}}=t;r.enqueue();try{let r=i.realpathSync(e),a=i.statSync(r);if(a.isDirectory()&&Ae(e,r,t))return;n(a,r)}catch(e){if(!a)throw e}};function ke(e,t){return!e.resolveSymlinks||e.excludeSymlinks?null:t?Oe:De}function Ae(e,t,n){if(n.options.useRealPaths)return je(t,n);let r=w(e),i=1;for(;r!==n.root&&i<2;){let e=n.symlinks.get(r);e&&(e===t||e.startsWith(t)||t.startsWith(e))?i++:r=w(r)}return n.symlinks.set(e,t),i>1}function je(e,t){return t.visited.includes(e+t.options.pathSeparator)}const Me=e=>e.counts,Ne=e=>e.groups,Pe=e=>e.paths,Fe=e=>e.paths.slice(0,e.options.maxFiles),Ie=(e,t,n)=>(Be(t,n,e.counts,e.options.suppressErrors),null),Le=(e,t,n)=>(Be(t,n,e.paths,e.options.suppressErrors),null),Re=(e,t,n)=>(Be(t,n,e.paths.slice(0,e.options.maxFiles),e.options.suppressErrors),null),ze=(e,t,n)=>(Be(t,n,e.groups,e.options.suppressErrors),null);function Be(e,t,n,r){t(e&&!r?e:null,n)}function Ve(e,t){let{onlyCounts:n,group:r,maxFiles:i}=e;return n?t?Me:Ie:r?t?Ne:ze:i?t?Fe:Re:t?Pe:Le}const He={withFileTypes:!0},Ue=(e,t,n,r,i)=>{if(e.queue.enqueue(),r<0)return e.queue.dequeue(null,e);let{fs:a}=e;e.visited.push(t),e.counts.directories++,a.readdir(t||`.`,He,(t,a=[])=>{i(a,n,r),e.queue.dequeue(e.options.suppressErrors?null:t,e)})},We=(e,t,n,r,i)=>{let{fs:a}=e;if(r<0)return;e.visited.push(t),e.counts.directories++;let o=[];try{o=a.readdirSync(t||`.`,He)}catch(t){if(!e.options.suppressErrors)throw t}i(o,n,r)};function Ge(e){return e?We:Ue}var Ke=class{count=0;constructor(e){this.onQueueEmpty=e}enqueue(){return this.count++,this.count}dequeue(e,t){this.onQueueEmpty&&(--this.count<=0||e)&&(this.onQueueEmpty(e,t),e&&(t.controller.abort(),this.onQueueEmpty=void 0))}},qe=class{_files=0;_directories=0;set files(e){this._files=e}get files(){return this._files}set directories(e){this._directories=e}get directories(){return this._directories}get dirs(){return this._directories}},Je=class{aborted=!1;abort(){this.aborted=!0}},Ye=class{root;isSynchronous;state;joinPath;pushDirectory;pushFile;getArray;groupFiles;resolveSymlink;walkDirectory;callbackInvoker;constructor(e,t,n){this.isSynchronous=!n,this.callbackInvoker=Ve(t,this.isSynchronous),this.root=re(e,t),this.state={root:ne(this.root)?this.root:this.root.slice(0,-1),paths:[``].slice(0,0),groups:[],counts:new qe,options:t,queue:new Ke((e,t)=>this.callbackInvoker(t,e,n)),symlinks:new Map,visited:[``].slice(0,0),controller:new Je,fs:t.fs||g},this.joinPath=ce(this.root,t),this.pushDirectory=me(this.root,t),this.pushFile=be(t),this.getArray=Ce(t),this.groupFiles=Ee(t),this.resolveSymlink=ke(t,this.isSynchronous),this.walkDirectory=Ge(this.isSynchronous)}start(){return this.pushDirectory(this.root,this.state.paths,this.state.options.filters),this.walkDirectory(this.state,this.root,this.root,this.state.options.maxDepth,this.walk),this.isSynchronous?this.callbackInvoker(this.state,null):null}walk=(e,t,n)=>{let{paths:r,options:{filters:i,resolveSymlinks:a,excludeSymlinks:o,exclude:s,maxFiles:c,signal:l,useRealPaths:u,pathSeparator:d},controller:f}=this.state;if(f.aborted||l&&l.aborted||c&&r.length>c)return;let p=this.getArray(this.state.paths);for(let c=0;c<e.length;++c){let l=e[c];if(l.isFile()||l.isSymbolicLink()&&!a&&!o){let e=this.joinPath(l.name,t);this.pushFile(e,p,this.state.counts,i)}else if(l.isDirectory()){let e=se(l.name,t,this.state.options.pathSeparator);if(s&&s(l.name,e))continue;this.pushDirectory(e,r,i),this.walkDirectory(this.state,e,e,n-1,this.walk)}else if(this.resolveSymlink&&l.isSymbolicLink()){let e=ie(l.name,t);this.resolveSymlink(e,this.state,(t,r)=>{if(t.isDirectory()){if(r=re(r,this.state.options),s&&s(l.name,u?r:e+d))return;this.walkDirectory(this.state,r,u?r:e+d,n-1,this.walk)}else{r=u?r:e;let t=C(r),n=re(w(r),this.state.options);r=this.joinPath(t,n),this.pushFile(r,p,this.state.counts,i)}})}}this.groupFiles(this.state.groups,t,p)}};function Xe(e,t){return new Promise((n,r)=>{Ze(e,t,(e,t)=>{if(e)return r(e);n(t)})})}function Ze(e,t,n){new Ye(e,t,n).start()}function Qe(e,t){return new Ye(e,t).start()}var $e=class{constructor(e,t){this.root=e,this.options=t}withPromise(){return Xe(this.root,this.options)}withCallback(e){Ze(this.root,this.options,e)}sync(){return Qe(this.root,this.options)}};let et=null;try{ee.resolve(`picomatch`),et=ee(`picomatch`)}catch{}var tt=class{globCache={};options={maxDepth:1/0,suppressErrors:!0,pathSeparator:A,filters:[]};globFunction;constructor(e){this.options={...this.options,...e},this.globFunction=this.options.globFunction}group(){return this.options.group=!0,this}withPathSeparator(e){return this.options.pathSeparator=e,this}withBasePath(){return this.options.includeBasePath=!0,this}withRelativePaths(){return this.options.relativePaths=!0,this}withDirs(){return this.options.includeDirs=!0,this}withMaxDepth(e){return this.options.maxDepth=e,this}withMaxFiles(e){return this.options.maxFiles=e,this}withFullPaths(){return this.options.resolvePaths=!0,this.options.includeBasePath=!0,this}withErrors(){return this.options.suppressErrors=!1,this}withSymlinks({resolvePaths:e=!0}={}){return this.options.resolveSymlinks=!0,this.options.useRealPaths=e,this.withFullPaths()}withAbortSignal(e){return this.options.signal=e,this}normalize(){return this.options.normalizePath=!0,this}filter(e){return this.options.filters.push(e),this}onlyDirs(){return this.options.excludeFiles=!0,this.options.includeDirs=!0,this}exclude(e){return this.options.exclude=e,this}onlyCounts(){return this.options.onlyCounts=!0,this}crawl(e){return new $e(e||`.`,this.options)}withGlobFunction(e){return this.globFunction=e,this}crawlWithOptions(e,t){return this.options={...this.options,...t},new $e(e||`.`,this.options)}glob(...e){return this.globFunction?this.globWithOptions(e):this.globWithOptions(e,{dot:!0})}globWithOptions(e,...t){let n=this.globFunction||et;if(!n)throw Error(`Please specify a glob function to use glob matching.`);var r=this.globCache[e.join(`\0`)];return r||(r=n(e,...t),this.globCache[e.join(`\0`)]=r),this.options.filters.push(e=>r(e)),this}},nt=B(((e,t)=>{let n=`[^\\\\/]`,r=`[^/]`,i=`(?:\\/|$)`,a=`(?:^|\\/)`,o=`\\.{1,2}${i}`,s={DOT_LITERAL:`\\.`,PLUS_LITERAL:`\\+`,QMARK_LITERAL:`\\?`,SLASH_LITERAL:`\\/`,ONE_CHAR:`(?=.)`,QMARK:r,END_ANCHOR:i,DOTS_SLASH:o,NO_DOT:`(?!\\.)`,NO_DOTS:`(?!${a}${o})`,NO_DOT_SLASH:`(?!\\.{0,1}${i})`,NO_DOTS_SLASH:`(?!${o})`,QMARK_NO_DOT:`[^.\\/]`,STAR:`${r}*?`,START_ANCHOR:a,SEP:`/`},c={...s,SLASH_LITERAL:`[\\\\/]`,QMARK:n,STAR:`${n}*?`,DOTS_SLASH:`\\.{1,2}(?:[\\\\/]|$)`,NO_DOT:`(?!\\.)`,NO_DOTS:`(?!(?:^|[\\\\/])\\.{1,2}(?:[\\\\/]|$))`,NO_DOT_SLASH:`(?!\\.{0,1}(?:[\\\\/]|$))`,NO_DOTS_SLASH:`(?!\\.{1,2}(?:[\\\\/]|$))`,QMARK_NO_DOT:`[^.\\\\/]`,START_ANCHOR:`(?:^|[\\\\/])`,END_ANCHOR:`(?:[\\\\/]|$)`,SEP:`\\`};t.exports={DEFAULT_MAX_EXTGLOB_RECURSION:0,MAX_LENGTH:1024*64,POSIX_REGEX_SOURCE:{__proto__:null,alnum:`a-zA-Z0-9`,alpha:`a-zA-Z`,ascii:`\\x00-\\x7F`,blank:` \\t`,cntrl:`\\x00-\\x1F\\x7F`,digit:`0-9`,graph:`\\x21-\\x7E`,lower:`a-z`,print:`\\x20-\\x7E `,punct:`\\-!"#$%&'()\\*+,./:;<=>?@[\\]^_\`{|}~`,space:` \\t\\r\\n\\v\\f`,upper:`A-Z`,word:`A-Za-z0-9_`,xdigit:`A-Fa-f0-9`},REGEX_BACKSLASH:/\\(?![*+?^${}(|)[\]])/g,REGEX_NON_SPECIAL_CHARS:/^[^@![\].,$*+?^{}()|\\/]+/,REGEX_SPECIAL_CHARS:/[-*+?.^${}(|)[\]]/,REGEX_SPECIAL_CHARS_BACKREF:/(\\?)((\W)(\3*))/g,REGEX_SPECIAL_CHARS_GLOBAL:/([-*+?.^${}(|)[\]])/g,REGEX_REMOVE_BACKSLASH:/(?:\[.*?[^\\]\]|\\(?=.))/g,REPLACEMENTS:{__proto__:null,"***":`*`,"**/**":`**`,"**/**/**":`**`},CHAR_0:48,CHAR_9:57,CHAR_UPPERCASE_A:65,CHAR_LOWERCASE_A:97,CHAR_UPPERCASE_Z:90,CHAR_LOWERCASE_Z:122,CHAR_LEFT_PARENTHESES:40,CHAR_RIGHT_PARENTHESES:41,CHAR_ASTERISK:42,CHAR_AMPERSAND:38,CHAR_AT:64,CHAR_BACKWARD_SLASH:92,CHAR_CARRIAGE_RETURN:13,CHAR_CIRCUMFLEX_ACCENT:94,CHAR_COLON:58,CHAR_COMMA:44,CHAR_DOT:46,CHAR_DOUBLE_QUOTE:34,CHAR_EQUAL:61,CHAR_EXCLAMATION_MARK:33,CHAR_FORM_FEED:12,CHAR_FORWARD_SLASH:47,CHAR_GRAVE_ACCENT:96,CHAR_HASH:35,CHAR_HYPHEN_MINUS:45,CHAR_LEFT_ANGLE_BRACKET:60,CHAR_LEFT_CURLY_BRACE:123,CHAR_LEFT_SQUARE_BRACKET:91,CHAR_LINE_FEED:10,CHAR_NO_BREAK_SPACE:160,CHAR_PERCENT:37,CHAR_PLUS:43,CHAR_QUESTION_MARK:63,CHAR_RIGHT_ANGLE_BRACKET:62,CHAR_RIGHT_CURLY_BRACE:125,CHAR_RIGHT_SQUARE_BRACKET:93,CHAR_SEMICOLON:59,CHAR_SINGLE_QUOTE:39,CHAR_SPACE:32,CHAR_TAB:9,CHAR_UNDERSCORE:95,CHAR_VERTICAL_LINE:124,CHAR_ZERO_WIDTH_NOBREAK_SPACE:65279,extglobChars(e){return{"!":{type:`negate`,open:`(?:(?!(?:`,close:`))${e.STAR})`},"?":{type:`qmark`,open:`(?:`,close:`)?`},"+":{type:`plus`,open:`(?:`,close:`)+`},"*":{type:`star`,open:`(?:`,close:`)*`},"@":{type:`at`,open:`(?:`,close:`)`}}},globChars(e){return e===!0?c:s}}})),rt=B((e=>{let{REGEX_BACKSLASH:t,REGEX_REMOVE_BACKSLASH:n,REGEX_SPECIAL_CHARS:r,REGEX_SPECIAL_CHARS_GLOBAL:i}=nt();e.isObject=e=>typeof e==`object`&&!!e&&!Array.isArray(e),e.hasRegexChars=e=>r.test(e),e.isRegexChar=t=>t.length===1&&e.hasRegexChars(t),e.escapeRegex=e=>e.replace(i,`\\$1`),e.toPosixSlashes=e=>e.replace(t,`/`),e.isWindows=()=>{if(typeof navigator<`u`&&navigator.platform){let e=navigator.platform.toLowerCase();return e===`win32`||e===`windows`}return typeof process<`u`&&process.platform?process.platform===`win32`:!1},e.removeBackslashes=e=>e.replace(n,e=>e===`\\`?``:e),e.escapeLast=(t,n,r)=>{let i=t.lastIndexOf(n,r);return i===-1?t:t[i-1]===`\\`?e.escapeLast(t,n,i-1):`${t.slice(0,i)}\\${t.slice(i)}`},e.removePrefix=(e,t={})=>{let n=e;return n.startsWith(`./`)&&(n=n.slice(2),t.prefix=`./`),n},e.wrapOutput=(e,t={},n={})=>{let r=`${n.contains?``:`^`}(?:${e})${n.contains?``:`$`}`;return t.negated===!0&&(r=`(?:^(?!${r}).*$)`),r},e.basename=(e,{windows:t}={})=>{let n=e.split(t?/[\\/]/:`/`),r=n[n.length-1];return r===``?n[n.length-2]:r}})),it=B(((e,t)=>{let n=rt(),{CHAR_ASTERISK:r,CHAR_AT:i,CHAR_BACKWARD_SLASH:a,CHAR_COMMA:o,CHAR_DOT:s,CHAR_EXCLAMATION_MARK:c,CHAR_FORWARD_SLASH:l,CHAR_LEFT_CURLY_BRACE:u,CHAR_LEFT_PARENTHESES:d,CHAR_LEFT_SQUARE_BRACKET:f,CHAR_PLUS:p,CHAR_QUESTION_MARK:m,CHAR_RIGHT_CURLY_BRACE:h,CHAR_RIGHT_PARENTHESES:g,CHAR_RIGHT_SQUARE_BRACKET:_}=nt(),v=e=>e===l||e===a,y=e=>{e.isPrefix!==!0&&(e.depth=e.isGlobstar?1/0:1)};t.exports=(e,t)=>{let b=t||{},x=e.length-1,S=b.parts===!0||b.scanToEnd===!0,C=[],w=[],T=[],E=e,D=-1,O=0,k=0,A=!1,j=!1,M=!1,N=!1,P=!1,F=!1,I=!1,L=!1,R=!1,z=!1,B=0,V,H,U={value:``,depth:0,isGlob:!1},W=()=>D>=x,G=()=>E.charCodeAt(D+1),K=()=>(V=H,E.charCodeAt(++D));for(;D<x;){H=K();let e;if(H===a){I=U.backslashes=!0,H=K(),H===u&&(F=!0);continue}if(F===!0||H===u){for(B++;W()!==!0&&(H=K());){if(H===a){I=U.backslashes=!0,K();continue}if(H===u){B++;continue}if(F!==!0&&H===s&&(H=K())===s){if(A=U.isBrace=!0,M=U.isGlob=!0,z=!0,S===!0)continue;break}if(F!==!0&&H===o){if(A=U.isBrace=!0,M=U.isGlob=!0,z=!0,S===!0)continue;break}if(H===h&&(B--,B===0)){F=!1,A=U.isBrace=!0,z=!0;break}}if(S===!0)continue;break}if(H===l){if(C.push(D),w.push(U),U={value:``,depth:0,isGlob:!1},z===!0)continue;if(V===s&&D===O+1){O+=2;continue}k=D+1;continue}if(b.noext!==!0&&(H===p||H===i||H===r||H===m||H===c)&&G()===d){if(M=U.isGlob=!0,N=U.isExtglob=!0,z=!0,H===c&&D===O&&(R=!0),S===!0){for(;W()!==!0&&(H=K());){if(H===a){I=U.backslashes=!0,H=K();continue}if(H===g){M=U.isGlob=!0,z=!0;break}}continue}break}if(H===r){if(V===r&&(P=U.isGlobstar=!0),M=U.isGlob=!0,z=!0,S===!0)continue;break}if(H===m){if(M=U.isGlob=!0,z=!0,S===!0)continue;break}if(H===f){for(;W()!==!0&&(e=K());){if(e===a){I=U.backslashes=!0,K();continue}if(e===_){j=U.isBracket=!0,M=U.isGlob=!0,z=!0;break}}if(S===!0)continue;break}if(b.nonegate!==!0&&H===c&&D===O){L=U.negated=!0,O++;continue}if(b.noparen!==!0&&H===d){if(M=U.isGlob=!0,S===!0){for(;W()!==!0&&(H=K());){if(H===d){I=U.backslashes=!0,H=K();continue}if(H===g){z=!0;break}}continue}break}if(M===!0){if(z=!0,S===!0)continue;break}}b.noext===!0&&(N=!1,M=!1);let q=E,J=``,ee=``;O>0&&(J=E.slice(0,O),E=E.slice(O),k-=O),q&&M===!0&&k>0?(q=E.slice(0,k),ee=E.slice(k)):M===!0?(q=``,ee=E):q=E,q&&q!==``&&q!==`/`&&q!==E&&v(q.charCodeAt(q.length-1))&&(q=q.slice(0,-1)),b.unescape===!0&&(ee&&=n.removeBackslashes(ee),q&&I===!0&&(q=n.removeBackslashes(q)));let Y={prefix:J,input:e,start:O,base:q,glob:ee,isBrace:A,isBracket:j,isGlob:M,isExtglob:N,isGlobstar:P,negated:L,negatedExtglob:R};if(b.tokens===!0&&(Y.maxDepth=0,v(H)||w.push(U),Y.tokens=w),b.parts===!0||b.tokens===!0){let t;for(let n=0;n<C.length;n++){let r=t?t+1:O,i=C[n],a=e.slice(r,i);b.tokens&&(n===0&&O!==0?(w[n].isPrefix=!0,w[n].value=J):w[n].value=a,y(w[n]),Y.maxDepth+=w[n].depth),(n!==0||a!==``)&&T.push(a),t=i}if(t&&t+1<e.length){let n=e.slice(t+1);T.push(n),b.tokens&&(w[w.length-1].value=n,y(w[w.length-1]),Y.maxDepth+=w[w.length-1].depth)}Y.slashes=C,Y.parts=T}return Y}})),at=B(((e,t)=>{let n=nt(),r=rt(),{MAX_LENGTH:i,POSIX_REGEX_SOURCE:a,REGEX_NON_SPECIAL_CHARS:o,REGEX_SPECIAL_CHARS_BACKREF:s,REPLACEMENTS:c}=n,l=(e,t)=>{if(typeof t.expandRange==`function`)return t.expandRange(...e,t);e.sort();let n=`[${e.join(`-`)}]`;try{new RegExp(n)}catch{return e.map(e=>r.escapeRegex(e)).join(`..`)}return n},u=(e,t)=>`Missing ${e}: "${t}" - use "\\\\${t}" to match literal characters`,d=e=>{let t=[],n=0,r=0,i=0,a=``,o=!1;for(let s of e){if(o===!0){a+=s,o=!1;continue}if(s===`\\`){a+=s,o=!0;continue}if(s===`"`){i=i===1?0:1,a+=s;continue}if(i===0){if(s===`[`)n++;else if(s===`]`&&n>0)n--;else if(n===0){if(s===`(`)r++;else if(s===`)`&&r>0)r--;else if(s===`|`&&r===0){t.push(a),a=``;continue}}}a+=s}return t.push(a),t},f=e=>{let t=!1;for(let n of e){if(t===!0){t=!1;continue}if(n===`\\`){t=!0;continue}if(/[?*+@!()[\]{}]/.test(n))return!1}return!0},p=e=>{let t=e.trim(),n=!0;for(;n===!0;)n=!1,/^@\([^\\()[\]{}|]+\)$/.test(t)&&(t=t.slice(2,-1),n=!0);if(f(t))return t.replace(/\\(.)/g,`$1`)},m=e=>{let t=e.map(p).filter(Boolean);for(let e=0;e<t.length;e++)for(let n=e+1;n<t.length;n++){let r=t[e],i=t[n],a=r[0];if(!(!a||r!==a.repeat(r.length)||i!==a.repeat(i.length))&&(r===i||r.startsWith(i)||i.startsWith(r)))return!0}return!1},h=(e,t=!0)=>{if(e[0]!==`+`&&e[0]!==`*`||e[1]!==`(`)return;let n=0,r=0,i=0,a=!1;for(let o=1;o<e.length;o++){let s=e[o];if(a===!0){a=!1;continue}if(s===`\\`){a=!0;continue}if(s===`"`){i=i===1?0:1;continue}if(i!==1){if(s===`[`){n++;continue}if(s===`]`&&n>0){n--;continue}if(!(n>0)){if(s===`(`){r++;continue}if(s===`)`&&(r--,r===0))return t===!0&&o!==e.length-1?void 0:{type:e[0],body:e.slice(2,o),end:o}}}}},g=e=>{let t=0,n=[];for(;t<e.length;){let r=h(e.slice(t),!1);if(!r||r.type!==`*`)return;let i=d(r.body).map(e=>e.trim());if(i.length!==1)return;let a=p(i[0]);if(!a||a.length!==1)return;n.push(a),t+=r.end+1}if(!(n.length<1))return`${n.length===1?r.escapeRegex(n[0]):`[${n.map(e=>r.escapeRegex(e)).join(``)}]`}*`},_=e=>{let t=0,n=e.trim(),r=h(n);for(;r;)t++,n=r.body.trim(),r=h(n);return t},v=(e,t)=>{if(t.maxExtglobRecursion===!1)return{risky:!1};let r=typeof t.maxExtglobRecursion==`number`?t.maxExtglobRecursion:n.DEFAULT_MAX_EXTGLOB_RECURSION,i=d(e).map(e=>e.trim());if(i.length>1&&(i.some(e=>e===``)||i.some(e=>/^[*?]+$/.test(e))||m(i)))return{risky:!0};for(let e of i){let t=g(e);if(t)return{risky:!0,safeOutput:t};if(_(e)>r)return{risky:!0}}return{risky:!1}},y=(e,t)=>{if(typeof e!=`string`)throw TypeError(`Expected a string`);e=c[e]||e;let d={...t},f=typeof d.maxLength==`number`?Math.min(i,d.maxLength):i,p=e.length;if(p>f)throw SyntaxError(`Input length: ${p}, exceeds maximum allowed length: ${f}`);let m={type:`bos`,value:``,output:d.prepend||``},h=[m],g=d.capture?``:`?:`,_=n.globChars(d.windows),b=n.extglobChars(_),{DOT_LITERAL:x,PLUS_LITERAL:S,SLASH_LITERAL:C,ONE_CHAR:w,DOTS_SLASH:T,NO_DOT:E,NO_DOT_SLASH:D,NO_DOTS_SLASH:O,QMARK:k,QMARK_NO_DOT:A,STAR:j,START_ANCHOR:M}=_,N=e=>`(${g}(?:(?!${M}${e.dot?T:x}).)*?)`,P=d.dot?``:E,F=d.dot?k:A,I=d.bash===!0?N(d):j;d.capture&&(I=`(${I})`),typeof d.noext==`boolean`&&(d.noextglob=d.noext);let L={input:e,index:-1,start:0,dot:d.dot===!0,consumed:``,output:``,prefix:``,backtrack:!1,negated:!1,brackets:0,braces:0,parens:0,quotes:0,globstar:!1,tokens:h};e=r.removePrefix(e,L),p=e.length;let R=[],z=[],B=[],V=m,H,U=()=>L.index===p-1,W=L.peek=(t=1)=>e[L.index+t],G=L.advance=()=>e[++L.index]||``,K=()=>e.slice(L.index+1),q=(e=``,t=0)=>{L.consumed+=e,L.index+=t},J=e=>{L.output+=e.output==null?e.value:e.output,q(e.value)},ee=()=>{let e=1;for(;W()===`!`&&(W(2)!==`(`||W(3)===`?`);)G(),L.start++,e++;return e%2==0?!1:(L.negated=!0,L.start++,!0)},Y=e=>{L[e]++,B.push(e)},X=e=>{L[e]--,B.pop()},Z=e=>{if(V.type===`globstar`){let t=L.braces>0&&(e.type===`comma`||e.type===`brace`),n=e.extglob===!0||R.length&&(e.type===`pipe`||e.type===`paren`);e.type!==`slash`&&e.type!==`paren`&&!t&&!n&&(L.output=L.output.slice(0,-V.output.length),V.type=`star`,V.value=`*`,V.output=I,L.output+=V.output)}if(R.length&&e.type!==`paren`&&(R[R.length-1].inner+=e.value),(e.value||e.output)&&J(e),V&&V.type===`text`&&e.type===`text`){V.output=(V.output||V.value)+e.value,V.value+=e.value;return}e.prev=V,h.push(e),V=e},te=(e,t)=>{let n={...b[t],conditions:1,inner:``};n.prev=V,n.parens=L.parens,n.output=L.output,n.startIndex=L.index,n.tokensIndex=h.length;let r=(d.capture?`(`:``)+n.open;Y(`parens`),Z({type:e,value:t,output:L.output?``:w}),Z({type:`paren`,extglob:!0,value:G(),output:r}),R.push(n)},ne=n=>{let i=e.slice(n.startIndex,L.index+1),a=v(e.slice(n.startIndex+2,L.index),d);if((n.type===`plus`||n.type===`star`)&&a.risky){let e=a.safeOutput?(n.output?``:w)+(d.capture?`(${a.safeOutput})`:a.safeOutput):void 0,t=h[n.tokensIndex];t.type=`text`,t.value=i,t.output=e||r.escapeRegex(i);for(let e=n.tokensIndex+1;e<h.length;e++)h[e].value=``,h[e].output=``,delete h[e].suffix;L.output=n.output+t.output,L.backtrack=!0,Z({type:`paren`,extglob:!0,value:H,output:``}),X(`parens`);return}let o=n.close+(d.capture?`)`:``),s;if(n.type===`negate`){let e=I;n.inner&&n.inner.length>1&&n.inner.includes(`/`)&&(e=N(d)),(e!==I||U()||/^\)+$/.test(K()))&&(o=n.close=`)$))${e}`),n.inner.includes(`*`)&&(s=K())&&/^\.[^\\/.]+$/.test(s)&&(o=n.close=`)${y(s,{...t,fastpaths:!1}).output})${e})`),n.prev.type===`bos`&&(L.negatedExtglob=!0)}Z({type:`paren`,extglob:!0,value:H,output:o}),X(`parens`)};if(d.fastpaths!==!1&&!/(^[*!]|[/()[\]{}"])/.test(e)){let n=!1,i=e.replace(s,(e,t,r,i,a,o)=>i===`\\`?(n=!0,e):i===`?`?t?t+i+(a?k.repeat(a.length):``):o===0?F+(a?k.repeat(a.length):``):k.repeat(r.length):i===`.`?x.repeat(r.length):i===`*`?t?t+i+(a?I:``):I:t?e:`\\${e}`);return n===!0&&(i=d.unescape===!0?i.replace(/\\/g,``):i.replace(/\\+/g,e=>e.length%2==0?`\\\\`:e?`\\`:``)),i===e&&d.contains===!0?(L.output=e,L):(L.output=r.wrapOutput(i,L,t),L)}for(;!U();){if(H=G(),H===`\0`)continue;if(H===`\\`){let e=W();if(e===`/`&&d.bash!==!0||e===`.`||e===`;`)continue;if(!e){H+=`\\`,Z({type:`text`,value:H});continue}let t=/^\\+/.exec(K()),n=0;if(t&&t[0].length>2&&(n=t[0].length,L.index+=n,n%2!=0&&(H+=`\\`)),d.unescape===!0?H=G():H+=G(),L.brackets===0){Z({type:`text`,value:H});continue}}if(L.brackets>0&&(H!==`]`||V.value===`[`||V.value===`[^`)){if(d.posix!==!1&&H===`:`){let e=V.value.slice(1);if(e.includes(`[`)&&(V.posix=!0,e.includes(`:`))){let e=V.value.lastIndexOf(`[`),t=V.value.slice(0,e),n=a[V.value.slice(e+2)];if(n){V.value=t+n,L.backtrack=!0,G(),!m.output&&h.indexOf(V)===1&&(m.output=w);continue}}}(H===`[`&&W()!==`:`||H===`-`&&W()===`]`)&&(H=`\\${H}`),H===`]`&&(V.value===`[`||V.value===`[^`)&&(H=`\\${H}`),d.posix===!0&&H===`!`&&V.value===`[`&&(H=`^`),V.value+=H,J({value:H});continue}if(L.quotes===1&&H!==`"`){H=r.escapeRegex(H),V.value+=H,J({value:H});continue}if(H===`"`){L.quotes=L.quotes===1?0:1,d.keepQuotes===!0&&Z({type:`text`,value:H});continue}if(H===`(`){Y(`parens`),Z({type:`paren`,value:H});continue}if(H===`)`){if(L.parens===0&&d.strictBrackets===!0)throw SyntaxError(u(`opening`,`(`));let e=R[R.length-1];if(e&&L.parens===e.parens+1){ne(R.pop());continue}Z({type:`paren`,value:H,output:L.parens?`)`:`\\)`}),X(`parens`);continue}if(H===`[`){if(d.nobracket===!0||!K().includes(`]`)){if(d.nobracket!==!0&&d.strictBrackets===!0)throw SyntaxError(u(`closing`,`]`));H=`\\${H}`}else Y(`brackets`);Z({type:`bracket`,value:H});continue}if(H===`]`){if(d.nobracket===!0||V&&V.type===`bracket`&&V.value.length===1){Z({type:`text`,value:H,output:`\\${H}`});continue}if(L.brackets===0){if(d.strictBrackets===!0)throw SyntaxError(u(`opening`,`[`));Z({type:`text`,value:H,output:`\\${H}`});continue}X(`brackets`);let e=V.value.slice(1);if(V.posix!==!0&&e[0]===`^`&&!e.includes(`/`)&&(H=`/${H}`),V.value+=H,J({value:H}),d.literalBrackets===!1||r.hasRegexChars(e))continue;let t=r.escapeRegex(V.value);if(L.output=L.output.slice(0,-V.value.length),d.literalBrackets===!0){L.output+=t,V.value=t;continue}V.value=`(${g}${t}|${V.value})`,L.output+=V.value;continue}if(H===`{`&&d.nobrace!==!0){Y(`braces`);let e={type:`brace`,value:H,output:`(`,outputIndex:L.output.length,tokensIndex:L.tokens.length};z.push(e),Z(e);continue}if(H===`}`){let e=z[z.length-1];if(d.nobrace===!0||!e){Z({type:`text`,value:H,output:H});continue}let t=`)`;if(e.dots===!0){let e=h.slice(),n=[];for(let t=e.length-1;t>=0&&(h.pop(),e[t].type!==`brace`);t--)e[t].type!==`dots`&&n.unshift(e[t].value);t=l(n,d),L.backtrack=!0}if(e.comma!==!0&&e.dots!==!0){let n=L.output.slice(0,e.outputIndex),r=L.tokens.slice(e.tokensIndex);e.value=e.output=`\\{`,H=t=`\\}`,L.output=n;for(let e of r)L.output+=e.output||e.value}Z({type:`brace`,value:H,output:t}),X(`braces`),z.pop();continue}if(H===`|`){R.length>0&&R[R.length-1].conditions++,Z({type:`text`,value:H});continue}if(H===`,`){let e=H,t=z[z.length-1];t&&B[B.length-1]===`braces`&&(t.comma=!0,e=`|`),Z({type:`comma`,value:H,output:e});continue}if(H===`/`){if(V.type===`dot`&&L.index===L.start+1){L.start=L.index+1,L.consumed=``,L.output=``,h.pop(),V=m;continue}Z({type:`slash`,value:H,output:C});continue}if(H===`.`){if(L.braces>0&&V.type===`dot`){V.value===`.`&&(V.output=x);let e=z[z.length-1];V.type=`dots`,V.output+=H,V.value+=H,e.dots=!0;continue}if(L.braces+L.parens===0&&V.type!==`bos`&&V.type!==`slash`){Z({type:`text`,value:H,output:x});continue}Z({type:`dot`,value:H,output:x});continue}if(H===`?`){if(!(V&&V.value===`(`)&&d.noextglob!==!0&&W()===`(`&&W(2)!==`?`){te(`qmark`,H);continue}if(V&&V.type===`paren`){let e=W(),t=H;(V.value===`(`&&!/[!=<:]/.test(e)||e===`<`&&!/<([!=]|\w+>)/.test(K()))&&(t=`\\${H}`),Z({type:`text`,value:H,output:t});continue}if(d.dot!==!0&&(V.type===`slash`||V.type===`bos`)){Z({type:`qmark`,value:H,output:A});continue}Z({type:`qmark`,value:H,output:k});continue}if(H===`!`){if(d.noextglob!==!0&&W()===`(`&&(W(2)!==`?`||!/[!=<:]/.test(W(3)))){te(`negate`,H);continue}if(d.nonegate!==!0&&L.index===0){ee();continue}}if(H===`+`){if(d.noextglob!==!0&&W()===`(`&&W(2)!==`?`){te(`plus`,H);continue}if(V&&V.value===`(`||d.regex===!1){Z({type:`plus`,value:H,output:S});continue}if(V&&(V.type===`bracket`||V.type===`paren`||V.type===`brace`)||L.parens>0){Z({type:`plus`,value:H});continue}Z({type:`plus`,value:S});continue}if(H===`@`){if(d.noextglob!==!0&&W()===`(`&&W(2)!==`?`){Z({type:`at`,extglob:!0,value:H,output:``});continue}Z({type:`text`,value:H});continue}if(H!==`*`){(H===`$`||H===`^`)&&(H=`\\${H}`);let e=o.exec(K());e&&(H+=e[0],L.index+=e[0].length),Z({type:`text`,value:H});continue}if(V&&(V.type===`globstar`||V.star===!0)){V.type=`star`,V.star=!0,V.value+=H,V.output=I,L.backtrack=!0,L.globstar=!0,q(H);continue}let t=K();if(d.noextglob!==!0&&/^\([^?]/.test(t)){te(`star`,H);continue}if(V.type===`star`){if(d.noglobstar===!0){q(H);continue}let n=V.prev,r=n.prev,i=n.type===`slash`||n.type===`bos`,a=r&&(r.type===`star`||r.type===`globstar`);if(d.bash===!0&&(!i||t[0]&&t[0]!==`/`)){Z({type:`star`,value:H,output:``});continue}let o=L.braces>0&&(n.type===`comma`||n.type===`brace`),s=R.length&&(n.type===`pipe`||n.type===`paren`);if(!i&&n.type!==`paren`&&!o&&!s){Z({type:`star`,value:H,output:``});continue}for(;t.slice(0,3)===`/**`;){let n=e[L.index+4];if(n&&n!==`/`)break;t=t.slice(3),q(`/**`,3)}if(n.type===`bos`&&U()){V.type=`globstar`,V.value+=H,V.output=N(d),L.output=V.output,L.globstar=!0,q(H);continue}if(n.type===`slash`&&n.prev.type!==`bos`&&!a&&U()){L.output=L.output.slice(0,-(n.output+V.output).length),n.output=`(?:${n.output}`,V.type=`globstar`,V.output=N(d)+(d.strictSlashes?`)`:`|$)`),V.value+=H,L.globstar=!0,L.output+=n.output+V.output,q(H);continue}if(n.type===`slash`&&n.prev.type!==`bos`&&t[0]===`/`){let e=t[1]===void 0?``:`|$`;L.output=L.output.slice(0,-(n.output+V.output).length),n.output=`(?:${n.output}`,V.type=`globstar`,V.output=`${N(d)}${C}|${C}${e})`,V.value+=H,L.output+=n.output+V.output,L.globstar=!0,q(H+G()),Z({type:`slash`,value:`/`,output:``});continue}if(n.type===`bos`&&t[0]===`/`){V.type=`globstar`,V.value+=H,V.output=`(?:^|${C}|${N(d)}${C})`,L.output=V.output,L.globstar=!0,q(H+G()),Z({type:`slash`,value:`/`,output:``});continue}L.output=L.output.slice(0,-V.output.length),V.type=`globstar`,V.output=N(d),V.value+=H,L.output+=V.output,L.globstar=!0,q(H);continue}let n={type:`star`,value:H,output:I};if(d.bash===!0){n.output=`.*?`,(V.type===`bos`||V.type===`slash`)&&(n.output=P+n.output),Z(n);continue}if(V&&(V.type===`bracket`||V.type===`paren`)&&d.regex===!0){n.output=H,Z(n);continue}(L.index===L.start||V.type===`slash`||V.type===`dot`)&&(V.type===`dot`?(L.output+=D,V.output+=D):d.dot===!0?(L.output+=O,V.output+=O):(L.output+=P,V.output+=P),W()!==`*`&&(L.output+=w,V.output+=w)),Z(n)}for(;L.brackets>0;){if(d.strictBrackets===!0)throw SyntaxError(u(`closing`,`]`));L.output=r.escapeLast(L.output,`[`),X(`brackets`)}for(;L.parens>0;){if(d.strictBrackets===!0)throw SyntaxError(u(`closing`,`)`));L.output=r.escapeLast(L.output,`(`),X(`parens`)}for(;L.braces>0;){if(d.strictBrackets===!0)throw SyntaxError(u(`closing`,`}`));L.output=r.escapeLast(L.output,`{`),X(`braces`)}if(d.strictSlashes!==!0&&(V.type===`star`||V.type===`bracket`)&&Z({type:`maybe_slash`,value:``,output:`${C}?`}),L.backtrack===!0){L.output=``;for(let e of L.tokens)L.output+=e.output==null?e.value:e.output,e.suffix&&(L.output+=e.suffix)}return L};y.fastpaths=(e,t)=>{let a={...t},o=typeof a.maxLength==`number`?Math.min(i,a.maxLength):i,s=e.length;if(s>o)throw SyntaxError(`Input length: ${s}, exceeds maximum allowed length: ${o}`);e=c[e]||e;let{DOT_LITERAL:l,SLASH_LITERAL:u,ONE_CHAR:d,DOTS_SLASH:f,NO_DOT:p,NO_DOTS:m,NO_DOTS_SLASH:h,STAR:g,START_ANCHOR:_}=n.globChars(a.windows),v=a.dot?m:p,y=a.dot?h:p,b=a.capture?``:`?:`,x={negated:!1,prefix:``},S=a.bash===!0?`.*?`:g;a.capture&&(S=`(${S})`);let C=e=>e.noglobstar===!0?S:`(${b}(?:(?!${_}${e.dot?f:l}).)*?)`,w=e=>{switch(e){case`*`:return`${v}${d}${S}`;case`.*`:return`${l}${d}${S}`;case`*.*`:return`${v}${S}${l}${d}${S}`;case`*/*`:return`${v}${S}${u}${d}${y}${S}`;case`**`:return v+C(a);case`**/*`:return`(?:${v}${C(a)}${u})?${y}${d}${S}`;case`**/*.*`:return`(?:${v}${C(a)}${u})?${y}${S}${l}${d}${S}`;case`**/.*`:return`(?:${v}${C(a)}${u})?${l}${d}${S}`;default:{let t=/^(.*?)\.(\w+)$/.exec(e);if(!t)return;let n=w(t[1]);return n?n+l+t[2]:void 0}}},T=w(r.removePrefix(e,x));return T&&a.strictSlashes!==!0&&(T+=`${u}?`),T},t.exports=y})),ot=B(((e,t)=>{let n=it(),r=at(),i=rt(),a=nt(),o=e=>e&&typeof e==`object`&&!Array.isArray(e),s=(e,t,n=!1)=>{if(Array.isArray(e)){let r=e.map(e=>s(e,t,n));return e=>{for(let t of r){let n=t(e);if(n)return n}return!1}}let r=o(e)&&e.tokens&&e.input;if(e===``||typeof e!=`string`&&!r)throw TypeError(`Expected pattern to be a non-empty string`);let i=t||{},a=i.windows,c=r?s.compileRe(e,t):s.makeRe(e,t,!1,!0),l=c.state;delete c.state;let u=()=>!1;if(i.ignore){let e={...t,ignore:null,onMatch:null,onResult:null};u=s(i.ignore,e,n)}let d=(n,r=!1)=>{let{isMatch:o,match:d,output:f}=s.test(n,c,t,{glob:e,posix:a}),p={glob:e,state:l,regex:c,posix:a,input:n,output:f,match:d,isMatch:o};return typeof i.onResult==`function`&&i.onResult(p),o===!1?(p.isMatch=!1,r?p:!1):u(n)?(typeof i.onIgnore==`function`&&i.onIgnore(p),p.isMatch=!1,r?p:!1):(typeof i.onMatch==`function`&&i.onMatch(p),r?p:!0)};return n&&(d.state=l),d};s.test=(e,t,n,{glob:r,posix:a}={})=>{if(typeof e!=`string`)throw TypeError(`Expected input to be a string`);if(e===``)return{isMatch:!1,output:``};let o=n||{},c=o.format||(a?i.toPosixSlashes:null),l=e===r,u=l&&c?c(e):e;return l===!1&&(u=c?c(e):e,l=u===r),(l===!1||o.capture===!0)&&(l=o.matchBase===!0||o.basename===!0?s.matchBase(e,t,n,a):t.exec(u)),{isMatch:!!l,match:l,output:u}},s.matchBase=(e,t,n)=>(t instanceof RegExp?t:s.makeRe(t,n)).test(i.basename(e)),s.isMatch=(e,t,n)=>s(t,n)(e),s.parse=(e,t)=>Array.isArray(e)?e.map(e=>s.parse(e,t)):r(e,{...t,fastpaths:!1}),s.scan=(e,t)=>n(e,t),s.compileRe=(e,t,n=!1,r=!1)=>{if(n===!0)return e.output;let i=t||{},a=i.contains?``:`^`,o=i.contains?``:`$`,c=`${a}(?:${e.output})${o}`;e&&e.negated===!0&&(c=`^(?!${c}).*$`);let l=s.toRegex(c,t);return r===!0&&(l.state=e),l},s.makeRe=(e,t={},n=!1,i=!1)=>{if(!e||typeof e!=`string`)throw TypeError(`Expected a non-empty string`);let a={negated:!1,fastpaths:!0};return t.fastpaths!==!1&&(e[0]===`.`||e[0]===`*`)&&(a.output=r.fastpaths(e,t)),a.output||(a=r(e,t)),s.compileRe(a,t,n,i)},s.toRegex=(e,t)=>{try{let n=t||{};return new RegExp(e,n.flags||(n.nocase?`i`:``))}catch(e){if(t&&t.debug===!0)throw e;return/$^/}},s.constants=a,t.exports=s})),st=H(B(((e,t)=>{let n=ot(),r=rt();function i(e,t,i=!1){return t&&(t.windows===null||t.windows===void 0)&&(t={...t,windows:r.isWindows()}),n(e,t,i)}Object.assign(i,n),t.exports=i}))(),1);const ct=Array.isArray,lt=/\\/g,ut=process.platform===`win32`,dt=/^(\/?\.\.)+$/;function ft(e,t={}){let n=e.length,r=Array(n),i=Array(n),a,o;for(a=0;a<n;a++){let n=vt(e[a]);r[a]=n;let s=n.length,c=Array(s);for(o=0;o<s;o++)c[o]=(0,st.default)(n[o],t);i[a]=c}return e=>{let s=e.split(`/`);if(s[0]===`..`&&dt.test(e))return!0;for(a=0;a<n;a++){let e=r[a],n=i[a],c=s.length,l=Math.min(c,e.length);for(o=0;o<l;){let r=e[o];if(r.includes(`/`))return!0;if(!n[o](s[o]))break;if(!t.noglobstar&&r===`**`)return!0;o++}if(o===c)return!0}return!1}}const pt=/^[A-Z]:\/$/i,mt=ut?e=>pt.test(e):e=>e===`/`;function ht(e,t,n){if(e===t||t.startsWith(`${e}/`)){if(n){let t=e.length+ +!mt(e);return(e,n)=>e.slice(t,n?-1:void 0)||`.`}let r=t.slice(e.length+1);return r?(e,t)=>{if(e===`.`)return r;let n=`${r}/${e}`;return t?n.slice(0,-1):n}:(e,t)=>t&&e!==`.`?e.slice(0,-1):e}return n?t=>D.relative(e,t)||`.`:n=>D.relative(e,`${t}/${n}`)||`.`}function gt(e,t){if(t.startsWith(`${e}/`)){let n=t.slice(e.length+1);return e=>`${n}/${e}`}return n=>{let r=D.relative(e,`${t}/${n}`);return n[n.length-1]===`/`&&r!==``?`${r}/`:r||`.`}}const _t={parts:!0};function vt(e){let t=st.default.scan(e,_t);return t.parts?.length?t.parts:[e]}const yt=/(?<!\\)([()[\]{}*?|]|^!|[!+@](?=\()|\\(?![()[\]{}!*+?@|]))/g,bt=/(?<!\\)([()[\]{}]|^!|[!+@](?=\())/g,xt=ut?e=>e.replace(bt,`\\$&`):e=>e.replace(yt,`\\$&`);function St(e,t){if(t?.caseSensitiveMatch===!1)return!0;let n=st.default.scan(e);return n.isGlob||n.negated}function Ct(...e){console.log(`[tinyglobby ${new Date().toLocaleTimeString(`es`)}]`,...e)}function wt(e){return typeof e==`string`?[e]:e??[]}const Tt=/^(\/?\.\.)+/,Et=/\\(?=[()[\]{}!*+?@|])/g;function Dt(e,t,n,r){let i=t.cwd,a=e;e[e.length-1]===`/`&&(a=e.slice(0,-1)),a[a.length-1]!==`*`&&t.expandDirectories&&(a+=`/**`);let o=xt(i);a=T(a.replace(Et,``))?D.relative(o,a):D.normalize(a);let s=Tt.exec(a)?.[0],c=vt(a);if(s){let e=(s.length+1)/3,t=0,r=o.split(`/`);for(;t<e&&c[t+e]===r[r.length+t-e];)a=a.slice(0,(e-t-1)*3)+a.slice((e-t)*3+c[t+e].length+1)||`.`,t++;let l=D.join(i,s.slice(t*3));l[0]!==`.`&&n.root.length>l.length&&(n.root=l,n.depthOffset=-e+t)}if(!r&&n.depthOffset>=0){n.commonPath??=c;let e=[],t=Math.min(n.commonPath.length,c.length);for(let r=0;r<t;r++){let t=c[r];if(t===`**`&&!c[r+1]){e.pop();break}if(r===c.length-1||t!==n.commonPath[r]||St(t))break;e.push(t)}n.depthOffset=e.length,n.commonPath=e,n.root=e.length>0?D.join(i,...e):i}return a}function Ot(e,t,n){let r=[],i=[];for(let t of e.ignore)t&&(t[0]!==`!`||t[1]===`(`)&&i.push(Dt(t,e,n,!0));for(let a of t)a&&(a[0]!==`!`||a[1]===`(`?r.push(Dt(a,e,n,!1)):(a[1]!==`!`||a[2]===`(`)&&i.push(Dt(a.slice(1),e,n,!0)));return{match:r,ignore:i}}function kt(e,t){let n=e.cwd,r={root:n,depthOffset:0},i=Ot(e,t,r);e.debug&&Ct(`internal processing patterns:`,i);let{absolute:a,caseSensitiveMatch:o,debug:s,dot:c,followSymbolicLinks:l,onlyDirectories:u}=e,d=r.root.replace(lt,``),f={dot:c,nobrace:e.braceExpansion===!1,nocase:!o,noextglob:e.extglob===!1,noglobstar:e.globstar===!1,posix:!0},p=(0,st.default)(i.match,f),m=(0,st.default)(i.ignore,f),h=ft(i.match,f),g=ht(n,d,a),_=a?g:ht(n,d,!0),v=(e,t)=>{let n=_(t,!0);return n!==`.`&&!h(n)||m(n)},y;e.deep!==void 0&&(y=Math.round(e.deep-r.depthOffset));let b=new tt({filters:[s?(e,t)=>{let n=g(e,t),r=p(n)&&!m(n);return r&&Ct(`matched ${n}`),r}:(e,t)=>{let n=g(e,t);return p(n)&&!m(n)}],exclude:s?(e,t)=>{let n=v(e,t);return Ct(`${n?`skipped`:`crawling`} ${t}`),n}:v,fs:e.fs,pathSeparator:`/`,relativePaths:!a,resolvePaths:a,includeBasePath:a,resolveSymlinks:l,excludeSymlinks:!l,excludeFiles:u,includeDirs:u||!e.onlyFiles,maxDepth:y,signal:e.signal}).crawl(d);return e.debug&&Ct(`internal properties:`,{...r,root:d}),[b,n!==d&&!a&>(n,d)]}function At(e,t){if(t)for(let n=e.length-1;n>=0;n--)e[n]=t(e[n]);return e}const jt={caseSensitiveMatch:!0,cwd:process.cwd(),debug:!!process.env.TINYGLOBBY_DEBUG,expandDirectories:!0,followSymbolicLinks:!0,onlyFiles:!0};function Mt(e){let t={...jt,...e};return t.cwd=(t.cwd instanceof URL?j(t.cwd):k(t.cwd)).replace(lt,`/`),t.ignore=wt(t.ignore),t.fs&&={readdir:t.fs.readdir||_,readdirSync:t.fs.readdirSync||v,realpath:t.fs.realpath||y,realpathSync:t.fs.realpathSync||b,stat:t.fs.stat||x,statSync:t.fs.statSync||S},t.debug&&Ct(`globbing with options:`,t),t}function Nt(e,t={}){if(e&&t?.patterns)throw Error(`Cannot pass patterns as both an argument and an option`);let n=ct(e)||typeof e==`string`,r=wt((n?e:e.patterns)??`**/*`),i=Mt(n?t:e);return r.length>0?kt(i,r):[]}async function Pt(e,t){let[n,r]=Nt(e,t);return n?At(await n.withPromise(),r):[]}var Ft=B(((e,t)=>{var n=Object.defineProperty,r=Object.getOwnPropertyDescriptor,i=Object.getOwnPropertyNames,a=Object.prototype.hasOwnProperty,o=(e,t)=>{for(var r in t)n(e,r,{get:t[r],enumerable:!0})},s=(e,t,o,s)=>{if(t&&typeof t==`object`||typeof t==`function`)for(let c of i(t))!a.call(e,c)&&c!==o&&n(e,c,{get:()=>t[c],enumerable:!(s=r(t,c))||s.enumerable});return e},c=e=>s(n({},`__esModule`,{value:!0}),e),l={};o(l,{DEFAULT_CLOCK_TOLERANCE_SEC:()=>f,DEFAULT_JWT_EXPIRE_TIME_MS:()=>d,FileTokenProvider:()=>C,HttpClient:()=>I,HttpError:()=>N,generateJWTToken:()=>m,parseJWTTokenWithVerify:()=>h,registerPlatformPlugin:()=>O,resolvePlatformBaseURL:()=>D}),t.exports=c(l);var u=U(`crypto`),d=1800*1e3,f=60,p={alg:`HS256`,typ:`JWT`};function m(e,t){let n=Math.floor(Date.now()/1e3),r={...e,iss:e.access_key,iat:n,nbf:n,exp:n+Math.floor(t.expireTimeMs/1e3),jti:(0,u.randomUUID)()},i=_(JSON.stringify(p)),a=_(JSON.stringify(r));return`${i}.${a}.${g(`${i}.${a}`,t.secretKey)}`}function h(e,t,n){let r=e.split(`.`);if(r.length!==3)throw Error(`invalid JWT token format`);let[i,a,o]=r;if(JSON.parse(v(i)).alg!==`HS256`)throw Error(`unsupported JWT alg`);let s=g(`${i}.${a}`,t.secretKey),c=Buffer.from(s),l=Buffer.from(o);if(c.length!==l.length||!(0,u.timingSafeEqual)(c,l))throw Error(`JWT signature verification failed`);let d=JSON.parse(v(a));if(!n?.skipExpiration){let e=n?.clockTolerance??f,t=Math.floor(Date.now()/1e3);if(d.exp!==void 0&&d.exp+e<t)throw Error(`JWT token expired at ${new Date(d.exp*1e3).toISOString()}`);if(d.nbf!==void 0&&d.nbf-e>t)throw Error(`JWT token not yet valid, will be valid at ${new Date(d.nbf*1e3).toISOString()}`);if(d.iat!==void 0&&d.iat-e>t)throw Error(`JWT token issued in the future at ${new Date(d.iat*1e3).toISOString()}`)}return d}function g(e,t){return(0,u.createHmac)(`sha256`,t).update(e).digest(`base64`).replace(/=/g,``).replace(/\+/g,`-`).replace(/\//g,`_`)}function _(e){return Buffer.from(e).toString(`base64`).replace(/=/g,``).replace(/\+/g,`-`).replace(/\//g,`_`)}function v(e){let t=(4-(e.length%4||4))%4,n=`${e}${`=`.repeat(t)}`.replace(/-/g,`+`).replace(/_/g,`/`);return Buffer.from(n,`base64`).toString(`utf8`)}var y=class{cache=new Map;config;constructor(e){this.config={refreshBeforeMs:300*1e3,...e}}getToken(e){let t=this.getCacheKey(e),n=this.cache.get(t),r=Date.now();if(n&&n.expiresAtMs-r>this.config.refreshBeforeMs)return n.token;let i=m(e,this.config),a=r+this.config.expireTimeMs;return this.cache.set(t,{token:i,expiresAtMs:a}),i}clearCache(){this.cache.clear()}clearCacheFor(e){let t=this.getCacheKey(e);this.cache.delete(t)}getCacheKey(e){return[e.access_key,e.tenant_id?.toString()||``,e.user_id||``,e.app_id||``,e.app_env||``,e.sandbox_id||``].join(`:`)}getCacheStats(){let e=Date.now(),t=0,n=0;for(let r of this.cache.values())r.expiresAtMs>e?t++:n++;return{total:this.cache.size,valid:t,expired:n}}},b=U(`fs`),x=300*1e3,S=[`/home/gem/workspace/.force/openclaw/miaoda-provider-key`],C=class{cache=new Map;paths;refreshBeforeMs;constructor(e){this.paths=e?.paths??S,this.refreshBeforeMs=e?.refreshBeforeMs??x}getToken(){let e=Date.now();for(let t of this.paths){let n=this.cache.get(t);if(n&&n.expiresAtMs-e>this.refreshBeforeMs)return{token:n.token,accessKey:n.accessKey};let r=this.readAndParse(t);if(r&&(this.cache.set(t,r),r.expiresAtMs>e))return{token:r.token,accessKey:r.accessKey};if(n&&n.expiresAtMs>e)return{token:n.token,accessKey:n.accessKey}}return null}clearCache(){this.cache.clear()}readAndParse(e){try{let t=(0,b.readFileSync)(e,`utf-8`).trim();if(!t)return null;let n=this.decodePayload(t);return n?.exp?{token:t,accessKey:n.access_key??``,expiresAtMs:n.exp*1e3}:null}catch{return null}}decodePayload(e){try{let t=e.split(`.`);if(t.length!==3)return null;let n=(4-(t[1].length%4||4))%4,r=`${t[1]}${`=`.repeat(n)}`.replace(/-/g,`+`).replace(/_/g,`/`);return JSON.parse(Buffer.from(r,`base64`).toString(`utf8`))}catch{return null}}},w=`FORCE_AUTHN_INNERAPI_DOMAIN`,T=`FORCE_AUTHN_ACCESS_KEY`,E=`FORCE_AUTHN_ACCESS_SECRET`;function D(e){if(!e?.enabled)return e?.baseURL;if(e.baseURL)return e.baseURL;let t=e.domainEnv||w,n=process.env[t];if(!n)throw Error(`\u5E73\u53F0\u6A21\u5F0F\u9700\u8981\u57FA\u7840\u57DF\u540D\uFF0C\u8BF7\u8BBE\u7F6E\u73AF\u5883\u53D8\u91CF ${t}`);return n}function O(e,t){if(!t.enabled)return;k(`platform.defaultClaims`,t.defaultClaims);let n;t.tokenProvider?.type===`file`&&(n=new C({paths:t.tokenProvider.paths,refreshBeforeMs:t.refreshBeforeMs}));let r=t.accessKeyEnv||T,i=t.secretKeyEnv||E,a=t.accessKey??(process.env[r]||``),o=new y({accessKey:a,secretKey:t.secretKey??(process.env[i]||``),expireTimeMs:t.expireTimeMs??d,refreshBeforeMs:t.refreshBeforeMs});return e.request.use(e=>{if(n){let t=n.getToken();if(t){let n={...e.headers,Authorization:`Bearer ${t.token}`,"x-api-key":t.accessKey};return{...e,headers:n}}}k(`request.platformAuth.customClaims`,e.platformAuth?.customClaims);let r={...t.defaultClaims||{},...e.platformAuth?.customClaims||{},access_key:a},i=o.getToken(r),s={...e.headers,Authorization:`Bearer ${i}`,"x-api-key":a};return{...e,headers:s}}),o}function k(e,t){if(t&&Object.prototype.hasOwnProperty.call(t,`access_key`))throw Error(`${e} \u4E0D\u5141\u8BB8\u8BBE\u7F6E access_key`)}var A=class{interceptors=[];use(e,t){return this.interceptors.push({onFulfilled:e,onRejected:t}),this.interceptors.length-1}eject(e){this.interceptors[e]&&(this.interceptors[e]=null)}clear(){this.interceptors=[]}forEach(e){this.interceptors.forEach(t=>{t!==null&&e(t)})}};function j(e){if(typeof e!=`object`||!e)return!1;let t=Object.getPrototypeOf(e);return t===Object.prototype||t===null}function M(e){if(!e)return{};if(e instanceof Headers){let t={};return e.forEach((e,n)=>{t[n]=e}),t}if(Array.isArray(e))return e.reduce((e,[t,n])=>(e[t]=n,e),{});let t={};return Object.entries(e).forEach(([e,n])=>{t[e]=Array.isArray(n)?n.join(`,`):n}),t}var N=class e extends Error{isHttpError=!0;response;config;constructor(t,n,r){super(r||`Request failed with status ${t?.status||`unknown`}`),this.name=`HttpError`,this.response=t,this.config=P(n),Object.setPrototypeOf(this,e.prototype)}};function P(e){let{headers:t,...n}=e;return{...n,headers:F(t)}}function F(e){if(!e)return;let t=M(e),n={},r=[`authorization`,`x-api-key`,`cookie`,`x-secret`];for(let[e,i]of Object.entries(t)){let t=e.toLowerCase();r.includes(t)?n[e]=`[REDACTED]`:n[e]=i}return n}var I=class{defaultConfig;securityConfig;interceptors={request:new A,response:new A};constructor(e){let{platform:t,security:n,...r}=e||{};this.defaultConfig={timeout:5e3,...r};let i=n?.strictMode??!1;this.securityConfig={allowedProtocols:i?[`http:`,`https:`]:null,maxResponseSize:i?50*1024*1024:0,strictMode:i,...n},t?.enabled&&(this.defaultConfig.baseURL||(this.defaultConfig.baseURL=D(t)),O(this.interceptors,t))}async get(e,t){return this.request({...t,url:e,method:`GET`})}async post(e,t,n){let r={...n?.headers},i=t;return j(t)&&(i=JSON.stringify(t),Object.keys(r).some(e=>e.toLowerCase()===`content-type`)||(r[`Content-Type`]=`application/json`)),this.request({...n,url:e,method:`POST`,body:i,headers:r})}async put(e,t,n){let r={...n?.headers},i=t;return j(t)&&(i=JSON.stringify(t),Object.keys(r).some(e=>e.toLowerCase()===`content-type`)||(r[`Content-Type`]=`application/json`)),this.request({...n,url:e,method:`PUT`,body:i,headers:r})}async delete(e,t){return this.request({...t,url:e,method:`DELETE`})}async patch(e,t,n){let r={...n?.headers},i=t;return j(t)&&(i=JSON.stringify(t),Object.keys(r).some(e=>e.toLowerCase()===`content-type`)||(r[`Content-Type`]=`application/json`)),this.request({...n,url:e,method:`PATCH`,body:i,headers:r})}async request(e){let t=M(this.defaultConfig.headers),n=M(e.headers),r={};for(let e in t)r[e.toLowerCase()]={key:e,value:t[e]};for(let e in n)r[e.toLowerCase()]={key:e,value:n[e]};let i={};for(let e in r){let{key:t,value:n}=r[e];i[t]=n}let a={...this.defaultConfig,...e,headers:i};try{a=await this.runRequestInterceptors(a)}catch(e){return Promise.reject(e)}a.headers=M(a.headers);let o=this.buildUrl(a.url,a.params),s=a.timeout||this.defaultConfig.timeout||5e3,c=new AbortController,l=setTimeout(()=>c.abort(),s),u=a.signal;u&&(u.aborted?(clearTimeout(l),c.abort()):u.addEventListener(`abort`,()=>c.abort(),{once:!0}));let{platformAuth:d,params:f,timeout:p,baseURL:m,url:h,...g}=a;try{let e=await fetch(o,{...g,signal:c.signal});if(clearTimeout(l),this.securityConfig.maxResponseSize>0){let t=e.headers.get(`content-length`);if(t){let e=parseInt(t,10);if(e>this.securityConfig.maxResponseSize)throw Error(`Response size ${e} bytes exceeds limit of ${this.securityConfig.maxResponseSize} bytes`)}}if(!e.ok){let t=new N(e,a);return this.runResponseInterceptors(Promise.reject(t))}return this.runResponseInterceptors(Promise.resolve(e))}catch(e){clearTimeout(l);let t=e instanceof N?e:new N(void 0,a,e.name===`AbortError`?`Request aborted`:e.message);return this.runResponseInterceptors(Promise.reject(t))}}runRequestInterceptors(e){let t=Promise.resolve(e),n=[];this.interceptors.request.forEach(e=>{n.push(e)});for(let e of n)t=t.then(e.onFulfilled,e.onRejected);return t}async runResponseInterceptors(e){let t=e,n=[];this.interceptors.response.forEach(e=>{n.push(e)});for(let e of n)t=t.then(e.onFulfilled,e.onRejected);return t}buildUrl(e,t){let n=this.defaultConfig.baseURL,r;r=!n||/^https?:\/\//i.test(e)?e:n.replace(/\/+$/,``)+`/`+e.replace(/^\/+/,``);let i=new URL(r),{allowedProtocols:a}=this.securityConfig;if(a&&!a.includes(i.protocol))throw Error(`Protocol ${i.protocol} is not allowed. Allowed: ${a.join(`, `)}`);if(t)for(let[e,n]of Object.entries(t))n!=null&&i.searchParams.set(e,String(n));return i.href}}}))();const It=new Set([`forced_quota_failed`,`k_st_ec_400002680`,`k_st_ec_400002681`,`k_st_ec_400002682`,`k_st_ec_400002683`,`k_st_ec_400002684`,`k_st_ec_400002685`,`k_st_ec_400002686`,`k_st_ec_400002687`,`k_st_ec_400002688`,`k_st_ec_400002690`,`k_st_ec_400002698`]),Lt=new Set([`k_st_ec_400002680`,`k_st_ec_400002681`,`k_st_ec_400002682`,`k_st_ec_400002683`,`k_st_ec_400002684`,`k_st_ec_400002685`,`k_st_ec_400002686`,`k_st_ec_400002687`,`k_st_ec_400002688`,`k_st_ec_400002689`,`k_st_ec_400002690`,`k_st_ec_400002698`]);function Rt(e){return!!e&&It.has(e)}function zt(e){return!!e&&Lt.has(e)}let Bt;function Vt(){if(Bt)return Bt;try{let e=l(s(N(import.meta.url)),`..`,`package.json`);Bt=JSON.parse(a(e,`utf-8`))}catch(e){console.warn(`[miaoda-coding] failed to read package.json: ${e instanceof Error?e.message:e}`),Bt={}}return Bt}function Ht(){let e=process.env.FORCE_AUTHN_INNERAPI_DOMAIN;if(!e)throw Error(`studio-client: 缺少环境变量,需要: FORCE_AUTHN_INNERAPI_DOMAIN`);return{apiUrl:e}}var Ut=class extends Error{userFacing=!0;constructor(e,t,n){super(e),this.statusCode=t,this.logId=n,this.name=`UserFacingError`}};function Wt(e){return!!e&&typeof e==`object`&&!Array.isArray(e)&&Object.values(e).every(e=>typeof e==`string`)}function Gt(...e){for(let t of e)if(typeof t==`string`&&t)return t}async function*Kt(e){let t=new TextDecoder,n=``,r;for await(let i of e){n+=t.decode(i,{stream:!0});let e=n.split(`
|
|
1
|
+
import{createRequire as e}from"node:module";import{execFile as t,spawn as n}from"node:child_process";import{randomUUID as r}from"node:crypto";import i,{readFileSync as a}from"node:fs";import o,{dirname as s,join as c,resolve as l}from"node:path";import{appendFile as u,mkdir as d,readFile as f,readdir as p,rm as m,writeFile as h}from"node:fs/promises";import*as g from"fs";import{readdir as _,readdirSync as v,realpath as y,realpathSync as b,stat as x,statSync as S}from"fs";import{basename as C,dirname as w,isAbsolute as T,normalize as E,posix as D,relative as O,resolve as k,sep as A}from"path";import{fileURLToPath as j}from"url";import{createRequire as M}from"module";import{fileURLToPath as N}from"node:url";var P=Object.create,F=Object.defineProperty,I=Object.getOwnPropertyDescriptor,L=Object.getOwnPropertyNames,R=Object.getPrototypeOf,z=Object.prototype.hasOwnProperty,B=(e,t)=>()=>(t||e((t={exports:{}}).exports,t),t.exports),V=(e,t,n,r)=>{if(t&&typeof t==`object`||typeof t==`function`)for(var i=L(t),a=0,o=i.length,s;a<o;a++)s=i[a],!z.call(e,s)&&s!==n&&F(e,s,{get:(e=>t[e]).bind(null,s),enumerable:!(r=I(t,s))||r.enumerable});return e},H=(e,t,n)=>(n=e==null?{}:P(R(e)),V(t||!e||!e.__esModule?F(n,`default`,{value:e,enumerable:!0}):n,e)),U=e(import.meta.url);function W(){return l(process.env.OPENCLAW_STATE_DIR||process.cwd())}function G(e){return c(e,`.agent`)}function K(e,t){return c(e,`app`,t)}function q(e,t){return c(e,t)}function J(e){let t=typeof e.workspaceDir==`string`&&e.workspaceDir!==``,n=typeof e.agentDir==`string`&&e.agentDir!==``;if(!t||!n)throw Error(`resolveToolPaths: workspaceDir and agentDir are required in tool factory context`);return{workspaceDir:e.workspaceDir,agentDir:e.agentDir,agentId:e.agentId,sessionKey:e.sessionKey}}var ee=M(import.meta.url);function Y(e){let t=E(e);return t.length>1&&t[t.length-1]===A&&(t=t.substring(0,t.length-1)),t}const X=/[\\/]/g;function Z(e,t){return e.replace(X,t)}const te=/^[a-z]:[\\/]$/i;function ne(e){return e===`/`||te.test(e)}function re(e,t){let{resolvePaths:n,normalizePath:r,pathSeparator:i}=t,a=process.platform===`win32`&&e.includes(`/`)||e.startsWith(`.`);return n&&(e=k(e)),(r||a)&&(e=Y(e)),e===`.`?``:Z(e[e.length-1]===i?e:e+i,i)}function ie(e,t){return t+e}function ae(e,t){return function(n,r){return r.startsWith(e)?r.slice(e.length)+n:Z(O(e,r),t.pathSeparator)+t.pathSeparator+n}}function oe(e){return e}function se(e,t,n){return t+e+n}function ce(e,t){let{relativePaths:n,includeBasePath:r}=t;return n&&e?ae(e,t):r?ie:oe}function le(e){return function(t,n){n.push(t.substring(e.length)||`.`)}}function ue(e){return function(t,n,r){let i=t.substring(e.length)||`.`;r.every(e=>e(i,!0))&&n.push(i)}}const de=(e,t)=>{t.push(e||`.`)},fe=(e,t,n)=>{let r=e||`.`;n.every(e=>e(r,!0))&&t.push(r)},pe=()=>{};function me(e,t){let{includeDirs:n,filters:r,relativePaths:i}=t;return n?i?r&&r.length?ue(e):le(e):r&&r.length?fe:de:pe}const he=(e,t,n,r)=>{r.every(t=>t(e,!1))&&n.files++},ge=(e,t,n,r)=>{r.every(t=>t(e,!1))&&t.push(e)},_e=(e,t,n,r)=>{n.files++},ve=(e,t)=>{t.push(e)},ye=()=>{};function be(e){let{excludeFiles:t,filters:n,onlyCounts:r}=e;return t?ye:n&&n.length?r?he:ge:r?_e:ve}const xe=e=>e,Se=()=>[``].slice(0,0);function Ce(e){return e.group?Se:xe}const we=(e,t,n)=>{e.push({directory:t,files:n,dir:t})},Te=()=>{};function Ee(e){return e.group?we:Te}const De=function(e,t,n){let{queue:r,fs:i,options:{suppressErrors:a}}=t;r.enqueue(),i.realpath(e,(o,s)=>{if(o)return r.dequeue(a?null:o,t);i.stat(s,(i,o)=>{if(i)return r.dequeue(a?null:i,t);if(o.isDirectory()&&Ae(e,s,t))return r.dequeue(null,t);n(o,s),r.dequeue(null,t)})})},Oe=function(e,t,n){let{queue:r,fs:i,options:{suppressErrors:a}}=t;r.enqueue();try{let r=i.realpathSync(e),a=i.statSync(r);if(a.isDirectory()&&Ae(e,r,t))return;n(a,r)}catch(e){if(!a)throw e}};function ke(e,t){return!e.resolveSymlinks||e.excludeSymlinks?null:t?Oe:De}function Ae(e,t,n){if(n.options.useRealPaths)return je(t,n);let r=w(e),i=1;for(;r!==n.root&&i<2;){let e=n.symlinks.get(r);e&&(e===t||e.startsWith(t)||t.startsWith(e))?i++:r=w(r)}return n.symlinks.set(e,t),i>1}function je(e,t){return t.visited.includes(e+t.options.pathSeparator)}const Me=e=>e.counts,Ne=e=>e.groups,Pe=e=>e.paths,Fe=e=>e.paths.slice(0,e.options.maxFiles),Ie=(e,t,n)=>(Be(t,n,e.counts,e.options.suppressErrors),null),Le=(e,t,n)=>(Be(t,n,e.paths,e.options.suppressErrors),null),Re=(e,t,n)=>(Be(t,n,e.paths.slice(0,e.options.maxFiles),e.options.suppressErrors),null),ze=(e,t,n)=>(Be(t,n,e.groups,e.options.suppressErrors),null);function Be(e,t,n,r){t(e&&!r?e:null,n)}function Ve(e,t){let{onlyCounts:n,group:r,maxFiles:i}=e;return n?t?Me:Ie:r?t?Ne:ze:i?t?Fe:Re:t?Pe:Le}const He={withFileTypes:!0},Ue=(e,t,n,r,i)=>{if(e.queue.enqueue(),r<0)return e.queue.dequeue(null,e);let{fs:a}=e;e.visited.push(t),e.counts.directories++,a.readdir(t||`.`,He,(t,a=[])=>{i(a,n,r),e.queue.dequeue(e.options.suppressErrors?null:t,e)})},We=(e,t,n,r,i)=>{let{fs:a}=e;if(r<0)return;e.visited.push(t),e.counts.directories++;let o=[];try{o=a.readdirSync(t||`.`,He)}catch(t){if(!e.options.suppressErrors)throw t}i(o,n,r)};function Ge(e){return e?We:Ue}var Ke=class{count=0;constructor(e){this.onQueueEmpty=e}enqueue(){return this.count++,this.count}dequeue(e,t){this.onQueueEmpty&&(--this.count<=0||e)&&(this.onQueueEmpty(e,t),e&&(t.controller.abort(),this.onQueueEmpty=void 0))}},qe=class{_files=0;_directories=0;set files(e){this._files=e}get files(){return this._files}set directories(e){this._directories=e}get directories(){return this._directories}get dirs(){return this._directories}},Je=class{aborted=!1;abort(){this.aborted=!0}},Ye=class{root;isSynchronous;state;joinPath;pushDirectory;pushFile;getArray;groupFiles;resolveSymlink;walkDirectory;callbackInvoker;constructor(e,t,n){this.isSynchronous=!n,this.callbackInvoker=Ve(t,this.isSynchronous),this.root=re(e,t),this.state={root:ne(this.root)?this.root:this.root.slice(0,-1),paths:[``].slice(0,0),groups:[],counts:new qe,options:t,queue:new Ke((e,t)=>this.callbackInvoker(t,e,n)),symlinks:new Map,visited:[``].slice(0,0),controller:new Je,fs:t.fs||g},this.joinPath=ce(this.root,t),this.pushDirectory=me(this.root,t),this.pushFile=be(t),this.getArray=Ce(t),this.groupFiles=Ee(t),this.resolveSymlink=ke(t,this.isSynchronous),this.walkDirectory=Ge(this.isSynchronous)}start(){return this.pushDirectory(this.root,this.state.paths,this.state.options.filters),this.walkDirectory(this.state,this.root,this.root,this.state.options.maxDepth,this.walk),this.isSynchronous?this.callbackInvoker(this.state,null):null}walk=(e,t,n)=>{let{paths:r,options:{filters:i,resolveSymlinks:a,excludeSymlinks:o,exclude:s,maxFiles:c,signal:l,useRealPaths:u,pathSeparator:d},controller:f}=this.state;if(f.aborted||l&&l.aborted||c&&r.length>c)return;let p=this.getArray(this.state.paths);for(let c=0;c<e.length;++c){let l=e[c];if(l.isFile()||l.isSymbolicLink()&&!a&&!o){let e=this.joinPath(l.name,t);this.pushFile(e,p,this.state.counts,i)}else if(l.isDirectory()){let e=se(l.name,t,this.state.options.pathSeparator);if(s&&s(l.name,e))continue;this.pushDirectory(e,r,i),this.walkDirectory(this.state,e,e,n-1,this.walk)}else if(this.resolveSymlink&&l.isSymbolicLink()){let e=ie(l.name,t);this.resolveSymlink(e,this.state,(t,r)=>{if(t.isDirectory()){if(r=re(r,this.state.options),s&&s(l.name,u?r:e+d))return;this.walkDirectory(this.state,r,u?r:e+d,n-1,this.walk)}else{r=u?r:e;let t=C(r),n=re(w(r),this.state.options);r=this.joinPath(t,n),this.pushFile(r,p,this.state.counts,i)}})}}this.groupFiles(this.state.groups,t,p)}};function Xe(e,t){return new Promise((n,r)=>{Ze(e,t,(e,t)=>{if(e)return r(e);n(t)})})}function Ze(e,t,n){new Ye(e,t,n).start()}function Qe(e,t){return new Ye(e,t).start()}var $e=class{constructor(e,t){this.root=e,this.options=t}withPromise(){return Xe(this.root,this.options)}withCallback(e){Ze(this.root,this.options,e)}sync(){return Qe(this.root,this.options)}};let et=null;try{ee.resolve(`picomatch`),et=ee(`picomatch`)}catch{}var tt=class{globCache={};options={maxDepth:1/0,suppressErrors:!0,pathSeparator:A,filters:[]};globFunction;constructor(e){this.options={...this.options,...e},this.globFunction=this.options.globFunction}group(){return this.options.group=!0,this}withPathSeparator(e){return this.options.pathSeparator=e,this}withBasePath(){return this.options.includeBasePath=!0,this}withRelativePaths(){return this.options.relativePaths=!0,this}withDirs(){return this.options.includeDirs=!0,this}withMaxDepth(e){return this.options.maxDepth=e,this}withMaxFiles(e){return this.options.maxFiles=e,this}withFullPaths(){return this.options.resolvePaths=!0,this.options.includeBasePath=!0,this}withErrors(){return this.options.suppressErrors=!1,this}withSymlinks({resolvePaths:e=!0}={}){return this.options.resolveSymlinks=!0,this.options.useRealPaths=e,this.withFullPaths()}withAbortSignal(e){return this.options.signal=e,this}normalize(){return this.options.normalizePath=!0,this}filter(e){return this.options.filters.push(e),this}onlyDirs(){return this.options.excludeFiles=!0,this.options.includeDirs=!0,this}exclude(e){return this.options.exclude=e,this}onlyCounts(){return this.options.onlyCounts=!0,this}crawl(e){return new $e(e||`.`,this.options)}withGlobFunction(e){return this.globFunction=e,this}crawlWithOptions(e,t){return this.options={...this.options,...t},new $e(e||`.`,this.options)}glob(...e){return this.globFunction?this.globWithOptions(e):this.globWithOptions(e,{dot:!0})}globWithOptions(e,...t){let n=this.globFunction||et;if(!n)throw Error(`Please specify a glob function to use glob matching.`);var r=this.globCache[e.join(`\0`)];return r||(r=n(e,...t),this.globCache[e.join(`\0`)]=r),this.options.filters.push(e=>r(e)),this}},nt=B(((e,t)=>{let n=`[^\\\\/]`,r=`[^/]`,i=`(?:\\/|$)`,a=`(?:^|\\/)`,o=`\\.{1,2}${i}`,s={DOT_LITERAL:`\\.`,PLUS_LITERAL:`\\+`,QMARK_LITERAL:`\\?`,SLASH_LITERAL:`\\/`,ONE_CHAR:`(?=.)`,QMARK:r,END_ANCHOR:i,DOTS_SLASH:o,NO_DOT:`(?!\\.)`,NO_DOTS:`(?!${a}${o})`,NO_DOT_SLASH:`(?!\\.{0,1}${i})`,NO_DOTS_SLASH:`(?!${o})`,QMARK_NO_DOT:`[^.\\/]`,STAR:`${r}*?`,START_ANCHOR:a,SEP:`/`},c={...s,SLASH_LITERAL:`[\\\\/]`,QMARK:n,STAR:`${n}*?`,DOTS_SLASH:`\\.{1,2}(?:[\\\\/]|$)`,NO_DOT:`(?!\\.)`,NO_DOTS:`(?!(?:^|[\\\\/])\\.{1,2}(?:[\\\\/]|$))`,NO_DOT_SLASH:`(?!\\.{0,1}(?:[\\\\/]|$))`,NO_DOTS_SLASH:`(?!\\.{1,2}(?:[\\\\/]|$))`,QMARK_NO_DOT:`[^.\\\\/]`,START_ANCHOR:`(?:^|[\\\\/])`,END_ANCHOR:`(?:[\\\\/]|$)`,SEP:`\\`};t.exports={DEFAULT_MAX_EXTGLOB_RECURSION:0,MAX_LENGTH:1024*64,POSIX_REGEX_SOURCE:{__proto__:null,alnum:`a-zA-Z0-9`,alpha:`a-zA-Z`,ascii:`\\x00-\\x7F`,blank:` \\t`,cntrl:`\\x00-\\x1F\\x7F`,digit:`0-9`,graph:`\\x21-\\x7E`,lower:`a-z`,print:`\\x20-\\x7E `,punct:`\\-!"#$%&'()\\*+,./:;<=>?@[\\]^_\`{|}~`,space:` \\t\\r\\n\\v\\f`,upper:`A-Z`,word:`A-Za-z0-9_`,xdigit:`A-Fa-f0-9`},REGEX_BACKSLASH:/\\(?![*+?^${}(|)[\]])/g,REGEX_NON_SPECIAL_CHARS:/^[^@![\].,$*+?^{}()|\\/]+/,REGEX_SPECIAL_CHARS:/[-*+?.^${}(|)[\]]/,REGEX_SPECIAL_CHARS_BACKREF:/(\\?)((\W)(\3*))/g,REGEX_SPECIAL_CHARS_GLOBAL:/([-*+?.^${}(|)[\]])/g,REGEX_REMOVE_BACKSLASH:/(?:\[.*?[^\\]\]|\\(?=.))/g,REPLACEMENTS:{__proto__:null,"***":`*`,"**/**":`**`,"**/**/**":`**`},CHAR_0:48,CHAR_9:57,CHAR_UPPERCASE_A:65,CHAR_LOWERCASE_A:97,CHAR_UPPERCASE_Z:90,CHAR_LOWERCASE_Z:122,CHAR_LEFT_PARENTHESES:40,CHAR_RIGHT_PARENTHESES:41,CHAR_ASTERISK:42,CHAR_AMPERSAND:38,CHAR_AT:64,CHAR_BACKWARD_SLASH:92,CHAR_CARRIAGE_RETURN:13,CHAR_CIRCUMFLEX_ACCENT:94,CHAR_COLON:58,CHAR_COMMA:44,CHAR_DOT:46,CHAR_DOUBLE_QUOTE:34,CHAR_EQUAL:61,CHAR_EXCLAMATION_MARK:33,CHAR_FORM_FEED:12,CHAR_FORWARD_SLASH:47,CHAR_GRAVE_ACCENT:96,CHAR_HASH:35,CHAR_HYPHEN_MINUS:45,CHAR_LEFT_ANGLE_BRACKET:60,CHAR_LEFT_CURLY_BRACE:123,CHAR_LEFT_SQUARE_BRACKET:91,CHAR_LINE_FEED:10,CHAR_NO_BREAK_SPACE:160,CHAR_PERCENT:37,CHAR_PLUS:43,CHAR_QUESTION_MARK:63,CHAR_RIGHT_ANGLE_BRACKET:62,CHAR_RIGHT_CURLY_BRACE:125,CHAR_RIGHT_SQUARE_BRACKET:93,CHAR_SEMICOLON:59,CHAR_SINGLE_QUOTE:39,CHAR_SPACE:32,CHAR_TAB:9,CHAR_UNDERSCORE:95,CHAR_VERTICAL_LINE:124,CHAR_ZERO_WIDTH_NOBREAK_SPACE:65279,extglobChars(e){return{"!":{type:`negate`,open:`(?:(?!(?:`,close:`))${e.STAR})`},"?":{type:`qmark`,open:`(?:`,close:`)?`},"+":{type:`plus`,open:`(?:`,close:`)+`},"*":{type:`star`,open:`(?:`,close:`)*`},"@":{type:`at`,open:`(?:`,close:`)`}}},globChars(e){return e===!0?c:s}}})),rt=B((e=>{let{REGEX_BACKSLASH:t,REGEX_REMOVE_BACKSLASH:n,REGEX_SPECIAL_CHARS:r,REGEX_SPECIAL_CHARS_GLOBAL:i}=nt();e.isObject=e=>typeof e==`object`&&!!e&&!Array.isArray(e),e.hasRegexChars=e=>r.test(e),e.isRegexChar=t=>t.length===1&&e.hasRegexChars(t),e.escapeRegex=e=>e.replace(i,`\\$1`),e.toPosixSlashes=e=>e.replace(t,`/`),e.isWindows=()=>{if(typeof navigator<`u`&&navigator.platform){let e=navigator.platform.toLowerCase();return e===`win32`||e===`windows`}return typeof process<`u`&&process.platform?process.platform===`win32`:!1},e.removeBackslashes=e=>e.replace(n,e=>e===`\\`?``:e),e.escapeLast=(t,n,r)=>{let i=t.lastIndexOf(n,r);return i===-1?t:t[i-1]===`\\`?e.escapeLast(t,n,i-1):`${t.slice(0,i)}\\${t.slice(i)}`},e.removePrefix=(e,t={})=>{let n=e;return n.startsWith(`./`)&&(n=n.slice(2),t.prefix=`./`),n},e.wrapOutput=(e,t={},n={})=>{let r=`${n.contains?``:`^`}(?:${e})${n.contains?``:`$`}`;return t.negated===!0&&(r=`(?:^(?!${r}).*$)`),r},e.basename=(e,{windows:t}={})=>{let n=e.split(t?/[\\/]/:`/`),r=n[n.length-1];return r===``?n[n.length-2]:r}})),it=B(((e,t)=>{let n=rt(),{CHAR_ASTERISK:r,CHAR_AT:i,CHAR_BACKWARD_SLASH:a,CHAR_COMMA:o,CHAR_DOT:s,CHAR_EXCLAMATION_MARK:c,CHAR_FORWARD_SLASH:l,CHAR_LEFT_CURLY_BRACE:u,CHAR_LEFT_PARENTHESES:d,CHAR_LEFT_SQUARE_BRACKET:f,CHAR_PLUS:p,CHAR_QUESTION_MARK:m,CHAR_RIGHT_CURLY_BRACE:h,CHAR_RIGHT_PARENTHESES:g,CHAR_RIGHT_SQUARE_BRACKET:_}=nt(),v=e=>e===l||e===a,y=e=>{e.isPrefix!==!0&&(e.depth=e.isGlobstar?1/0:1)};t.exports=(e,t)=>{let b=t||{},x=e.length-1,S=b.parts===!0||b.scanToEnd===!0,C=[],w=[],T=[],E=e,D=-1,O=0,k=0,A=!1,j=!1,M=!1,N=!1,P=!1,F=!1,I=!1,L=!1,R=!1,z=!1,B=0,V,H,U={value:``,depth:0,isGlob:!1},W=()=>D>=x,G=()=>E.charCodeAt(D+1),K=()=>(V=H,E.charCodeAt(++D));for(;D<x;){H=K();let e;if(H===a){I=U.backslashes=!0,H=K(),H===u&&(F=!0);continue}if(F===!0||H===u){for(B++;W()!==!0&&(H=K());){if(H===a){I=U.backslashes=!0,K();continue}if(H===u){B++;continue}if(F!==!0&&H===s&&(H=K())===s){if(A=U.isBrace=!0,M=U.isGlob=!0,z=!0,S===!0)continue;break}if(F!==!0&&H===o){if(A=U.isBrace=!0,M=U.isGlob=!0,z=!0,S===!0)continue;break}if(H===h&&(B--,B===0)){F=!1,A=U.isBrace=!0,z=!0;break}}if(S===!0)continue;break}if(H===l){if(C.push(D),w.push(U),U={value:``,depth:0,isGlob:!1},z===!0)continue;if(V===s&&D===O+1){O+=2;continue}k=D+1;continue}if(b.noext!==!0&&(H===p||H===i||H===r||H===m||H===c)&&G()===d){if(M=U.isGlob=!0,N=U.isExtglob=!0,z=!0,H===c&&D===O&&(R=!0),S===!0){for(;W()!==!0&&(H=K());){if(H===a){I=U.backslashes=!0,H=K();continue}if(H===g){M=U.isGlob=!0,z=!0;break}}continue}break}if(H===r){if(V===r&&(P=U.isGlobstar=!0),M=U.isGlob=!0,z=!0,S===!0)continue;break}if(H===m){if(M=U.isGlob=!0,z=!0,S===!0)continue;break}if(H===f){for(;W()!==!0&&(e=K());){if(e===a){I=U.backslashes=!0,K();continue}if(e===_){j=U.isBracket=!0,M=U.isGlob=!0,z=!0;break}}if(S===!0)continue;break}if(b.nonegate!==!0&&H===c&&D===O){L=U.negated=!0,O++;continue}if(b.noparen!==!0&&H===d){if(M=U.isGlob=!0,S===!0){for(;W()!==!0&&(H=K());){if(H===d){I=U.backslashes=!0,H=K();continue}if(H===g){z=!0;break}}continue}break}if(M===!0){if(z=!0,S===!0)continue;break}}b.noext===!0&&(N=!1,M=!1);let q=E,J=``,ee=``;O>0&&(J=E.slice(0,O),E=E.slice(O),k-=O),q&&M===!0&&k>0?(q=E.slice(0,k),ee=E.slice(k)):M===!0?(q=``,ee=E):q=E,q&&q!==``&&q!==`/`&&q!==E&&v(q.charCodeAt(q.length-1))&&(q=q.slice(0,-1)),b.unescape===!0&&(ee&&=n.removeBackslashes(ee),q&&I===!0&&(q=n.removeBackslashes(q)));let Y={prefix:J,input:e,start:O,base:q,glob:ee,isBrace:A,isBracket:j,isGlob:M,isExtglob:N,isGlobstar:P,negated:L,negatedExtglob:R};if(b.tokens===!0&&(Y.maxDepth=0,v(H)||w.push(U),Y.tokens=w),b.parts===!0||b.tokens===!0){let t;for(let n=0;n<C.length;n++){let r=t?t+1:O,i=C[n],a=e.slice(r,i);b.tokens&&(n===0&&O!==0?(w[n].isPrefix=!0,w[n].value=J):w[n].value=a,y(w[n]),Y.maxDepth+=w[n].depth),(n!==0||a!==``)&&T.push(a),t=i}if(t&&t+1<e.length){let n=e.slice(t+1);T.push(n),b.tokens&&(w[w.length-1].value=n,y(w[w.length-1]),Y.maxDepth+=w[w.length-1].depth)}Y.slashes=C,Y.parts=T}return Y}})),at=B(((e,t)=>{let n=nt(),r=rt(),{MAX_LENGTH:i,POSIX_REGEX_SOURCE:a,REGEX_NON_SPECIAL_CHARS:o,REGEX_SPECIAL_CHARS_BACKREF:s,REPLACEMENTS:c}=n,l=(e,t)=>{if(typeof t.expandRange==`function`)return t.expandRange(...e,t);e.sort();let n=`[${e.join(`-`)}]`;try{new RegExp(n)}catch{return e.map(e=>r.escapeRegex(e)).join(`..`)}return n},u=(e,t)=>`Missing ${e}: "${t}" - use "\\\\${t}" to match literal characters`,d=e=>{let t=[],n=0,r=0,i=0,a=``,o=!1;for(let s of e){if(o===!0){a+=s,o=!1;continue}if(s===`\\`){a+=s,o=!0;continue}if(s===`"`){i=i===1?0:1,a+=s;continue}if(i===0){if(s===`[`)n++;else if(s===`]`&&n>0)n--;else if(n===0){if(s===`(`)r++;else if(s===`)`&&r>0)r--;else if(s===`|`&&r===0){t.push(a),a=``;continue}}}a+=s}return t.push(a),t},f=e=>{let t=!1;for(let n of e){if(t===!0){t=!1;continue}if(n===`\\`){t=!0;continue}if(/[?*+@!()[\]{}]/.test(n))return!1}return!0},p=e=>{let t=e.trim(),n=!0;for(;n===!0;)n=!1,/^@\([^\\()[\]{}|]+\)$/.test(t)&&(t=t.slice(2,-1),n=!0);if(f(t))return t.replace(/\\(.)/g,`$1`)},m=e=>{let t=e.map(p).filter(Boolean);for(let e=0;e<t.length;e++)for(let n=e+1;n<t.length;n++){let r=t[e],i=t[n],a=r[0];if(!(!a||r!==a.repeat(r.length)||i!==a.repeat(i.length))&&(r===i||r.startsWith(i)||i.startsWith(r)))return!0}return!1},h=(e,t=!0)=>{if(e[0]!==`+`&&e[0]!==`*`||e[1]!==`(`)return;let n=0,r=0,i=0,a=!1;for(let o=1;o<e.length;o++){let s=e[o];if(a===!0){a=!1;continue}if(s===`\\`){a=!0;continue}if(s===`"`){i=i===1?0:1;continue}if(i!==1){if(s===`[`){n++;continue}if(s===`]`&&n>0){n--;continue}if(!(n>0)){if(s===`(`){r++;continue}if(s===`)`&&(r--,r===0))return t===!0&&o!==e.length-1?void 0:{type:e[0],body:e.slice(2,o),end:o}}}}},g=e=>{let t=0,n=[];for(;t<e.length;){let r=h(e.slice(t),!1);if(!r||r.type!==`*`)return;let i=d(r.body).map(e=>e.trim());if(i.length!==1)return;let a=p(i[0]);if(!a||a.length!==1)return;n.push(a),t+=r.end+1}if(!(n.length<1))return`${n.length===1?r.escapeRegex(n[0]):`[${n.map(e=>r.escapeRegex(e)).join(``)}]`}*`},_=e=>{let t=0,n=e.trim(),r=h(n);for(;r;)t++,n=r.body.trim(),r=h(n);return t},v=(e,t)=>{if(t.maxExtglobRecursion===!1)return{risky:!1};let r=typeof t.maxExtglobRecursion==`number`?t.maxExtglobRecursion:n.DEFAULT_MAX_EXTGLOB_RECURSION,i=d(e).map(e=>e.trim());if(i.length>1&&(i.some(e=>e===``)||i.some(e=>/^[*?]+$/.test(e))||m(i)))return{risky:!0};for(let e of i){let t=g(e);if(t)return{risky:!0,safeOutput:t};if(_(e)>r)return{risky:!0}}return{risky:!1}},y=(e,t)=>{if(typeof e!=`string`)throw TypeError(`Expected a string`);e=c[e]||e;let d={...t},f=typeof d.maxLength==`number`?Math.min(i,d.maxLength):i,p=e.length;if(p>f)throw SyntaxError(`Input length: ${p}, exceeds maximum allowed length: ${f}`);let m={type:`bos`,value:``,output:d.prepend||``},h=[m],g=d.capture?``:`?:`,_=n.globChars(d.windows),b=n.extglobChars(_),{DOT_LITERAL:x,PLUS_LITERAL:S,SLASH_LITERAL:C,ONE_CHAR:w,DOTS_SLASH:T,NO_DOT:E,NO_DOT_SLASH:D,NO_DOTS_SLASH:O,QMARK:k,QMARK_NO_DOT:A,STAR:j,START_ANCHOR:M}=_,N=e=>`(${g}(?:(?!${M}${e.dot?T:x}).)*?)`,P=d.dot?``:E,F=d.dot?k:A,I=d.bash===!0?N(d):j;d.capture&&(I=`(${I})`),typeof d.noext==`boolean`&&(d.noextglob=d.noext);let L={input:e,index:-1,start:0,dot:d.dot===!0,consumed:``,output:``,prefix:``,backtrack:!1,negated:!1,brackets:0,braces:0,parens:0,quotes:0,globstar:!1,tokens:h};e=r.removePrefix(e,L),p=e.length;let R=[],z=[],B=[],V=m,H,U=()=>L.index===p-1,W=L.peek=(t=1)=>e[L.index+t],G=L.advance=()=>e[++L.index]||``,K=()=>e.slice(L.index+1),q=(e=``,t=0)=>{L.consumed+=e,L.index+=t},J=e=>{L.output+=e.output==null?e.value:e.output,q(e.value)},ee=()=>{let e=1;for(;W()===`!`&&(W(2)!==`(`||W(3)===`?`);)G(),L.start++,e++;return e%2==0?!1:(L.negated=!0,L.start++,!0)},Y=e=>{L[e]++,B.push(e)},X=e=>{L[e]--,B.pop()},Z=e=>{if(V.type===`globstar`){let t=L.braces>0&&(e.type===`comma`||e.type===`brace`),n=e.extglob===!0||R.length&&(e.type===`pipe`||e.type===`paren`);e.type!==`slash`&&e.type!==`paren`&&!t&&!n&&(L.output=L.output.slice(0,-V.output.length),V.type=`star`,V.value=`*`,V.output=I,L.output+=V.output)}if(R.length&&e.type!==`paren`&&(R[R.length-1].inner+=e.value),(e.value||e.output)&&J(e),V&&V.type===`text`&&e.type===`text`){V.output=(V.output||V.value)+e.value,V.value+=e.value;return}e.prev=V,h.push(e),V=e},te=(e,t)=>{let n={...b[t],conditions:1,inner:``};n.prev=V,n.parens=L.parens,n.output=L.output,n.startIndex=L.index,n.tokensIndex=h.length;let r=(d.capture?`(`:``)+n.open;Y(`parens`),Z({type:e,value:t,output:L.output?``:w}),Z({type:`paren`,extglob:!0,value:G(),output:r}),R.push(n)},ne=n=>{let i=e.slice(n.startIndex,L.index+1),a=v(e.slice(n.startIndex+2,L.index),d);if((n.type===`plus`||n.type===`star`)&&a.risky){let e=a.safeOutput?(n.output?``:w)+(d.capture?`(${a.safeOutput})`:a.safeOutput):void 0,t=h[n.tokensIndex];t.type=`text`,t.value=i,t.output=e||r.escapeRegex(i);for(let e=n.tokensIndex+1;e<h.length;e++)h[e].value=``,h[e].output=``,delete h[e].suffix;L.output=n.output+t.output,L.backtrack=!0,Z({type:`paren`,extglob:!0,value:H,output:``}),X(`parens`);return}let o=n.close+(d.capture?`)`:``),s;if(n.type===`negate`){let e=I;n.inner&&n.inner.length>1&&n.inner.includes(`/`)&&(e=N(d)),(e!==I||U()||/^\)+$/.test(K()))&&(o=n.close=`)$))${e}`),n.inner.includes(`*`)&&(s=K())&&/^\.[^\\/.]+$/.test(s)&&(o=n.close=`)${y(s,{...t,fastpaths:!1}).output})${e})`),n.prev.type===`bos`&&(L.negatedExtglob=!0)}Z({type:`paren`,extglob:!0,value:H,output:o}),X(`parens`)};if(d.fastpaths!==!1&&!/(^[*!]|[/()[\]{}"])/.test(e)){let n=!1,i=e.replace(s,(e,t,r,i,a,o)=>i===`\\`?(n=!0,e):i===`?`?t?t+i+(a?k.repeat(a.length):``):o===0?F+(a?k.repeat(a.length):``):k.repeat(r.length):i===`.`?x.repeat(r.length):i===`*`?t?t+i+(a?I:``):I:t?e:`\\${e}`);return n===!0&&(i=d.unescape===!0?i.replace(/\\/g,``):i.replace(/\\+/g,e=>e.length%2==0?`\\\\`:e?`\\`:``)),i===e&&d.contains===!0?(L.output=e,L):(L.output=r.wrapOutput(i,L,t),L)}for(;!U();){if(H=G(),H===`\0`)continue;if(H===`\\`){let e=W();if(e===`/`&&d.bash!==!0||e===`.`||e===`;`)continue;if(!e){H+=`\\`,Z({type:`text`,value:H});continue}let t=/^\\+/.exec(K()),n=0;if(t&&t[0].length>2&&(n=t[0].length,L.index+=n,n%2!=0&&(H+=`\\`)),d.unescape===!0?H=G():H+=G(),L.brackets===0){Z({type:`text`,value:H});continue}}if(L.brackets>0&&(H!==`]`||V.value===`[`||V.value===`[^`)){if(d.posix!==!1&&H===`:`){let e=V.value.slice(1);if(e.includes(`[`)&&(V.posix=!0,e.includes(`:`))){let e=V.value.lastIndexOf(`[`),t=V.value.slice(0,e),n=a[V.value.slice(e+2)];if(n){V.value=t+n,L.backtrack=!0,G(),!m.output&&h.indexOf(V)===1&&(m.output=w);continue}}}(H===`[`&&W()!==`:`||H===`-`&&W()===`]`)&&(H=`\\${H}`),H===`]`&&(V.value===`[`||V.value===`[^`)&&(H=`\\${H}`),d.posix===!0&&H===`!`&&V.value===`[`&&(H=`^`),V.value+=H,J({value:H});continue}if(L.quotes===1&&H!==`"`){H=r.escapeRegex(H),V.value+=H,J({value:H});continue}if(H===`"`){L.quotes=L.quotes===1?0:1,d.keepQuotes===!0&&Z({type:`text`,value:H});continue}if(H===`(`){Y(`parens`),Z({type:`paren`,value:H});continue}if(H===`)`){if(L.parens===0&&d.strictBrackets===!0)throw SyntaxError(u(`opening`,`(`));let e=R[R.length-1];if(e&&L.parens===e.parens+1){ne(R.pop());continue}Z({type:`paren`,value:H,output:L.parens?`)`:`\\)`}),X(`parens`);continue}if(H===`[`){if(d.nobracket===!0||!K().includes(`]`)){if(d.nobracket!==!0&&d.strictBrackets===!0)throw SyntaxError(u(`closing`,`]`));H=`\\${H}`}else Y(`brackets`);Z({type:`bracket`,value:H});continue}if(H===`]`){if(d.nobracket===!0||V&&V.type===`bracket`&&V.value.length===1){Z({type:`text`,value:H,output:`\\${H}`});continue}if(L.brackets===0){if(d.strictBrackets===!0)throw SyntaxError(u(`opening`,`[`));Z({type:`text`,value:H,output:`\\${H}`});continue}X(`brackets`);let e=V.value.slice(1);if(V.posix!==!0&&e[0]===`^`&&!e.includes(`/`)&&(H=`/${H}`),V.value+=H,J({value:H}),d.literalBrackets===!1||r.hasRegexChars(e))continue;let t=r.escapeRegex(V.value);if(L.output=L.output.slice(0,-V.value.length),d.literalBrackets===!0){L.output+=t,V.value=t;continue}V.value=`(${g}${t}|${V.value})`,L.output+=V.value;continue}if(H===`{`&&d.nobrace!==!0){Y(`braces`);let e={type:`brace`,value:H,output:`(`,outputIndex:L.output.length,tokensIndex:L.tokens.length};z.push(e),Z(e);continue}if(H===`}`){let e=z[z.length-1];if(d.nobrace===!0||!e){Z({type:`text`,value:H,output:H});continue}let t=`)`;if(e.dots===!0){let e=h.slice(),n=[];for(let t=e.length-1;t>=0&&(h.pop(),e[t].type!==`brace`);t--)e[t].type!==`dots`&&n.unshift(e[t].value);t=l(n,d),L.backtrack=!0}if(e.comma!==!0&&e.dots!==!0){let n=L.output.slice(0,e.outputIndex),r=L.tokens.slice(e.tokensIndex);e.value=e.output=`\\{`,H=t=`\\}`,L.output=n;for(let e of r)L.output+=e.output||e.value}Z({type:`brace`,value:H,output:t}),X(`braces`),z.pop();continue}if(H===`|`){R.length>0&&R[R.length-1].conditions++,Z({type:`text`,value:H});continue}if(H===`,`){let e=H,t=z[z.length-1];t&&B[B.length-1]===`braces`&&(t.comma=!0,e=`|`),Z({type:`comma`,value:H,output:e});continue}if(H===`/`){if(V.type===`dot`&&L.index===L.start+1){L.start=L.index+1,L.consumed=``,L.output=``,h.pop(),V=m;continue}Z({type:`slash`,value:H,output:C});continue}if(H===`.`){if(L.braces>0&&V.type===`dot`){V.value===`.`&&(V.output=x);let e=z[z.length-1];V.type=`dots`,V.output+=H,V.value+=H,e.dots=!0;continue}if(L.braces+L.parens===0&&V.type!==`bos`&&V.type!==`slash`){Z({type:`text`,value:H,output:x});continue}Z({type:`dot`,value:H,output:x});continue}if(H===`?`){if(!(V&&V.value===`(`)&&d.noextglob!==!0&&W()===`(`&&W(2)!==`?`){te(`qmark`,H);continue}if(V&&V.type===`paren`){let e=W(),t=H;(V.value===`(`&&!/[!=<:]/.test(e)||e===`<`&&!/<([!=]|\w+>)/.test(K()))&&(t=`\\${H}`),Z({type:`text`,value:H,output:t});continue}if(d.dot!==!0&&(V.type===`slash`||V.type===`bos`)){Z({type:`qmark`,value:H,output:A});continue}Z({type:`qmark`,value:H,output:k});continue}if(H===`!`){if(d.noextglob!==!0&&W()===`(`&&(W(2)!==`?`||!/[!=<:]/.test(W(3)))){te(`negate`,H);continue}if(d.nonegate!==!0&&L.index===0){ee();continue}}if(H===`+`){if(d.noextglob!==!0&&W()===`(`&&W(2)!==`?`){te(`plus`,H);continue}if(V&&V.value===`(`||d.regex===!1){Z({type:`plus`,value:H,output:S});continue}if(V&&(V.type===`bracket`||V.type===`paren`||V.type===`brace`)||L.parens>0){Z({type:`plus`,value:H});continue}Z({type:`plus`,value:S});continue}if(H===`@`){if(d.noextglob!==!0&&W()===`(`&&W(2)!==`?`){Z({type:`at`,extglob:!0,value:H,output:``});continue}Z({type:`text`,value:H});continue}if(H!==`*`){(H===`$`||H===`^`)&&(H=`\\${H}`);let e=o.exec(K());e&&(H+=e[0],L.index+=e[0].length),Z({type:`text`,value:H});continue}if(V&&(V.type===`globstar`||V.star===!0)){V.type=`star`,V.star=!0,V.value+=H,V.output=I,L.backtrack=!0,L.globstar=!0,q(H);continue}let t=K();if(d.noextglob!==!0&&/^\([^?]/.test(t)){te(`star`,H);continue}if(V.type===`star`){if(d.noglobstar===!0){q(H);continue}let n=V.prev,r=n.prev,i=n.type===`slash`||n.type===`bos`,a=r&&(r.type===`star`||r.type===`globstar`);if(d.bash===!0&&(!i||t[0]&&t[0]!==`/`)){Z({type:`star`,value:H,output:``});continue}let o=L.braces>0&&(n.type===`comma`||n.type===`brace`),s=R.length&&(n.type===`pipe`||n.type===`paren`);if(!i&&n.type!==`paren`&&!o&&!s){Z({type:`star`,value:H,output:``});continue}for(;t.slice(0,3)===`/**`;){let n=e[L.index+4];if(n&&n!==`/`)break;t=t.slice(3),q(`/**`,3)}if(n.type===`bos`&&U()){V.type=`globstar`,V.value+=H,V.output=N(d),L.output=V.output,L.globstar=!0,q(H);continue}if(n.type===`slash`&&n.prev.type!==`bos`&&!a&&U()){L.output=L.output.slice(0,-(n.output+V.output).length),n.output=`(?:${n.output}`,V.type=`globstar`,V.output=N(d)+(d.strictSlashes?`)`:`|$)`),V.value+=H,L.globstar=!0,L.output+=n.output+V.output,q(H);continue}if(n.type===`slash`&&n.prev.type!==`bos`&&t[0]===`/`){let e=t[1]===void 0?``:`|$`;L.output=L.output.slice(0,-(n.output+V.output).length),n.output=`(?:${n.output}`,V.type=`globstar`,V.output=`${N(d)}${C}|${C}${e})`,V.value+=H,L.output+=n.output+V.output,L.globstar=!0,q(H+G()),Z({type:`slash`,value:`/`,output:``});continue}if(n.type===`bos`&&t[0]===`/`){V.type=`globstar`,V.value+=H,V.output=`(?:^|${C}|${N(d)}${C})`,L.output=V.output,L.globstar=!0,q(H+G()),Z({type:`slash`,value:`/`,output:``});continue}L.output=L.output.slice(0,-V.output.length),V.type=`globstar`,V.output=N(d),V.value+=H,L.output+=V.output,L.globstar=!0,q(H);continue}let n={type:`star`,value:H,output:I};if(d.bash===!0){n.output=`.*?`,(V.type===`bos`||V.type===`slash`)&&(n.output=P+n.output),Z(n);continue}if(V&&(V.type===`bracket`||V.type===`paren`)&&d.regex===!0){n.output=H,Z(n);continue}(L.index===L.start||V.type===`slash`||V.type===`dot`)&&(V.type===`dot`?(L.output+=D,V.output+=D):d.dot===!0?(L.output+=O,V.output+=O):(L.output+=P,V.output+=P),W()!==`*`&&(L.output+=w,V.output+=w)),Z(n)}for(;L.brackets>0;){if(d.strictBrackets===!0)throw SyntaxError(u(`closing`,`]`));L.output=r.escapeLast(L.output,`[`),X(`brackets`)}for(;L.parens>0;){if(d.strictBrackets===!0)throw SyntaxError(u(`closing`,`)`));L.output=r.escapeLast(L.output,`(`),X(`parens`)}for(;L.braces>0;){if(d.strictBrackets===!0)throw SyntaxError(u(`closing`,`}`));L.output=r.escapeLast(L.output,`{`),X(`braces`)}if(d.strictSlashes!==!0&&(V.type===`star`||V.type===`bracket`)&&Z({type:`maybe_slash`,value:``,output:`${C}?`}),L.backtrack===!0){L.output=``;for(let e of L.tokens)L.output+=e.output==null?e.value:e.output,e.suffix&&(L.output+=e.suffix)}return L};y.fastpaths=(e,t)=>{let a={...t},o=typeof a.maxLength==`number`?Math.min(i,a.maxLength):i,s=e.length;if(s>o)throw SyntaxError(`Input length: ${s}, exceeds maximum allowed length: ${o}`);e=c[e]||e;let{DOT_LITERAL:l,SLASH_LITERAL:u,ONE_CHAR:d,DOTS_SLASH:f,NO_DOT:p,NO_DOTS:m,NO_DOTS_SLASH:h,STAR:g,START_ANCHOR:_}=n.globChars(a.windows),v=a.dot?m:p,y=a.dot?h:p,b=a.capture?``:`?:`,x={negated:!1,prefix:``},S=a.bash===!0?`.*?`:g;a.capture&&(S=`(${S})`);let C=e=>e.noglobstar===!0?S:`(${b}(?:(?!${_}${e.dot?f:l}).)*?)`,w=e=>{switch(e){case`*`:return`${v}${d}${S}`;case`.*`:return`${l}${d}${S}`;case`*.*`:return`${v}${S}${l}${d}${S}`;case`*/*`:return`${v}${S}${u}${d}${y}${S}`;case`**`:return v+C(a);case`**/*`:return`(?:${v}${C(a)}${u})?${y}${d}${S}`;case`**/*.*`:return`(?:${v}${C(a)}${u})?${y}${S}${l}${d}${S}`;case`**/.*`:return`(?:${v}${C(a)}${u})?${l}${d}${S}`;default:{let t=/^(.*?)\.(\w+)$/.exec(e);if(!t)return;let n=w(t[1]);return n?n+l+t[2]:void 0}}},T=w(r.removePrefix(e,x));return T&&a.strictSlashes!==!0&&(T+=`${u}?`),T},t.exports=y})),ot=B(((e,t)=>{let n=it(),r=at(),i=rt(),a=nt(),o=e=>e&&typeof e==`object`&&!Array.isArray(e),s=(e,t,n=!1)=>{if(Array.isArray(e)){let r=e.map(e=>s(e,t,n));return e=>{for(let t of r){let n=t(e);if(n)return n}return!1}}let r=o(e)&&e.tokens&&e.input;if(e===``||typeof e!=`string`&&!r)throw TypeError(`Expected pattern to be a non-empty string`);let i=t||{},a=i.windows,c=r?s.compileRe(e,t):s.makeRe(e,t,!1,!0),l=c.state;delete c.state;let u=()=>!1;if(i.ignore){let e={...t,ignore:null,onMatch:null,onResult:null};u=s(i.ignore,e,n)}let d=(n,r=!1)=>{let{isMatch:o,match:d,output:f}=s.test(n,c,t,{glob:e,posix:a}),p={glob:e,state:l,regex:c,posix:a,input:n,output:f,match:d,isMatch:o};return typeof i.onResult==`function`&&i.onResult(p),o===!1?(p.isMatch=!1,r?p:!1):u(n)?(typeof i.onIgnore==`function`&&i.onIgnore(p),p.isMatch=!1,r?p:!1):(typeof i.onMatch==`function`&&i.onMatch(p),r?p:!0)};return n&&(d.state=l),d};s.test=(e,t,n,{glob:r,posix:a}={})=>{if(typeof e!=`string`)throw TypeError(`Expected input to be a string`);if(e===``)return{isMatch:!1,output:``};let o=n||{},c=o.format||(a?i.toPosixSlashes:null),l=e===r,u=l&&c?c(e):e;return l===!1&&(u=c?c(e):e,l=u===r),(l===!1||o.capture===!0)&&(l=o.matchBase===!0||o.basename===!0?s.matchBase(e,t,n,a):t.exec(u)),{isMatch:!!l,match:l,output:u}},s.matchBase=(e,t,n)=>(t instanceof RegExp?t:s.makeRe(t,n)).test(i.basename(e)),s.isMatch=(e,t,n)=>s(t,n)(e),s.parse=(e,t)=>Array.isArray(e)?e.map(e=>s.parse(e,t)):r(e,{...t,fastpaths:!1}),s.scan=(e,t)=>n(e,t),s.compileRe=(e,t,n=!1,r=!1)=>{if(n===!0)return e.output;let i=t||{},a=i.contains?``:`^`,o=i.contains?``:`$`,c=`${a}(?:${e.output})${o}`;e&&e.negated===!0&&(c=`^(?!${c}).*$`);let l=s.toRegex(c,t);return r===!0&&(l.state=e),l},s.makeRe=(e,t={},n=!1,i=!1)=>{if(!e||typeof e!=`string`)throw TypeError(`Expected a non-empty string`);let a={negated:!1,fastpaths:!0};return t.fastpaths!==!1&&(e[0]===`.`||e[0]===`*`)&&(a.output=r.fastpaths(e,t)),a.output||(a=r(e,t)),s.compileRe(a,t,n,i)},s.toRegex=(e,t)=>{try{let n=t||{};return new RegExp(e,n.flags||(n.nocase?`i`:``))}catch(e){if(t&&t.debug===!0)throw e;return/$^/}},s.constants=a,t.exports=s})),st=H(B(((e,t)=>{let n=ot(),r=rt();function i(e,t,i=!1){return t&&(t.windows===null||t.windows===void 0)&&(t={...t,windows:r.isWindows()}),n(e,t,i)}Object.assign(i,n),t.exports=i}))(),1);const ct=Array.isArray,lt=/\\/g,ut=process.platform===`win32`,dt=/^(\/?\.\.)+$/;function ft(e,t={}){let n=e.length,r=Array(n),i=Array(n),a,o;for(a=0;a<n;a++){let n=vt(e[a]);r[a]=n;let s=n.length,c=Array(s);for(o=0;o<s;o++)c[o]=(0,st.default)(n[o],t);i[a]=c}return e=>{let s=e.split(`/`);if(s[0]===`..`&&dt.test(e))return!0;for(a=0;a<n;a++){let e=r[a],n=i[a],c=s.length,l=Math.min(c,e.length);for(o=0;o<l;){let r=e[o];if(r.includes(`/`))return!0;if(!n[o](s[o]))break;if(!t.noglobstar&&r===`**`)return!0;o++}if(o===c)return!0}return!1}}const pt=/^[A-Z]:\/$/i,mt=ut?e=>pt.test(e):e=>e===`/`;function ht(e,t,n){if(e===t||t.startsWith(`${e}/`)){if(n){let t=e.length+ +!mt(e);return(e,n)=>e.slice(t,n?-1:void 0)||`.`}let r=t.slice(e.length+1);return r?(e,t)=>{if(e===`.`)return r;let n=`${r}/${e}`;return t?n.slice(0,-1):n}:(e,t)=>t&&e!==`.`?e.slice(0,-1):e}return n?t=>D.relative(e,t)||`.`:n=>D.relative(e,`${t}/${n}`)||`.`}function gt(e,t){if(t.startsWith(`${e}/`)){let n=t.slice(e.length+1);return e=>`${n}/${e}`}return n=>{let r=D.relative(e,`${t}/${n}`);return n[n.length-1]===`/`&&r!==``?`${r}/`:r||`.`}}const _t={parts:!0};function vt(e){let t=st.default.scan(e,_t);return t.parts?.length?t.parts:[e]}const yt=/(?<!\\)([()[\]{}*?|]|^!|[!+@](?=\()|\\(?![()[\]{}!*+?@|]))/g,bt=/(?<!\\)([()[\]{}]|^!|[!+@](?=\())/g,xt=ut?e=>e.replace(bt,`\\$&`):e=>e.replace(yt,`\\$&`);function St(e,t){if(t?.caseSensitiveMatch===!1)return!0;let n=st.default.scan(e);return n.isGlob||n.negated}function Ct(...e){console.log(`[tinyglobby ${new Date().toLocaleTimeString(`es`)}]`,...e)}function wt(e){return typeof e==`string`?[e]:e??[]}const Tt=/^(\/?\.\.)+/,Et=/\\(?=[()[\]{}!*+?@|])/g;function Dt(e,t,n,r){let i=t.cwd,a=e;e[e.length-1]===`/`&&(a=e.slice(0,-1)),a[a.length-1]!==`*`&&t.expandDirectories&&(a+=`/**`);let o=xt(i);a=T(a.replace(Et,``))?D.relative(o,a):D.normalize(a);let s=Tt.exec(a)?.[0],c=vt(a);if(s){let e=(s.length+1)/3,t=0,r=o.split(`/`);for(;t<e&&c[t+e]===r[r.length+t-e];)a=a.slice(0,(e-t-1)*3)+a.slice((e-t)*3+c[t+e].length+1)||`.`,t++;let l=D.join(i,s.slice(t*3));l[0]!==`.`&&n.root.length>l.length&&(n.root=l,n.depthOffset=-e+t)}if(!r&&n.depthOffset>=0){n.commonPath??=c;let e=[],t=Math.min(n.commonPath.length,c.length);for(let r=0;r<t;r++){let t=c[r];if(t===`**`&&!c[r+1]){e.pop();break}if(r===c.length-1||t!==n.commonPath[r]||St(t))break;e.push(t)}n.depthOffset=e.length,n.commonPath=e,n.root=e.length>0?D.join(i,...e):i}return a}function Ot(e,t,n){let r=[],i=[];for(let t of e.ignore)t&&(t[0]!==`!`||t[1]===`(`)&&i.push(Dt(t,e,n,!0));for(let a of t)a&&(a[0]!==`!`||a[1]===`(`?r.push(Dt(a,e,n,!1)):(a[1]!==`!`||a[2]===`(`)&&i.push(Dt(a.slice(1),e,n,!0)));return{match:r,ignore:i}}function kt(e,t){let n=e.cwd,r={root:n,depthOffset:0},i=Ot(e,t,r);e.debug&&Ct(`internal processing patterns:`,i);let{absolute:a,caseSensitiveMatch:o,debug:s,dot:c,followSymbolicLinks:l,onlyDirectories:u}=e,d=r.root.replace(lt,``),f={dot:c,nobrace:e.braceExpansion===!1,nocase:!o,noextglob:e.extglob===!1,noglobstar:e.globstar===!1,posix:!0},p=(0,st.default)(i.match,f),m=(0,st.default)(i.ignore,f),h=ft(i.match,f),g=ht(n,d,a),_=a?g:ht(n,d,!0),v=(e,t)=>{let n=_(t,!0);return n!==`.`&&!h(n)||m(n)},y;e.deep!==void 0&&(y=Math.round(e.deep-r.depthOffset));let b=new tt({filters:[s?(e,t)=>{let n=g(e,t),r=p(n)&&!m(n);return r&&Ct(`matched ${n}`),r}:(e,t)=>{let n=g(e,t);return p(n)&&!m(n)}],exclude:s?(e,t)=>{let n=v(e,t);return Ct(`${n?`skipped`:`crawling`} ${t}`),n}:v,fs:e.fs,pathSeparator:`/`,relativePaths:!a,resolvePaths:a,includeBasePath:a,resolveSymlinks:l,excludeSymlinks:!l,excludeFiles:u,includeDirs:u||!e.onlyFiles,maxDepth:y,signal:e.signal}).crawl(d);return e.debug&&Ct(`internal properties:`,{...r,root:d}),[b,n!==d&&!a&>(n,d)]}function At(e,t){if(t)for(let n=e.length-1;n>=0;n--)e[n]=t(e[n]);return e}const jt={caseSensitiveMatch:!0,cwd:process.cwd(),debug:!!process.env.TINYGLOBBY_DEBUG,expandDirectories:!0,followSymbolicLinks:!0,onlyFiles:!0};function Mt(e){let t={...jt,...e};return t.cwd=(t.cwd instanceof URL?j(t.cwd):k(t.cwd)).replace(lt,`/`),t.ignore=wt(t.ignore),t.fs&&={readdir:t.fs.readdir||_,readdirSync:t.fs.readdirSync||v,realpath:t.fs.realpath||y,realpathSync:t.fs.realpathSync||b,stat:t.fs.stat||x,statSync:t.fs.statSync||S},t.debug&&Ct(`globbing with options:`,t),t}function Nt(e,t={}){if(e&&t?.patterns)throw Error(`Cannot pass patterns as both an argument and an option`);let n=ct(e)||typeof e==`string`,r=wt((n?e:e.patterns)??`**/*`),i=Mt(n?t:e);return r.length>0?kt(i,r):[]}async function Pt(e,t){let[n,r]=Nt(e,t);return n?At(await n.withPromise(),r):[]}var Ft=B(((e,t)=>{var n=Object.defineProperty,r=Object.getOwnPropertyDescriptor,i=Object.getOwnPropertyNames,a=Object.prototype.hasOwnProperty,o=(e,t)=>{for(var r in t)n(e,r,{get:t[r],enumerable:!0})},s=(e,t,o,s)=>{if(t&&typeof t==`object`||typeof t==`function`)for(let c of i(t))!a.call(e,c)&&c!==o&&n(e,c,{get:()=>t[c],enumerable:!(s=r(t,c))||s.enumerable});return e},c=e=>s(n({},`__esModule`,{value:!0}),e),l={};o(l,{DEFAULT_CLOCK_TOLERANCE_SEC:()=>f,DEFAULT_JWT_EXPIRE_TIME_MS:()=>d,HttpClient:()=>F,HttpError:()=>M,generateJWTToken:()=>m,parseJWTTokenWithVerify:()=>h,registerPlatformPlugin:()=>D,resolvePlatformBaseURL:()=>E}),t.exports=c(l);var u=U(`crypto`),d=1800*1e3,f=60,p={alg:`HS256`,typ:`JWT`};function m(e,t){let n=Math.floor(Date.now()/1e3),r={...e,iss:e.access_key,iat:n,nbf:n,exp:n+Math.floor(t.expireTimeMs/1e3),jti:(0,u.randomUUID)()},i=_(JSON.stringify(p)),a=_(JSON.stringify(r));return`${i}.${a}.${g(`${i}.${a}`,t.secretKey)}`}function h(e,t,n){let r=e.split(`.`);if(r.length!==3)throw Error(`invalid JWT token format`);let[i,a,o]=r;if(JSON.parse(v(i)).alg!==`HS256`)throw Error(`unsupported JWT alg`);let s=g(`${i}.${a}`,t.secretKey),c=Buffer.from(s),l=Buffer.from(o);if(c.length!==l.length||!(0,u.timingSafeEqual)(c,l))throw Error(`JWT signature verification failed`);let d=JSON.parse(v(a));if(!n?.skipExpiration){let e=n?.clockTolerance??f,t=Math.floor(Date.now()/1e3);if(d.exp!==void 0&&d.exp+e<t)throw Error(`JWT token expired at ${new Date(d.exp*1e3).toISOString()}`);if(d.nbf!==void 0&&d.nbf-e>t)throw Error(`JWT token not yet valid, will be valid at ${new Date(d.nbf*1e3).toISOString()}`);if(d.iat!==void 0&&d.iat-e>t)throw Error(`JWT token issued in the future at ${new Date(d.iat*1e3).toISOString()}`)}return d}function g(e,t){return(0,u.createHmac)(`sha256`,t).update(e).digest(`base64`).replace(/=/g,``).replace(/\+/g,`-`).replace(/\//g,`_`)}function _(e){return Buffer.from(e).toString(`base64`).replace(/=/g,``).replace(/\+/g,`-`).replace(/\//g,`_`)}function v(e){let t=(4-(e.length%4||4))%4,n=`${e}${`=`.repeat(t)}`.replace(/-/g,`+`).replace(/_/g,`/`);return Buffer.from(n,`base64`).toString(`utf8`)}var y=class{cache=new Map;config;constructor(e){this.config={refreshBeforeMs:300*1e3,...e}}getToken(e){let t=this.getCacheKey(e),n=this.cache.get(t),r=Date.now();if(n&&n.expiresAtMs-r>this.config.refreshBeforeMs)return n.token;let i=m(e,this.config),a=r+this.config.expireTimeMs;return this.cache.set(t,{token:i,expiresAtMs:a}),i}clearCache(){this.cache.clear()}clearCacheFor(e){let t=this.getCacheKey(e);this.cache.delete(t)}getCacheKey(e){return[e.access_key,e.tenant_id?.toString()||``,e.user_id||``,e.app_id||``,e.app_env||``,e.sandbox_id||``].join(`:`)}getCacheStats(){let e=Date.now(),t=0,n=0;for(let r of this.cache.values())r.expiresAtMs>e?t++:n++;return{total:this.cache.size,valid:t,expired:n}}},b=`FORCE_AUTHN_INNERAPI_DOMAIN`,x=`FORCE_AUTHN_ACCESS_KEY`,S=`FORCE_AUTHN_ACCESS_SECRET`,C=`MIAODA_DEV_INNER_DOMAIN_WITH_PREFIX`,w=`MIAODA_AUTHN_CODE`,T=`X-Miaoda-Client-Token`;function E(e){if(!e?.enabled)return e?.baseURL;if(e.baseURL)return e.baseURL;let t=e.adminInnerApi?e.adminDomainEnv||C:e.domainEnv||b,n=process.env[t];if(!n)throw Error(`\u5E73\u53F0\u6A21\u5F0F\u9700\u8981\u57FA\u7840\u57DF\u540D\uFF0C\u8BF7\u8BBE\u7F6E\u73AF\u5883\u53D8\u91CF ${t}`);return n}function D(e,t){if(!t.enabled)return;O(`platform.defaultClaims`,t.defaultClaims);let n=t.accessKeyEnv||x,r=t.secretKeyEnv||S,i=t.accessKey??(process.env[n]||``),a=new y({accessKey:i,secretKey:t.secretKey??(process.env[r]||``),expireTimeMs:t.expireTimeMs??d,refreshBeforeMs:t.refreshBeforeMs}),o=t.clientTokenEnv||w;return e.request.use(e=>{O(`request.platformAuth.customClaims`,e.platformAuth?.customClaims);let n={...t.defaultClaims||{},...e.platformAuth?.customClaims||{},access_key:i},r=a.getToken(n),s={...e.headers,Authorization:`Bearer ${r}`,"x-api-key":i};if(t.adminInnerApi){let e=process.env[o];e&&(s[T]=e)}return{...e,headers:s}}),a}function O(e,t){if(t&&Object.prototype.hasOwnProperty.call(t,`access_key`))throw Error(`${e} \u4E0D\u5141\u8BB8\u8BBE\u7F6E access_key`)}var k=class{interceptors=[];use(e,t){return this.interceptors.push({onFulfilled:e,onRejected:t}),this.interceptors.length-1}eject(e){this.interceptors[e]&&(this.interceptors[e]=null)}clear(){this.interceptors=[]}forEach(e){this.interceptors.forEach(t=>{t!==null&&e(t)})}};function A(e){if(typeof e!=`object`||!e)return!1;let t=Object.getPrototypeOf(e);return t===Object.prototype||t===null}function j(e){if(!e)return{};if(e instanceof Headers){let t={};return e.forEach((e,n)=>{t[n]=e}),t}if(Array.isArray(e))return e.reduce((e,[t,n])=>(e[t]=n,e),{});let t={};return Object.entries(e).forEach(([e,n])=>{t[e]=Array.isArray(n)?n.join(`,`):n}),t}var M=class e extends Error{isHttpError=!0;response;config;constructor(t,n,r){super(r||`Request failed with status ${t?.status||`unknown`}`),this.name=`HttpError`,this.response=t,this.config=N(n),Object.setPrototypeOf(this,e.prototype)}};function N(e){let{headers:t,...n}=e;return{...n,headers:P(t)}}function P(e){if(!e)return;let t=j(e),n={},r=[`authorization`,`x-api-key`,`cookie`,`x-secret`];for(let[e,i]of Object.entries(t)){let t=e.toLowerCase();r.includes(t)?n[e]=`[REDACTED]`:n[e]=i}return n}var F=class{defaultConfig;securityConfig;interceptors={request:new k,response:new k};constructor(e){let{platform:t,security:n,...r}=e||{};this.defaultConfig={timeout:5e3,...r};let i=n?.strictMode??!1;this.securityConfig={allowedProtocols:i?[`http:`,`https:`]:null,maxResponseSize:i?50*1024*1024:0,strictMode:i,...n},t?.enabled&&(this.defaultConfig.baseURL||(this.defaultConfig.baseURL=E(t)),D(this.interceptors,t))}async get(e,t){return this.request({...t,url:e,method:`GET`})}async post(e,t,n){let r={...n?.headers},i=t;return A(t)&&(i=JSON.stringify(t),Object.keys(r).some(e=>e.toLowerCase()===`content-type`)||(r[`Content-Type`]=`application/json`)),this.request({...n,url:e,method:`POST`,body:i,headers:r})}async put(e,t,n){let r={...n?.headers},i=t;return A(t)&&(i=JSON.stringify(t),Object.keys(r).some(e=>e.toLowerCase()===`content-type`)||(r[`Content-Type`]=`application/json`)),this.request({...n,url:e,method:`PUT`,body:i,headers:r})}async delete(e,t){return this.request({...t,url:e,method:`DELETE`})}async patch(e,t,n){let r={...n?.headers},i=t;return A(t)&&(i=JSON.stringify(t),Object.keys(r).some(e=>e.toLowerCase()===`content-type`)||(r[`Content-Type`]=`application/json`)),this.request({...n,url:e,method:`PATCH`,body:i,headers:r})}async request(e){let t=j(this.defaultConfig.headers),n=j(e.headers),r={};for(let e in t)r[e.toLowerCase()]={key:e,value:t[e]};for(let e in n)r[e.toLowerCase()]={key:e,value:n[e]};let i={};for(let e in r){let{key:t,value:n}=r[e];i[t]=n}let a={...this.defaultConfig,...e,headers:i};try{a=await this.runRequestInterceptors(a)}catch(e){return Promise.reject(e)}a.headers=j(a.headers);let o=this.buildUrl(a.url,a.params),s=a.timeout||this.defaultConfig.timeout||5e3,c=new AbortController,l=setTimeout(()=>c.abort(),s),u=a.signal;u&&(u.aborted?(clearTimeout(l),c.abort()):u.addEventListener(`abort`,()=>c.abort(),{once:!0}));let{platformAuth:d,params:f,timeout:p,baseURL:m,url:h,...g}=a;try{let e=await fetch(o,{...g,signal:c.signal});if(clearTimeout(l),this.securityConfig.maxResponseSize>0){let t=e.headers.get(`content-length`);if(t){let e=parseInt(t,10);if(e>this.securityConfig.maxResponseSize)throw Error(`Response size ${e} bytes exceeds limit of ${this.securityConfig.maxResponseSize} bytes`)}}if(!e.ok){let t=new M(e,a);return this.runResponseInterceptors(Promise.reject(t))}return this.runResponseInterceptors(Promise.resolve(e))}catch(e){clearTimeout(l);let t=e instanceof M?e:new M(void 0,a,e.name===`AbortError`?`Request aborted`:e.message);return this.runResponseInterceptors(Promise.reject(t))}}runRequestInterceptors(e){let t=Promise.resolve(e),n=[];this.interceptors.request.forEach(e=>{n.push(e)});for(let e of n)t=t.then(e.onFulfilled,e.onRejected);return t}async runResponseInterceptors(e){let t=e,n=[];this.interceptors.response.forEach(e=>{n.push(e)});for(let e of n)t=t.then(e.onFulfilled,e.onRejected);return t}buildUrl(e,t){let n=this.defaultConfig.baseURL,r;r=!n||/^https?:\/\//i.test(e)?e:n.replace(/\/+$/,``)+`/`+e.replace(/^\/+/,``);let i=new URL(r),{allowedProtocols:a}=this.securityConfig;if(a&&!a.includes(i.protocol))throw Error(`Protocol ${i.protocol} is not allowed. Allowed: ${a.join(`, `)}`);if(t)for(let[e,n]of Object.entries(t))n!=null&&i.searchParams.set(e,String(n));return i.href}}}))();const It=new Set([`forced_quota_failed`,`k_st_ec_400002680`,`k_st_ec_400002681`,`k_st_ec_400002682`,`k_st_ec_400002683`,`k_st_ec_400002684`,`k_st_ec_400002685`,`k_st_ec_400002686`,`k_st_ec_400002687`,`k_st_ec_400002688`,`k_st_ec_400002690`,`k_st_ec_400002698`]),Lt=new Set([`k_st_ec_400002680`,`k_st_ec_400002681`,`k_st_ec_400002682`,`k_st_ec_400002683`,`k_st_ec_400002684`,`k_st_ec_400002685`,`k_st_ec_400002686`,`k_st_ec_400002687`,`k_st_ec_400002688`,`k_st_ec_400002689`,`k_st_ec_400002690`,`k_st_ec_400002698`]);function Rt(e){return!!e&&It.has(e)}function zt(e){return!!e&&Lt.has(e)}let Bt;function Vt(){if(Bt)return Bt;try{let e=l(s(N(import.meta.url)),`..`,`package.json`);Bt=JSON.parse(a(e,`utf-8`))}catch(e){console.warn(`[miaoda-coding] failed to read package.json: ${e instanceof Error?e.message:e}`),Bt={}}return Bt}function Ht(){let e=process.env.FORCE_AUTHN_INNERAPI_DOMAIN;if(!e)throw Error(`studio-client: 缺少环境变量,需要: FORCE_AUTHN_INNERAPI_DOMAIN`);return{apiUrl:e}}var Ut=class extends Error{userFacing=!0;constructor(e,t,n){super(e),this.statusCode=t,this.logId=n,this.name=`UserFacingError`}};function Wt(e){return!!e&&typeof e==`object`&&!Array.isArray(e)&&Object.values(e).every(e=>typeof e==`string`)}function Gt(...e){for(let t of e)if(typeof t==`string`&&t)return t}async function*Kt(e){let t=new TextDecoder,n=``,r;for await(let i of e){n+=t.decode(i,{stream:!0});let e=n.split(`
|
|
2
2
|
|
|
3
3
|
`);n=e.pop();for(let t of e){let e=t.split(`
|
|
4
4
|
`),n=e.find(e=>e.startsWith(`id:`));n&&(r=n.slice(3).trim());let i=e.find(e=>e.startsWith(`data:`));if(!i)continue;let a=i.slice(5).trim();if(a){if(a===`[DONE]`){yield{data:null,id:r,done:!0};return}try{yield{data:JSON.parse(a),id:r,done:!1}}catch{}}}}}var qt=class{#e;#t;constructor(){this.#t=Ht();let e=Vt().headers;this.#e=new Ft.HttpClient({baseURL:this.#t.apiUrl,timeout:9e5,...process.env.FORCE_FRAMEWORK_ENVIRONMENT!==`online`&&Wt(e)?{headers:e}:{},platform:{enabled:!0,tokenProvider:{type:`file`}}})}async createSubApp(e={}){let t=`${this.#t.apiUrl}/api/v1/studio/innerapi/openclaw/sub_app/create`,n={};e.message&&(n.message=e.message),e.agentId&&(n.agentId=e.agentId);let r;try{r=await this.#e.post(t,n,{headers:{"Content-Type":`application/json`}})}catch(e){if(e instanceof Ft.HttpError&&e.response){let t=e.response.headers.get(`x-tt-logid`)??``;throw Error(`createSubApp 请求失败 (logID: ${t}): ${e.response.status}`)}throw e}let i=r.headers?.get?.(`x-tt-logid`)??``,a=await r.json();if(a.BaseResp?.StatusCode!==0&&a.BaseResp?.StatusMessage)throw Error(`createSubApp 业务错误 (logID: ${i}): ${a.BaseResp.StatusMessage}`);if(a.error_msg&&a.status_code!==`0`)throw zt(a.status_code)?new Ut(a.error_msg,a.status_code,i):Error(`createSubApp 服务错误 (logID: ${i}): ${a.error_msg}`);let o=Gt(a.appID,a.appId,a.app_id,a.data?.appID,a.data?.appId,a.data?.app_id),s=Gt(a.conversationID,a.conversationId,a.conversation_id,a.data?.conversationID,a.data?.conversationId,a.data?.conversation_id);if(!o){let e=Object.keys(a).join(`,`)||`(none)`,t=a.data&&typeof a.data==`object`&&Object.keys(a.data).join(`,`)||`(none)`;throw Error(`createSubApp 返回异常 (logID: ${i}): 缺少 appID,topLevelKeys=${e} dataKeys=${t}`)}return{appID:o,conversationID:s,logId:i}}async*streamChat(e){let t=`${this.#t.apiUrl}/api/v1/studio/innerapi/openclaw/sub_app/${e.appID}/stream_chat`,n={appID:e.appID,message:e.message};e.workDir&&(n.workDir=e.workDir),e.channelAppId&&(n.channelAppId=e.channelAppId);let r={"Content-Type":`application/json`,Accept:`text/event-stream`};e.lastEventID&&(r[`Last-Event-ID`]=e.lastEventID);let i;try{i=await this.#e.post(t,n,{headers:r})}catch(e){if(e instanceof Ft.HttpError&&e.response){let t=e.response.headers.get(`x-tt-logid`)??``,n=Error(`streamChat 请求失败 (logID: ${t}): ${e.response.status}`);throw n.logId=t,n}let t=e.cause?` cause: ${e.cause.message||e.cause}`:``,n=e.code?` code: ${e.code}`:``;throw Error(`streamChat 网络错误: ${e.message}${n}${t}`)}yield{__meta:!0,logId:i.headers?.get?.(`x-tt-logid`)??``},yield*Kt(i.body)}};const Jt=`.spark`,Yt=`meta.json`;function Xt(e){return c(e,Jt,Yt)}async function Zt(e){try{return JSON.parse(await f(Xt(e),`utf8`))}catch{return null}}async function Qt(e){if(!e)return null;try{return JSON.parse(await f(c(l(e),Jt,Yt),`utf8`))}catch{return null}}async function $t(e,t,n){await d(c(e,Jt),{recursive:!0});let r=await Zt(e),i={...r??{},...t};if(i.features||=[],!r){let e=await Qt(n?.rootDir);if(e)for(let[t,n]of Object.entries(e))t in i||(i[t]=n)}await h(Xt(e),JSON.stringify(i,null,2),`utf8`)}function en(e){let t=e;return t?.data?.message??t?.Data?.Message??null}function tn(e){return(typeof e?.finishReason==`string`&&e.finishReason?e.finishReason:void 0)||(typeof e?.metadata?.finishReason==`string`&&e.metadata.finishReason?e.metadata.finishReason:void 0)}function nn(e){let t=[e?.metadata?.error?.message,e?.metadata?.error?.Message,e?.error?.message,e?.error?.Message];for(let e of t)if(typeof e==`string`&&e.trim())return e.trim()}function rn(e){let t=[e?.metadata?.error?.code,e?.metadata?.error?.Code,e?.error?.code,e?.error?.Code];for(let e of t)if(typeof e==`string`&&e.trim())return e.trim()}function an(e){return e===`credit_limit`}function on(e){let t=e;if(en(t))return;let n=t?.BaseResp??t?.baseResp,r=typeof t?.StatusMessage==`string`?t.StatusMessage:void 0,i=typeof t?.StatusCode==`number`?t.StatusCode:typeof t?.status_code==`number`?t.status_code:void 0,a=typeof n?.KStatusMessage==`string`&&n.KStatusMessage?n.KStatusMessage:typeof n?.StatusMessage==`string`&&n.StatusMessage?n.StatusMessage:void 0,o=typeof n?.KStatusCode==`string`&&n.KStatusCode?n.KStatusCode:void 0;if(r===`error`||typeof i==`number`&&i!==0||o||a&&a!==`success`)return{message:a??r??`stream service failed`,code:o}}async function sn(e){let t=e.maxReconnect??2,n=e.maxTotalReconnect??10,r=e.reconnectDelayMs??1500,i,a=0,o=0,s=0,c,l,u,d,f,p;for(;;){let m=!1,h=!1,g=!1,_=i;try{for await(let t of e.createStream(_)){if(e.signal?.aborted)return{totalEvents:s,reconnectCount:o,lastEventId:i,finalText:c,logId:l,terminalReason:`stream_interrupted`,finishReasonRaw:f,errorCodeRaw:p,success:!1,error:`cancelled`};let n=t;if(n?.__meta){l=n.logId||l;continue}let r=n;r.id&&(i=r.id);let h=en(r.data),v=on(r.data),y=!!(r.id&&_&&r.id===_);v&&(p=v.code??p,u=Rt(v.code)?`quota_exceeded`:`service_failed`,d=v.message);let b=tn(h);b&&(f=b);let x=h?.type===`metadata`&&h?.status!==`in_progress`;x&&(m=!0,b===`user_stop`&&u!==`service_failed`&&u!==`quota_exceeded`&&(u=`user_stopped`,d=`user stopped`));let S=h?.status===`failed`;if(S){let e=rn(h);p=e??p,u=Rt(e)||an(b)?`quota_exceeded`:`service_failed`,d=nn(h)??(b?`stream failed: ${b}`:`stream failed`)}if(y){if(x||S||v)break;continue}if(r.done)break;if(s++,a>0&&(a=0),h?.role===`assistant`&&h?.type===`message`&&h?.status===`completed`&&typeof h?.content==`string`&&h.content&&(c=h.content),e.onEvent&&e.onEvent(r,{lastEventId:i,reconnectCount:o})===!1){g=!0;break}}}catch(e){if(!m){let t=e instanceof Error?e.message:String(e);if(/\b4[0-9]{2}\b/.test(t)||t.includes(`业务错误`))return{totalEvents:s,reconnectCount:o,lastEventId:i,finalText:c,logId:l,terminalReason:`service_failed`,finishReasonRaw:f,errorCodeRaw:p,success:!1,error:t};h=!0}}if(g)break;if(u===`service_failed`||u===`quota_exceeded`)return{totalEvents:s,reconnectCount:o,lastEventId:i,finalText:c,logId:l,terminalReason:u,finishReasonRaw:f,errorCodeRaw:p,success:!1,error:d??`stream failed`};if(u===`user_stopped`)break;if(s===0&&!m&&!h)return{totalEvents:s,reconnectCount:o,lastEventId:i,finalText:c,logId:l,terminalReason:`stream_interrupted`,finishReasonRaw:f,errorCodeRaw:p,success:!1,error:`stream returned no events`};if(m){u??=`completed`;break}if(h||i){if(a++,o++,a<=t&&o<=n&&i){if(e.onReconnect?.(o,i),await new Promise(t=>{let n=setTimeout(t,r);e.signal&&e.signal.addEventListener(`abort`,()=>{clearTimeout(n),t()},{once:!0})}),e.signal?.aborted)return{totalEvents:s,reconnectCount:o,lastEventId:i,finalText:c,logId:l,terminalReason:`stream_interrupted`,finishReasonRaw:f,errorCodeRaw:p,success:!1,error:`cancelled`};continue}let u=`stream disconnected, reconnect exhausted`;return e.onFailed?.(u),{totalEvents:s,reconnectCount:o,lastEventId:i,finalText:c,logId:l,terminalReason:`stream_interrupted`,finishReasonRaw:f,errorCodeRaw:p,success:!1,error:u}}break}return u===`completed`&&e.onComplete?.({totalEvents:s,reconnectCount:o,lastEventId:i}),{totalEvents:s,reconnectCount:o,lastEventId:i,finalText:c,logId:l,terminalReason:u,finishReasonRaw:f,errorCodeRaw:p,success:!u||u===`completed`,error:u===`user_stopped`?d:void 0}}let cn=``,ln=0;function un(e){try{let t=dn(e);if(!t)return null;let n=t.replace(/\s*\(.*\)$/,``).replace(/\s*:.*$/,``),r=Date.now();return n===cn&&r-ln<3e4?null:(cn=n,ln=r,t)}catch{return null}}function dn(e){let t=e.role,n=e.tool_calls,r=e.content;if(e.finish_reason,t===`assistant`&&n?.length)for(let e of n){let t=e?.function?.name??e?.name,n={};try{let t=e?.function?.arguments??e?.arguments;n=typeof t==`string`?JSON.parse(t):t??{}}catch{}if(t===`bash`){let e=String(n.command??``);if(e.includes(`init`))return`初始化项目`;if(e.includes(`db sql`))return`数据库操作`;if(e.includes(`deploy`))return`部署中`}}return t===`tool`&&typeof r==`string`&&(r.startsWith(`执行 run_shell_command 工具失败`)||r.startsWith(`command exitcode:`))?`失败: ${r.slice(0,200)+(r.length>200?`...`:``)}`:null}const fn=`.spark`,pn=new Intl.DateTimeFormat(`en-CA`,{timeZone:`Asia/Shanghai`,year:`numeric`,month:`2-digit`,day:`2-digit`,hour:`2-digit`,minute:`2-digit`,second:`2-digit`,hour12:!1,timeZoneName:`longOffset`});async function mn(e){return(await Pt(`**/SKILL.md`,{cwd:e,followSymbolicLinks:!0}).catch(()=>[])).length>0}async function hn(e){try{return JSON.parse(await f(c(e,`.spark`,`meta.json`),`utf8`))}catch{return null}}async function gn(e,t){if(!await mn(c(e,`.agent`,`skills`)))return`.agent/skills 下未找到 SKILL.md,项目 Agent 技能未配置`;let n=await hn(e)??(t?await hn(t):null);return n?!n.stack||!n.version?`.spark/meta.json 缺少 stack 或 version 字段`:null:`缺少 .spark/meta.json,项目未初始化`}function _n(e){return c(e,fn,`progress.txt`)}function vn(){let e=Object.fromEntries(pn.formatToParts(new Date).filter(e=>e.type!==`literal`).map(e=>[e.type,e.value])),t=e.timeZoneName===`GMT`?`+00:00`:e.timeZoneName.replace(/^GMT/,``);return`${e.year}-${e.month}-${e.day}T${e.hour}:${e.minute}:${e.second}${t}`}function yn(e){let t=[],n=``,r=``,i=``,a=e.includes(`## 已完成`)||e.includes(`## 当前任务`),o=!1,s=!a;for(let c of e.split(`
|
package/package.json
CHANGED
|
@@ -4,6 +4,12 @@ description: 创建数据库、建表、执行 SQL、查询数据、查看表结
|
|
|
4
4
|
---
|
|
5
5
|
# Database Skill
|
|
6
6
|
|
|
7
|
+
## 路由前置检查(必读)
|
|
8
|
+
|
|
9
|
+
**每一次**执行 `db init / sql / schema` 等命令前,**必须遵守 `structured-storage-router` skill 的决策规则**,仅当本轮路由结果是 `database` 时再回到本 skill 继续。**不要因为上一轮 query 已经走过路由、已经选了数据库就省略本轮的判定**——每次 query 独立判断。
|
|
10
|
+
|
|
11
|
+
---
|
|
12
|
+
|
|
7
13
|
本技能指导 Agent 通过 `miaoda-data-cli db` 命令操作数据库,包括:
|
|
8
14
|
- **db sql**:执行 SQL 语句(DDL/SELECT/DML)
|
|
9
15
|
- **db schema**:查看数据库表结构(默认 DDL,`--json` 输出结构化 JSON)
|
|
@@ -0,0 +1,138 @@
|
|
|
1
|
+
---
|
|
2
|
+
name: structured-storage-router
|
|
3
|
+
description: 结构化数据存储路由。当用户要求记录、存储、整理、保存数据(如建表、记录客户信息、整理反馈、存档名单等)时使用。判断意图明确性,引导优先使用数据库(便于沉淀成完整应用),含糊时读取历史偏好或询问用户后路由到 miaoda-database-skill 或 feishu-bitable。不自己执行存储动作。
|
|
4
|
+
---
|
|
5
|
+
|
|
6
|
+
# 结构化存储路由
|
|
7
|
+
|
|
8
|
+
**核心原则**:
|
|
9
|
+
|
|
10
|
+
1. 本 skill 只做路由决策,不执行任何存储动作。实际存储由 `miaoda-database-skill` 或 `feishu-bitable` 完成。
|
|
11
|
+
2. **每次用户发起新的结构化存储需求时,都必须从 §1 重新走完整判定流程**。是否跳过询问、是否需要告知,**仅由本次 query 的明确性(关键词白名单)+ 当前偏好记忆决定**,**不要因为上一轮 query 已经问过 / 已经选过而省略本轮的判断和告知**。
|
|
12
|
+
- 例:上一轮 query1 用户选了数据库,本轮 query2 仍是含糊的"再建一张客户表"——本轮**仍需走 §4**:读偏好(此时 db=1, bitable=0,差值=1 还不到 2)→ 仍需询问用户。**绝不能因为上一轮选了数据库就默认本轮也走数据库**。
|
|
13
|
+
- 唯一能跳过 §4 的两种情况:(a) 本轮 query 命中明确数据库/多维表格的关键词;(b) 偏好记忆差值 ≥ 2(此时仍需输出告知话术)。
|
|
14
|
+
|
|
15
|
+
## 何时使用本 skill
|
|
16
|
+
|
|
17
|
+
**触发条件**(同时满足):
|
|
18
|
+
- 用户有明确的结构化数据存储诉求(记录、整理、存储、建档等)
|
|
19
|
+
- 用户未指定具体载体(未提到数据库、SQL、多维表格、bitable、飞书表格等关键词)
|
|
20
|
+
|
|
21
|
+
**加载后自检**:如果**当前对话已在某一载体上继续作业**(例如正在修改已建好的数据库表、或正在往已有多维表格追加字段),**直接沿用当前载体,不介入决策树**,也不写记忆。
|
|
22
|
+
|
|
23
|
+
其他情况一律按下面的决策树执行。
|
|
24
|
+
|
|
25
|
+
---
|
|
26
|
+
|
|
27
|
+
## 第一步:意图分类
|
|
28
|
+
|
|
29
|
+
判定原则:**"表 / 字段 / 建表 / 数据表 / 一张表"等词在中文里数据库和多维表格都用,单凭这些词不能判明确**。只有用户**主动出现下列任一关键词**才算明确:
|
|
30
|
+
|
|
31
|
+
- 明确数据库:`SQL` / `数据库` / `db` / `Postgres` / `DDL` / `DML` / `建表语句`
|
|
32
|
+
- 明确多维表格:`多维表格` / `bitable` / `飞书表格` / `飞书多维表`
|
|
33
|
+
|
|
34
|
+
其他全部按**含糊意图**处理(即使提到"建表/字段"也算含糊),进入 §4。
|
|
35
|
+
|
|
36
|
+
**明确数据库**(直接走 §2):
|
|
37
|
+
- "用 SQL 查一下订单记录"
|
|
38
|
+
- "把这些数据存到数据库里"
|
|
39
|
+
- "用 Postgres 建一张订单表"
|
|
40
|
+
- "给我写个建表语句"
|
|
41
|
+
- "执行这个 DDL"
|
|
42
|
+
|
|
43
|
+
**明确多维表格**(直接走 §3):
|
|
44
|
+
- "帮我在飞书表格里记一下这些反馈"
|
|
45
|
+
- "做个多维表格来管理这些客户"
|
|
46
|
+
- "建个 bitable 追踪这些任务"
|
|
47
|
+
- "我要在多维表格里存这些数据"
|
|
48
|
+
- "用飞书多维表整理一下这份名单"
|
|
49
|
+
|
|
50
|
+
**含糊意图**(走 §4,包括所有"只说建表/字段但未指明载体"的场景):
|
|
51
|
+
- "创建一张客户信息表,包含公司名、联系人、电话、合作等级"
|
|
52
|
+
- "建一张用户表,有姓名、电话、备注字段"
|
|
53
|
+
- "帮我建一个表存放客户信息"
|
|
54
|
+
- "帮我记录最近联系过的客户"
|
|
55
|
+
- "把这些需求反馈整理存起来"
|
|
56
|
+
- "把这份名单存下来"
|
|
57
|
+
- "整理一下这些采购记录"
|
|
58
|
+
- "你决定/看着来就行,帮我把这些数据存一下"
|
|
59
|
+
- "哪个方便用哪个,帮我建个地方记客户"
|
|
60
|
+
|
|
61
|
+
不确定时,按含糊意图处理,进入 §4。
|
|
62
|
+
|
|
63
|
+
---
|
|
64
|
+
|
|
65
|
+
## §2 明确数据库路径
|
|
66
|
+
|
|
67
|
+
使用 `miaoda-database-skill` 完成操作。不读取、不写入倾向记忆。
|
|
68
|
+
|
|
69
|
+
---
|
|
70
|
+
|
|
71
|
+
## §3 明确多维表格路径
|
|
72
|
+
|
|
73
|
+
使用 `feishu-bitable`(属于 `openclaw-lark` 扩展)完成操作。不读取、不写入倾向记忆。
|
|
74
|
+
|
|
75
|
+
---
|
|
76
|
+
|
|
77
|
+
## §4 含糊意图路径
|
|
78
|
+
|
|
79
|
+
### §4.1 读取当前倾向
|
|
80
|
+
|
|
81
|
+
从记忆中查找以 `结构化存储偏好:` 开头的记录,期望格式为:
|
|
82
|
+
|
|
83
|
+
```
|
|
84
|
+
结构化存储偏好: db=<非负整数>, bitable=<非负整数>
|
|
85
|
+
```
|
|
86
|
+
|
|
87
|
+
具体使用哪个 memory tool(`memory_get` / `memory_search` / `memory_store` 或其他)由 agent 根据手头可用的工具自行决定。查找时优先检查 system prompt 里已注入的记忆;若未注入,则主动调用 memory 工具按前缀搜索一次。
|
|
88
|
+
|
|
89
|
+
找不到记录时,`db` 和 `bitable` 均视作 0。字段缺失或非整数时,该字段按 0 处理。
|
|
90
|
+
|
|
91
|
+
匹配前缀时兼容中英文冒号(`:` 和 `:`)以及前后空格。**写回时统一使用英文冒号加一个空格**(即 `结构化存储偏好: db=X, bitable=Y`),确保跨次运行稳定可召回。
|
|
92
|
+
|
|
93
|
+
### §4.2 判定
|
|
94
|
+
|
|
95
|
+
计算 `diff = abs(db - bitable)`:
|
|
96
|
+
|
|
97
|
+
- 若 `diff >= 2`:确定有历史倾向。按优势方走(db 更大走数据库,bitable 更大走多维表格),并在回复首句加一句告知话术。**原文使用,不得自由改写,不得保留方括号**。按 choice 选其中一条:
|
|
98
|
+
|
|
99
|
+
- 若走数据库:
|
|
100
|
+
> 根据你的历史偏好,这次用**数据库**;如需换成多维表格,请直接告诉我。
|
|
101
|
+
|
|
102
|
+
- 若走多维表格:
|
|
103
|
+
> 根据你的历史偏好,这次用**多维表格**;如需换成数据库,请直接告诉我。
|
|
104
|
+
|
|
105
|
+
然后路由到对应 skill 执行。**不写入记忆。**
|
|
106
|
+
|
|
107
|
+
**短路**:若用户本轮已主动明示 "你决定 / 看着来 / 哪个方便用哪个" 等**委托决定**的措辞,且 diff < 2(无倾向),**直接默认 `choice = database` 路由并告知**(使用 §4.4 的默认告知话术),**跳过 §4.3 询问**,**不写记忆**(委托决定不是主动选择)。
|
|
108
|
+
|
|
109
|
+
- 若 `diff < 2`(且用户无委托决定措辞):无明显倾向,进入 §4.3 询问用户。
|
|
110
|
+
|
|
111
|
+
### §4.3 标准询问话术
|
|
112
|
+
|
|
113
|
+
原文使用,不得自由改写:
|
|
114
|
+
|
|
115
|
+
> 这个需求我可以用两种方式存:
|
|
116
|
+
> - **数据库**(推荐长期使用,未来可以直接沉淀成一个完整的小应用)
|
|
117
|
+
> - **多维表格**(飞书里可以直接打开查看编辑)
|
|
118
|
+
>
|
|
119
|
+
> 你倾向哪种?
|
|
120
|
+
|
|
121
|
+
等待用户答复后,进入 §4.4。
|
|
122
|
+
|
|
123
|
+
### §4.4 接收答复并写记忆
|
|
124
|
+
|
|
125
|
+
**解析用户 choice**:
|
|
126
|
+
|
|
127
|
+
- 用户说"数据库""db""第一个"等 → `choice = database`
|
|
128
|
+
- 用户说"多维表格""bitable""飞书表格""第二个"等 → `choice = bitable`
|
|
129
|
+
- 答复含糊或委托 agent 决定("随便""都行""你决定""看情况"等) → 默认 `choice = database`,并告知:
|
|
130
|
+
|
|
131
|
+
> 好的,那就用数据库来存,以后方便沉淀成完整应用。
|
|
132
|
+
|
|
133
|
+
**写记忆**:
|
|
134
|
+
|
|
135
|
+
1. 沿用 §4.1 已读出的 `db` 和 `bitable` 值
|
|
136
|
+
2. 按 choice 给对应方 +1
|
|
137
|
+
3. 用 agent 手头可用的 memory tool 将偏好记录**覆盖写回**:`结构化存储偏好: db=<新值>, bitable=<新值>`。若已有同前缀记录则更新,否则新建
|
|
138
|
+
4. 按 choice 路由到对应 skill(`database` → `miaoda-database-skill`;`bitable` → `feishu-bitable`)执行存储
|