@dahawa/hawa-code 2.8.9 → 2.8.10

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/cli.js CHANGED
@@ -652,7 +652,7 @@ globstar while`,e,d,t,f,p),this.matchOne(e.slice(d),t.slice(f),r))return this.de
652
652
  `)),Ezr(e,i,{encoding:r,flush:!0})}var Cot=new $j.default({fetchMethod:e=>vzr(e),ttl:300*1e3,ttlAutopurge:!1,max:1e3});async function Dot(e){let t=SU(e);return Cot.get(t)||Cot.fetchMethod?.(t)}async function vzr(e){let t=new AbortController;setTimeout(()=>{t.abort()},1e3);let r=await Yet(e,t.signal,15),n=0;for(let i of r)D1(i)==="CRLF"&&n++;return n>3?"CRLF":"LF"}function Oot(e,t,r){if(e.has(t))return e.get(t);let n=r();return e.set(t,n),n}var xzr=new $j.default({fetchMethod:e=>Bot(e),ttl:300*1e3,ttlAutopurge:!1,max:1e3});function Hd(e){let t=SU(e);return Oot(xzr,t,()=>Bot(t))}function Bot(e){let r=Buffer.alloc(4096),n;try{n=Tot(e,"r");let i=Iot(n,r,0,4096,0);return i===0?"utf8":i>=2&&r[0]===255&&r[1]===254?"utf16le":i>=3&&r[0]===239&&r[1]===187&&r[2]===191||r.slice(0,i).toString("utf8").length>0?"utf8":"ascii"}catch(i){return Ee(`Error detecting encoding for file ${e}: ${i}`),"utf8"}finally{n&&vot(n)}}var wzr=new $j.default({fetchMethod:e=>Mot(e),ttl:300*1e3,ttlAutopurge:!1,max:1e3});function D1(e){let t=SU(e);return Oot(wzr,t,()=>Mot(t))}function Mot(e,t="utf8"){try{if(!xot(e).isFile())return"LF";let n=Buffer.alloc(4096),i=Tot(e,"r"),o=Iot(i,n,0,4096,0);vot(i);let s=n.toString(t,0,o),a=0,l=0;for(let c=0;c<s.length;c++)s[c]===`
653
653
  `&&(c>0&&s[c-1]==="\r"?a++:l++);return a>l?"CRLF":"LF"}catch(r){return Ee(`Error detecting line endings for file ${e}: ${r}`),"LF"}}function pB(e){let t=wot(e)?e:SU(De(),e);return t.endsWith(" AM.png")?t.replace(" AM.png","\u202FAM.png"):t.endsWith(" PM.png")?t.replace(" PM.png","\u202FPM.png"):t}function $_e(e){return e?wot(e)?e:SU(De(),e):void 0}function kot(e){try{let t=$_e(e),r=t?Czr(De(),t):void 0;return{absolutePath:t,relativePath:r}}catch(t){return X("getAbsoluteAndRelativePaths error ",t),{absolutePath:null,relativePath:null}}}function Yj(e){try{let t=Tzr(e),r=Sot(e,bot(e));if(!Szr(t))return;let o=bzr(t).filter(s=>Sot(s,bot(s))===r&&Izr(t,s)!==e)[0];return o||void 0}catch(t){Ee(`Error finding similar file for ${e}: ${t}`);return}}function q_e(){let e=process.env.HAWA_CODE_COMPACT_LINE_PREFIX;return!(e==="0"||e==="false")}function sC({content:e,startLine:t}){if(!e)return"";let r=e.split(/\r?\n/);return q_e()?r.map((n,i)=>`${i+t} ${n}`).join(`
654
654
  `):r.map((n,i)=>{let o=String(i+t);return o.length>=6?`${o}\u2192${n}`:`${o.padStart(6," ")}\u2192${n}`}).join(`
655
- `)}function Lot(e){try{let t=yzr(e),r=t.readSync();return t.closeSync(),r===null}catch(t){return Ee(`Error checking directory: ${t}`),!1}}Fe();function rC(){let e=Rn();e.hasCompletedProjectOnboarding||Ji({...e,hasCompletedProjectOnboarding:!0})}function Y_e({workspaceDir:e}){let r=!Rn().hasCompletedProjectOnboarding;if(!r)return null;let n=Rzr(Nzr(e,Pi)),i=Lot(e),o=!n&&!i,s=oB.isEnabled&&!zr().shiftEnterKeyBindingInstalled,a=oe();return(0,A.jsxs)(w,{flexDirection:"column",gap:1,padding:1,paddingBottom:0,children:[r&&(0,A.jsxs)(A.Fragment,{children:[(0,A.jsx)(I,{color:a.secondaryText,children:"Tips for getting started:"}),(0,A.jsx)(Ec,{children:(()=>{let l=[];return i&&l.push((0,A.jsx)(Ec.Item,{children:(0,A.jsxs)(I,{color:a.secondaryText,children:["Ask ",nt," to create a new app or clone a repository."]})},"workspace")),o&&l.push((0,A.jsx)(Ec.Item,{children:(0,A.jsxs)(I,{color:a.secondaryText,children:["Run ",(0,A.jsx)(I,{color:a.text,children:"/init"})," to create a",Pi," file with instructions for Hawa code."]})},"claudemd")),s&&l.push((0,A.jsx)(Ec.Item,{children:(0,A.jsxs)(I,{color:a.secondaryText,children:["Run ",(0,A.jsx)(I,{color:a.text,children:"/terminal-setup"}),(0,A.jsx)(I,{bold:!1,children:" to set up terminal integration"})]})},"terminal")),l.push((0,A.jsx)(Ec.Item,{children:(0,A.jsxs)(I,{color:a.secondaryText,children:["Ask ",nt," questions about your codebase."]})},"questions")),l.push((0,A.jsx)(Ec.Item,{children:(0,A.jsxs)(I,{color:a.secondaryText,children:["Ask ",nt," to implement changes to your codebase."]})},"changes")),l})()})]}),e===Dzr()&&(0,A.jsxs)(I,{color:oe().warning,children:["Note: You have launched ",(0,A.jsx)(I,{bold:!0,children:nt})," in your home directory. For the best experience, launch it in a project directory instead."]})]})}function z_e({isFocused:e,isSelected:t,smallPointer:r,children:n}){let{styles:i}=Ao("Select");return(0,A.jsxs)(w,{...i.option({isFocused:e}),children:[e&&(0,A.jsx)(I,{...i.focusIndicator(),children:r?nr.triangleDownSmall:nr.pointer}),(0,A.jsx)(I,{...i.label({isFocused:e,isSelected:t}),children:n}),t&&(0,A.jsx)(I,{...i.selectedIndicator(),children:nr.tick})]})}var $d=Ie(Ye(),1);import{isDeepStrictEqual as Ozr}from"node:util";var bU=class extends Map{first;constructor(t){let r=[],n,i,o=0;for(let s of t){let a={...s,previous:i,next:void 0,index:o};i&&(i.next=a),n||=a;let l="value"in s?s.value:V_e(s);r.push([l,a]),o++,i=a}super(r),this.first=n}};var Bzr=(e,t)=>{switch(t.type){case"focus-next-option":{if(!e.focusedValue)return e;let r=e.optionMap.get(e.focusedValue);if(!r)return e;let n=r.next;for(;n&&!("value"in n);)n=n.next;if(!n)return e;if(!(n.index>=e.visibleToIndex))return{...e,focusedValue:n.value};let o=Math.min(e.optionMap.size,e.visibleToIndex+1),s=o-e.visibleOptionCount;return{...e,focusedValue:n.value,visibleFromIndex:s,visibleToIndex:o}}case"focus-previous-option":{if(!e.focusedValue)return e;let r=e.optionMap.get(e.focusedValue);if(!r)return e;let n=r.previous;for(;n&&!("value"in n);)n=n.previous;if(!n)return e;if(!(n.index<=e.visibleFromIndex))return{...e,focusedValue:n.value};let o=Math.max(0,e.visibleFromIndex-1),s=o+e.visibleOptionCount;return{...e,focusedValue:n.value,visibleFromIndex:o,visibleToIndex:s}}case"select-focused-option":return{...e,previousValue:e.value,value:e.focusedValue};case"reset":return t.state;case"set-focus":return{...e,focusedValue:t.value}}},W_e=e=>e.flatMap(t=>{if("options"in t){let r=W_e(t.options),n=r.flatMap(o=>"value"in o?o.value:[]);return[...t.header!==void 0?[{header:t.header,optionValues:n}]:[],...r]}return t}),Pot=({visibleOptionCount:e,defaultValue:t,options:r})=>{let n=W_e(r),i=typeof e=="number"?Math.min(e,n.length):n.length,o=new bU(n),s=o.first,a=s&&"value"in s?s.value:void 0;return{optionMap:o,visibleOptionCount:i,focusedValue:a,visibleFromIndex:0,visibleToIndex:i,previousValue:t,value:t}},j_e=({visibleOptionCount:e=5,options:t,defaultValue:r,onChange:n,onFocus:i,focusValue:o})=>{let s=W_e(t),[a,l]=(0,$d.useReducer)(Bzr,{visibleOptionCount:e,defaultValue:r,options:t},Pot),[c,u]=(0,$d.useState)(s);s!==c&&!Ozr(s,c)&&(l({type:"reset",state:Pot({visibleOptionCount:e,defaultValue:r,options:t})}),u(s));let d=(0,$d.useCallback)(()=>{l({type:"focus-next-option"})},[]),f=(0,$d.useCallback)(()=>{l({type:"focus-previous-option"})},[]),p=(0,$d.useCallback)(()=>{l({type:"select-focused-option"})},[]),h=(0,$d.useMemo)(()=>s.map((_,E)=>({..._,index:E})).slice(a.visibleFromIndex,a.visibleToIndex),[s,a.visibleFromIndex,a.visibleToIndex]);return(0,$d.useEffect)(()=>{a.value&&a.previousValue!==a.value&&n?.(a.value)},[a.previousValue,a.value,t,n]),(0,$d.useEffect)(()=>{a.focusedValue&&i?.(a.focusedValue)},[a.focusedValue,i]),(0,$d.useEffect)(()=>{o&&l({type:"set-focus",value:o})},[o]),{focusedValue:a.focusedValue,visibleFromIndex:a.visibleFromIndex,visibleToIndex:a.visibleToIndex,value:a.value,visibleOptions:h,focusNextOption:d,focusPreviousOption:f,selectFocusedOption:p}};var K_e=({isDisabled:e=!1,state:t})=>{_t((r,n)=>{n.downArrow&&t.focusNextOption(),n.upArrow&&t.focusPreviousOption(),n.return&&t.selectFocusedOption()},{isActive:!e})};var V_e=e=>`HEADER-${e.optionValues.join(",")}`;function BS({isDisabled:e=!1,visibleOptionCount:t=5,highlightText:r,options:n,defaultValue:i,onChange:o,onFocus:s,focusValue:a}){let l=j_e({visibleOptionCount:t,options:n,defaultValue:i,onChange:o,onFocus:s,focusValue:a});K_e({isDisabled:e,state:l});let{styles:c}=Ao("Select");return(0,A.jsx)(w,{...c.container(),children:l.visibleOptions.map(u=>{let d="value"in u?u.value:V_e(u),f=!e&&l.focusedValue!==void 0&&("value"in u?l.focusedValue===u.value:u.optionValues.includes(l.focusedValue)),p=!!l.value&&("value"in u?l.value===u.value:u.optionValues.includes(l.value)),h="header"in u,_="label"in u?u.label:u.header,E=_;if(r&&_.includes(r)){let b=_.indexOf(r);E=(0,A.jsxs)(A.Fragment,{children:[_.slice(0,b),(0,A.jsx)(I,{...c.highlightedText(),children:r}),_.slice(b+r.length)]})}return(0,A.jsx)(z_e,{isFocused:f,isSelected:p,smallPointer:h,children:E},d)})})}function Fot({onDone:e}){return _t((t,r)=>{(r.ctrl&&(t==="c"||t==="d")||r.escape)&&e()}),(0,A.jsxs)(w,{flexDirection:"column",borderStyle:"round",padding:1,borderColor:oe().secondaryBorder,children:[(0,A.jsx)(w,{marginBottom:1,flexDirection:"column",children:(0,A.jsx)(I,{bold:!0,children:"You've spent $5 this session."})}),(0,A.jsx)(w,{children:(0,A.jsx)(BS,{options:[{value:"ok",label:"Got it, thanks!"}],onChange:e})})]})}var vr=Ie(Ye(),1);Fe();mr();WA();var Lzr="2.8.9",MS={VERSION:Lzr,PACKAGE_URL:"@dahawa/hawa-code",README_URL:"https://github.com/italking/hawa-code",ISSUES_EXPLAINER:"report the issue at https://github.com/italking/hawa-code/issues"};var X_e=46,Got=["(\u2740\u2579\u25E1\u2579)","(\u25D5\u072B\u25D5)","\u239D(\u25D5u\u25D5)\u23A0","\u10DA(\u25C9\u25DE\u0C6A\u25DF\u25C9 )\u10DA","(\xB4\u25C9\u203F\u25C9\uFF40)","\u0E01\u0E47\u0295\u2022\u0361\u1D25\u2022\u0294 \u0E01\u0E49","\uFF0F/( \u25D5\u203F\u203F\u25D5 )\uFF3C"];function zj({isDefaultModel:e=!1}){let t=Math.max(X_e,De().length+12),r=oe(),n=Got[Math.floor(Math.random()*Got.length)];return(0,A.jsx)(w,{flexDirection:"column",children:(0,A.jsxs)(w,{flexDirection:"column",gap:1,paddingLeft:1,width:"100%",children:[(0,A.jsxs)(I,{children:[(0,A.jsx)(I,{children:n})," Welcome to"," ",(0,A.jsx)(I,{bold:!0,children:nt}),(0,A.jsxs)(I,{color:r.secondaryText,children:[" v",MS.VERSION]})]}),(0,A.jsx)(A.Fragment,{children:(0,A.jsxs)(w,{paddingLeft:2,flexDirection:"column",gap:1,children:[(0,A.jsx)(I,{color:r.secondaryText,italic:!0,children:"/help for help"}),(0,A.jsxs)(I,{color:r.secondaryText,children:["cwd: ",De()]}),(0,A.jsxs)(I,{color:r.secondaryText,children:["model: ",Wn.getConfig().routing.MODEL?.map(i=>`${i.source}__${i.model}`).join(", ")??"N/A"]}),(0,A.jsxs)(I,{color:r.secondaryText,children:["small fast model: ",Wn.getConfig().routing.SMALL_FAST_MODEL?.map(i=>`${i.source}__${i.model}`).join(", ")??"N/A"]})]})})]})})}Te();import{randomUUID as Mg}from"crypto";wo();Te();cr();mr();Te();Fe();import{existsSync as PS,readdirSync as dKr,statSync as pKr}from"fs";import{join as dC,relative as mKr}from"path";import{homedir as Mlt}from"os";import{platform as fKr}from"process";import{readFile as pC}from"fs/promises";mr();rm();Jt();import{join as Hzr,sep as $zr}from"path";function Wu(){if(!Sc())return!1;try{let e=Ve();if(e.autoMemory?.teamMemoryEnabled!==void 0)return e.autoMemory.teamMemoryEnabled}catch{}return!1}function qd(){return(Hzr(De(),".hcode","team-memory")+$zr).normalize("NFC")}function Lf(e){let t=e.normalize("NFC"),r=qd();return t.startsWith(r)}rm();var klt=Ie(NU(),1);li();var AEe=(e,t,r)=>{let n=e instanceof RegExp?llt(e,r):e,i=t instanceof RegExp?llt(t,r):t,o=n!==null&&i!=null&&tjr(n,i,r);return o&&{start:o[0],end:o[1],pre:r.slice(0,o[0]),body:r.slice(o[0]+n.length,o[1]),post:r.slice(o[1]+i.length)}},llt=(e,t)=>{let r=t.match(e);return r?r[0]:null},tjr=(e,t,r)=>{let n,i,o,s,a,l=r.indexOf(e),c=r.indexOf(t,l+1),u=l;if(l>=0&&c>0){if(e===t)return[l,c];for(n=[],o=r.length;u>=0&&!a;){if(u===l)n.push(u),l=r.indexOf(e,u+1);else if(n.length===1){let d=n.pop();d!==void 0&&(a=[d,c])}else i=n.pop(),i!==void 0&&i<o&&(o=i,s=c),c=r.indexOf(t,u+1);u=l<c&&l>=0?l:c}n.length&&s!==void 0&&(a=[o,s])}return a};var clt="\0SLASH"+Math.random()+"\0",ult="\0OPEN"+Math.random()+"\0",SEe="\0CLOSE"+Math.random()+"\0",dlt="\0COMMA"+Math.random()+"\0",plt="\0PERIOD"+Math.random()+"\0",rjr=new RegExp(clt,"g"),njr=new RegExp(ult,"g"),ijr=new RegExp(SEe,"g"),ojr=new RegExp(dlt,"g"),sjr=new RegExp(plt,"g"),ajr=/\\\\/g,ljr=/\\{/g,cjr=/\\}/g,ujr=/\\,/g,djr=/\\\./g,pjr=1e5,mjr=4e6;function _Ee(e){return isNaN(e)?e.charCodeAt(0):parseInt(e,10)}function fjr(e){return e.replace(ajr,clt).replace(ljr,ult).replace(cjr,SEe).replace(ujr,dlt).replace(djr,plt)}function gjr(e){return e.replace(rjr,"\\").replace(njr,"{").replace(ijr,"}").replace(ojr,",").replace(sjr,".")}function mlt(e){if(!e)return[""];let t=[],r=AEe("{","}",e);if(!r)return e.split(",");let{pre:n,body:i,post:o}=r,s=n.split(",");s[s.length-1]+="{"+i+"}";let a=mlt(o);return o.length&&(s[s.length-1]+=a.shift(),s.push.apply(s,a)),t.push.apply(t,s),t}function flt(e,t={}){if(!e)return[];let{max:r=pjr,maxLength:n=mjr}=t;return e.slice(0,2)==="{}"&&(e="\\{\\}"+e.slice(2)),EEe(fjr(e),r,n,!0).map(gjr)}function hjr(e){return"{"+e+"}"}function Ajr(e){return/^-?0\d/.test(e)}function _jr(e,t){return e<=t}function Ejr(e,t){return e>=t}function DU(e,t,r,n,i,o){let s=[],a=0;for(let l=0;l<e.length;l++)for(let c=0;c<r.length;c++){if(s.length>=n)return s;let u=e[l]+t+r[c];if(!(o&&!u)){if(a+u.length>i)return s;s.push(u),a+=u.length}}return s}function Sjr(e,t,r,n){let i=e.split(/\.\./),o=[];if(i[0]===void 0||i[1]===void 0)return o;let s=_Ee(i[0]),a=_Ee(i[1]),l=Math.max(i[0].length,i[1].length),c=i.length===3&&i[2]!==void 0?Math.max(Math.abs(_Ee(i[2])),1):1,u=_jr;a<s&&(c*=-1,u=Ejr);let f=i.some(Ajr),p=0;for(let h=s;u(h,a)&&o.length<r;h+=c){let _;if(t)_=String.fromCharCode(h),_==="\\"&&(_="");else if(_=String(h),f){let E=l-_.length;if(E>0){let b=new Array(E+1).join("0");h<0?_="-"+b+_.slice(1):_=b+_}}if(p+_.length>n)break;o.push(_),p+=_.length}return o}function EEe(e,t,r,n){let i=[""],o=!1,s=!0;for(;;){let a=AEe("{","}",e);if(!a)return DU(i,e,[""],t,r,o);let l=a.pre;if(/\$$/.test(l)){if(i=DU(i,l+"{"+a.body+"}",[""],t,r,o&&!a.post.length),s=!1,!a.post.length)break;e=a.post;continue}let c=/^-?\d+\.\.-?\d+(?:\.\.-?\d+)?$/.test(a.body),u=/^[a-zA-Z]\.\.[a-zA-Z](?:\.\.-?\d+)?$/.test(a.body),d=c||u,f=a.body.indexOf(",")>=0;if(!d&&!f){if(a.post.match(/,(?!,).*\}/)){e=a.pre+"{"+a.body+SEe+a.post,n=!0;continue}return DU(i,l+"{"+a.body+"}"+a.post,[""],t,r,o)}s&&(o=n&&!d,s=!1);let p;if(d)p=Sjr(a.body,u,t,r);else{let h=mlt(a.body);if(h.length===1&&h[0]!==void 0&&(h=EEe(h[0],t,r,!1).map(hjr),h.length===1)){if(i=DU(i,l+h[0],[""],t,r,o&&!a.post.length),!a.post.length)break;e=a.post;continue}let _=o&&!a.post.length&&!l;for(let b=0;_&&b<i.length;b++)i[b]&&(_=!1);p=[];let E=0;e:for(let b=0;b<h.length;b++){let C=EEe(h[b],t,r,!1);for(let v=0;v<C.length;v++){let R=C[v];if(!(_&&!R)){if(p.length>=t||E+R.length>r)break e;p.push(R),E+=R.length}}}}if(i=DU(i,l,p,t,r,o&&!a.post.length),!a.post.length)break;e=a.post}return i}var OU=e=>{if(typeof e!="string")throw new TypeError("invalid pattern");if(e.length>65536)throw new TypeError("pattern is too long")};var bjr={"[:alnum:]":["\\p{L}\\p{Nl}\\p{Nd}",!0],"[:alpha:]":["\\p{L}\\p{Nl}",!0],"[:ascii:]":["\\x00-\\x7f",!1],"[:blank:]":["\\p{Zs}\\t",!0],"[:cntrl:]":["\\p{Cc}",!0],"[:digit:]":["\\p{Nd}",!0],"[:graph:]":["\\p{Z}\\p{C}",!0,!0],"[:lower:]":["\\p{Ll}",!0],"[:print:]":["\\p{C}",!0],"[:punct:]":["\\p{P}",!0],"[:space:]":["\\p{Z}\\t\\r\\n\\v\\f",!0],"[:upper:]":["\\p{Lu}",!0],"[:word:]":["\\p{L}\\p{Nl}\\p{Nd}\\p{Pc}",!0],"[:xdigit:]":["A-Fa-f0-9",!1]},BU=e=>e.replace(/[[\]\\-]/g,"\\$&"),yjr=e=>e.replace(/[-[\]{}()*+?.,\\^$|#\s]/g,"\\$&"),glt=e=>e.join(""),hlt=(e,t)=>{let r=t;if(e.charAt(r)!=="[")throw new Error("not in a brace expression");let n=[],i=[],o=r+1,s=!1,a=!1,l=!1,c=!1,u=r,d="";e:for(;o<e.length;){let _=e.charAt(o);if((_==="!"||_==="^")&&o===r+1){c=!0,o++;continue}if(_==="]"&&s&&!l){u=o+1;break}if(s=!0,_==="\\"&&!l){l=!0,o++;continue}if(_==="["&&!l){for(let[E,[b,C,v]]of Object.entries(bjr))if(e.startsWith(E,o)){if(d)return["$.",!1,e.length-r,!0];o+=E.length,v?i.push(b):n.push(b),a=a||C;continue e}}if(l=!1,d){_>d?n.push(BU(d)+"-"+BU(_)):_===d&&n.push(BU(_)),d="",o++;continue}if(e.startsWith("-]",o+1)){n.push(BU(_+"-")),o+=2;continue}if(e.startsWith("-",o+1)){d=_,o+=2;continue}n.push(BU(_)),o++}if(u<o)return["",!1,0,!1];if(!n.length&&!i.length)return["$.",!1,e.length-r,!0];if(i.length===0&&n.length===1&&/^\\?.$/.test(n[0])&&!c){let _=n[0].length===2?n[0].slice(-1):n[0];return[yjr(_),!1,u-r,!1]}let f="["+(c?"^":"")+glt(n)+"]",p="["+(c?"":"^")+glt(i)+"]";return[n.length&&i.length?"("+f+"|"+p+")":n.length?f:p,a,u-r,!0]};var uC=(e,{windowsPathsNoEscape:t=!1,magicalBraces:r=!0}={})=>r?t?e.replace(/\[([^/\\])\]/g,"$1"):e.replace(/((?!\\).|^)\[([^/\\])\]/g,"$1$2").replace(/\\([^/])/g,"$1"):t?e.replace(/\[([^/\\{}])\]/g,"$1"):e.replace(/((?!\\).|^)\[([^/\\{}])\]/g,"$1$2").replace(/\\([^/{}])/g,"$1");var zd,Cjr=new Set(["!","?","+","*","@"]),bEe=e=>Cjr.has(e),Alt=e=>bEe(e.type),Tjr=new Map([["!",["@"]],["?",["?","@"]],["@",["@"]],["*",["*","+","?","@"]],["+",["+","@"]]]),Ijr=new Map([["!",["?"]],["@",["?"]],["+",["?","*"]]]),vjr=new Map([["!",["?","@"]],["?",["?","@"]],["@",["?","@"]],["*",["*","+","?","@"]],["+",["+","@","?","*"]]]),_lt=new Map([["!",new Map([["!","@"]])],["?",new Map([["*","*"],["+","*"]])],["@",new Map([["!","!"],["?","?"],["@","@"],["*","*"],["+","+"]])],["+",new Map([["?","*"],["*","*"]])]]),xjr="(?!(?:^|/)\\.\\.?(?:$|/))",iK="(?!\\.)",wjr=new Set(["[","."]),Rjr=new Set(["..","."]),Njr=new Set("().*{}+?[]^$\\!"),Djr=e=>e.replace(/[-[\]{}()*+?.,\\^$|#\s]/g,"\\$&"),yEe="[^/]",Elt=yEe+"*?",Slt=yEe+"+?",Ojr=0,Q1=class{type;#e;#t;#n=!1;#r=[];#o;#i;#l;#s=!1;#a;#d;#m=!1;id=++Ojr;get depth(){return(this.#o?.depth??-1)+1}[Symbol.for("nodejs.util.inspect.custom")](){return{"@@type":"AST",id:this.id,type:this.type,root:this.#e.id,parent:this.#o?.id,depth:this.depth,partsLength:this.#r.length,parts:this.#r}}constructor(t,r,n={}){this.type=t,t&&(this.#t=!0),this.#o=r,this.#e=this.#o?this.#o.#e:this,this.#a=this.#e===this?n:this.#e.#a,this.#l=this.#e===this?[]:this.#e.#l,t==="!"&&!this.#e.#s&&this.#l.push(this),this.#i=this.#o?this.#o.#r.length:0}get hasMagic(){if(this.#t!==void 0)return this.#t;for(let t of this.#r)if(typeof t!="string"&&(t.type||t.hasMagic))return this.#t=!0;return this.#t}toString(){return this.#d!==void 0?this.#d:this.type?this.#d=this.type+"("+this.#r.map(t=>String(t)).join("|")+")":this.#d=this.#r.map(t=>String(t)).join("")}#p(){if(this!==this.#e)throw new Error("should only call on root");if(this.#s)return this;this.toString(),this.#s=!0;let t;for(;t=this.#l.pop();){if(t.type!=="!")continue;let r=t,n=r.#o;for(;n;){for(let i=r.#i+1;!n.type&&i<n.#r.length;i++)for(let o of t.#r){if(typeof o=="string")throw new Error("string part in extglob AST??");o.copyIn(n.#r[i])}r=n,n=r.#o}}return this}push(...t){for(let r of t)if(r!==""){if(typeof r!="string"&&!(r instanceof zd&&r.#o===this))throw new Error("invalid part: "+r);this.#r.push(r)}}toJSON(){let t=this.type===null?this.#r.slice().map(r=>typeof r=="string"?r:r.toJSON()):[this.type,...this.#r.map(r=>r.toJSON())];return this.isStart()&&!this.type&&t.unshift([]),this.isEnd()&&(this===this.#e||this.#e.#s&&this.#o?.type==="!")&&t.push({}),t}isStart(){if(this.#e===this)return!0;if(!this.#o?.isStart())return!1;if(this.#i===0)return!0;let t=this.#o;for(let r=0;r<this.#i;r++){let n=t.#r[r];if(!(n instanceof zd&&n.type==="!"))return!1}return!0}isEnd(){if(this.#e===this||this.#o?.type==="!")return!0;if(!this.#o?.isEnd())return!1;if(!this.type)return this.#o?.isEnd();let t=this.#o?this.#o.#r.length:0;return this.#i===t-1}copyIn(t){typeof t=="string"?this.push(t):this.push(t.clone(this))}clone(t){let r=new zd(this.type,t);for(let n of this.#r)r.copyIn(n);return r}static#c(t,r,n,i,o){let s=i.maxExtglobRecursion??2,a=!1,l=!1,c=-1,u=!1;if(r.type===null){let _=n,E="";for(;_<t.length;){let b=t.charAt(_++);if(a||b==="\\"){a=!a,E+=b;continue}if(l){_===c+1?(b==="^"||b==="!")&&(u=!0):b==="]"&&!(_===c+2&&u)&&(l=!1),E+=b;continue}else if(b==="["){l=!0,c=_,u=!1,E+=b;continue}if(!i.noext&&bEe(b)&&t.charAt(_)==="("&&o<=s){r.push(E),E="";let v=new zd(b,r);_=zd.#c(t,v,_,i,o+1),r.push(v);continue}E+=b}return r.push(E),_}let d=n+1,f=new zd(null,r),p=[],h="";for(;d<t.length;){let _=t.charAt(d++);if(a||_==="\\"){a=!a,h+=_;continue}if(l){d===c+1?(_==="^"||_==="!")&&(u=!0):_==="]"&&!(d===c+2&&u)&&(l=!1),h+=_;continue}else if(_==="["){l=!0,c=d,u=!1,h+=_;continue}if(!i.noext&&bEe(_)&&t.charAt(d)==="("&&(o<=s||r&&r.#_(_))){let b=r&&r.#_(_)?0:1;f.push(h),h="";let C=new zd(_,f);f.push(C),d=zd.#c(t,C,d,i,o+b);continue}if(_==="|"){f.push(h),h="",p.push(f),f=new zd(null,r);continue}if(_===")")return h===""&&r.#r.length===0&&(r.#m=!0),f.push(h),h="",r.push(...p,f),d;h+=_}return r.type=null,r.#t=void 0,r.#r=[t.substring(n-1)],d}#g(t){return this.#A(t,Ijr)}#A(t,r=Tjr){if(!t||typeof t!="object"||t.type!==null||t.#r.length!==1||this.type===null)return!1;let n=t.#r[0];return!n||typeof n!="object"||n.type===null?!1:this.#_(n.type,r)}#_(t,r=vjr){return!!r.get(this.type)?.includes(t)}#h(t,r){let n=t.#r[0],i=new zd(null,n,this.options);i.#r.push(""),n.push(i),this.#v(t,r)}#v(t,r){let n=t.#r[0];this.#r.splice(r,1,...n.#r);for(let i of n.#r)typeof i=="object"&&(i.#o=this);this.#d=void 0}#S(t){return!!_lt.get(this.type)?.has(t)}#C(t){if(!t||typeof t!="object"||t.type!==null||t.#r.length!==1||this.type===null||this.#r.length!==1)return!1;let r=t.#r[0];return!r||typeof r!="object"||r.type===null?!1:this.#S(r.type)}#T(t){let r=_lt.get(this.type),n=t.#r[0],i=r?.get(n.type);if(!i)return!1;this.#r=n.#r;for(let o of this.#r)typeof o=="object"&&(o.#o=this);this.type=i,this.#d=void 0,this.#m=!1}static fromGlob(t,r={}){let n=new zd(null,void 0,r);return zd.#c(t,n,0,r,0),n}toMMPattern(){if(this!==this.#e)return this.#e.toMMPattern();let t=this.toString(),[r,n,i,o]=this.toRegExpSource();if(!(i||this.#t||this.#a.nocase&&!this.#a.nocaseMagicOnly&&t.toUpperCase()!==t.toLowerCase()))return n;let a=(this.#a.nocase?"i":"")+(o?"u":"");return Object.assign(new RegExp(`^${r}$`,a),{_src:r,_glob:t})}get options(){return this.#a}toRegExpSource(t){let r=t??!!this.#a.dot;if(this.#e===this&&(this.#E(),this.#p()),!Alt(this)){let l=this.isStart()&&this.isEnd()&&!this.#r.some(p=>typeof p!="string"),c=this.#r.map(p=>{let[h,_,E,b]=typeof p=="string"?zd.#y(p,this.#t,l):p.toRegExpSource(t);return this.#t=this.#t||E,this.#n=this.#n||b,h}).join(""),u="";if(this.isStart()&&typeof this.#r[0]=="string"&&!(this.#r.length===1&&Rjr.has(this.#r[0]))){let h=wjr,_=r&&h.has(c.charAt(0))||c.startsWith("\\.")&&h.has(c.charAt(2))||c.startsWith("\\.\\.")&&h.has(c.charAt(4)),E=!r&&!t&&h.has(c.charAt(0));u=_?xjr:E?iK:""}let d="";return this.isEnd()&&this.#e.#s&&this.#o?.type==="!"&&(d="(?:$|\\/)"),[u+c+d,uC(c),this.#t=!!this.#t,this.#n]}let n=this.type==="*"||this.type==="+",i=this.type==="!"?"(?:(?!(?:":"(?:",o=this.#b(r);if(this.isStart()&&this.isEnd()&&!o&&this.type!=="!"){let l=this.toString(),c=this;return c.#r=[l],c.type=null,c.#t=void 0,[l,uC(this.toString()),!1,!1]}let s=!n||t||r||!iK?"":this.#b(!0);s===o&&(s=""),s&&(o=`(?:${o})(?:${s})*?`);let a="";if(this.type==="!"&&this.#m)a=(this.isStart()&&!r?iK:"")+Slt;else{let l=this.type==="!"?"))"+(this.isStart()&&!r&&!t?iK:"")+Elt+")":this.type==="@"?")":this.type==="?"?")?":this.type==="+"&&s?")":this.type==="*"&&s?")?":`)${this.type}`;a=i+o+l}return[a,uC(o),this.#t=!!this.#t,this.#n]}#E(){if(Alt(this)){let t=0,r=!1;do{r=!0;for(let n=0;n<this.#r.length;n++){let i=this.#r[n];typeof i=="object"&&(i.#E(),this.#A(i)?(r=!1,this.#v(i,n)):this.#g(i)?(r=!1,this.#h(i,n)):this.#C(i)&&(r=!1,this.#T(i)))}}while(!r&&++t<10)}else for(let t of this.#r)typeof t=="object"&&t.#E();this.#d=void 0}#b(t){return this.#r.map(r=>{if(typeof r=="string")throw new Error("string type in extglob ast??");let[n,i,o,s]=r.toRegExpSource(t);return this.#n=this.#n||s,n}).filter(r=>!(this.isStart()&&this.isEnd())||!!r).join("|")}static#y(t,r,n=!1){let i=!1,o="",s=!1,a=!1;for(let l=0;l<t.length;l++){let c=t.charAt(l);if(i){i=!1,o+=(Njr.has(c)?"\\":"")+c;continue}if(c==="*"){if(a)continue;a=!0,o+=n&&/^[*]+$/.test(t)?Slt:Elt,r=!0;continue}else a=!1;if(c==="\\"){l===t.length-1?o+="\\\\":i=!0;continue}if(c==="["){let[u,d,f,p]=hlt(t,l);if(f){o+=u,s=s||d,l+=f-1,r=r||p;continue}}if(c==="?"){o+=yEe,r=!0;continue}o+=Djr(c)}return[o,uC(t),!!r,s]}};zd=Q1;var CEe=(e,{windowsPathsNoEscape:t=!1,magicalBraces:r=!1}={})=>r?t?e.replace(/[?*()[\]{}]/g,"[$&]"):e.replace(/[?*()[\]\\{}]/g,"\\$&"):t?e.replace(/[?*()[\]]/g,"[$&]"):e.replace(/[?*()[\]\\]/g,"\\$&");var bc=(e,t,r={})=>(OU(t),!r.nocomment&&t.charAt(0)==="#"?!1:new CB(t,r).match(e)),Bjr=/^\*+([^+@!?*[(]*)$/,Mjr=e=>t=>!t.startsWith(".")&&t.endsWith(e),kjr=e=>t=>t.endsWith(e),Ljr=e=>(e=e.toLowerCase(),t=>!t.startsWith(".")&&t.toLowerCase().endsWith(e)),Pjr=e=>(e=e.toLowerCase(),t=>t.toLowerCase().endsWith(e)),Fjr=/^\*+\.\*+$/,Qjr=e=>!e.startsWith(".")&&e.includes("."),Ujr=e=>e!=="."&&e!==".."&&e.includes("."),Gjr=/^\.\*+$/,Hjr=e=>e!=="."&&e!==".."&&e.startsWith("."),$jr=/^\*+$/,qjr=e=>e.length!==0&&!e.startsWith("."),Yjr=e=>e.length!==0&&e!=="."&&e!=="..",zjr=/^\?+([^+@!?*[(]*)?$/,Vjr=([e,t=""])=>{let r=Clt([e]);return t?(t=t.toLowerCase(),n=>r(n)&&n.toLowerCase().endsWith(t)):r},Wjr=([e,t=""])=>{let r=Tlt([e]);return t?(t=t.toLowerCase(),n=>r(n)&&n.toLowerCase().endsWith(t)):r},jjr=([e,t=""])=>{let r=Tlt([e]);return t?n=>r(n)&&n.endsWith(t):r},Kjr=([e,t=""])=>{let r=Clt([e]);return t?n=>r(n)&&n.endsWith(t):r},Clt=([e])=>{let t=e.length;return r=>r.length===t&&!r.startsWith(".")},Tlt=([e])=>{let t=e.length;return r=>r.length===t&&r!=="."&&r!==".."},Ilt=typeof process=="object"&&process?typeof process.env=="object"&&process.env&&process.env.__MINIMATCH_TESTING_PLATFORM__||process.platform:"posix",blt={win32:{sep:"\\"},posix:{sep:"/"}},Jjr=Ilt==="win32"?blt.win32.sep:blt.posix.sep;bc.sep=Jjr;var fu=Symbol("globstar **");bc.GLOBSTAR=fu;var Zjr="[^/]",Xjr=Zjr+"*?",eKr="(?:(?!(?:\\/|^)(?:\\.{1,2})($|\\/)).)*?",tKr="(?:(?!(?:\\/|^)\\.).)*?",rKr=(e,t={})=>r=>bc(r,e,t);bc.filter=rKr;var Pf=(e,t={})=>Object.assign({},e,t),nKr=e=>{if(!e||typeof e!="object"||!Object.keys(e).length)return bc;let t=bc;return Object.assign((n,i,o={})=>t(n,i,Pf(e,o)),{Minimatch:class extends t.Minimatch{constructor(i,o={}){super(i,Pf(e,o))}static defaults(i){return t.defaults(Pf(e,i)).Minimatch}},AST:class extends t.AST{constructor(i,o,s={}){super(i,o,Pf(e,s))}static fromGlob(i,o={}){return t.AST.fromGlob(i,Pf(e,o))}},unescape:(n,i={})=>t.unescape(n,Pf(e,i)),escape:(n,i={})=>t.escape(n,Pf(e,i)),filter:(n,i={})=>t.filter(n,Pf(e,i)),defaults:n=>t.defaults(Pf(e,n)),makeRe:(n,i={})=>t.makeRe(n,Pf(e,i)),braceExpand:(n,i={})=>t.braceExpand(n,Pf(e,i)),match:(n,i,o={})=>t.match(n,i,Pf(e,o)),sep:t.sep,GLOBSTAR:fu})};bc.defaults=nKr;var vlt=(e,t={})=>(OU(e),t.nobrace||!/\{(?:(?!\{).)*\}/.test(e)?[e]:flt(e,{max:t.braceExpandMax}));bc.braceExpand=vlt;var iKr=(e,t={})=>new CB(e,t).makeRe();bc.makeRe=iKr;var oKr=(e,t,r={})=>{let n=new CB(t,r);return e=e.filter(i=>n.match(i)),n.options.nonull&&!e.length&&e.push(t),e};bc.match=oKr;var ylt=/[?*]|[+@!]\(.*?\)|\[|\]/,sKr=e=>e.replace(/[-[\]{}()*+?.,\\^$|#\s]/g,"\\$&"),CB=class{options;set;pattern;windowsPathsNoEscape;nonegate;negate;comment;empty;preserveMultipleSlashes;partial;globSet;globParts;nocase;isWindows;platform;windowsNoMagicRoot;maxGlobstarRecursion;regexp;constructor(t,r={}){OU(t),r=r||{},this.options=r,this.maxGlobstarRecursion=r.maxGlobstarRecursion??200,this.pattern=t,this.platform=r.platform||Ilt,this.isWindows=this.platform==="win32";let n="allowWindowsEscape";this.windowsPathsNoEscape=!!r.windowsPathsNoEscape||r[n]===!1,this.windowsPathsNoEscape&&(this.pattern=this.pattern.replace(/\\/g,"/")),this.preserveMultipleSlashes=!!r.preserveMultipleSlashes,this.regexp=null,this.negate=!1,this.nonegate=!!r.nonegate,this.comment=!1,this.empty=!1,this.partial=!!r.partial,this.nocase=!!this.options.nocase,this.windowsNoMagicRoot=r.windowsNoMagicRoot!==void 0?r.windowsNoMagicRoot:!!(this.isWindows&&this.nocase),this.globSet=[],this.globParts=[],this.set=[],this.make()}hasMagic(){if(this.options.magicalBraces&&this.set.length>1)return!0;for(let t of this.set)for(let r of t)if(typeof r!="string")return!0;return!1}debug(...t){}make(){let t=this.pattern,r=this.options;if(!r.nocomment&&t.charAt(0)==="#"){this.comment=!0;return}if(!t){this.empty=!0;return}this.parseNegate(),this.globSet=[...new Set(this.braceExpand())],r.debug&&(this.debug=(...o)=>console.error(...o)),this.debug(this.pattern,this.globSet);let n=this.globSet.map(o=>this.slashSplit(o));this.globParts=this.preprocess(n),this.debug(this.pattern,this.globParts);let i=this.globParts.map((o,s,a)=>{if(this.isWindows&&this.windowsNoMagicRoot){let l=o[0]===""&&o[1]===""&&(o[2]==="?"||!ylt.test(o[2]))&&!ylt.test(o[3]),c=/^[a-z]:/i.test(o[0]);if(l)return[...o.slice(0,4),...o.slice(4).map(u=>this.parse(u))];if(c)return[o[0],...o.slice(1).map(u=>this.parse(u))]}return o.map(l=>this.parse(l))});if(this.debug(this.pattern,i),this.set=i.filter(o=>o.indexOf(!1)===-1),this.isWindows)for(let o=0;o<this.set.length;o++){let s=this.set[o];s[0]===""&&s[1]===""&&this.globParts[o][2]==="?"&&typeof s[3]=="string"&&/^[a-z]:$/i.test(s[3])&&(s[2]="?")}this.debug(this.pattern,this.set)}preprocess(t){if(this.options.noglobstar)for(let n of t)for(let i=0;i<n.length;i++)n[i]==="**"&&(n[i]="*");let{optimizationLevel:r=1}=this.options;return r>=2?(t=this.firstPhasePreProcess(t),t=this.secondPhasePreProcess(t)):r>=1?t=this.levelOneOptimize(t):t=this.adjascentGlobstarOptimize(t),t}adjascentGlobstarOptimize(t){return t.map(r=>{let n=-1;for(;(n=r.indexOf("**",n+1))!==-1;){let i=n;for(;r[i+1]==="**";)i++;i!==n&&r.splice(n,i-n)}return r})}levelOneOptimize(t){return t.map(r=>(r=r.reduce((n,i)=>{let o=n[n.length-1];return i==="**"&&o==="**"?n:i===".."&&o&&o!==".."&&o!=="."&&o!=="**"?(n.pop(),n):(n.push(i),n)},[]),r.length===0?[""]:r))}levelTwoFileOptimize(t){Array.isArray(t)||(t=this.slashSplit(t));let r=!1;do{if(r=!1,!this.preserveMultipleSlashes){for(let i=1;i<t.length-1;i++){let o=t[i];i===1&&o===""&&t[0]===""||(o==="."||o==="")&&(r=!0,t.splice(i,1),i--)}t[0]==="."&&t.length===2&&(t[1]==="."||t[1]==="")&&(r=!0,t.pop())}let n=0;for(;(n=t.indexOf("..",n+1))!==-1;){let i=t[n-1];i&&i!=="."&&i!==".."&&i!=="**"&&!(this.isWindows&&/^[a-z]:$/i.test(i))&&(r=!0,t.splice(n-1,2),n-=2)}}while(r);return t.length===0?[""]:t}firstPhasePreProcess(t){let r=!1;do{r=!1;for(let n of t){let i=-1;for(;(i=n.indexOf("**",i+1))!==-1;){let s=i;for(;n[s+1]==="**";)s++;s>i&&n.splice(i+1,s-i);let a=n[i+1],l=n[i+2],c=n[i+3];if(a!==".."||!l||l==="."||l===".."||!c||c==="."||c==="..")continue;r=!0,n.splice(i,1);let u=n.slice(0);u[i]="**",t.push(u),i--}if(!this.preserveMultipleSlashes){for(let s=1;s<n.length-1;s++){let a=n[s];s===1&&a===""&&n[0]===""||(a==="."||a==="")&&(r=!0,n.splice(s,1),s--)}n[0]==="."&&n.length===2&&(n[1]==="."||n[1]==="")&&(r=!0,n.pop())}let o=0;for(;(o=n.indexOf("..",o+1))!==-1;){let s=n[o-1];if(s&&s!=="."&&s!==".."&&s!=="**"){r=!0;let l=o===1&&n[o+1]==="**"?["."]:[];n.splice(o-1,2,...l),n.length===0&&n.push(""),o-=2}}}}while(r);return t}secondPhasePreProcess(t){for(let r=0;r<t.length-1;r++)for(let n=r+1;n<t.length;n++){let i=this.partsMatch(t[r],t[n],!this.preserveMultipleSlashes);if(i){t[r]=[],t[n]=i;break}}return t.filter(r=>r.length)}partsMatch(t,r,n=!1){let i=0,o=0,s=[],a="";for(;i<t.length&&o<r.length;)if(t[i]===r[o])s.push(a==="b"?r[o]:t[i]),i++,o++;else if(n&&t[i]==="**"&&r[o]===t[i+1])s.push(t[i]),i++;else if(n&&r[o]==="**"&&t[i]===r[o+1])s.push(r[o]),o++;else if(t[i]==="*"&&r[o]&&(this.options.dot||!r[o].startsWith("."))&&r[o]!=="**"){if(a==="b")return!1;a="a",s.push(t[i]),i++,o++}else if(r[o]==="*"&&t[i]&&(this.options.dot||!t[i].startsWith("."))&&t[i]!=="**"){if(a==="a")return!1;a="b",s.push(r[o]),i++,o++}else return!1;return t.length===r.length&&s}parseNegate(){if(this.nonegate)return;let t=this.pattern,r=!1,n=0;for(let i=0;i<t.length&&t.charAt(i)==="!";i++)r=!r,n++;n&&(this.pattern=t.slice(n)),this.negate=r}matchOne(t,r,n=!1){let i=0,o=0;if(this.isWindows){let a=typeof t[0]=="string"&&/^[a-z]:$/i.test(t[0]),l=!a&&t[0]===""&&t[1]===""&&t[2]==="?"&&/^[a-z]:$/i.test(t[3]),c=typeof r[0]=="string"&&/^[a-z]:$/i.test(r[0]),u=!c&&r[0]===""&&r[1]===""&&r[2]==="?"&&typeof r[3]=="string"&&/^[a-z]:$/i.test(r[3]),d=l?3:a?0:void 0,f=u?3:c?0:void 0;if(typeof d=="number"&&typeof f=="number"){let[p,h]=[t[d],r[f]];p.toLowerCase()===h.toLowerCase()&&(r[f]=p,o=f,i=d)}}let{optimizationLevel:s=1}=this.options;return s>=2&&(t=this.levelTwoFileOptimize(t)),r.includes(fu)?this.#e(t,r,n,i,o):this.#n(t,r,n,i,o)}#e(t,r,n,i,o){let s=r.indexOf(fu,o),a=r.lastIndexOf(fu),[l,c,u]=n?[r.slice(o,s),r.slice(s+1),[]]:[r.slice(o,s),r.slice(s+1,a),r.slice(a+1)];if(l.length){let C=t.slice(i,i+l.length);if(!this.#n(C,l,n,0,0))return!1;i+=l.length,o+=l.length}let d=0;if(u.length){if(u.length+i>t.length)return!1;let C=t.length-u.length;if(this.#n(t,u,n,C,0))d=u.length;else{if(t[t.length-1]!==""||i+u.length===t.length||(C--,!this.#n(t,u,n,C,0)))return!1;d=u.length+1}}if(!c.length){let C=!!d;for(let v=i;v<t.length-d;v++){let R=String(t[v]);if(C=!0,R==="."||R===".."||!this.options.dot&&R.startsWith("."))return!1}return n||C}let f=[[[],0]],p=f[0],h=0,_=[0];for(let C of c)C===fu?(_.push(h),p=[[],0],f.push(p)):(p[0].push(C),h++);let E=f.length-1,b=t.length-d;for(let C of f)C[1]=b-(_[E--]+C[0].length);return!!this.#t(t,f,i,0,n,0,!!d)}#t(t,r,n,i,o,s,a){let l=r[i];if(!l){for(let d=n;d<t.length;d++){a=!0;let f=t[d];if(f==="."||f===".."||!this.options.dot&&f.startsWith("."))return!1}return a}let[c,u]=l;for(;n<=u;){if(this.#n(t.slice(0,n+c.length),c,o,n,0)&&s<this.maxGlobstarRecursion){let p=this.#t(t,r,n+c.length,i+1,o,s+1,a);if(p!==!1)return p}let f=t[n];if(f==="."||f===".."||!this.options.dot&&f.startsWith("."))return!1;n++}return o||null}#n(t,r,n,i,o){let s,a,l,c;for(s=i,a=o,c=t.length,l=r.length;s<c&&a<l;s++,a++){this.debug("matchOne loop");let u=r[a],d=t[s];if(this.debug(r,u,d),u===!1||u===fu)return!1;let f;if(typeof u=="string"?(f=d===u,this.debug("string match",u,d,f)):(f=u.test(d),this.debug("pattern match",u,d,f)),!f)return!1}if(s===c&&a===l)return!0;if(s===c)return n;if(a===l)return s===c-1&&t[s]==="";throw new Error("wtf?")}braceExpand(){return vlt(this.pattern,this.options)}parse(t){OU(t);let r=this.options;if(t==="**")return fu;if(t==="")return"";let n,i=null;(n=t.match($jr))?i=r.dot?Yjr:qjr:(n=t.match(Bjr))?i=(r.nocase?r.dot?Pjr:Ljr:r.dot?kjr:Mjr)(n[1]):(n=t.match(zjr))?i=(r.nocase?r.dot?Wjr:Vjr:r.dot?jjr:Kjr)(n):(n=t.match(Fjr))?i=r.dot?Ujr:Qjr:(n=t.match(Gjr))&&(i=Hjr);let o=Q1.fromGlob(t,this.options).toMMPattern();return i&&typeof o=="object"&&Reflect.defineProperty(o,"test",{value:i}),o}makeRe(){if(this.regexp||this.regexp===!1)return this.regexp;let t=this.set;if(!t.length)return this.regexp=!1,this.regexp;let r=this.options,n=r.noglobstar?Xjr:r.dot?eKr:tKr,i=new Set(r.nocase?["i"]:[]),o=t.map(l=>{let c=l.map(d=>{if(d instanceof RegExp)for(let f of d.flags.split(""))i.add(f);return typeof d=="string"?sKr(d):d===fu?fu:d._src});c.forEach((d,f)=>{let p=c[f+1],h=c[f-1];d!==fu||h===fu||(h===void 0?p!==void 0&&p!==fu?c[f+1]="(?:\\/|"+n+"\\/)?"+p:c[f]=n:p===void 0?c[f-1]=h+"(?:\\/|\\/"+n+")?":p!==fu&&(c[f-1]=h+"(?:\\/|\\/"+n+"\\/)"+p,c[f+1]=fu))});let u=c.filter(d=>d!==fu);if(this.partial&&u.length>=1){let d=[];for(let f=1;f<=u.length;f++)d.push(u.slice(0,f).join("/"));return"(?:"+d.join("|")+")"}return u.join("/")}).join("|"),[s,a]=t.length>1?["(?:",")"]:["",""];o="^"+s+o+a+"$",this.partial&&(o="^(?:\\/|"+s+o.slice(1,-1)+a+")$"),this.negate&&(o="^(?!"+o+").+$");try{this.regexp=new RegExp(o,[...i].join(""))}catch{this.regexp=!1}return this.regexp}slashSplit(t){return this.preserveMultipleSlashes?t.split("/"):this.isWindows&&/^\/\/[^/]+/.test(t)?["",...t.split(/\/+/)]:t.split(/\/+/)}match(t,r=this.partial){if(this.debug("match",t,this.pattern),this.comment)return!1;if(this.empty)return t==="";if(t==="/"&&r)return!0;let n=this.options;this.isWindows&&(t=t.split("\\").join("/"));let i=this.slashSplit(t);this.debug(this.pattern,"split",i);let o=this.set;this.debug(this.pattern,"set",o);let s=i[i.length-1];if(!s)for(let a=i.length-2;!s&&a>=0;a--)s=i[a];for(let a of o){let l=i;if(n.matchBase&&a.length===1&&(l=[s]),this.matchOne(l,a,r))return n.flipNegate?!0:!this.negate}return n.flipNegate?!1:this.negate}static defaults(t){return bc.defaults(t).Minimatch}};bc.AST=Q1;bc.Minimatch=CB;bc.escape=CEe;bc.unescape=uC;var Rlt=Ie(NU(),1);mr();Fe();Te();qu();import{readFile as xlt}from"fs/promises";import{existsSync as TEe,readdirSync as aKr,statSync as lKr}from"fs";import{join as IEe,relative as Nlt}from"path";import{homedir as cKr}from"os";function wlt(e){try{let t=(0,Rlt.default)(e),r=t.data.paths,n=[];return typeof r=="string"?n=r.split(",").map(i=>i.trim()).filter(Boolean):Array.isArray(r)&&(n=r.filter(i=>typeof i=="string")),{paths:n,content:t.content.trim()}}catch(t){return Ee(t),{paths:[],content:e.trim()}}}function uKr(e,t){return t.length===0?!0:t.some(r=>{try{return bc(e,r,{matchBase:!0,dot:!0})}catch(n){return Ee(n),!1}})}function vEe(e){let t=[];try{if(!TEe(e))return t;let r=aKr(e);for(let n of r){let i=IEe(e,n),o=lKr(i);o.isDirectory()?t.push(...vEe(i)):o.isFile()&&n.endsWith(".md")&&t.push(i)}}catch(r){Ee(r)}return t}async function oK(){let e=[];try{let t=IEe(cKr(),bn,"rules");if(TEe(t)){let r=vEe(t);for(let n of r)try{let i=await xlt(n,"utf-8"),{paths:o,content:s}=wlt(i);o.length>0&&e.push({filePath:n,content:s,paths:o,isProjectRule:!1})}catch(i){Ee(i)}}}catch(t){Ee(t)}try{let t=IEe(De(),bn,"rules");if(TEe(t)){let r=vEe(t);for(let n of r)try{let i=await xlt(n,"utf-8"),{paths:o,content:s}=wlt(i);o.length>0&&e.push({filePath:Nlt(De(),n),content:s,paths:o,isProjectRule:!0})}catch(i){Ee(i)}}}catch(t){Ee(t)}return e}function Dlt(e,t){e=Q7(e);let r=Q7(De()),n=e.startsWith(r)?Nlt(r,e):e;return t.filter(i=>uKr(n,i.paths))}function Olt(e){return e.length===0?"":e.map(r=>{let n=r.isProjectRule?"project instructions, checked into the codebase":"user's private global instructions for all projects";return`Contents of ${r.filePath} (${n}):
655
+ `)}function Lot(e){try{let t=yzr(e),r=t.readSync();return t.closeSync(),r===null}catch(t){return Ee(`Error checking directory: ${t}`),!1}}Fe();function rC(){let e=Rn();e.hasCompletedProjectOnboarding||Ji({...e,hasCompletedProjectOnboarding:!0})}function Y_e({workspaceDir:e}){let r=!Rn().hasCompletedProjectOnboarding;if(!r)return null;let n=Rzr(Nzr(e,Pi)),i=Lot(e),o=!n&&!i,s=oB.isEnabled&&!zr().shiftEnterKeyBindingInstalled,a=oe();return(0,A.jsxs)(w,{flexDirection:"column",gap:1,padding:1,paddingBottom:0,children:[r&&(0,A.jsxs)(A.Fragment,{children:[(0,A.jsx)(I,{color:a.secondaryText,children:"Tips for getting started:"}),(0,A.jsx)(Ec,{children:(()=>{let l=[];return i&&l.push((0,A.jsx)(Ec.Item,{children:(0,A.jsxs)(I,{color:a.secondaryText,children:["Ask ",nt," to create a new app or clone a repository."]})},"workspace")),o&&l.push((0,A.jsx)(Ec.Item,{children:(0,A.jsxs)(I,{color:a.secondaryText,children:["Run ",(0,A.jsx)(I,{color:a.text,children:"/init"})," to create a",Pi," file with instructions for Hawa code."]})},"claudemd")),s&&l.push((0,A.jsx)(Ec.Item,{children:(0,A.jsxs)(I,{color:a.secondaryText,children:["Run ",(0,A.jsx)(I,{color:a.text,children:"/terminal-setup"}),(0,A.jsx)(I,{bold:!1,children:" to set up terminal integration"})]})},"terminal")),l.push((0,A.jsx)(Ec.Item,{children:(0,A.jsxs)(I,{color:a.secondaryText,children:["Ask ",nt," questions about your codebase."]})},"questions")),l.push((0,A.jsx)(Ec.Item,{children:(0,A.jsxs)(I,{color:a.secondaryText,children:["Ask ",nt," to implement changes to your codebase."]})},"changes")),l})()})]}),e===Dzr()&&(0,A.jsxs)(I,{color:oe().warning,children:["Note: You have launched ",(0,A.jsx)(I,{bold:!0,children:nt})," in your home directory. For the best experience, launch it in a project directory instead."]})]})}function z_e({isFocused:e,isSelected:t,smallPointer:r,children:n}){let{styles:i}=Ao("Select");return(0,A.jsxs)(w,{...i.option({isFocused:e}),children:[e&&(0,A.jsx)(I,{...i.focusIndicator(),children:r?nr.triangleDownSmall:nr.pointer}),(0,A.jsx)(I,{...i.label({isFocused:e,isSelected:t}),children:n}),t&&(0,A.jsx)(I,{...i.selectedIndicator(),children:nr.tick})]})}var $d=Ie(Ye(),1);import{isDeepStrictEqual as Ozr}from"node:util";var bU=class extends Map{first;constructor(t){let r=[],n,i,o=0;for(let s of t){let a={...s,previous:i,next:void 0,index:o};i&&(i.next=a),n||=a;let l="value"in s?s.value:V_e(s);r.push([l,a]),o++,i=a}super(r),this.first=n}};var Bzr=(e,t)=>{switch(t.type){case"focus-next-option":{if(!e.focusedValue)return e;let r=e.optionMap.get(e.focusedValue);if(!r)return e;let n=r.next;for(;n&&!("value"in n);)n=n.next;if(!n)return e;if(!(n.index>=e.visibleToIndex))return{...e,focusedValue:n.value};let o=Math.min(e.optionMap.size,e.visibleToIndex+1),s=o-e.visibleOptionCount;return{...e,focusedValue:n.value,visibleFromIndex:s,visibleToIndex:o}}case"focus-previous-option":{if(!e.focusedValue)return e;let r=e.optionMap.get(e.focusedValue);if(!r)return e;let n=r.previous;for(;n&&!("value"in n);)n=n.previous;if(!n)return e;if(!(n.index<=e.visibleFromIndex))return{...e,focusedValue:n.value};let o=Math.max(0,e.visibleFromIndex-1),s=o+e.visibleOptionCount;return{...e,focusedValue:n.value,visibleFromIndex:o,visibleToIndex:s}}case"select-focused-option":return{...e,previousValue:e.value,value:e.focusedValue};case"reset":return t.state;case"set-focus":return{...e,focusedValue:t.value}}},W_e=e=>e.flatMap(t=>{if("options"in t){let r=W_e(t.options),n=r.flatMap(o=>"value"in o?o.value:[]);return[...t.header!==void 0?[{header:t.header,optionValues:n}]:[],...r]}return t}),Pot=({visibleOptionCount:e,defaultValue:t,options:r})=>{let n=W_e(r),i=typeof e=="number"?Math.min(e,n.length):n.length,o=new bU(n),s=o.first,a=s&&"value"in s?s.value:void 0;return{optionMap:o,visibleOptionCount:i,focusedValue:a,visibleFromIndex:0,visibleToIndex:i,previousValue:t,value:t}},j_e=({visibleOptionCount:e=5,options:t,defaultValue:r,onChange:n,onFocus:i,focusValue:o})=>{let s=W_e(t),[a,l]=(0,$d.useReducer)(Bzr,{visibleOptionCount:e,defaultValue:r,options:t},Pot),[c,u]=(0,$d.useState)(s);s!==c&&!Ozr(s,c)&&(l({type:"reset",state:Pot({visibleOptionCount:e,defaultValue:r,options:t})}),u(s));let d=(0,$d.useCallback)(()=>{l({type:"focus-next-option"})},[]),f=(0,$d.useCallback)(()=>{l({type:"focus-previous-option"})},[]),p=(0,$d.useCallback)(()=>{l({type:"select-focused-option"})},[]),h=(0,$d.useMemo)(()=>s.map((_,E)=>({..._,index:E})).slice(a.visibleFromIndex,a.visibleToIndex),[s,a.visibleFromIndex,a.visibleToIndex]);return(0,$d.useEffect)(()=>{a.value&&a.previousValue!==a.value&&n?.(a.value)},[a.previousValue,a.value,t,n]),(0,$d.useEffect)(()=>{a.focusedValue&&i?.(a.focusedValue)},[a.focusedValue,i]),(0,$d.useEffect)(()=>{o&&l({type:"set-focus",value:o})},[o]),{focusedValue:a.focusedValue,visibleFromIndex:a.visibleFromIndex,visibleToIndex:a.visibleToIndex,value:a.value,visibleOptions:h,focusNextOption:d,focusPreviousOption:f,selectFocusedOption:p}};var K_e=({isDisabled:e=!1,state:t})=>{_t((r,n)=>{n.downArrow&&t.focusNextOption(),n.upArrow&&t.focusPreviousOption(),n.return&&t.selectFocusedOption()},{isActive:!e})};var V_e=e=>`HEADER-${e.optionValues.join(",")}`;function BS({isDisabled:e=!1,visibleOptionCount:t=5,highlightText:r,options:n,defaultValue:i,onChange:o,onFocus:s,focusValue:a}){let l=j_e({visibleOptionCount:t,options:n,defaultValue:i,onChange:o,onFocus:s,focusValue:a});K_e({isDisabled:e,state:l});let{styles:c}=Ao("Select");return(0,A.jsx)(w,{...c.container(),children:l.visibleOptions.map(u=>{let d="value"in u?u.value:V_e(u),f=!e&&l.focusedValue!==void 0&&("value"in u?l.focusedValue===u.value:u.optionValues.includes(l.focusedValue)),p=!!l.value&&("value"in u?l.value===u.value:u.optionValues.includes(l.value)),h="header"in u,_="label"in u?u.label:u.header,E=_;if(r&&_.includes(r)){let b=_.indexOf(r);E=(0,A.jsxs)(A.Fragment,{children:[_.slice(0,b),(0,A.jsx)(I,{...c.highlightedText(),children:r}),_.slice(b+r.length)]})}return(0,A.jsx)(z_e,{isFocused:f,isSelected:p,smallPointer:h,children:E},d)})})}function Fot({onDone:e}){return _t((t,r)=>{(r.ctrl&&(t==="c"||t==="d")||r.escape)&&e()}),(0,A.jsxs)(w,{flexDirection:"column",borderStyle:"round",padding:1,borderColor:oe().secondaryBorder,children:[(0,A.jsx)(w,{marginBottom:1,flexDirection:"column",children:(0,A.jsx)(I,{bold:!0,children:"You've spent $5 this session."})}),(0,A.jsx)(w,{children:(0,A.jsx)(BS,{options:[{value:"ok",label:"Got it, thanks!"}],onChange:e})})]})}var vr=Ie(Ye(),1);Fe();mr();WA();var Lzr="2.8.10",MS={VERSION:Lzr,PACKAGE_URL:"@dahawa/hawa-code",README_URL:"https://github.com/italking/hawa-code",ISSUES_EXPLAINER:"report the issue at https://github.com/italking/hawa-code/issues"};var X_e=46,Got=["(\u2740\u2579\u25E1\u2579)","(\u25D5\u072B\u25D5)","\u239D(\u25D5u\u25D5)\u23A0","\u10DA(\u25C9\u25DE\u0C6A\u25DF\u25C9 )\u10DA","(\xB4\u25C9\u203F\u25C9\uFF40)","\u0E01\u0E47\u0295\u2022\u0361\u1D25\u2022\u0294 \u0E01\u0E49","\uFF0F/( \u25D5\u203F\u203F\u25D5 )\uFF3C"];function zj({isDefaultModel:e=!1}){let t=Math.max(X_e,De().length+12),r=oe(),n=Got[Math.floor(Math.random()*Got.length)];return(0,A.jsx)(w,{flexDirection:"column",children:(0,A.jsxs)(w,{flexDirection:"column",gap:1,paddingLeft:1,width:"100%",children:[(0,A.jsxs)(I,{children:[(0,A.jsx)(I,{children:n})," Welcome to"," ",(0,A.jsx)(I,{bold:!0,children:nt}),(0,A.jsxs)(I,{color:r.secondaryText,children:[" v",MS.VERSION]})]}),(0,A.jsx)(A.Fragment,{children:(0,A.jsxs)(w,{paddingLeft:2,flexDirection:"column",gap:1,children:[(0,A.jsx)(I,{color:r.secondaryText,italic:!0,children:"/help for help"}),(0,A.jsxs)(I,{color:r.secondaryText,children:["cwd: ",De()]}),(0,A.jsxs)(I,{color:r.secondaryText,children:["model: ",Wn.getConfig().routing.MODEL?.map(i=>`${i.source}__${i.model}`).join(", ")??"N/A"]}),(0,A.jsxs)(I,{color:r.secondaryText,children:["small fast model: ",Wn.getConfig().routing.SMALL_FAST_MODEL?.map(i=>`${i.source}__${i.model}`).join(", ")??"N/A"]})]})})]})})}Te();import{randomUUID as Mg}from"crypto";wo();Te();cr();mr();Te();Fe();import{existsSync as PS,readdirSync as dKr,statSync as pKr}from"fs";import{join as dC,relative as mKr}from"path";import{homedir as Mlt}from"os";import{platform as fKr}from"process";import{readFile as pC}from"fs/promises";mr();rm();Jt();import{join as Hzr,sep as $zr}from"path";function Wu(){if(!Sc())return!1;try{let e=Ve();if(e.autoMemory?.teamMemoryEnabled!==void 0)return e.autoMemory.teamMemoryEnabled}catch{}return!1}function qd(){return(Hzr(De(),".hcode","team-memory")+$zr).normalize("NFC")}function Lf(e){let t=e.normalize("NFC"),r=qd();return t.startsWith(r)}rm();var klt=Ie(NU(),1);li();var AEe=(e,t,r)=>{let n=e instanceof RegExp?llt(e,r):e,i=t instanceof RegExp?llt(t,r):t,o=n!==null&&i!=null&&tjr(n,i,r);return o&&{start:o[0],end:o[1],pre:r.slice(0,o[0]),body:r.slice(o[0]+n.length,o[1]),post:r.slice(o[1]+i.length)}},llt=(e,t)=>{let r=t.match(e);return r?r[0]:null},tjr=(e,t,r)=>{let n,i,o,s,a,l=r.indexOf(e),c=r.indexOf(t,l+1),u=l;if(l>=0&&c>0){if(e===t)return[l,c];for(n=[],o=r.length;u>=0&&!a;){if(u===l)n.push(u),l=r.indexOf(e,u+1);else if(n.length===1){let d=n.pop();d!==void 0&&(a=[d,c])}else i=n.pop(),i!==void 0&&i<o&&(o=i,s=c),c=r.indexOf(t,u+1);u=l<c&&l>=0?l:c}n.length&&s!==void 0&&(a=[o,s])}return a};var clt="\0SLASH"+Math.random()+"\0",ult="\0OPEN"+Math.random()+"\0",SEe="\0CLOSE"+Math.random()+"\0",dlt="\0COMMA"+Math.random()+"\0",plt="\0PERIOD"+Math.random()+"\0",rjr=new RegExp(clt,"g"),njr=new RegExp(ult,"g"),ijr=new RegExp(SEe,"g"),ojr=new RegExp(dlt,"g"),sjr=new RegExp(plt,"g"),ajr=/\\\\/g,ljr=/\\{/g,cjr=/\\}/g,ujr=/\\,/g,djr=/\\\./g,pjr=1e5,mjr=4e6;function _Ee(e){return isNaN(e)?e.charCodeAt(0):parseInt(e,10)}function fjr(e){return e.replace(ajr,clt).replace(ljr,ult).replace(cjr,SEe).replace(ujr,dlt).replace(djr,plt)}function gjr(e){return e.replace(rjr,"\\").replace(njr,"{").replace(ijr,"}").replace(ojr,",").replace(sjr,".")}function mlt(e){if(!e)return[""];let t=[],r=AEe("{","}",e);if(!r)return e.split(",");let{pre:n,body:i,post:o}=r,s=n.split(",");s[s.length-1]+="{"+i+"}";let a=mlt(o);return o.length&&(s[s.length-1]+=a.shift(),s.push.apply(s,a)),t.push.apply(t,s),t}function flt(e,t={}){if(!e)return[];let{max:r=pjr,maxLength:n=mjr}=t;return e.slice(0,2)==="{}"&&(e="\\{\\}"+e.slice(2)),EEe(fjr(e),r,n,!0).map(gjr)}function hjr(e){return"{"+e+"}"}function Ajr(e){return/^-?0\d/.test(e)}function _jr(e,t){return e<=t}function Ejr(e,t){return e>=t}function DU(e,t,r,n,i,o){let s=[],a=0;for(let l=0;l<e.length;l++)for(let c=0;c<r.length;c++){if(s.length>=n)return s;let u=e[l]+t+r[c];if(!(o&&!u)){if(a+u.length>i)return s;s.push(u),a+=u.length}}return s}function Sjr(e,t,r,n){let i=e.split(/\.\./),o=[];if(i[0]===void 0||i[1]===void 0)return o;let s=_Ee(i[0]),a=_Ee(i[1]),l=Math.max(i[0].length,i[1].length),c=i.length===3&&i[2]!==void 0?Math.max(Math.abs(_Ee(i[2])),1):1,u=_jr;a<s&&(c*=-1,u=Ejr);let f=i.some(Ajr),p=0;for(let h=s;u(h,a)&&o.length<r;h+=c){let _;if(t)_=String.fromCharCode(h),_==="\\"&&(_="");else if(_=String(h),f){let E=l-_.length;if(E>0){let b=new Array(E+1).join("0");h<0?_="-"+b+_.slice(1):_=b+_}}if(p+_.length>n)break;o.push(_),p+=_.length}return o}function EEe(e,t,r,n){let i=[""],o=!1,s=!0;for(;;){let a=AEe("{","}",e);if(!a)return DU(i,e,[""],t,r,o);let l=a.pre;if(/\$$/.test(l)){if(i=DU(i,l+"{"+a.body+"}",[""],t,r,o&&!a.post.length),s=!1,!a.post.length)break;e=a.post;continue}let c=/^-?\d+\.\.-?\d+(?:\.\.-?\d+)?$/.test(a.body),u=/^[a-zA-Z]\.\.[a-zA-Z](?:\.\.-?\d+)?$/.test(a.body),d=c||u,f=a.body.indexOf(",")>=0;if(!d&&!f){if(a.post.match(/,(?!,).*\}/)){e=a.pre+"{"+a.body+SEe+a.post,n=!0;continue}return DU(i,l+"{"+a.body+"}"+a.post,[""],t,r,o)}s&&(o=n&&!d,s=!1);let p;if(d)p=Sjr(a.body,u,t,r);else{let h=mlt(a.body);if(h.length===1&&h[0]!==void 0&&(h=EEe(h[0],t,r,!1).map(hjr),h.length===1)){if(i=DU(i,l+h[0],[""],t,r,o&&!a.post.length),!a.post.length)break;e=a.post;continue}let _=o&&!a.post.length&&!l;for(let b=0;_&&b<i.length;b++)i[b]&&(_=!1);p=[];let E=0;e:for(let b=0;b<h.length;b++){let C=EEe(h[b],t,r,!1);for(let v=0;v<C.length;v++){let R=C[v];if(!(_&&!R)){if(p.length>=t||E+R.length>r)break e;p.push(R),E+=R.length}}}}if(i=DU(i,l,p,t,r,o&&!a.post.length),!a.post.length)break;e=a.post}return i}var OU=e=>{if(typeof e!="string")throw new TypeError("invalid pattern");if(e.length>65536)throw new TypeError("pattern is too long")};var bjr={"[:alnum:]":["\\p{L}\\p{Nl}\\p{Nd}",!0],"[:alpha:]":["\\p{L}\\p{Nl}",!0],"[:ascii:]":["\\x00-\\x7f",!1],"[:blank:]":["\\p{Zs}\\t",!0],"[:cntrl:]":["\\p{Cc}",!0],"[:digit:]":["\\p{Nd}",!0],"[:graph:]":["\\p{Z}\\p{C}",!0,!0],"[:lower:]":["\\p{Ll}",!0],"[:print:]":["\\p{C}",!0],"[:punct:]":["\\p{P}",!0],"[:space:]":["\\p{Z}\\t\\r\\n\\v\\f",!0],"[:upper:]":["\\p{Lu}",!0],"[:word:]":["\\p{L}\\p{Nl}\\p{Nd}\\p{Pc}",!0],"[:xdigit:]":["A-Fa-f0-9",!1]},BU=e=>e.replace(/[[\]\\-]/g,"\\$&"),yjr=e=>e.replace(/[-[\]{}()*+?.,\\^$|#\s]/g,"\\$&"),glt=e=>e.join(""),hlt=(e,t)=>{let r=t;if(e.charAt(r)!=="[")throw new Error("not in a brace expression");let n=[],i=[],o=r+1,s=!1,a=!1,l=!1,c=!1,u=r,d="";e:for(;o<e.length;){let _=e.charAt(o);if((_==="!"||_==="^")&&o===r+1){c=!0,o++;continue}if(_==="]"&&s&&!l){u=o+1;break}if(s=!0,_==="\\"&&!l){l=!0,o++;continue}if(_==="["&&!l){for(let[E,[b,C,v]]of Object.entries(bjr))if(e.startsWith(E,o)){if(d)return["$.",!1,e.length-r,!0];o+=E.length,v?i.push(b):n.push(b),a=a||C;continue e}}if(l=!1,d){_>d?n.push(BU(d)+"-"+BU(_)):_===d&&n.push(BU(_)),d="",o++;continue}if(e.startsWith("-]",o+1)){n.push(BU(_+"-")),o+=2;continue}if(e.startsWith("-",o+1)){d=_,o+=2;continue}n.push(BU(_)),o++}if(u<o)return["",!1,0,!1];if(!n.length&&!i.length)return["$.",!1,e.length-r,!0];if(i.length===0&&n.length===1&&/^\\?.$/.test(n[0])&&!c){let _=n[0].length===2?n[0].slice(-1):n[0];return[yjr(_),!1,u-r,!1]}let f="["+(c?"^":"")+glt(n)+"]",p="["+(c?"":"^")+glt(i)+"]";return[n.length&&i.length?"("+f+"|"+p+")":n.length?f:p,a,u-r,!0]};var uC=(e,{windowsPathsNoEscape:t=!1,magicalBraces:r=!0}={})=>r?t?e.replace(/\[([^/\\])\]/g,"$1"):e.replace(/((?!\\).|^)\[([^/\\])\]/g,"$1$2").replace(/\\([^/])/g,"$1"):t?e.replace(/\[([^/\\{}])\]/g,"$1"):e.replace(/((?!\\).|^)\[([^/\\{}])\]/g,"$1$2").replace(/\\([^/{}])/g,"$1");var zd,Cjr=new Set(["!","?","+","*","@"]),bEe=e=>Cjr.has(e),Alt=e=>bEe(e.type),Tjr=new Map([["!",["@"]],["?",["?","@"]],["@",["@"]],["*",["*","+","?","@"]],["+",["+","@"]]]),Ijr=new Map([["!",["?"]],["@",["?"]],["+",["?","*"]]]),vjr=new Map([["!",["?","@"]],["?",["?","@"]],["@",["?","@"]],["*",["*","+","?","@"]],["+",["+","@","?","*"]]]),_lt=new Map([["!",new Map([["!","@"]])],["?",new Map([["*","*"],["+","*"]])],["@",new Map([["!","!"],["?","?"],["@","@"],["*","*"],["+","+"]])],["+",new Map([["?","*"],["*","*"]])]]),xjr="(?!(?:^|/)\\.\\.?(?:$|/))",iK="(?!\\.)",wjr=new Set(["[","."]),Rjr=new Set(["..","."]),Njr=new Set("().*{}+?[]^$\\!"),Djr=e=>e.replace(/[-[\]{}()*+?.,\\^$|#\s]/g,"\\$&"),yEe="[^/]",Elt=yEe+"*?",Slt=yEe+"+?",Ojr=0,Q1=class{type;#e;#t;#n=!1;#r=[];#o;#i;#l;#s=!1;#a;#d;#m=!1;id=++Ojr;get depth(){return(this.#o?.depth??-1)+1}[Symbol.for("nodejs.util.inspect.custom")](){return{"@@type":"AST",id:this.id,type:this.type,root:this.#e.id,parent:this.#o?.id,depth:this.depth,partsLength:this.#r.length,parts:this.#r}}constructor(t,r,n={}){this.type=t,t&&(this.#t=!0),this.#o=r,this.#e=this.#o?this.#o.#e:this,this.#a=this.#e===this?n:this.#e.#a,this.#l=this.#e===this?[]:this.#e.#l,t==="!"&&!this.#e.#s&&this.#l.push(this),this.#i=this.#o?this.#o.#r.length:0}get hasMagic(){if(this.#t!==void 0)return this.#t;for(let t of this.#r)if(typeof t!="string"&&(t.type||t.hasMagic))return this.#t=!0;return this.#t}toString(){return this.#d!==void 0?this.#d:this.type?this.#d=this.type+"("+this.#r.map(t=>String(t)).join("|")+")":this.#d=this.#r.map(t=>String(t)).join("")}#p(){if(this!==this.#e)throw new Error("should only call on root");if(this.#s)return this;this.toString(),this.#s=!0;let t;for(;t=this.#l.pop();){if(t.type!=="!")continue;let r=t,n=r.#o;for(;n;){for(let i=r.#i+1;!n.type&&i<n.#r.length;i++)for(let o of t.#r){if(typeof o=="string")throw new Error("string part in extglob AST??");o.copyIn(n.#r[i])}r=n,n=r.#o}}return this}push(...t){for(let r of t)if(r!==""){if(typeof r!="string"&&!(r instanceof zd&&r.#o===this))throw new Error("invalid part: "+r);this.#r.push(r)}}toJSON(){let t=this.type===null?this.#r.slice().map(r=>typeof r=="string"?r:r.toJSON()):[this.type,...this.#r.map(r=>r.toJSON())];return this.isStart()&&!this.type&&t.unshift([]),this.isEnd()&&(this===this.#e||this.#e.#s&&this.#o?.type==="!")&&t.push({}),t}isStart(){if(this.#e===this)return!0;if(!this.#o?.isStart())return!1;if(this.#i===0)return!0;let t=this.#o;for(let r=0;r<this.#i;r++){let n=t.#r[r];if(!(n instanceof zd&&n.type==="!"))return!1}return!0}isEnd(){if(this.#e===this||this.#o?.type==="!")return!0;if(!this.#o?.isEnd())return!1;if(!this.type)return this.#o?.isEnd();let t=this.#o?this.#o.#r.length:0;return this.#i===t-1}copyIn(t){typeof t=="string"?this.push(t):this.push(t.clone(this))}clone(t){let r=new zd(this.type,t);for(let n of this.#r)r.copyIn(n);return r}static#c(t,r,n,i,o){let s=i.maxExtglobRecursion??2,a=!1,l=!1,c=-1,u=!1;if(r.type===null){let _=n,E="";for(;_<t.length;){let b=t.charAt(_++);if(a||b==="\\"){a=!a,E+=b;continue}if(l){_===c+1?(b==="^"||b==="!")&&(u=!0):b==="]"&&!(_===c+2&&u)&&(l=!1),E+=b;continue}else if(b==="["){l=!0,c=_,u=!1,E+=b;continue}if(!i.noext&&bEe(b)&&t.charAt(_)==="("&&o<=s){r.push(E),E="";let v=new zd(b,r);_=zd.#c(t,v,_,i,o+1),r.push(v);continue}E+=b}return r.push(E),_}let d=n+1,f=new zd(null,r),p=[],h="";for(;d<t.length;){let _=t.charAt(d++);if(a||_==="\\"){a=!a,h+=_;continue}if(l){d===c+1?(_==="^"||_==="!")&&(u=!0):_==="]"&&!(d===c+2&&u)&&(l=!1),h+=_;continue}else if(_==="["){l=!0,c=d,u=!1,h+=_;continue}if(!i.noext&&bEe(_)&&t.charAt(d)==="("&&(o<=s||r&&r.#_(_))){let b=r&&r.#_(_)?0:1;f.push(h),h="";let C=new zd(_,f);f.push(C),d=zd.#c(t,C,d,i,o+b);continue}if(_==="|"){f.push(h),h="",p.push(f),f=new zd(null,r);continue}if(_===")")return h===""&&r.#r.length===0&&(r.#m=!0),f.push(h),h="",r.push(...p,f),d;h+=_}return r.type=null,r.#t=void 0,r.#r=[t.substring(n-1)],d}#g(t){return this.#A(t,Ijr)}#A(t,r=Tjr){if(!t||typeof t!="object"||t.type!==null||t.#r.length!==1||this.type===null)return!1;let n=t.#r[0];return!n||typeof n!="object"||n.type===null?!1:this.#_(n.type,r)}#_(t,r=vjr){return!!r.get(this.type)?.includes(t)}#h(t,r){let n=t.#r[0],i=new zd(null,n,this.options);i.#r.push(""),n.push(i),this.#v(t,r)}#v(t,r){let n=t.#r[0];this.#r.splice(r,1,...n.#r);for(let i of n.#r)typeof i=="object"&&(i.#o=this);this.#d=void 0}#S(t){return!!_lt.get(this.type)?.has(t)}#C(t){if(!t||typeof t!="object"||t.type!==null||t.#r.length!==1||this.type===null||this.#r.length!==1)return!1;let r=t.#r[0];return!r||typeof r!="object"||r.type===null?!1:this.#S(r.type)}#T(t){let r=_lt.get(this.type),n=t.#r[0],i=r?.get(n.type);if(!i)return!1;this.#r=n.#r;for(let o of this.#r)typeof o=="object"&&(o.#o=this);this.type=i,this.#d=void 0,this.#m=!1}static fromGlob(t,r={}){let n=new zd(null,void 0,r);return zd.#c(t,n,0,r,0),n}toMMPattern(){if(this!==this.#e)return this.#e.toMMPattern();let t=this.toString(),[r,n,i,o]=this.toRegExpSource();if(!(i||this.#t||this.#a.nocase&&!this.#a.nocaseMagicOnly&&t.toUpperCase()!==t.toLowerCase()))return n;let a=(this.#a.nocase?"i":"")+(o?"u":"");return Object.assign(new RegExp(`^${r}$`,a),{_src:r,_glob:t})}get options(){return this.#a}toRegExpSource(t){let r=t??!!this.#a.dot;if(this.#e===this&&(this.#E(),this.#p()),!Alt(this)){let l=this.isStart()&&this.isEnd()&&!this.#r.some(p=>typeof p!="string"),c=this.#r.map(p=>{let[h,_,E,b]=typeof p=="string"?zd.#y(p,this.#t,l):p.toRegExpSource(t);return this.#t=this.#t||E,this.#n=this.#n||b,h}).join(""),u="";if(this.isStart()&&typeof this.#r[0]=="string"&&!(this.#r.length===1&&Rjr.has(this.#r[0]))){let h=wjr,_=r&&h.has(c.charAt(0))||c.startsWith("\\.")&&h.has(c.charAt(2))||c.startsWith("\\.\\.")&&h.has(c.charAt(4)),E=!r&&!t&&h.has(c.charAt(0));u=_?xjr:E?iK:""}let d="";return this.isEnd()&&this.#e.#s&&this.#o?.type==="!"&&(d="(?:$|\\/)"),[u+c+d,uC(c),this.#t=!!this.#t,this.#n]}let n=this.type==="*"||this.type==="+",i=this.type==="!"?"(?:(?!(?:":"(?:",o=this.#b(r);if(this.isStart()&&this.isEnd()&&!o&&this.type!=="!"){let l=this.toString(),c=this;return c.#r=[l],c.type=null,c.#t=void 0,[l,uC(this.toString()),!1,!1]}let s=!n||t||r||!iK?"":this.#b(!0);s===o&&(s=""),s&&(o=`(?:${o})(?:${s})*?`);let a="";if(this.type==="!"&&this.#m)a=(this.isStart()&&!r?iK:"")+Slt;else{let l=this.type==="!"?"))"+(this.isStart()&&!r&&!t?iK:"")+Elt+")":this.type==="@"?")":this.type==="?"?")?":this.type==="+"&&s?")":this.type==="*"&&s?")?":`)${this.type}`;a=i+o+l}return[a,uC(o),this.#t=!!this.#t,this.#n]}#E(){if(Alt(this)){let t=0,r=!1;do{r=!0;for(let n=0;n<this.#r.length;n++){let i=this.#r[n];typeof i=="object"&&(i.#E(),this.#A(i)?(r=!1,this.#v(i,n)):this.#g(i)?(r=!1,this.#h(i,n)):this.#C(i)&&(r=!1,this.#T(i)))}}while(!r&&++t<10)}else for(let t of this.#r)typeof t=="object"&&t.#E();this.#d=void 0}#b(t){return this.#r.map(r=>{if(typeof r=="string")throw new Error("string type in extglob ast??");let[n,i,o,s]=r.toRegExpSource(t);return this.#n=this.#n||s,n}).filter(r=>!(this.isStart()&&this.isEnd())||!!r).join("|")}static#y(t,r,n=!1){let i=!1,o="",s=!1,a=!1;for(let l=0;l<t.length;l++){let c=t.charAt(l);if(i){i=!1,o+=(Njr.has(c)?"\\":"")+c;continue}if(c==="*"){if(a)continue;a=!0,o+=n&&/^[*]+$/.test(t)?Slt:Elt,r=!0;continue}else a=!1;if(c==="\\"){l===t.length-1?o+="\\\\":i=!0;continue}if(c==="["){let[u,d,f,p]=hlt(t,l);if(f){o+=u,s=s||d,l+=f-1,r=r||p;continue}}if(c==="?"){o+=yEe,r=!0;continue}o+=Djr(c)}return[o,uC(t),!!r,s]}};zd=Q1;var CEe=(e,{windowsPathsNoEscape:t=!1,magicalBraces:r=!1}={})=>r?t?e.replace(/[?*()[\]{}]/g,"[$&]"):e.replace(/[?*()[\]\\{}]/g,"\\$&"):t?e.replace(/[?*()[\]]/g,"[$&]"):e.replace(/[?*()[\]\\]/g,"\\$&");var bc=(e,t,r={})=>(OU(t),!r.nocomment&&t.charAt(0)==="#"?!1:new CB(t,r).match(e)),Bjr=/^\*+([^+@!?*[(]*)$/,Mjr=e=>t=>!t.startsWith(".")&&t.endsWith(e),kjr=e=>t=>t.endsWith(e),Ljr=e=>(e=e.toLowerCase(),t=>!t.startsWith(".")&&t.toLowerCase().endsWith(e)),Pjr=e=>(e=e.toLowerCase(),t=>t.toLowerCase().endsWith(e)),Fjr=/^\*+\.\*+$/,Qjr=e=>!e.startsWith(".")&&e.includes("."),Ujr=e=>e!=="."&&e!==".."&&e.includes("."),Gjr=/^\.\*+$/,Hjr=e=>e!=="."&&e!==".."&&e.startsWith("."),$jr=/^\*+$/,qjr=e=>e.length!==0&&!e.startsWith("."),Yjr=e=>e.length!==0&&e!=="."&&e!=="..",zjr=/^\?+([^+@!?*[(]*)?$/,Vjr=([e,t=""])=>{let r=Clt([e]);return t?(t=t.toLowerCase(),n=>r(n)&&n.toLowerCase().endsWith(t)):r},Wjr=([e,t=""])=>{let r=Tlt([e]);return t?(t=t.toLowerCase(),n=>r(n)&&n.toLowerCase().endsWith(t)):r},jjr=([e,t=""])=>{let r=Tlt([e]);return t?n=>r(n)&&n.endsWith(t):r},Kjr=([e,t=""])=>{let r=Clt([e]);return t?n=>r(n)&&n.endsWith(t):r},Clt=([e])=>{let t=e.length;return r=>r.length===t&&!r.startsWith(".")},Tlt=([e])=>{let t=e.length;return r=>r.length===t&&r!=="."&&r!==".."},Ilt=typeof process=="object"&&process?typeof process.env=="object"&&process.env&&process.env.__MINIMATCH_TESTING_PLATFORM__||process.platform:"posix",blt={win32:{sep:"\\"},posix:{sep:"/"}},Jjr=Ilt==="win32"?blt.win32.sep:blt.posix.sep;bc.sep=Jjr;var fu=Symbol("globstar **");bc.GLOBSTAR=fu;var Zjr="[^/]",Xjr=Zjr+"*?",eKr="(?:(?!(?:\\/|^)(?:\\.{1,2})($|\\/)).)*?",tKr="(?:(?!(?:\\/|^)\\.).)*?",rKr=(e,t={})=>r=>bc(r,e,t);bc.filter=rKr;var Pf=(e,t={})=>Object.assign({},e,t),nKr=e=>{if(!e||typeof e!="object"||!Object.keys(e).length)return bc;let t=bc;return Object.assign((n,i,o={})=>t(n,i,Pf(e,o)),{Minimatch:class extends t.Minimatch{constructor(i,o={}){super(i,Pf(e,o))}static defaults(i){return t.defaults(Pf(e,i)).Minimatch}},AST:class extends t.AST{constructor(i,o,s={}){super(i,o,Pf(e,s))}static fromGlob(i,o={}){return t.AST.fromGlob(i,Pf(e,o))}},unescape:(n,i={})=>t.unescape(n,Pf(e,i)),escape:(n,i={})=>t.escape(n,Pf(e,i)),filter:(n,i={})=>t.filter(n,Pf(e,i)),defaults:n=>t.defaults(Pf(e,n)),makeRe:(n,i={})=>t.makeRe(n,Pf(e,i)),braceExpand:(n,i={})=>t.braceExpand(n,Pf(e,i)),match:(n,i,o={})=>t.match(n,i,Pf(e,o)),sep:t.sep,GLOBSTAR:fu})};bc.defaults=nKr;var vlt=(e,t={})=>(OU(e),t.nobrace||!/\{(?:(?!\{).)*\}/.test(e)?[e]:flt(e,{max:t.braceExpandMax}));bc.braceExpand=vlt;var iKr=(e,t={})=>new CB(e,t).makeRe();bc.makeRe=iKr;var oKr=(e,t,r={})=>{let n=new CB(t,r);return e=e.filter(i=>n.match(i)),n.options.nonull&&!e.length&&e.push(t),e};bc.match=oKr;var ylt=/[?*]|[+@!]\(.*?\)|\[|\]/,sKr=e=>e.replace(/[-[\]{}()*+?.,\\^$|#\s]/g,"\\$&"),CB=class{options;set;pattern;windowsPathsNoEscape;nonegate;negate;comment;empty;preserveMultipleSlashes;partial;globSet;globParts;nocase;isWindows;platform;windowsNoMagicRoot;maxGlobstarRecursion;regexp;constructor(t,r={}){OU(t),r=r||{},this.options=r,this.maxGlobstarRecursion=r.maxGlobstarRecursion??200,this.pattern=t,this.platform=r.platform||Ilt,this.isWindows=this.platform==="win32";let n="allowWindowsEscape";this.windowsPathsNoEscape=!!r.windowsPathsNoEscape||r[n]===!1,this.windowsPathsNoEscape&&(this.pattern=this.pattern.replace(/\\/g,"/")),this.preserveMultipleSlashes=!!r.preserveMultipleSlashes,this.regexp=null,this.negate=!1,this.nonegate=!!r.nonegate,this.comment=!1,this.empty=!1,this.partial=!!r.partial,this.nocase=!!this.options.nocase,this.windowsNoMagicRoot=r.windowsNoMagicRoot!==void 0?r.windowsNoMagicRoot:!!(this.isWindows&&this.nocase),this.globSet=[],this.globParts=[],this.set=[],this.make()}hasMagic(){if(this.options.magicalBraces&&this.set.length>1)return!0;for(let t of this.set)for(let r of t)if(typeof r!="string")return!0;return!1}debug(...t){}make(){let t=this.pattern,r=this.options;if(!r.nocomment&&t.charAt(0)==="#"){this.comment=!0;return}if(!t){this.empty=!0;return}this.parseNegate(),this.globSet=[...new Set(this.braceExpand())],r.debug&&(this.debug=(...o)=>console.error(...o)),this.debug(this.pattern,this.globSet);let n=this.globSet.map(o=>this.slashSplit(o));this.globParts=this.preprocess(n),this.debug(this.pattern,this.globParts);let i=this.globParts.map((o,s,a)=>{if(this.isWindows&&this.windowsNoMagicRoot){let l=o[0]===""&&o[1]===""&&(o[2]==="?"||!ylt.test(o[2]))&&!ylt.test(o[3]),c=/^[a-z]:/i.test(o[0]);if(l)return[...o.slice(0,4),...o.slice(4).map(u=>this.parse(u))];if(c)return[o[0],...o.slice(1).map(u=>this.parse(u))]}return o.map(l=>this.parse(l))});if(this.debug(this.pattern,i),this.set=i.filter(o=>o.indexOf(!1)===-1),this.isWindows)for(let o=0;o<this.set.length;o++){let s=this.set[o];s[0]===""&&s[1]===""&&this.globParts[o][2]==="?"&&typeof s[3]=="string"&&/^[a-z]:$/i.test(s[3])&&(s[2]="?")}this.debug(this.pattern,this.set)}preprocess(t){if(this.options.noglobstar)for(let n of t)for(let i=0;i<n.length;i++)n[i]==="**"&&(n[i]="*");let{optimizationLevel:r=1}=this.options;return r>=2?(t=this.firstPhasePreProcess(t),t=this.secondPhasePreProcess(t)):r>=1?t=this.levelOneOptimize(t):t=this.adjascentGlobstarOptimize(t),t}adjascentGlobstarOptimize(t){return t.map(r=>{let n=-1;for(;(n=r.indexOf("**",n+1))!==-1;){let i=n;for(;r[i+1]==="**";)i++;i!==n&&r.splice(n,i-n)}return r})}levelOneOptimize(t){return t.map(r=>(r=r.reduce((n,i)=>{let o=n[n.length-1];return i==="**"&&o==="**"?n:i===".."&&o&&o!==".."&&o!=="."&&o!=="**"?(n.pop(),n):(n.push(i),n)},[]),r.length===0?[""]:r))}levelTwoFileOptimize(t){Array.isArray(t)||(t=this.slashSplit(t));let r=!1;do{if(r=!1,!this.preserveMultipleSlashes){for(let i=1;i<t.length-1;i++){let o=t[i];i===1&&o===""&&t[0]===""||(o==="."||o==="")&&(r=!0,t.splice(i,1),i--)}t[0]==="."&&t.length===2&&(t[1]==="."||t[1]==="")&&(r=!0,t.pop())}let n=0;for(;(n=t.indexOf("..",n+1))!==-1;){let i=t[n-1];i&&i!=="."&&i!==".."&&i!=="**"&&!(this.isWindows&&/^[a-z]:$/i.test(i))&&(r=!0,t.splice(n-1,2),n-=2)}}while(r);return t.length===0?[""]:t}firstPhasePreProcess(t){let r=!1;do{r=!1;for(let n of t){let i=-1;for(;(i=n.indexOf("**",i+1))!==-1;){let s=i;for(;n[s+1]==="**";)s++;s>i&&n.splice(i+1,s-i);let a=n[i+1],l=n[i+2],c=n[i+3];if(a!==".."||!l||l==="."||l===".."||!c||c==="."||c==="..")continue;r=!0,n.splice(i,1);let u=n.slice(0);u[i]="**",t.push(u),i--}if(!this.preserveMultipleSlashes){for(let s=1;s<n.length-1;s++){let a=n[s];s===1&&a===""&&n[0]===""||(a==="."||a==="")&&(r=!0,n.splice(s,1),s--)}n[0]==="."&&n.length===2&&(n[1]==="."||n[1]==="")&&(r=!0,n.pop())}let o=0;for(;(o=n.indexOf("..",o+1))!==-1;){let s=n[o-1];if(s&&s!=="."&&s!==".."&&s!=="**"){r=!0;let l=o===1&&n[o+1]==="**"?["."]:[];n.splice(o-1,2,...l),n.length===0&&n.push(""),o-=2}}}}while(r);return t}secondPhasePreProcess(t){for(let r=0;r<t.length-1;r++)for(let n=r+1;n<t.length;n++){let i=this.partsMatch(t[r],t[n],!this.preserveMultipleSlashes);if(i){t[r]=[],t[n]=i;break}}return t.filter(r=>r.length)}partsMatch(t,r,n=!1){let i=0,o=0,s=[],a="";for(;i<t.length&&o<r.length;)if(t[i]===r[o])s.push(a==="b"?r[o]:t[i]),i++,o++;else if(n&&t[i]==="**"&&r[o]===t[i+1])s.push(t[i]),i++;else if(n&&r[o]==="**"&&t[i]===r[o+1])s.push(r[o]),o++;else if(t[i]==="*"&&r[o]&&(this.options.dot||!r[o].startsWith("."))&&r[o]!=="**"){if(a==="b")return!1;a="a",s.push(t[i]),i++,o++}else if(r[o]==="*"&&t[i]&&(this.options.dot||!t[i].startsWith("."))&&t[i]!=="**"){if(a==="a")return!1;a="b",s.push(r[o]),i++,o++}else return!1;return t.length===r.length&&s}parseNegate(){if(this.nonegate)return;let t=this.pattern,r=!1,n=0;for(let i=0;i<t.length&&t.charAt(i)==="!";i++)r=!r,n++;n&&(this.pattern=t.slice(n)),this.negate=r}matchOne(t,r,n=!1){let i=0,o=0;if(this.isWindows){let a=typeof t[0]=="string"&&/^[a-z]:$/i.test(t[0]),l=!a&&t[0]===""&&t[1]===""&&t[2]==="?"&&/^[a-z]:$/i.test(t[3]),c=typeof r[0]=="string"&&/^[a-z]:$/i.test(r[0]),u=!c&&r[0]===""&&r[1]===""&&r[2]==="?"&&typeof r[3]=="string"&&/^[a-z]:$/i.test(r[3]),d=l?3:a?0:void 0,f=u?3:c?0:void 0;if(typeof d=="number"&&typeof f=="number"){let[p,h]=[t[d],r[f]];p.toLowerCase()===h.toLowerCase()&&(r[f]=p,o=f,i=d)}}let{optimizationLevel:s=1}=this.options;return s>=2&&(t=this.levelTwoFileOptimize(t)),r.includes(fu)?this.#e(t,r,n,i,o):this.#n(t,r,n,i,o)}#e(t,r,n,i,o){let s=r.indexOf(fu,o),a=r.lastIndexOf(fu),[l,c,u]=n?[r.slice(o,s),r.slice(s+1),[]]:[r.slice(o,s),r.slice(s+1,a),r.slice(a+1)];if(l.length){let C=t.slice(i,i+l.length);if(!this.#n(C,l,n,0,0))return!1;i+=l.length,o+=l.length}let d=0;if(u.length){if(u.length+i>t.length)return!1;let C=t.length-u.length;if(this.#n(t,u,n,C,0))d=u.length;else{if(t[t.length-1]!==""||i+u.length===t.length||(C--,!this.#n(t,u,n,C,0)))return!1;d=u.length+1}}if(!c.length){let C=!!d;for(let v=i;v<t.length-d;v++){let R=String(t[v]);if(C=!0,R==="."||R===".."||!this.options.dot&&R.startsWith("."))return!1}return n||C}let f=[[[],0]],p=f[0],h=0,_=[0];for(let C of c)C===fu?(_.push(h),p=[[],0],f.push(p)):(p[0].push(C),h++);let E=f.length-1,b=t.length-d;for(let C of f)C[1]=b-(_[E--]+C[0].length);return!!this.#t(t,f,i,0,n,0,!!d)}#t(t,r,n,i,o,s,a){let l=r[i];if(!l){for(let d=n;d<t.length;d++){a=!0;let f=t[d];if(f==="."||f===".."||!this.options.dot&&f.startsWith("."))return!1}return a}let[c,u]=l;for(;n<=u;){if(this.#n(t.slice(0,n+c.length),c,o,n,0)&&s<this.maxGlobstarRecursion){let p=this.#t(t,r,n+c.length,i+1,o,s+1,a);if(p!==!1)return p}let f=t[n];if(f==="."||f===".."||!this.options.dot&&f.startsWith("."))return!1;n++}return o||null}#n(t,r,n,i,o){let s,a,l,c;for(s=i,a=o,c=t.length,l=r.length;s<c&&a<l;s++,a++){this.debug("matchOne loop");let u=r[a],d=t[s];if(this.debug(r,u,d),u===!1||u===fu)return!1;let f;if(typeof u=="string"?(f=d===u,this.debug("string match",u,d,f)):(f=u.test(d),this.debug("pattern match",u,d,f)),!f)return!1}if(s===c&&a===l)return!0;if(s===c)return n;if(a===l)return s===c-1&&t[s]==="";throw new Error("wtf?")}braceExpand(){return vlt(this.pattern,this.options)}parse(t){OU(t);let r=this.options;if(t==="**")return fu;if(t==="")return"";let n,i=null;(n=t.match($jr))?i=r.dot?Yjr:qjr:(n=t.match(Bjr))?i=(r.nocase?r.dot?Pjr:Ljr:r.dot?kjr:Mjr)(n[1]):(n=t.match(zjr))?i=(r.nocase?r.dot?Wjr:Vjr:r.dot?jjr:Kjr)(n):(n=t.match(Fjr))?i=r.dot?Ujr:Qjr:(n=t.match(Gjr))&&(i=Hjr);let o=Q1.fromGlob(t,this.options).toMMPattern();return i&&typeof o=="object"&&Reflect.defineProperty(o,"test",{value:i}),o}makeRe(){if(this.regexp||this.regexp===!1)return this.regexp;let t=this.set;if(!t.length)return this.regexp=!1,this.regexp;let r=this.options,n=r.noglobstar?Xjr:r.dot?eKr:tKr,i=new Set(r.nocase?["i"]:[]),o=t.map(l=>{let c=l.map(d=>{if(d instanceof RegExp)for(let f of d.flags.split(""))i.add(f);return typeof d=="string"?sKr(d):d===fu?fu:d._src});c.forEach((d,f)=>{let p=c[f+1],h=c[f-1];d!==fu||h===fu||(h===void 0?p!==void 0&&p!==fu?c[f+1]="(?:\\/|"+n+"\\/)?"+p:c[f]=n:p===void 0?c[f-1]=h+"(?:\\/|\\/"+n+")?":p!==fu&&(c[f-1]=h+"(?:\\/|\\/"+n+"\\/)"+p,c[f+1]=fu))});let u=c.filter(d=>d!==fu);if(this.partial&&u.length>=1){let d=[];for(let f=1;f<=u.length;f++)d.push(u.slice(0,f).join("/"));return"(?:"+d.join("|")+")"}return u.join("/")}).join("|"),[s,a]=t.length>1?["(?:",")"]:["",""];o="^"+s+o+a+"$",this.partial&&(o="^(?:\\/|"+s+o.slice(1,-1)+a+")$"),this.negate&&(o="^(?!"+o+").+$");try{this.regexp=new RegExp(o,[...i].join(""))}catch{this.regexp=!1}return this.regexp}slashSplit(t){return this.preserveMultipleSlashes?t.split("/"):this.isWindows&&/^\/\/[^/]+/.test(t)?["",...t.split(/\/+/)]:t.split(/\/+/)}match(t,r=this.partial){if(this.debug("match",t,this.pattern),this.comment)return!1;if(this.empty)return t==="";if(t==="/"&&r)return!0;let n=this.options;this.isWindows&&(t=t.split("\\").join("/"));let i=this.slashSplit(t);this.debug(this.pattern,"split",i);let o=this.set;this.debug(this.pattern,"set",o);let s=i[i.length-1];if(!s)for(let a=i.length-2;!s&&a>=0;a--)s=i[a];for(let a of o){let l=i;if(n.matchBase&&a.length===1&&(l=[s]),this.matchOne(l,a,r))return n.flipNegate?!0:!this.negate}return n.flipNegate?!1:this.negate}static defaults(t){return bc.defaults(t).Minimatch}};bc.AST=Q1;bc.Minimatch=CB;bc.escape=CEe;bc.unescape=uC;var Rlt=Ie(NU(),1);mr();Fe();Te();qu();import{readFile as xlt}from"fs/promises";import{existsSync as TEe,readdirSync as aKr,statSync as lKr}from"fs";import{join as IEe,relative as Nlt}from"path";import{homedir as cKr}from"os";function wlt(e){try{let t=(0,Rlt.default)(e),r=t.data.paths,n=[];return typeof r=="string"?n=r.split(",").map(i=>i.trim()).filter(Boolean):Array.isArray(r)&&(n=r.filter(i=>typeof i=="string")),{paths:n,content:t.content.trim()}}catch(t){return Ee(t),{paths:[],content:e.trim()}}}function uKr(e,t){return t.length===0?!0:t.some(r=>{try{return bc(e,r,{matchBase:!0,dot:!0})}catch(n){return Ee(n),!1}})}function vEe(e){let t=[];try{if(!TEe(e))return t;let r=aKr(e);for(let n of r){let i=IEe(e,n),o=lKr(i);o.isDirectory()?t.push(...vEe(i)):o.isFile()&&n.endsWith(".md")&&t.push(i)}}catch(r){Ee(r)}return t}async function oK(){let e=[];try{let t=IEe(cKr(),bn,"rules");if(TEe(t)){let r=vEe(t);for(let n of r)try{let i=await xlt(n,"utf-8"),{paths:o,content:s}=wlt(i);o.length>0&&e.push({filePath:n,content:s,paths:o,isProjectRule:!1})}catch(i){Ee(i)}}}catch(t){Ee(t)}try{let t=IEe(De(),bn,"rules");if(TEe(t)){let r=vEe(t);for(let n of r)try{let i=await xlt(n,"utf-8"),{paths:o,content:s}=wlt(i);o.length>0&&e.push({filePath:Nlt(De(),n),content:s,paths:o,isProjectRule:!0})}catch(i){Ee(i)}}}catch(t){Ee(t)}return e}function Dlt(e,t){e=Q7(e);let r=Q7(De()),n=e.startsWith(r)?Nlt(r,e):e;return t.filter(i=>uKr(n,i.paths))}function Olt(e){return e.length===0?"":e.map(r=>{let n=r.isProjectRule?"project instructions, checked into the codebase":"user's private global instructions for all projects";return`Contents of ${r.filePath} (${n}):
656
656
 
657
657
  ${r.content}`}).join(`
658
658
 
@@ -753,7 +753,7 @@ data: ${JSON.stringify(P)}
753
753
  `);a=O.pop()||"";for(let P of O){let H=P.trim();if(!(!H||H==="data: [DONE]"))if(H.startsWith("data: ")){let Q=H.slice(6);try{let V=JSON.parse(Q);R(V)}catch(V){this.logger&&this.logger.error({err:V,line:H},"Failed to parse Gemini SSE chunk")}}else try{let Q=JSON.parse(H);R(Q)}catch{}}};(async()=>{try{for(;;){let{value:O,done:P}=await s.read();if(P)break;a+=n.decode(O,{stream:!0}),D()}v()}catch(O){o.error(O)}})()}})}convertGeminiResponseToAnthropic(t){this.logger&&this.logger.debug({response:t},"Original Gemini response");try{if(!t.candidates||!t.candidates[0])throw new Error("No candidates found in Gemini response");let r=t.candidates[0],n=[];r.content&&r.content.parts&&r.content.parts.forEach(o=>{if(o.text&&n.push({type:"text",text:o.text}),o.functionCall){let s=`toolu_${zB()}`,a=o.functionCall.thoughtSignature||o.functionCall.thought_signature||null;n.push({type:"tool_use",id:s,name:o.functionCall.name,input:o.functionCall.args||{},thought_signature:a})}}),r.groundingMetadata&&(this.logger&&this.logger.debug({groundingMetadata:r.groundingMetadata},"Processing grounding metadata"),r.groundingMetadata.webSearchQueries&&n.push({type:"text",text:`
754
754
 
755
755
  [Search queries used: ${r.groundingMetadata.webSearchQueries.join(", ")}]`}));let i={id:`msg_${Math.random().toString(36).slice(2)}`,type:"message",role:"assistant",model:t.modelVersion||"gemini",content:n,stop_reason:r.finishReason?r.finishReason==="STOP"&&n.some(o=>o.type==="tool_use")?"tool_use":this.mapGeminiFinishReason(r.finishReason):"end_turn",stop_sequence:null,usage:{input_tokens:t.usageMetadata?.promptTokenCount||0,output_tokens:t.usageMetadata?.candidatesTokenCount||0}};return this.logger&&this.logger.debug({result:i},"Conversion complete, final Anthropic response"),i}catch{throw Otn(`Provider error: ${JSON.stringify(t)}`,500,"provider_error")}}mapGeminiFinishReason(t){switch(t){case"STOP":return"end_turn";case"MAX_TOKENS":return"max_tokens";case"SAFETY":case"RECITATION":return"stop_sequence";default:return"end_turn"}}},Pbe=new Lbe;var jEt=Ie(zEt(),1);Jt();wo();function Ch(e){return e?typeof e.entries=="function"?Object.fromEntries(e.entries()):{...e}:{}}function VEt(e){let t=String(e?.["x-thinking-level"]??"medium").toLowerCase();return["off","low","medium","high"].includes(t)?t:"medium"}function zAn(e,t){if(t==="off"){delete e.reasoning;return}e.reasoning={effort:t}}function VAn(e,t){if(t==="off"){delete e.reasoning;return}e.reasoning={effort:t,summary:"auto"}}function WAn(e,t="chat"){let r={request:{},response:{},openai:{request:{},response:{}}};return r.request.model=e.request.body.model,r.request.messages=e.request.body.messages,r.request.system=e.request.body.system,r.response.content=e.response.body.content,r.response.usage=e.response.body?.usage,t==="responses"?(r.openai.request.model=e.openai.request.body.model,r.openai.request.input=e.openai.request.body.input,r.openai.response.output=e.openai.response.body?.output,r.openai.response.usage=e.openai.response.body?.usage):(r.openai.request.model=e.openai.request.body.model,r.openai.request.messages=e.openai.request.body.messages,r.openai.response.choices=e.openai.response.body.choices,r.openai.response.usage=e.openai.response.body?.usage),r}function R4(e,t,r){BY(t,e),MY(t,WAn(e,r),r)}function MM(e){let t=[],r=e.getReader(),n,i=new Promise(l=>n=l),o=!1,s=()=>{o||(o=!0,n(Buffer.concat(t).toString("utf8")))};return{stream:new ReadableStream({async pull(l){try{let{done:c,value:u}=await r.read();if(c){l.close(),s();return}t.push(u),l.enqueue(u)}catch(c){l.error(c),s()}},cancel(l){r.cancel(l).catch(()=>{}),s()}}),done:i}}function N4(e){let t=new Headers(e);return t.delete("content-encoding"),t.delete("content-length"),t.delete("transfer-encoding"),t}function dIe(e,t,r,n,i){let o;try{o={type:"error",error:{type:"api_error",message:JSON.parse(i).error?.message??`${e}: ${n}`,code:`${t}_${r}_ERROR`}}}catch{o={type:"error",error:{type:"api_error",message:`${e}: ${n}`,code:`${t}_${r}_ERROR`}}}return new Response(JSON.stringify(o),{status:r,statusText:n,headers:{"Content-Type":"application/json"}})}var WEt=["/v1/messages"];function pIe(e){let t;try{typeof e=="string"?t=new wx(e):e instanceof wx?t=e:t=new wx(e.url)}catch{return""}let r=t.pathname;for(let n of WEt){let i=r.indexOf(n);if(i!==-1)return t.origin+r.slice(0,i)}return t.origin}function UX(e,t){let r=typeof e=="string"?e:e instanceof wx?e.toString():e.url,n;try{n=new wx(r).pathname}catch{return!1}return WEt.some(i=>n.includes(i))&&(t.method==="POST"||t.method==="post")}function jAn(e){return async(t,r)=>{if(!UX(t,r))return e(t,r);let n=JSON.parse(r.body),i=await GJ.transformRequestOut(n),o=pIe(t)+"/chat/completions",s=Ch(r.headers),a=s.authorization??s.Authorization??"";zAn(i,VEt(s));let l=await e(o,{method:"POST",headers:{"Content-Type":"application/json",Authorization:a},body:JSON.stringify(i),signal:r.signal});if(!l.ok){let E=await l.text();return X(`OpenAI Chat Completions API error: ${l.status}`,{url:o,errorResponse:E}),dIe("OpenAI Chat Completions API error","OPENROUTER",l.status,l.statusText,E)}let c=n.stream===!0,u=s["x-agent-id"],d={request:{url:o,method:r.method,headers:s,body:n},response:{status:l.status,statusText:l.statusText,headers:Ch(l.headers)},openai:{request:{body:i},response:{}}};if(!c){let E=await l.text(),b=new Response(E,{status:l.status,statusText:l.statusText,headers:N4(l.headers)}),C=await GJ.transformResponseIn(b,n),v=await C.text();try{R4({...d,openai:{...d.openai,response:{body:JSON.parse(E)}},response:{...d.response,body:JSON.parse(v)}},u)}catch(R){X("\u65E5\u5FD7\u89E3\u6790\u9519\u8BEF(Chat \u975E\u6D41\u5F0F):",R)}return new Response(v,{status:C.status,statusText:C.statusText,headers:C.headers})}let f=MM(l.body),p=new Response(f.stream,{status:l.status,statusText:l.statusText,headers:N4(l.headers)}),h=await GJ.transformResponseIn(p,n),_=MM(h.body);return Promise.all([f.done,_.done]).then(async([E,b])=>{try{R4({...d,openai:{...d.openai,response:{body:await yut(E)}},response:{...d.response,body:await b9(b)}},u)}catch(C){X("\u65E5\u5FD7\u89E3\u6790\u9519\u8BEF(Chat \u6D41\u5F0F):"+C?.stack)}}).catch(E=>X("\u65E5\u5FD7\u805A\u5408\u9519\u8BEF(Chat):"+E)),new Response(_.stream,{status:h.status,statusText:h.statusText,headers:h.headers})}}function KAn(e){return async(t,r)=>{if(!UX(t,r))return e(t,r);let n=JSON.parse(r.body),i=await HJ.transformRequestOut(n),o=Ch(r.headers);VAn(i,VEt(o));let s=JSON.stringify(i),l=pIe(t)+"/responses",c=o.authorization??o.Authorization??"";if(!c)return new Response(JSON.stringify({type:"error",error:{type:"api_error",message:"Missing Authorization header",code:"RESPONSES_AUTH_MISSING"}}),{status:401,headers:{"Content-Type":"application/json"}});let u=await e(l,{method:"POST",headers:{"Content-Type":"application/json",Authorization:c,"x-api-key":c.replace(/^Bearer\s+/i,"").trim()},body:s,signal:r.signal});if(!u.ok){let C=await u.text();return X(`OpenAI Responses API error: ${u.status} ${u.statusText}`,{url:l,status:u.status,errorResponse:C}),dIe("OpenAI Responses API error","RESPONSES",u.status,u.statusText,C)}let d=n.stream===!0,f=o["x-agent-id"],p={request:{url:l,method:r.method,headers:o,body:n},response:{status:u.status,statusText:u.statusText,headers:Ch(u.headers)},openai:{request:{body:i},response:{}}};if(!d){let C=await u.text(),v=new Response(C,{status:u.status,statusText:u.statusText,headers:N4(u.headers)}),R=await HJ.transformResponseIn(v,n),D=await R.text();try{R4({...p,openai:{...p.openai,response:{body:JSON.parse(C)}},response:{...p.response,body:JSON.parse(D)}},f,"responses")}catch(O){X("\u65E5\u5FD7\u89E3\u6790\u9519\u8BEF(Responses \u975E\u6D41\u5F0F):",O)}return new Response(D,{status:R.status,statusText:R.statusText,headers:R.headers})}let h=MM(u.body),_=new Response(h.stream,{status:u.status,statusText:u.statusText,headers:N4(u.headers)}),E=await HJ.transformResponseIn(_,n),b=MM(E.body);return Promise.all([h.done,b.done]).then(async([C,v])=>{try{R4({...p,openai:{...p.openai,response:{body:await but(C)}},response:{...p.response,body:await b9(v)}},f,"responses")}catch(R){X("\u65E5\u5FD7\u89E3\u6790\u9519\u8BEF(Responses \u6D41\u5F0F):"+R?.stack)}}).catch(C=>X("\u65E5\u5FD7\u805A\u5408\u9519\u8BEF(Responses):"+C)),new Response(b.stream,{status:E.status,statusText:E.statusText,headers:E.headers})}}function JAn(e){return async(t,r)=>{if(!UX(t,r))return e(t,r);let n=JSON.parse(r.body),i=Ch(r.headers),o=await Pbe.transformRequestOut(n),s=JSON.stringify(o),a=pIe(t)+`/models/${n.model}:streamGenerateContent?alt=sse`,l=i.authorization??i.Authorization??"",c;try{c=await e(a,{method:"POST",headers:{"Content-Type":"application/json","x-goog-api-key":String(l).replace(/^Bearer\s+/i,"").trim()},body:s,signal:r.signal})}catch(b){throw X("gemini request error:",b),b}if(!c.ok){let b=await c.text();return X(`Gemini API error response: ${c.status} ${c.statusText}`,{url:a,status:c.status,errorResponse:b}),dIe("Gemini API error","Gemini",c.status,c.statusText,b)}let u=n.stream===!0,d=i["x-agent-id"],f={request:{url:a,method:r.method,headers:Ch(r.headers),body:n},response:{status:c.status,statusText:c.statusText,headers:Ch(c.headers)},openai:{request:{body:o},response:{}}},p=MM(c.body),h=new Response(p.stream,{status:c.status,statusText:c.statusText,headers:N4(c.headers)}),_=await Pbe.transformResponseIn(h),E=MM(_.body);return Promise.all([p.done,E.done]).then(async([b,C])=>{try{let v=u?Cut(b):JSON.parse(b),R=u?await b9(C):JSON.parse(C);R4({...f,openai:{...f.openai,response:{body:v}},response:{...f.response,body:R}},d)}catch(v){X("\u65E5\u5FD7\u89E3\u6790\u9519\u8BEF(Gemini):"+v?.stack)}}).catch(b=>X("\u65E5\u5FD7\u805A\u5408\u9519\u8BEF(Gemini):"+b)),new Response(E.stream,{status:_.status,statusText:_.statusText,headers:_.headers})}}function ZAn(e){return async(t,r)=>{if(!UX(t,r))return e(t,r);let n=r.body;if(r.body)try{let d=JSON.parse(r.body);n=JSON.stringify(d)}catch{}let i=Ch(r.headers);["1","true"].includes(String(process.env.HAWA_CODE_X_API_KEY_DISABLED??"").toLowerCase())&&(delete i["x-api-key"],delete i["X-API-Key"]),["1","true"].includes(String(process.env.HAWA_CODE_AUTH_DISABLED??"").toLowerCase())&&(delete i.authorization,delete i.Authorization),delete i["content-length"];let a=await e(t,{method:r.method,headers:i,body:n,signal:r.signal});if(!a.ok){let d=await a.text();X(`API error response: ${a.status} ${a.statusText}`,{url:typeof t=="string"?t:t instanceof wx?t.toString():t.url,status:a.status,errorResponse:d});let f;try{let p=JSON.parse(d);f={type:"error",error:{type:"api_error",message:p.error?.message||p.message||`API error: ${a.statusText}`,code:p.error?.code||p.code||`API_${a.status}_ERROR`}},p.error?.details&&(f.error.details=p.error.details)}catch{f={type:"error",error:{type:"api_error",message:`API error: ${a.statusText}`,code:`API_${a.status}_ERROR`}}}return new Response(JSON.stringify(f),{status:a.status,statusText:a.statusText,headers:{"Content-Type":"application/json"}})}let l=a.clone(),c=!(Object.hasOwn(JSON.parse(n),"stream")&&!JSON.parse(n).stream),u={request:{url:typeof t=="string"?t:t instanceof wx?t.toString():t.url,method:r.method,headers:Ch(r.headers),body:JSON.parse(n)},response:{status:a.status,statusText:a.statusText,headers:Ch(a.headers)}};return(async()=>{if(c){let p=await a.text();u.response.body=await b9(p)}else u.response.body=await a.json();let f=Ch(r.headers)["x-agent-id"];BY(f,u),MY(f,{request:u.request.body.messages,response:u.response.body.content,usage:u.response.body?.usage})})().catch(d=>X(`\u65E5\u5FD7\u89E3\u6790\u9519\u8BEF:
756
- Stack trace: `+d.stack)),new Response(l.body,{status:a.status,statusText:a.statusText,headers:a.headers})}}var QX=null,uIe=!1;function XAn(){QX=null,uIe=!1}Tt.on("proxy:changed",XAn);function e_n(){if(uIe)return QX;if(uIe=!0,Ve().proxy!==!0)return null;let e=process.env.HTTPS_PROXY||process.env.HTTP_PROXY||process.env.https_proxy||process.env.http_proxy;return e&&(QX=new jEt.ProxyAgent({uri:e}),St(`[proxy] using proxy: ${e}`)),QX}function t_n(){let e=e_n();return e?((t,r={})=>global.fetch(t,{...r,dispatcher:e})):global.fetch}function GX(e){let t=e||process.env.API_TYPE,r=t_n();switch(t){case"openai":return jAn(r);case"openai-responses":return KAn(r);case"gemini":return JAn(r);default:return ZAn(r)}}WA();Te();Fe();Fe();var mIe="2.8.9";globalThis.MACRO={VERSION:mIe,PACKAGE_URL:`@dahawa/${Fi}`,README_URL:"https://github.com/italking/hawa-code",ISSUES_EXPLAINER:"report the issue at https://github.com/italking/hawa-code/issues"};var HX=process.env.HAWA_CODE_USER_AGENT||`${Fi}/${mIe} (${process.env.USER_TYPE})`;Te();Te();cr();function Au(e,t){let r=[],n=new Set;return e.filter(i=>i.type!=="progress"&&i.type!=="reminder").forEach(i=>{switch(i.type){case"user":{let o=Yp(r);if(o?.type==="user"){r[r.length-1]=KEt(o,i);return}r.push(i);return}case"assistant":r.push(i);return;case"insert":{let o=Yp(r);o?.type==="user"&&(r[r.length-1]=r_n(o,i));return}case"path_rules":{let o=t?.pathRules;if(!o)return;let s=i.content.paths.filter(u=>!n.has(u));if(s.length===0)return;let a=s.map(u=>o.get(u)).filter(u=>u!==void 0);if(s.forEach(u=>n.add(u)),a.length===0)return;let l=Bt([{type:"text",text:`<system-rules>
756
+ Stack trace: `+d.stack)),new Response(l.body,{status:a.status,statusText:a.statusText,headers:a.headers})}}var QX=null,uIe=!1;function XAn(){QX=null,uIe=!1}Tt.on("proxy:changed",XAn);function e_n(){if(uIe)return QX;if(uIe=!0,Ve().proxy!==!0)return null;let e=process.env.HTTPS_PROXY||process.env.HTTP_PROXY||process.env.https_proxy||process.env.http_proxy;return e&&(QX=new jEt.ProxyAgent({uri:e}),St(`[proxy] using proxy: ${e}`)),QX}function t_n(){let e=e_n();return e?((t,r={})=>global.fetch(t,{...r,dispatcher:e})):global.fetch}function GX(e){let t=e||process.env.API_TYPE,r=t_n();switch(t){case"openai":return jAn(r);case"openai-responses":return KAn(r);case"gemini":return JAn(r);default:return ZAn(r)}}WA();Te();Fe();Fe();var mIe="2.8.10";globalThis.MACRO={VERSION:mIe,PACKAGE_URL:`@dahawa/${Fi}`,README_URL:"https://github.com/italking/hawa-code",ISSUES_EXPLAINER:"report the issue at https://github.com/italking/hawa-code/issues"};var HX=process.env.HAWA_CODE_USER_AGENT||`${Fi}/${mIe} (${process.env.USER_TYPE})`;Te();Te();cr();function Au(e,t){let r=[],n=new Set;return e.filter(i=>i.type!=="progress"&&i.type!=="reminder").forEach(i=>{switch(i.type){case"user":{let o=Yp(r);if(o?.type==="user"){r[r.length-1]=KEt(o,i);return}r.push(i);return}case"assistant":r.push(i);return;case"insert":{let o=Yp(r);o?.type==="user"&&(r[r.length-1]=r_n(o,i));return}case"path_rules":{let o=t?.pathRules;if(!o)return;let s=i.content.paths.filter(u=>!n.has(u));if(s.length===0)return;let a=s.map(u=>o.get(u)).filter(u=>u!==void 0);if(s.forEach(u=>n.add(u)),a.length===0)return;let l=Bt([{type:"text",text:`<system-rules>
757
757
  ${Olt(a)}
758
758
  </system-rules>`}]),c=Yp(r);c?.type==="user"?r[r.length-1]=KEt(c,l,{skipTrailingSystemReminders:!0}):r.push(l);return}}}),r}function r_n(e,t){return{...e,message:{...e.message,content:i_n(e.message.content,n_n(t.content.content))}}}function n_n(e){return`
759
759
  <system-reminder>
@@ -3350,7 +3350,7 @@ ${r.allowedTools.join(`
3350
3350
 
3351
3351
  Slash commands available during an interactive session:
3352
3352
  ${c}`).argument("[prompt]","Your prompt",String).option("-c, --cwd <cwd>","The current working directory",String,vp()).option("-d, --debug","Enable debug mode",()=>!0).option("--verbose","Override verbose mode setting from config",()=>!0).option("-ea, --enable-architect","Enable the Architect tool",()=>!0).option("-p, --print","Print response and exit (useful for pipes)",()=>!0).option("--dangerously-skip-permissions","Skip all permission checks. Only works in Docker containers with no internet access. Will crash otherwise.",()=>!0).action(async(_,{cwd:E,debug:b,verbose:C,enableArchitect:v,print:R,dangerouslySkipPermissions:D})=>{await Ggi(D,R),$e("tengu_init",{entrypoint:"hawacode",hasInitialPrompt:(!!_).toString(),hasStdin:(!!e).toString(),enableArchitect:v?.toString()??"false",verbose:C?.toString()??"false",debug:b?.toString()??"false",print:R?.toString()??"false"}),await zm(E,D),x3e();let O=R?()=>{}:sGe("Loading MCP tools, please wait..."),P;try{[P]=await Promise.all([Bg(),vg()])}finally{O()}jur();let H=[_,e].filter(Boolean).join(`
3353
- `);if(R){H||(console.error("Error: Input must be provided either through stdin or as a prompt argument when using --print"),process.exit(1)),RI(H);let{resultText:Q}=await aur({commands:l,hasPermissionsToUseTool:eI,prompt:H,cwd:E,tools:P,dangerouslySkipPermissions:D});console.log(Q),process.exit(0)}else{let Q=await U5(),V=Xe.getSessionContext().getSessionId();await Wur("startup",V,D),yl.loadSession(V);let{PluginUpdateService:U}=await Promise.resolve().then(()=>(qur(),$ur));U.start(),uc((0,A.jsx)(j$,{commands:l,debug:b,initialPrompt:H,shouldShowPromptInput:!0,verbose:C,tools:P,dangerouslySkipPermissions:D,isDefaultModel:Q}),t)}}).version(MACRO.VERSION,"-v, --version"),process.env.USER_TYPE==="ant"&&r.option("--melon","Enable melon mode").hook("preAction",async()=>{if(r.opts().melon){let{runMelonWrapper:_}=await Promise.resolve().then(()=>(zur(),Yur)),E=process.argv.slice(process.argv.indexOf("--melon")+1),b=_(E);process.exit(b)}});let u=r.command("config").description("Manage configuration (eg. ${PRODUCT_NAME} config set -g theme dark)");u.command("get <key>").description("Get a config value").option("-c, --cwd <cwd>","The current working directory",String,vp()).option("-g, --global","Use global config").action(async(_,{cwd:E,global:b})=>{await zm(E,!1),console.log(urt(_,b??!1)),process.exit(0)}),u.command("set <key> <value>").description("Set a config value").option("-c, --cwd <cwd>","The current working directory",String,vp()).option("-g, --global","Use global config").action(async(_,E,{cwd:b,global:C})=>{await zm(b,!1),drt(_,E,C??!1),console.log(`Set ${_} to ${E}`),process.exit(0)}),u.command("remove <key>").description("Remove a config value").option("-c, --cwd <cwd>","The current working directory",String,vp()).option("-g, --global","Use global config").action(async(_,{cwd:E,global:b})=>{await zm(E,!1),prt(_,b??!1),console.log(`Removed ${_}`),process.exit(0)}),u.command("list").description("List all config values").option("-c, --cwd <cwd>","The current working directory",String,vp()).option("-g, --global","Use global config",!1).action(async({cwd:_,global:E})=>{await zm(_,!1),console.log(JSON.stringify(E?VAe(!0):VAe(!1),null,2)),process.exit(0)});let d=r.command("approved-tools").description("Manage approved tools");d.command("list").description("List all approved tools").action(async()=>{let _=kur(De());console.log(_),process.exit(0)}),d.command("remove <tool>").description("Remove a tool from the list of approved tools").action(async _=>{let E=Lur(_);$e("tengu_approved_tool_remove",{tool:_,success:String(E.success)}),console.log(E.message),process.exit(E.success?0:1)}),r.command("hands").description(`Start the ${nt} MCP server`).option("-c, --cwd <cwd>","The current working directory",String,vp()).action(async _=>{let E=_.cwd??r.opts().cwd??vp();$e("tengu_mcp_start",{providedCwd:E}),Vur(E)||(console.error(`Error: Directory ${E} does not exist`),process.exit(1));try{await zm(E,!1),await Dur(E)}catch(b){console.error("Error: Failed to start MCP server:",b),process.exit(1)}}),r.command("server").description("\u4EE5 headless \u6A21\u5F0F\u542F\u52A8\uFF1A\u4E0D\u6E32\u67D3\u7EC8\u7AEF UI\uFF0C\u4EC5\u901A\u8FC7 WebServer \u63D0\u4F9B\u6D4F\u89C8\u5668\u8FDC\u7A0B\u63A7\u5236").option("--resume <id>","\u6062\u590D\u6307\u5B9A\u5386\u53F2\u4F1A\u8BDD").option("--cwd <path>","\u5DE5\u4F5C\u76EE\u5F55\uFF08\u9ED8\u8BA4\u8FDB\u7A0B cwd\uFF09").option("--verbose","\u8F93\u51FA\u8BE6\u7EC6\u4FE1\u606F",!1).option("--dangerously-skip-permissions","\u8DF3\u8FC7\u6743\u9650\u786E\u8BA4\uFF08\u4EC5\u9650\u53D7\u4FE1\u73AF\u5883\uFF09",!1).action(async _=>{await Gur({resume:_.resume,cwd:_.cwd,verbose:_.verbose,dangerouslySkipPermissions:_.dangerouslySkipPermissions})});let f=r.command("mcp").description("Configure and manage MCP servers");process.env.USER_TYPE==="ant"&&f.command("add-sse <name> <url>").description("Add an SSE server").option("-s, --scope <scope>","Configuration scope (project or global)","project").action(async(_,E,b)=>{try{let C=Fse(b.scope);$e("tengu_mcp_add",{name:_,type:"sse",scope:C}),$Fe(_,{type:"sse",url:E,headers:{}},C),console.log(`Added SSE MCP server ${_} with URL ${E} to ${C} config`),process.exit(0)}catch(C){console.error(C.message),process.exit(1)}}),f.command("add <name> <command> [args...]").description("Add a stdio server").option("-s, --scope <scope>","Configuration scope (project or global)","project").option("-e, --env <env...>","Set environment variables (e.g. -e KEY=value)").action(async(_,E,b,C)=>{try{let v=Fse(C.scope);$e("tengu_mcp_add",{name:_,type:"stdio",scope:v});let R=PHt(C.env);$Fe(_,{type:"stdio",command:E,args:b||[],env:R},v),console.log(`Added stdio MCP server ${_} with command: ${E} ${(b||[]).join(" ")} to ${v} config`),process.exit(0)}catch(v){console.error(v.message),process.exit(1)}}),f.command("remove <name>").description("Remove an MCP server").option("-s, --scope <scope>","Configuration scope (project, global, or mcprc)","project").action(async(_,E)=>{try{let b=Fse(E.scope);$e("tengu_mcp_delete",{name:_,scope:b}),FHt(_,b),console.log(`Removed MCP server ${_} from ${b} config`),process.exit(0)}catch(b){console.error(b.message),process.exit(1)}}),f.command("list").description("List configured MCP servers").action(()=>{$e("tengu_mcp_list",{});let _=qFe();if(Object.keys(_).length===0)console.log(`No MCP servers configured. Use \`${nt} mcp add\` to add a server.`);else for(let[E,b]of Object.entries(_))"command"in b?console.log(`${E}: ${b.command} ${b.args.join(" ")}`):console.log(`${E}: ${b.url} (${b.type.toUpperCase()})`);process.exit(0)}),f.command("get <name>").description("Get details about an MCP server").action(_=>{$e("tengu_mcp_get",{name:_});let E=Qse(_);if(E||(console.error(`No MCP server found with name: ${_}`),process.exit(1)),console.log(`${_}:`),console.log(` Scope: ${E.scope}`),"command"in E){if(console.log(" Type: stdio"),console.log(` Command: ${E.command}`),console.log(` Args: ${E.args.join(" ")}`),E.env){console.log(" Environment:");for(let[b,C]of Object.entries(E.env))console.log(` ${b}=${C}`)}}else console.log(` Type: ${E.type}`),console.log(` URL: ${E.url}`);process.exit(0)}),process.env.USER_TYPE==="ant"&&f.command("reset-mcprc-choices").description("Reset all approved and rejected .mcp.json servers for this project").action(()=>{$e("tengu_mcp_reset_mcprc_choices",{});let _=Rn();Ji({..._,approvedMcprcServers:[],rejectedMcprcServers:[]}),console.log("All .mcp.json server approvals and rejections have been reset."),console.log(`You will be prompted for approval next time you start ${nt}.`),process.exit(0)});let p=r.command("plugin").description("Manage plugins and marketplaces"),h=p.command("marketplace").description("Manage plugin marketplaces");if(h.command("add <source>").description("Add a marketplace from a local path, GitHub shorthand, git URL, or marketplace.json URL").action(async _=>{let{MarketplaceService:E}=await Promise.resolve().then(()=>(pg(),cw)),b=await E.add(_);b.success||(console.error(`Error: ${b.error}`),process.exit(1)),console.log(`Added marketplace "${b.name}"`),process.exit(0)}),h.command("install <name>").description("Install a registered marketplace by fetching its contents").action(async _=>{let{MarketplaceService:E}=await Promise.resolve().then(()=>(pg(),cw)),b=await E.install(_);b.success||(console.error(`Error: ${b.error}`),process.exit(1)),console.log(`Installed marketplace "${_}"`),process.exit(0)}),h.command("uninstall <name>").description("Uninstall a marketplace by removing its local cache").action(async _=>{let{MarketplaceService:E}=await Promise.resolve().then(()=>(pg(),cw)),b=await E.uninstall(_);b.success||(console.error(`Error: ${b.error}`),process.exit(1)),console.log(`Uninstalled marketplace "${_}"`),process.exit(0)}),h.command("remove <name>").alias("rm").description("Remove a marketplace from the list").action(async _=>{let{MarketplaceService:E}=await Promise.resolve().then(()=>(pg(),cw)),b=E.remove(_);b.success||(console.error(`Error: ${b.error}`),process.exit(1)),console.log(`Removed marketplace "${_}"`),process.exit(0)}),h.command("list").description("List registered marketplaces").option("--json","Output as JSON").action(async _=>{let{MarketplaceService:E}=await Promise.resolve().then(()=>(pg(),cw)),b=E.list();if(_.json)console.log(JSON.stringify(b,null,2));else if(b.length===0)console.log("No marketplaces registered.");else for(let C of b)console.log(`${C.name} (${C.type}): ${C.source}`);process.exit(0)}),h.command("update [name]").description("Refresh marketplaces from their sources").action(async _=>{let{MarketplaceService:E}=await Promise.resolve().then(()=>(pg(),cw)),b=await E.update(_);b.updated.length>0&&console.log(`Updated: ${b.updated.join(", ")}`),b.errors.length>0&&(console.error(`Errors:
3353
+ `);if(R){H||(console.error("Error: Input must be provided either through stdin or as a prompt argument when using --print"),process.exit(1)),RI(H);let{resultText:Q}=await aur({commands:l,hasPermissionsToUseTool:eI,prompt:H,cwd:E,tools:P,dangerouslySkipPermissions:D});console.log(Q),process.exit(0)}else{let Q=await U5(),V=Xe.getSessionContext().getSessionId();await Wur("startup",V,D),yl.loadSession(V);let{PluginUpdateService:U}=await Promise.resolve().then(()=>(qur(),$ur));U.start(),uc((0,A.jsx)(j$,{commands:l,debug:b,initialPrompt:H,shouldShowPromptInput:!0,verbose:C,tools:P,dangerouslySkipPermissions:D,isDefaultModel:Q}),t)}}).version(MACRO.VERSION,"-v, --version"),process.env.USER_TYPE==="ant"&&r.option("--melon","Enable melon mode").hook("preAction",async()=>{if(r.opts().melon){let{runMelonWrapper:_}=await Promise.resolve().then(()=>(zur(),Yur)),E=process.argv.slice(process.argv.indexOf("--melon")+1),b=_(E);process.exit(b)}});let u=r.command("config").description("Manage configuration (eg. ${PRODUCT_NAME} config set -g theme dark)");u.command("get <key>").description("Get a config value").option("-c, --cwd <cwd>","The current working directory",String,vp()).option("-g, --global","Use global config").action(async(_,{cwd:E,global:b})=>{await zm(E,!1),console.log(urt(_,b??!1)),process.exit(0)}),u.command("set <key> <value>").description("Set a config value").option("-c, --cwd <cwd>","The current working directory",String,vp()).option("-g, --global","Use global config").action(async(_,E,{cwd:b,global:C})=>{await zm(b,!1),drt(_,E,C??!1),console.log(`Set ${_} to ${E}`),process.exit(0)}),u.command("remove <key>").description("Remove a config value").option("-c, --cwd <cwd>","The current working directory",String,vp()).option("-g, --global","Use global config").action(async(_,{cwd:E,global:b})=>{await zm(E,!1),prt(_,b??!1),console.log(`Removed ${_}`),process.exit(0)}),u.command("list").description("List all config values").option("-c, --cwd <cwd>","The current working directory",String,vp()).option("-g, --global","Use global config",!1).action(async({cwd:_,global:E})=>{await zm(_,!1),console.log(JSON.stringify(E?VAe(!0):VAe(!1),null,2)),process.exit(0)});let d=r.command("approved-tools").description("Manage approved tools");d.command("list").description("List all approved tools").action(async()=>{let _=kur(De());console.log(_),process.exit(0)}),d.command("remove <tool>").description("Remove a tool from the list of approved tools").action(async _=>{let E=Lur(_);$e("tengu_approved_tool_remove",{tool:_,success:String(E.success)}),console.log(E.message),process.exit(E.success?0:1)}),r.command("hands").description(`Start the ${nt} MCP server`).option("-c, --cwd <cwd>","The current working directory",String,vp()).action(async _=>{let E=_.cwd??r.opts().cwd??vp();$e("tengu_mcp_start",{providedCwd:E}),Vur(E)||(console.error(`Error: Directory ${E} does not exist`),process.exit(1));try{await zm(E,!1),await Dur(E)}catch(b){console.error("Error: Failed to start MCP server:",b),process.exit(1)}}),r.command("server").description("\u4EE5 headless \u6A21\u5F0F\u542F\u52A8\uFF1A\u4E0D\u6E32\u67D3\u7EC8\u7AEF UI\uFF0C\u4EC5\u901A\u8FC7 WebServer \u63D0\u4F9B\u6D4F\u89C8\u5668\u8FDC\u7A0B\u63A7\u5236").option("--resume <id>","\u6062\u590D\u6307\u5B9A\u5386\u53F2\u4F1A\u8BDD").option("--cwd <path>","\u5DE5\u4F5C\u76EE\u5F55\uFF08\u9ED8\u8BA4\u8FDB\u7A0B cwd\uFF09").option("--verbose","\u8F93\u51FA\u8BE6\u7EC6\u4FE1\u606F",!1).option("--dangerously-skip-permissions","\u8DF3\u8FC7\u6743\u9650\u786E\u8BA4\uFF08\u4EC5\u9650\u53D7\u4FE1\u73AF\u5883\uFF09",!1).action(async _=>{let E=r.opts(),b=_.dangerouslySkipPermissions||E.dangerouslySkipPermissions,C=_.verbose||E.verbose;await Gur({resume:_.resume,cwd:_.cwd,verbose:C,dangerouslySkipPermissions:b})});let f=r.command("mcp").description("Configure and manage MCP servers");process.env.USER_TYPE==="ant"&&f.command("add-sse <name> <url>").description("Add an SSE server").option("-s, --scope <scope>","Configuration scope (project or global)","project").action(async(_,E,b)=>{try{let C=Fse(b.scope);$e("tengu_mcp_add",{name:_,type:"sse",scope:C}),$Fe(_,{type:"sse",url:E,headers:{}},C),console.log(`Added SSE MCP server ${_} with URL ${E} to ${C} config`),process.exit(0)}catch(C){console.error(C.message),process.exit(1)}}),f.command("add <name> <command> [args...]").description("Add a stdio server").option("-s, --scope <scope>","Configuration scope (project or global)","project").option("-e, --env <env...>","Set environment variables (e.g. -e KEY=value)").action(async(_,E,b,C)=>{try{let v=Fse(C.scope);$e("tengu_mcp_add",{name:_,type:"stdio",scope:v});let R=PHt(C.env);$Fe(_,{type:"stdio",command:E,args:b||[],env:R},v),console.log(`Added stdio MCP server ${_} with command: ${E} ${(b||[]).join(" ")} to ${v} config`),process.exit(0)}catch(v){console.error(v.message),process.exit(1)}}),f.command("remove <name>").description("Remove an MCP server").option("-s, --scope <scope>","Configuration scope (project, global, or mcprc)","project").action(async(_,E)=>{try{let b=Fse(E.scope);$e("tengu_mcp_delete",{name:_,scope:b}),FHt(_,b),console.log(`Removed MCP server ${_} from ${b} config`),process.exit(0)}catch(b){console.error(b.message),process.exit(1)}}),f.command("list").description("List configured MCP servers").action(()=>{$e("tengu_mcp_list",{});let _=qFe();if(Object.keys(_).length===0)console.log(`No MCP servers configured. Use \`${nt} mcp add\` to add a server.`);else for(let[E,b]of Object.entries(_))"command"in b?console.log(`${E}: ${b.command} ${b.args.join(" ")}`):console.log(`${E}: ${b.url} (${b.type.toUpperCase()})`);process.exit(0)}),f.command("get <name>").description("Get details about an MCP server").action(_=>{$e("tengu_mcp_get",{name:_});let E=Qse(_);if(E||(console.error(`No MCP server found with name: ${_}`),process.exit(1)),console.log(`${_}:`),console.log(` Scope: ${E.scope}`),"command"in E){if(console.log(" Type: stdio"),console.log(` Command: ${E.command}`),console.log(` Args: ${E.args.join(" ")}`),E.env){console.log(" Environment:");for(let[b,C]of Object.entries(E.env))console.log(` ${b}=${C}`)}}else console.log(` Type: ${E.type}`),console.log(` URL: ${E.url}`);process.exit(0)}),process.env.USER_TYPE==="ant"&&f.command("reset-mcprc-choices").description("Reset all approved and rejected .mcp.json servers for this project").action(()=>{$e("tengu_mcp_reset_mcprc_choices",{});let _=Rn();Ji({..._,approvedMcprcServers:[],rejectedMcprcServers:[]}),console.log("All .mcp.json server approvals and rejections have been reset."),console.log(`You will be prompted for approval next time you start ${nt}.`),process.exit(0)});let p=r.command("plugin").description("Manage plugins and marketplaces"),h=p.command("marketplace").description("Manage plugin marketplaces");if(h.command("add <source>").description("Add a marketplace from a local path, GitHub shorthand, git URL, or marketplace.json URL").action(async _=>{let{MarketplaceService:E}=await Promise.resolve().then(()=>(pg(),cw)),b=await E.add(_);b.success||(console.error(`Error: ${b.error}`),process.exit(1)),console.log(`Added marketplace "${b.name}"`),process.exit(0)}),h.command("install <name>").description("Install a registered marketplace by fetching its contents").action(async _=>{let{MarketplaceService:E}=await Promise.resolve().then(()=>(pg(),cw)),b=await E.install(_);b.success||(console.error(`Error: ${b.error}`),process.exit(1)),console.log(`Installed marketplace "${_}"`),process.exit(0)}),h.command("uninstall <name>").description("Uninstall a marketplace by removing its local cache").action(async _=>{let{MarketplaceService:E}=await Promise.resolve().then(()=>(pg(),cw)),b=await E.uninstall(_);b.success||(console.error(`Error: ${b.error}`),process.exit(1)),console.log(`Uninstalled marketplace "${_}"`),process.exit(0)}),h.command("remove <name>").alias("rm").description("Remove a marketplace from the list").action(async _=>{let{MarketplaceService:E}=await Promise.resolve().then(()=>(pg(),cw)),b=E.remove(_);b.success||(console.error(`Error: ${b.error}`),process.exit(1)),console.log(`Removed marketplace "${_}"`),process.exit(0)}),h.command("list").description("List registered marketplaces").option("--json","Output as JSON").action(async _=>{let{MarketplaceService:E}=await Promise.resolve().then(()=>(pg(),cw)),b=E.list();if(_.json)console.log(JSON.stringify(b,null,2));else if(b.length===0)console.log("No marketplaces registered.");else for(let C of b)console.log(`${C.name} (${C.type}): ${C.source}`);process.exit(0)}),h.command("update [name]").description("Refresh marketplaces from their sources").action(async _=>{let{MarketplaceService:E}=await Promise.resolve().then(()=>(pg(),cw)),b=await E.update(_);b.updated.length>0&&console.log(`Updated: ${b.updated.join(", ")}`),b.errors.length>0&&(console.error(`Errors:
3354
3354
  ${b.errors.join(`
3355
3355
  `)}`),process.exit(1)),b.updated.length===0&&console.log("All marketplaces are up to date"),process.exit(0)}),p.command("install <spec>").description("Install a plugin: <plugin[@marketplace]>").action(async _=>{let{PluginInstallService:E}=await Promise.resolve().then(()=>(N_(),yk)),b=await E.install(_);b.success||(console.error(`Error: ${b.error}`),process.exit(1)),console.log(`Installed plugin "${b.id}"`),process.exit(0)}),p.command("uninstall <spec>").description("Uninstall a plugin").action(async _=>{let{PluginInstallService:E}=await Promise.resolve().then(()=>(N_(),yk)),b=E.uninstall(_);b.success||(console.error(`Error: ${b.error}`),process.exit(1)),console.log(`Uninstalled plugin "${_}"`),process.exit(0)}),p.command("update [spec]").description("Update installed plugins").action(async _=>{let{PluginInstallService:E}=await Promise.resolve().then(()=>(N_(),yk)),b=await E.update(_);b.updated.length>0&&console.log(`Updated:
3356
3356
  ${b.updated.join(`
package/hands.js CHANGED
@@ -622,7 +622,7 @@ data: ${JSON.stringify(z)}
622
622
  `);a=M.pop()||"";for(let z of M){let Y=z.trim();if(!(!Y||Y==="data: [DONE]"))if(Y.startsWith("data: ")){let q=Y.slice(6);try{let K=JSON.parse(q);D(K)}catch(K){this.logger&&this.logger.error({err:K,line:Y},"Failed to parse Gemini SSE chunk")}}else try{let q=JSON.parse(Y);D(q)}catch{}}};(async()=>{try{for(;;){let{value:M,done:z}=await s.read();if(z)break;a+=n.decode(M,{stream:!0}),B()}T()}catch(M){o.error(M)}})()}})}convertGeminiResponseToAnthropic(t){this.logger&&this.logger.debug({response:t},"Original Gemini response");try{if(!t.candidates||!t.candidates[0])throw new Error("No candidates found in Gemini response");let r=t.candidates[0],n=[];r.content&&r.content.parts&&r.content.parts.forEach(o=>{if(o.text&&n.push({type:"text",text:o.text}),o.functionCall){let s=`toolu_${NN()}`,a=o.functionCall.thoughtSignature||o.functionCall.thought_signature||null;n.push({type:"tool_use",id:s,name:o.functionCall.name,input:o.functionCall.args||{},thought_signature:a})}}),r.groundingMetadata&&(this.logger&&this.logger.debug({groundingMetadata:r.groundingMetadata},"Processing grounding metadata"),r.groundingMetadata.webSearchQueries&&n.push({type:"text",text:`
623
623
 
624
624
  [Search queries used: ${r.groundingMetadata.webSearchQueries.join(", ")}]`}));let i={id:`msg_${Math.random().toString(36).slice(2)}`,type:"message",role:"assistant",model:t.modelVersion||"gemini",content:n,stop_reason:r.finishReason?r.finishReason==="STOP"&&n.some(o=>o.type==="tool_use")?"tool_use":this.mapGeminiFinishReason(r.finishReason):"end_turn",stop_sequence:null,usage:{input_tokens:t.usageMetadata?.promptTokenCount||0,output_tokens:t.usageMetadata?.candidatesTokenCount||0}};return this.logger&&this.logger.debug({result:i},"Conversion complete, final Anthropic response"),i}catch{throw X4r(`Provider error: ${JSON.stringify(t)}`,500,"provider_error")}}mapGeminiFinishReason(t){switch(t){case"STOP":return"end_turn";case"MAX_TOKENS":return"max_tokens";case"SAFETY":case"RECITATION":return"stop_sequence";default:return"end_turn"}}},q_e=new $_e;var Rpt=we(xpt(),1);Zt();rs();function tg(e){return e?typeof e.entries=="function"?Object.fromEntries(e.entries()):{...e}:{}}function wpt(e){let t=String(e?.["x-thinking-level"]??"medium").toLowerCase();return["off","low","medium","high"].includes(t)?t:"medium"}function pXr(e,t){if(t==="off"){delete e.reasoning;return}e.reasoning={effort:t}}function mXr(e,t){if(t==="off"){delete e.reasoning;return}e.reasoning={effort:t,summary:"auto"}}function gXr(e,t="chat"){let r={request:{},response:{},openai:{request:{},response:{}}};return r.request.model=e.request.body.model,r.request.messages=e.request.body.messages,r.request.system=e.request.body.system,r.response.content=e.response.body.content,r.response.usage=e.response.body?.usage,t==="responses"?(r.openai.request.model=e.openai.request.body.model,r.openai.request.input=e.openai.request.body.input,r.openai.response.output=e.openai.response.body?.output,r.openai.response.usage=e.openai.response.body?.usage):(r.openai.request.model=e.openai.request.body.model,r.openai.request.messages=e.openai.request.body.messages,r.openai.response.choices=e.openai.response.body.choices,r.openai.response.usage=e.openai.response.body?.usage),r}function bU(e,t,r){mG(t,e),gG(t,gXr(e,r),r)}function _B(e){let t=[],r=e.getReader(),n,i=new Promise(l=>n=l),o=!1,s=()=>{o||(o=!0,n(Buffer.concat(t).toString("utf8")))};return{stream:new ReadableStream({async pull(l){try{let{done:c,value:u}=await r.read();if(c){l.close(),s();return}t.push(u),l.enqueue(u)}catch(c){l.error(c),s()}},cancel(l){r.cancel(l).catch(()=>{}),s()}}),done:i}}function CU(e){let t=new Headers(e);return t.delete("content-encoding"),t.delete("content-length"),t.delete("transfer-encoding"),t}function h1e(e,t,r,n,i){let o;try{o={type:"error",error:{type:"api_error",message:JSON.parse(i).error?.message??`${e}: ${n}`,code:`${t}_${r}_ERROR`}}}catch{o={type:"error",error:{type:"api_error",message:`${e}: ${n}`,code:`${t}_${r}_ERROR`}}}return new Response(JSON.stringify(o),{status:r,statusText:n,headers:{"Content-Type":"application/json"}})}var Dpt=["/v1/messages"];function E1e(e){let t;try{typeof e=="string"?t=new _T(e):e instanceof _T?t=e:t=new _T(e.url)}catch{return""}let r=t.pathname;for(let n of Dpt){let i=r.indexOf(n);if(i!==-1)return t.origin+r.slice(0,i)}return t.origin}function vJ(e,t){let r=typeof e=="string"?e:e instanceof _T?e.toString():e.url,n;try{n=new _T(r).pathname}catch{return!1}return Dpt.some(i=>n.includes(i))&&(t.method==="POST"||t.method==="post")}function AXr(e){return async(t,r)=>{if(!vJ(t,r))return e(t,r);let n=JSON.parse(r.body),i=await xW.transformRequestOut(n),o=E1e(t)+"/chat/completions",s=tg(r.headers),a=s.authorization??s.Authorization??"";pXr(i,wpt(s));let l=await e(o,{method:"POST",headers:{"Content-Type":"application/json",Authorization:a},body:JSON.stringify(i),signal:r.signal});if(!l.ok){let y=await l.text();return V(`OpenAI Chat Completions API error: ${l.status}`,{url:o,errorResponse:y}),h1e("OpenAI Chat Completions API error","OPENROUTER",l.status,l.statusText,y)}let c=n.stream===!0,u=s["x-agent-id"],f={request:{url:o,method:r.method,headers:s,body:n},response:{status:l.status,statusText:l.statusText,headers:tg(l.headers)},openai:{request:{body:i},response:{}}};if(!c){let y=await l.text(),C=new Response(y,{status:l.status,statusText:l.statusText,headers:CU(l.headers)}),I=await xW.transformResponseIn(C,n),T=await I.text();try{bU({...f,openai:{...f.openai,response:{body:JSON.parse(y)}},response:{...f.response,body:JSON.parse(T)}},u)}catch(D){V("\u65E5\u5FD7\u89E3\u6790\u9519\u8BEF(Chat \u975E\u6D41\u5F0F):",D)}return new Response(T,{status:I.status,statusText:I.statusText,headers:I.headers})}let g=_B(l.body),m=new Response(g.stream,{status:l.status,statusText:l.statusText,headers:CU(l.headers)}),A=await xW.transformResponseIn(m,n),h=_B(A.body);return Promise.all([g.done,h.done]).then(async([y,C])=>{try{bU({...f,openai:{...f.openai,response:{body:await nit(y)}},response:{...f.response,body:await pF(C)}},u)}catch(I){V("\u65E5\u5FD7\u89E3\u6790\u9519\u8BEF(Chat \u6D41\u5F0F):"+I?.stack)}}).catch(y=>V("\u65E5\u5FD7\u805A\u5408\u9519\u8BEF(Chat):"+y)),new Response(h.stream,{status:A.status,statusText:A.statusText,headers:A.headers})}}function hXr(e){return async(t,r)=>{if(!vJ(t,r))return e(t,r);let n=JSON.parse(r.body),i=await wW.transformRequestOut(n),o=tg(r.headers);mXr(i,wpt(o));let s=JSON.stringify(i),l=E1e(t)+"/responses",c=o.authorization??o.Authorization??"";if(!c)return new Response(JSON.stringify({type:"error",error:{type:"api_error",message:"Missing Authorization header",code:"RESPONSES_AUTH_MISSING"}}),{status:401,headers:{"Content-Type":"application/json"}});let u=await e(l,{method:"POST",headers:{"Content-Type":"application/json",Authorization:c,"x-api-key":c.replace(/^Bearer\s+/i,"").trim()},body:s,signal:r.signal});if(!u.ok){let I=await u.text();return V(`OpenAI Responses API error: ${u.status} ${u.statusText}`,{url:l,status:u.status,errorResponse:I}),h1e("OpenAI Responses API error","RESPONSES",u.status,u.statusText,I)}let f=n.stream===!0,g=o["x-agent-id"],m={request:{url:l,method:r.method,headers:o,body:n},response:{status:u.status,statusText:u.statusText,headers:tg(u.headers)},openai:{request:{body:i},response:{}}};if(!f){let I=await u.text(),T=new Response(I,{status:u.status,statusText:u.statusText,headers:CU(u.headers)}),D=await wW.transformResponseIn(T,n),B=await D.text();try{bU({...m,openai:{...m.openai,response:{body:JSON.parse(I)}},response:{...m.response,body:JSON.parse(B)}},g,"responses")}catch(M){V("\u65E5\u5FD7\u89E3\u6790\u9519\u8BEF(Responses \u975E\u6D41\u5F0F):",M)}return new Response(B,{status:D.status,statusText:D.statusText,headers:D.headers})}let A=_B(u.body),h=new Response(A.stream,{status:u.status,statusText:u.statusText,headers:CU(u.headers)}),y=await wW.transformResponseIn(h,n),C=_B(y.body);return Promise.all([A.done,C.done]).then(async([I,T])=>{try{bU({...m,openai:{...m.openai,response:{body:await rit(I)}},response:{...m.response,body:await pF(T)}},g,"responses")}catch(D){V("\u65E5\u5FD7\u89E3\u6790\u9519\u8BEF(Responses \u6D41\u5F0F):"+D?.stack)}}).catch(I=>V("\u65E5\u5FD7\u805A\u5408\u9519\u8BEF(Responses):"+I)),new Response(C.stream,{status:y.status,statusText:y.statusText,headers:y.headers})}}function EXr(e){return async(t,r)=>{if(!vJ(t,r))return e(t,r);let n=JSON.parse(r.body),i=tg(r.headers),o=await q_e.transformRequestOut(n),s=JSON.stringify(o),a=E1e(t)+`/models/${n.model}:streamGenerateContent?alt=sse`,l=i.authorization??i.Authorization??"",c;try{c=await e(a,{method:"POST",headers:{"Content-Type":"application/json","x-goog-api-key":String(l).replace(/^Bearer\s+/i,"").trim()},body:s,signal:r.signal})}catch(C){throw V("gemini request error:",C),C}if(!c.ok){let C=await c.text();return V(`Gemini API error response: ${c.status} ${c.statusText}`,{url:a,status:c.status,errorResponse:C}),h1e("Gemini API error","Gemini",c.status,c.statusText,C)}let u=n.stream===!0,f=i["x-agent-id"],g={request:{url:a,method:r.method,headers:tg(r.headers),body:n},response:{status:c.status,statusText:c.statusText,headers:tg(c.headers)},openai:{request:{body:o},response:{}}},m=_B(c.body),A=new Response(m.stream,{status:c.status,statusText:c.statusText,headers:CU(c.headers)}),h=await q_e.transformResponseIn(A),y=_B(h.body);return Promise.all([m.done,y.done]).then(async([C,I])=>{try{let T=u?iit(C):JSON.parse(C),D=u?await pF(I):JSON.parse(I);bU({...g,openai:{...g.openai,response:{body:T}},response:{...g.response,body:D}},f)}catch(T){V("\u65E5\u5FD7\u89E3\u6790\u9519\u8BEF(Gemini):"+T?.stack)}}).catch(C=>V("\u65E5\u5FD7\u805A\u5408\u9519\u8BEF(Gemini):"+C)),new Response(y.stream,{status:h.status,statusText:h.statusText,headers:h.headers})}}function _Xr(e){return async(t,r)=>{if(!vJ(t,r))return e(t,r);let n=r.body;if(r.body)try{let f=JSON.parse(r.body);n=JSON.stringify(f)}catch{}let i=tg(r.headers);["1","true"].includes(String(process.env.HAWA_CODE_X_API_KEY_DISABLED??"").toLowerCase())&&(delete i["x-api-key"],delete i["X-API-Key"]),["1","true"].includes(String(process.env.HAWA_CODE_AUTH_DISABLED??"").toLowerCase())&&(delete i.authorization,delete i.Authorization),delete i["content-length"];let a=await e(t,{method:r.method,headers:i,body:n,signal:r.signal});if(!a.ok){let f=await a.text();V(`API error response: ${a.status} ${a.statusText}`,{url:typeof t=="string"?t:t instanceof _T?t.toString():t.url,status:a.status,errorResponse:f});let g;try{let m=JSON.parse(f);g={type:"error",error:{type:"api_error",message:m.error?.message||m.message||`API error: ${a.statusText}`,code:m.error?.code||m.code||`API_${a.status}_ERROR`}},m.error?.details&&(g.error.details=m.error.details)}catch{g={type:"error",error:{type:"api_error",message:`API error: ${a.statusText}`,code:`API_${a.status}_ERROR`}}}return new Response(JSON.stringify(g),{status:a.status,statusText:a.statusText,headers:{"Content-Type":"application/json"}})}let l=a.clone(),c=!(Object.hasOwn(JSON.parse(n),"stream")&&!JSON.parse(n).stream),u={request:{url:typeof t=="string"?t:t instanceof _T?t.toString():t.url,method:r.method,headers:tg(r.headers),body:JSON.parse(n)},response:{status:a.status,statusText:a.statusText,headers:tg(a.headers)}};return(async()=>{if(c){let m=await a.text();u.response.body=await pF(m)}else u.response.body=await a.json();let g=tg(r.headers)["x-agent-id"];mG(g,u),gG(g,{request:u.request.body.messages,response:u.response.body.content,usage:u.response.body?.usage})})().catch(f=>V(`\u65E5\u5FD7\u89E3\u6790\u9519\u8BEF:
625
- Stack trace: `+f.stack)),new Response(l.body,{status:a.status,statusText:a.statusText,headers:a.headers})}}var TJ=null,A1e=!1;function yXr(){TJ=null,A1e=!1}Yt.on("proxy:changed",yXr);function bXr(){if(A1e)return TJ;if(A1e=!0,Ze().proxy!==!0)return null;let e=process.env.HTTPS_PROXY||process.env.HTTP_PROXY||process.env.https_proxy||process.env.http_proxy;return e&&(TJ=new Rpt.ProxyAgent({uri:e}),yt(`[proxy] using proxy: ${e}`)),TJ}function CXr(){let e=bXr();return e?((t,r={})=>global.fetch(t,{...r,dispatcher:e})):global.fetch}function xJ(e){let t=e||process.env.API_TYPE,r=CXr();switch(t){case"openai":return AXr(r);case"openai-responses":return hXr(r);case"gemini":return EXr(r);default:return _Xr(r)}}SA();var vXr=we(et(),1);function Npt(e,t){let r=[],n=Math.max(1,Math.floor(t)),i="",o=0;for(let s of e){let a=SXr(s);i&&o+a>n?(r.push(i),i=s,o=a):(i+=s,o+=a)}return i&&r.push(i),r}function SXr(e){if(e===" ")return 4;let t=e.codePointAt(0);return t===void 0||t===0||t<32||t>=127&&t<160||IXr(t)?0:TXr(t)?2:1}function IXr(e){return e>=768&&e<=879||e>=6832&&e<=6911||e>=7616&&e<=7679||e>=8400&&e<=8447||e>=65056&&e<=65071}function TXr(e){return e>=4352&&(e<=4447||e===9001||e===9002||e>=11904&&e<=42191&&e!==12351||e>=44032&&e<=55203||e>=63744&&e<=64255||e>=65040&&e<=65049||e>=65072&&e<=65135||e>=65280&&e<=65376||e>=65504&&e<=65510||e>=127744&&e<=128591||e>=129280&&e<=129535||e>=131072&&e<=262141)}function SU(e){if(e<6e4)return`${(e/1e3).toFixed(1)}s`;let t=Math.floor(e/36e5),r=Math.floor(e%36e5/6e4),n=(e%6e4/1e3).toFixed(1);return t>0?`${t}h ${r}m ${n}s`:r>0?`${r}m ${n}s`:`${n}s`}function wJ(e){return new Intl.NumberFormat("en",{notation:"compact",maximumFractionDigits:1}).format(e).toLowerCase()}De();rs();var zl={totalCost:0,totalAPIDuration:0,startTime:Date.now(),inputTokens:0,outputTokens:0,cacheCreationTokens:0,cacheReadTokens:0,currentContextTokens:0};function DJ(e,t){zl.totalCost+=e,zl.totalAPIDuration+=t}function RJ(e,t){zl.inputTokens+=e,zl.outputTokens+=t,Yt.emit("token:change",{inputTokens:zl.inputTokens,outputTokens:zl.outputTokens})}function NJ(e,t){zl.cacheCreationTokens+=e,zl.cacheReadTokens+=t}function _1e(){return{inputTokens:zl.inputTokens,outputTokens:zl.outputTokens,cacheCreationTokens:zl.cacheCreationTokens,cacheReadTokens:zl.cacheReadTokens}}function Bpt(){return zl.totalCost}function Opt(){return Date.now()-zl.startTime}function kpt(){return zl.totalAPIDuration}function Mpt(e){zl.currentContextTokens=e}function Qpt(){return zl.currentContextTokens}De();$e();$e();var y1e="2.8.9";globalThis.MACRO={VERSION:y1e,PACKAGE_URL:`@dahawa/${qi}`,README_URL:"https://github.com/italking/hawa-code",ISSUES_EXPLAINER:"report the issue at https://github.com/italking/hawa-code/issues"};var BJ=process.env.HAWA_CODE_USER_AGENT||`${qi}/${y1e} (${process.env.USER_TYPE})`;import{randomUUID as kh}from"crypto";rs();De();sr();Sr();De();$e();import{existsSync as w0,readdirSync as ein,statSync as tin}from"fs";import{join as iC,relative as rin}from"path";import{homedir as xAt}from"os";import{platform as nin}from"process";import{readFile as oC}from"fs/promises";Sr();Up();Zt();import{join as NXr,sep as BXr}from"path";function Hp(){if(!au())return!1;try{let e=Ze();if(e.autoMemory?.teamMemoryEnabled!==void 0)return e.autoMemory.teamMemoryEnabled}catch{}return!1}function bf(){return(NXr(Ne(),".hcode","team-memory")+BXr).normalize("NFC")}function T0(e){let t=e.normalize("NFC"),r=bf();return t.startsWith(r)}Up();var wAt=we(BU(),1);vi();var P1e=(e,t,r)=>{let n=e instanceof RegExp?tAt(e,r):e,i=t instanceof RegExp?tAt(t,r):t,o=n!==null&&i!=null&&Grn(n,i,r);return o&&{start:o[0],end:o[1],pre:r.slice(0,o[0]),body:r.slice(o[0]+n.length,o[1]),post:r.slice(o[1]+i.length)}},tAt=(e,t)=>{let r=t.match(e);return r?r[0]:null},Grn=(e,t,r)=>{let n,i,o,s,a,l=r.indexOf(e),c=r.indexOf(t,l+1),u=l;if(l>=0&&c>0){if(e===t)return[l,c];for(n=[],o=r.length;u>=0&&!a;){if(u===l)n.push(u),l=r.indexOf(e,u+1);else if(n.length===1){let f=n.pop();f!==void 0&&(a=[f,c])}else i=n.pop(),i!==void 0&&i<o&&(o=i,s=c),c=r.indexOf(t,u+1);u=l<c&&l>=0?l:c}n.length&&s!==void 0&&(a=[o,s])}return a};var rAt="\0SLASH"+Math.random()+"\0",nAt="\0OPEN"+Math.random()+"\0",U1e="\0CLOSE"+Math.random()+"\0",iAt="\0COMMA"+Math.random()+"\0",oAt="\0PERIOD"+Math.random()+"\0",zrn=new RegExp(rAt,"g"),jrn=new RegExp(nAt,"g"),Yrn=new RegExp(U1e,"g"),Vrn=new RegExp(iAt,"g"),Wrn=new RegExp(oAt,"g"),Krn=/\\\\/g,Jrn=/\\{/g,Zrn=/\\}/g,Xrn=/\\,/g,enn=/\\\./g,tnn=1e5,rnn=4e6;function L1e(e){return isNaN(e)?e.charCodeAt(0):parseInt(e,10)}function nnn(e){return e.replace(Krn,rAt).replace(Jrn,nAt).replace(Zrn,U1e).replace(Xrn,iAt).replace(enn,oAt)}function inn(e){return e.replace(zrn,"\\").replace(jrn,"{").replace(Yrn,"}").replace(Vrn,",").replace(Wrn,".")}function sAt(e){if(!e)return[""];let t=[],r=P1e("{","}",e);if(!r)return e.split(",");let{pre:n,body:i,post:o}=r,s=n.split(",");s[s.length-1]+="{"+i+"}";let a=sAt(o);return o.length&&(s[s.length-1]+=a.shift(),s.push.apply(s,a)),t.push.apply(t,s),t}function aAt(e,t={}){if(!e)return[];let{max:r=tnn,maxLength:n=rnn}=t;return e.slice(0,2)==="{}"&&(e="\\{\\}"+e.slice(2)),F1e(nnn(e),r,n,!0).map(inn)}function onn(e){return"{"+e+"}"}function snn(e){return/^-?0\d/.test(e)}function ann(e,t){return e<=t}function lnn(e,t){return e>=t}function OU(e,t,r,n,i,o){let s=[],a=0;for(let l=0;l<e.length;l++)for(let c=0;c<r.length;c++){if(s.length>=n)return s;let u=e[l]+t+r[c];if(!(o&&!u)){if(a+u.length>i)return s;s.push(u),a+=u.length}}return s}function cnn(e,t,r,n){let i=e.split(/\.\./),o=[];if(i[0]===void 0||i[1]===void 0)return o;let s=L1e(i[0]),a=L1e(i[1]),l=Math.max(i[0].length,i[1].length),c=i.length===3&&i[2]!==void 0?Math.max(Math.abs(L1e(i[2])),1):1,u=ann;a<s&&(c*=-1,u=lnn);let g=i.some(snn),m=0;for(let A=s;u(A,a)&&o.length<r;A+=c){let h;if(t)h=String.fromCharCode(A),h==="\\"&&(h="");else if(h=String(A),g){let y=l-h.length;if(y>0){let C=new Array(y+1).join("0");A<0?h="-"+C+h.slice(1):h=C+h}}if(m+h.length>n)break;o.push(h),m+=h.length}return o}function F1e(e,t,r,n){let i=[""],o=!1,s=!0;for(;;){let a=P1e("{","}",e);if(!a)return OU(i,e,[""],t,r,o);let l=a.pre;if(/\$$/.test(l)){if(i=OU(i,l+"{"+a.body+"}",[""],t,r,o&&!a.post.length),s=!1,!a.post.length)break;e=a.post;continue}let c=/^-?\d+\.\.-?\d+(?:\.\.-?\d+)?$/.test(a.body),u=/^[a-zA-Z]\.\.[a-zA-Z](?:\.\.-?\d+)?$/.test(a.body),f=c||u,g=a.body.indexOf(",")>=0;if(!f&&!g){if(a.post.match(/,(?!,).*\}/)){e=a.pre+"{"+a.body+U1e+a.post,n=!0;continue}return OU(i,l+"{"+a.body+"}"+a.post,[""],t,r,o)}s&&(o=n&&!f,s=!1);let m;if(f)m=cnn(a.body,u,t,r);else{let A=sAt(a.body);if(A.length===1&&A[0]!==void 0&&(A=F1e(A[0],t,r,!1).map(onn),A.length===1)){if(i=OU(i,l+A[0],[""],t,r,o&&!a.post.length),!a.post.length)break;e=a.post;continue}let h=o&&!a.post.length&&!l;for(let C=0;h&&C<i.length;C++)i[C]&&(h=!1);m=[];let y=0;e:for(let C=0;C<A.length;C++){let I=F1e(A[C],t,r,!1);for(let T=0;T<I.length;T++){let D=I[T];if(!(h&&!D)){if(m.length>=t||y+D.length>r)break e;m.push(D),y+=D.length}}}}if(i=OU(i,l,m,t,r,o&&!a.post.length),!a.post.length)break;e=a.post}return i}var kU=e=>{if(typeof e!="string")throw new TypeError("invalid pattern");if(e.length>65536)throw new TypeError("pattern is too long")};var unn={"[:alnum:]":["\\p{L}\\p{Nl}\\p{Nd}",!0],"[:alpha:]":["\\p{L}\\p{Nl}",!0],"[:ascii:]":["\\x00-\\x7f",!1],"[:blank:]":["\\p{Zs}\\t",!0],"[:cntrl:]":["\\p{Cc}",!0],"[:digit:]":["\\p{Nd}",!0],"[:graph:]":["\\p{Z}\\p{C}",!0,!0],"[:lower:]":["\\p{Ll}",!0],"[:print:]":["\\p{C}",!0],"[:punct:]":["\\p{P}",!0],"[:space:]":["\\p{Z}\\t\\r\\n\\v\\f",!0],"[:upper:]":["\\p{Lu}",!0],"[:word:]":["\\p{L}\\p{Nl}\\p{Nd}\\p{Pc}",!0],"[:xdigit:]":["A-Fa-f0-9",!1]},MU=e=>e.replace(/[[\]\\-]/g,"\\$&"),dnn=e=>e.replace(/[-[\]{}()*+?.,\\^$|#\s]/g,"\\$&"),lAt=e=>e.join(""),cAt=(e,t)=>{let r=t;if(e.charAt(r)!=="[")throw new Error("not in a brace expression");let n=[],i=[],o=r+1,s=!1,a=!1,l=!1,c=!1,u=r,f="";e:for(;o<e.length;){let h=e.charAt(o);if((h==="!"||h==="^")&&o===r+1){c=!0,o++;continue}if(h==="]"&&s&&!l){u=o+1;break}if(s=!0,h==="\\"&&!l){l=!0,o++;continue}if(h==="["&&!l){for(let[y,[C,I,T]]of Object.entries(unn))if(e.startsWith(y,o)){if(f)return["$.",!1,e.length-r,!0];o+=y.length,T?i.push(C):n.push(C),a=a||I;continue e}}if(l=!1,f){h>f?n.push(MU(f)+"-"+MU(h)):h===f&&n.push(MU(h)),f="",o++;continue}if(e.startsWith("-]",o+1)){n.push(MU(h+"-")),o+=2;continue}if(e.startsWith("-",o+1)){f=h,o+=2;continue}n.push(MU(h)),o++}if(u<o)return["",!1,0,!1];if(!n.length&&!i.length)return["$.",!1,e.length-r,!0];if(i.length===0&&n.length===1&&/^\\?.$/.test(n[0])&&!c){let h=n[0].length===2?n[0].slice(-1):n[0];return[dnn(h),!1,u-r,!1]}let g="["+(c?"^":"")+lAt(n)+"]",m="["+(c?"":"^")+lAt(i)+"]";return[n.length&&i.length?"("+g+"|"+m+")":n.length?g:m,a,u-r,!0]};var nC=(e,{windowsPathsNoEscape:t=!1,magicalBraces:r=!0}={})=>r?t?e.replace(/\[([^/\\])\]/g,"$1"):e.replace(/((?!\\).|^)\[([^/\\])\]/g,"$1$2").replace(/\\([^/])/g,"$1"):t?e.replace(/\[([^/\\{}])\]/g,"$1"):e.replace(/((?!\\).|^)\[([^/\\{}])\]/g,"$1$2").replace(/\\([^/{}])/g,"$1");var dd,fnn=new Set(["!","?","+","*","@"]),H1e=e=>fnn.has(e),uAt=e=>H1e(e.type),pnn=new Map([["!",["@"]],["?",["?","@"]],["@",["@"]],["*",["*","+","?","@"]],["+",["+","@"]]]),mnn=new Map([["!",["?"]],["@",["?"]],["+",["?","*"]]]),gnn=new Map([["!",["?","@"]],["?",["?","@"]],["@",["?","@"]],["*",["*","+","?","@"]],["+",["+","@","?","*"]]]),dAt=new Map([["!",new Map([["!","@"]])],["?",new Map([["*","*"],["+","*"]])],["@",new Map([["!","!"],["?","?"],["@","@"],["*","*"],["+","+"]])],["+",new Map([["?","*"],["*","*"]])]]),Ann="(?!(?:^|/)\\.\\.?(?:$|/))",zJ="(?!\\.)",hnn=new Set(["[","."]),Enn=new Set(["..","."]),_nn=new Set("().*{}+?[]^$\\!"),ynn=e=>e.replace(/[-[\]{}()*+?.,\\^$|#\s]/g,"\\$&"),$1e="[^/]",fAt=$1e+"*?",pAt=$1e+"+?",bnn=0,xT=class{type;#e;#t;#n=!1;#r=[];#o;#i;#l;#s=!1;#a;#d;#p=!1;id=++bnn;get depth(){return(this.#o?.depth??-1)+1}[Symbol.for("nodejs.util.inspect.custom")](){return{"@@type":"AST",id:this.id,type:this.type,root:this.#e.id,parent:this.#o?.id,depth:this.depth,partsLength:this.#r.length,parts:this.#r}}constructor(t,r,n={}){this.type=t,t&&(this.#t=!0),this.#o=r,this.#e=this.#o?this.#o.#e:this,this.#a=this.#e===this?n:this.#e.#a,this.#l=this.#e===this?[]:this.#e.#l,t==="!"&&!this.#e.#s&&this.#l.push(this),this.#i=this.#o?this.#o.#r.length:0}get hasMagic(){if(this.#t!==void 0)return this.#t;for(let t of this.#r)if(typeof t!="string"&&(t.type||t.hasMagic))return this.#t=!0;return this.#t}toString(){return this.#d!==void 0?this.#d:this.type?this.#d=this.type+"("+this.#r.map(t=>String(t)).join("|")+")":this.#d=this.#r.map(t=>String(t)).join("")}#f(){if(this!==this.#e)throw new Error("should only call on root");if(this.#s)return this;this.toString(),this.#s=!0;let t;for(;t=this.#l.pop();){if(t.type!=="!")continue;let r=t,n=r.#o;for(;n;){for(let i=r.#i+1;!n.type&&i<n.#r.length;i++)for(let o of t.#r){if(typeof o=="string")throw new Error("string part in extglob AST??");o.copyIn(n.#r[i])}r=n,n=r.#o}}return this}push(...t){for(let r of t)if(r!==""){if(typeof r!="string"&&!(r instanceof dd&&r.#o===this))throw new Error("invalid part: "+r);this.#r.push(r)}}toJSON(){let t=this.type===null?this.#r.slice().map(r=>typeof r=="string"?r:r.toJSON()):[this.type,...this.#r.map(r=>r.toJSON())];return this.isStart()&&!this.type&&t.unshift([]),this.isEnd()&&(this===this.#e||this.#e.#s&&this.#o?.type==="!")&&t.push({}),t}isStart(){if(this.#e===this)return!0;if(!this.#o?.isStart())return!1;if(this.#i===0)return!0;let t=this.#o;for(let r=0;r<this.#i;r++){let n=t.#r[r];if(!(n instanceof dd&&n.type==="!"))return!1}return!0}isEnd(){if(this.#e===this||this.#o?.type==="!")return!0;if(!this.#o?.isEnd())return!1;if(!this.type)return this.#o?.isEnd();let t=this.#o?this.#o.#r.length:0;return this.#i===t-1}copyIn(t){typeof t=="string"?this.push(t):this.push(t.clone(this))}clone(t){let r=new dd(this.type,t);for(let n of this.#r)r.copyIn(n);return r}static#c(t,r,n,i,o){let s=i.maxExtglobRecursion??2,a=!1,l=!1,c=-1,u=!1;if(r.type===null){let h=n,y="";for(;h<t.length;){let C=t.charAt(h++);if(a||C==="\\"){a=!a,y+=C;continue}if(l){h===c+1?(C==="^"||C==="!")&&(u=!0):C==="]"&&!(h===c+2&&u)&&(l=!1),y+=C;continue}else if(C==="["){l=!0,c=h,u=!1,y+=C;continue}if(!i.noext&&H1e(C)&&t.charAt(h)==="("&&o<=s){r.push(y),y="";let T=new dd(C,r);h=dd.#c(t,T,h,i,o+1),r.push(T);continue}y+=C}return r.push(y),h}let f=n+1,g=new dd(null,r),m=[],A="";for(;f<t.length;){let h=t.charAt(f++);if(a||h==="\\"){a=!a,A+=h;continue}if(l){f===c+1?(h==="^"||h==="!")&&(u=!0):h==="]"&&!(f===c+2&&u)&&(l=!1),A+=h;continue}else if(h==="["){l=!0,c=f,u=!1,A+=h;continue}if(!i.noext&&H1e(h)&&t.charAt(f)==="("&&(o<=s||r&&r.#E(h))){let C=r&&r.#E(h)?0:1;g.push(A),A="";let I=new dd(h,g);g.push(I),f=dd.#c(t,I,f,i,o+C);continue}if(h==="|"){g.push(A),A="",m.push(g),g=new dd(null,r);continue}if(h===")")return A===""&&r.#r.length===0&&(r.#p=!0),g.push(A),A="",r.push(...m,g),f;A+=h}return r.type=null,r.#t=void 0,r.#r=[t.substring(n-1)],f}#g(t){return this.#h(t,mnn)}#h(t,r=pnn){if(!t||typeof t!="object"||t.type!==null||t.#r.length!==1||this.type===null)return!1;let n=t.#r[0];return!n||typeof n!="object"||n.type===null?!1:this.#E(n.type,r)}#E(t,r=gnn){return!!r.get(this.type)?.includes(t)}#A(t,r){let n=t.#r[0],i=new dd(null,n,this.options);i.#r.push(""),n.push(i),this.#v(t,r)}#v(t,r){let n=t.#r[0];this.#r.splice(r,1,...n.#r);for(let i of n.#r)typeof i=="object"&&(i.#o=this);this.#d=void 0}#y(t){return!!dAt.get(this.type)?.has(t)}#S(t){if(!t||typeof t!="object"||t.type!==null||t.#r.length!==1||this.type===null||this.#r.length!==1)return!1;let r=t.#r[0];return!r||typeof r!="object"||r.type===null?!1:this.#y(r.type)}#I(t){let r=dAt.get(this.type),n=t.#r[0],i=r?.get(n.type);if(!i)return!1;this.#r=n.#r;for(let o of this.#r)typeof o=="object"&&(o.#o=this);this.type=i,this.#d=void 0,this.#p=!1}static fromGlob(t,r={}){let n=new dd(null,void 0,r);return dd.#c(t,n,0,r,0),n}toMMPattern(){if(this!==this.#e)return this.#e.toMMPattern();let t=this.toString(),[r,n,i,o]=this.toRegExpSource();if(!(i||this.#t||this.#a.nocase&&!this.#a.nocaseMagicOnly&&t.toUpperCase()!==t.toLowerCase()))return n;let a=(this.#a.nocase?"i":"")+(o?"u":"");return Object.assign(new RegExp(`^${r}$`,a),{_src:r,_glob:t})}get options(){return this.#a}toRegExpSource(t){let r=t??!!this.#a.dot;if(this.#e===this&&(this.#_(),this.#f()),!uAt(this)){let l=this.isStart()&&this.isEnd()&&!this.#r.some(m=>typeof m!="string"),c=this.#r.map(m=>{let[A,h,y,C]=typeof m=="string"?dd.#C(m,this.#t,l):m.toRegExpSource(t);return this.#t=this.#t||y,this.#n=this.#n||C,A}).join(""),u="";if(this.isStart()&&typeof this.#r[0]=="string"&&!(this.#r.length===1&&Enn.has(this.#r[0]))){let A=hnn,h=r&&A.has(c.charAt(0))||c.startsWith("\\.")&&A.has(c.charAt(2))||c.startsWith("\\.\\.")&&A.has(c.charAt(4)),y=!r&&!t&&A.has(c.charAt(0));u=h?Ann:y?zJ:""}let f="";return this.isEnd()&&this.#e.#s&&this.#o?.type==="!"&&(f="(?:$|\\/)"),[u+c+f,nC(c),this.#t=!!this.#t,this.#n]}let n=this.type==="*"||this.type==="+",i=this.type==="!"?"(?:(?!(?:":"(?:",o=this.#b(r);if(this.isStart()&&this.isEnd()&&!o&&this.type!=="!"){let l=this.toString(),c=this;return c.#r=[l],c.type=null,c.#t=void 0,[l,nC(this.toString()),!1,!1]}let s=!n||t||r||!zJ?"":this.#b(!0);s===o&&(s=""),s&&(o=`(?:${o})(?:${s})*?`);let a="";if(this.type==="!"&&this.#p)a=(this.isStart()&&!r?zJ:"")+pAt;else{let l=this.type==="!"?"))"+(this.isStart()&&!r&&!t?zJ:"")+fAt+")":this.type==="@"?")":this.type==="?"?")?":this.type==="+"&&s?")":this.type==="*"&&s?")?":`)${this.type}`;a=i+o+l}return[a,nC(o),this.#t=!!this.#t,this.#n]}#_(){if(uAt(this)){let t=0,r=!1;do{r=!0;for(let n=0;n<this.#r.length;n++){let i=this.#r[n];typeof i=="object"&&(i.#_(),this.#h(i)?(r=!1,this.#v(i,n)):this.#g(i)?(r=!1,this.#A(i,n)):this.#S(i)&&(r=!1,this.#I(i)))}}while(!r&&++t<10)}else for(let t of this.#r)typeof t=="object"&&t.#_();this.#d=void 0}#b(t){return this.#r.map(r=>{if(typeof r=="string")throw new Error("string type in extglob ast??");let[n,i,o,s]=r.toRegExpSource(t);return this.#n=this.#n||s,n}).filter(r=>!(this.isStart()&&this.isEnd())||!!r).join("|")}static#C(t,r,n=!1){let i=!1,o="",s=!1,a=!1;for(let l=0;l<t.length;l++){let c=t.charAt(l);if(i){i=!1,o+=(_nn.has(c)?"\\":"")+c;continue}if(c==="*"){if(a)continue;a=!0,o+=n&&/^[*]+$/.test(t)?pAt:fAt,r=!0;continue}else a=!1;if(c==="\\"){l===t.length-1?o+="\\\\":i=!0;continue}if(c==="["){let[u,f,g,m]=cAt(t,l);if(g){o+=u,s=s||f,l+=g-1,r=r||m;continue}}if(c==="?"){o+=$1e,r=!0;continue}o+=ynn(c)}return[o,nC(t),!!r,s]}};dd=xT;var q1e=(e,{windowsPathsNoEscape:t=!1,magicalBraces:r=!1}={})=>r?t?e.replace(/[?*()[\]{}]/g,"[$&]"):e.replace(/[?*()[\]\\{}]/g,"\\$&"):t?e.replace(/[?*()[\]]/g,"[$&]"):e.replace(/[?*()[\]\\]/g,"\\$&");var Yl=(e,t,r={})=>(kU(t),!r.nocomment&&t.charAt(0)==="#"?!1:new DB(t,r).match(e)),Cnn=/^\*+([^+@!?*[(]*)$/,Snn=e=>t=>!t.startsWith(".")&&t.endsWith(e),Inn=e=>t=>t.endsWith(e),Tnn=e=>(e=e.toLowerCase(),t=>!t.startsWith(".")&&t.toLowerCase().endsWith(e)),vnn=e=>(e=e.toLowerCase(),t=>t.toLowerCase().endsWith(e)),xnn=/^\*+\.\*+$/,wnn=e=>!e.startsWith(".")&&e.includes("."),Dnn=e=>e!=="."&&e!==".."&&e.includes("."),Rnn=/^\.\*+$/,Nnn=e=>e!=="."&&e!==".."&&e.startsWith("."),Bnn=/^\*+$/,Onn=e=>e.length!==0&&!e.startsWith("."),knn=e=>e.length!==0&&e!=="."&&e!=="..",Mnn=/^\?+([^+@!?*[(]*)?$/,Qnn=([e,t=""])=>{let r=AAt([e]);return t?(t=t.toLowerCase(),n=>r(n)&&n.toLowerCase().endsWith(t)):r},Pnn=([e,t=""])=>{let r=hAt([e]);return t?(t=t.toLowerCase(),n=>r(n)&&n.toLowerCase().endsWith(t)):r},Lnn=([e,t=""])=>{let r=hAt([e]);return t?n=>r(n)&&n.endsWith(t):r},Fnn=([e,t=""])=>{let r=AAt([e]);return t?n=>r(n)&&n.endsWith(t):r},AAt=([e])=>{let t=e.length;return r=>r.length===t&&!r.startsWith(".")},hAt=([e])=>{let t=e.length;return r=>r.length===t&&r!=="."&&r!==".."},EAt=typeof process=="object"&&process?typeof process.env=="object"&&process.env&&process.env.__MINIMATCH_TESTING_PLATFORM__||process.platform:"posix",mAt={win32:{sep:"\\"},posix:{sep:"/"}},Unn=EAt==="win32"?mAt.win32.sep:mAt.posix.sep;Yl.sep=Unn;var xc=Symbol("globstar **");Yl.GLOBSTAR=xc;var Hnn="[^/]",$nn=Hnn+"*?",qnn="(?:(?!(?:\\/|^)(?:\\.{1,2})($|\\/)).)*?",Gnn="(?:(?!(?:\\/|^)\\.).)*?",znn=(e,t={})=>r=>Yl(r,e,t);Yl.filter=znn;var $p=(e,t={})=>Object.assign({},e,t),jnn=e=>{if(!e||typeof e!="object"||!Object.keys(e).length)return Yl;let t=Yl;return Object.assign((n,i,o={})=>t(n,i,$p(e,o)),{Minimatch:class extends t.Minimatch{constructor(i,o={}){super(i,$p(e,o))}static defaults(i){return t.defaults($p(e,i)).Minimatch}},AST:class extends t.AST{constructor(i,o,s={}){super(i,o,$p(e,s))}static fromGlob(i,o={}){return t.AST.fromGlob(i,$p(e,o))}},unescape:(n,i={})=>t.unescape(n,$p(e,i)),escape:(n,i={})=>t.escape(n,$p(e,i)),filter:(n,i={})=>t.filter(n,$p(e,i)),defaults:n=>t.defaults($p(e,n)),makeRe:(n,i={})=>t.makeRe(n,$p(e,i)),braceExpand:(n,i={})=>t.braceExpand(n,$p(e,i)),match:(n,i,o={})=>t.match(n,i,$p(e,o)),sep:t.sep,GLOBSTAR:xc})};Yl.defaults=jnn;var _At=(e,t={})=>(kU(e),t.nobrace||!/\{(?:(?!\{).)*\}/.test(e)?[e]:aAt(e,{max:t.braceExpandMax}));Yl.braceExpand=_At;var Ynn=(e,t={})=>new DB(e,t).makeRe();Yl.makeRe=Ynn;var Vnn=(e,t,r={})=>{let n=new DB(t,r);return e=e.filter(i=>n.match(i)),n.options.nonull&&!e.length&&e.push(t),e};Yl.match=Vnn;var gAt=/[?*]|[+@!]\(.*?\)|\[|\]/,Wnn=e=>e.replace(/[-[\]{}()*+?.,\\^$|#\s]/g,"\\$&"),DB=class{options;set;pattern;windowsPathsNoEscape;nonegate;negate;comment;empty;preserveMultipleSlashes;partial;globSet;globParts;nocase;isWindows;platform;windowsNoMagicRoot;maxGlobstarRecursion;regexp;constructor(t,r={}){kU(t),r=r||{},this.options=r,this.maxGlobstarRecursion=r.maxGlobstarRecursion??200,this.pattern=t,this.platform=r.platform||EAt,this.isWindows=this.platform==="win32";let n="allowWindowsEscape";this.windowsPathsNoEscape=!!r.windowsPathsNoEscape||r[n]===!1,this.windowsPathsNoEscape&&(this.pattern=this.pattern.replace(/\\/g,"/")),this.preserveMultipleSlashes=!!r.preserveMultipleSlashes,this.regexp=null,this.negate=!1,this.nonegate=!!r.nonegate,this.comment=!1,this.empty=!1,this.partial=!!r.partial,this.nocase=!!this.options.nocase,this.windowsNoMagicRoot=r.windowsNoMagicRoot!==void 0?r.windowsNoMagicRoot:!!(this.isWindows&&this.nocase),this.globSet=[],this.globParts=[],this.set=[],this.make()}hasMagic(){if(this.options.magicalBraces&&this.set.length>1)return!0;for(let t of this.set)for(let r of t)if(typeof r!="string")return!0;return!1}debug(...t){}make(){let t=this.pattern,r=this.options;if(!r.nocomment&&t.charAt(0)==="#"){this.comment=!0;return}if(!t){this.empty=!0;return}this.parseNegate(),this.globSet=[...new Set(this.braceExpand())],r.debug&&(this.debug=(...o)=>console.error(...o)),this.debug(this.pattern,this.globSet);let n=this.globSet.map(o=>this.slashSplit(o));this.globParts=this.preprocess(n),this.debug(this.pattern,this.globParts);let i=this.globParts.map((o,s,a)=>{if(this.isWindows&&this.windowsNoMagicRoot){let l=o[0]===""&&o[1]===""&&(o[2]==="?"||!gAt.test(o[2]))&&!gAt.test(o[3]),c=/^[a-z]:/i.test(o[0]);if(l)return[...o.slice(0,4),...o.slice(4).map(u=>this.parse(u))];if(c)return[o[0],...o.slice(1).map(u=>this.parse(u))]}return o.map(l=>this.parse(l))});if(this.debug(this.pattern,i),this.set=i.filter(o=>o.indexOf(!1)===-1),this.isWindows)for(let o=0;o<this.set.length;o++){let s=this.set[o];s[0]===""&&s[1]===""&&this.globParts[o][2]==="?"&&typeof s[3]=="string"&&/^[a-z]:$/i.test(s[3])&&(s[2]="?")}this.debug(this.pattern,this.set)}preprocess(t){if(this.options.noglobstar)for(let n of t)for(let i=0;i<n.length;i++)n[i]==="**"&&(n[i]="*");let{optimizationLevel:r=1}=this.options;return r>=2?(t=this.firstPhasePreProcess(t),t=this.secondPhasePreProcess(t)):r>=1?t=this.levelOneOptimize(t):t=this.adjascentGlobstarOptimize(t),t}adjascentGlobstarOptimize(t){return t.map(r=>{let n=-1;for(;(n=r.indexOf("**",n+1))!==-1;){let i=n;for(;r[i+1]==="**";)i++;i!==n&&r.splice(n,i-n)}return r})}levelOneOptimize(t){return t.map(r=>(r=r.reduce((n,i)=>{let o=n[n.length-1];return i==="**"&&o==="**"?n:i===".."&&o&&o!==".."&&o!=="."&&o!=="**"?(n.pop(),n):(n.push(i),n)},[]),r.length===0?[""]:r))}levelTwoFileOptimize(t){Array.isArray(t)||(t=this.slashSplit(t));let r=!1;do{if(r=!1,!this.preserveMultipleSlashes){for(let i=1;i<t.length-1;i++){let o=t[i];i===1&&o===""&&t[0]===""||(o==="."||o==="")&&(r=!0,t.splice(i,1),i--)}t[0]==="."&&t.length===2&&(t[1]==="."||t[1]==="")&&(r=!0,t.pop())}let n=0;for(;(n=t.indexOf("..",n+1))!==-1;){let i=t[n-1];i&&i!=="."&&i!==".."&&i!=="**"&&!(this.isWindows&&/^[a-z]:$/i.test(i))&&(r=!0,t.splice(n-1,2),n-=2)}}while(r);return t.length===0?[""]:t}firstPhasePreProcess(t){let r=!1;do{r=!1;for(let n of t){let i=-1;for(;(i=n.indexOf("**",i+1))!==-1;){let s=i;for(;n[s+1]==="**";)s++;s>i&&n.splice(i+1,s-i);let a=n[i+1],l=n[i+2],c=n[i+3];if(a!==".."||!l||l==="."||l===".."||!c||c==="."||c==="..")continue;r=!0,n.splice(i,1);let u=n.slice(0);u[i]="**",t.push(u),i--}if(!this.preserveMultipleSlashes){for(let s=1;s<n.length-1;s++){let a=n[s];s===1&&a===""&&n[0]===""||(a==="."||a==="")&&(r=!0,n.splice(s,1),s--)}n[0]==="."&&n.length===2&&(n[1]==="."||n[1]==="")&&(r=!0,n.pop())}let o=0;for(;(o=n.indexOf("..",o+1))!==-1;){let s=n[o-1];if(s&&s!=="."&&s!==".."&&s!=="**"){r=!0;let l=o===1&&n[o+1]==="**"?["."]:[];n.splice(o-1,2,...l),n.length===0&&n.push(""),o-=2}}}}while(r);return t}secondPhasePreProcess(t){for(let r=0;r<t.length-1;r++)for(let n=r+1;n<t.length;n++){let i=this.partsMatch(t[r],t[n],!this.preserveMultipleSlashes);if(i){t[r]=[],t[n]=i;break}}return t.filter(r=>r.length)}partsMatch(t,r,n=!1){let i=0,o=0,s=[],a="";for(;i<t.length&&o<r.length;)if(t[i]===r[o])s.push(a==="b"?r[o]:t[i]),i++,o++;else if(n&&t[i]==="**"&&r[o]===t[i+1])s.push(t[i]),i++;else if(n&&r[o]==="**"&&t[i]===r[o+1])s.push(r[o]),o++;else if(t[i]==="*"&&r[o]&&(this.options.dot||!r[o].startsWith("."))&&r[o]!=="**"){if(a==="b")return!1;a="a",s.push(t[i]),i++,o++}else if(r[o]==="*"&&t[i]&&(this.options.dot||!t[i].startsWith("."))&&t[i]!=="**"){if(a==="a")return!1;a="b",s.push(r[o]),i++,o++}else return!1;return t.length===r.length&&s}parseNegate(){if(this.nonegate)return;let t=this.pattern,r=!1,n=0;for(let i=0;i<t.length&&t.charAt(i)==="!";i++)r=!r,n++;n&&(this.pattern=t.slice(n)),this.negate=r}matchOne(t,r,n=!1){let i=0,o=0;if(this.isWindows){let a=typeof t[0]=="string"&&/^[a-z]:$/i.test(t[0]),l=!a&&t[0]===""&&t[1]===""&&t[2]==="?"&&/^[a-z]:$/i.test(t[3]),c=typeof r[0]=="string"&&/^[a-z]:$/i.test(r[0]),u=!c&&r[0]===""&&r[1]===""&&r[2]==="?"&&typeof r[3]=="string"&&/^[a-z]:$/i.test(r[3]),f=l?3:a?0:void 0,g=u?3:c?0:void 0;if(typeof f=="number"&&typeof g=="number"){let[m,A]=[t[f],r[g]];m.toLowerCase()===A.toLowerCase()&&(r[g]=m,o=g,i=f)}}let{optimizationLevel:s=1}=this.options;return s>=2&&(t=this.levelTwoFileOptimize(t)),r.includes(xc)?this.#e(t,r,n,i,o):this.#n(t,r,n,i,o)}#e(t,r,n,i,o){let s=r.indexOf(xc,o),a=r.lastIndexOf(xc),[l,c,u]=n?[r.slice(o,s),r.slice(s+1),[]]:[r.slice(o,s),r.slice(s+1,a),r.slice(a+1)];if(l.length){let I=t.slice(i,i+l.length);if(!this.#n(I,l,n,0,0))return!1;i+=l.length,o+=l.length}let f=0;if(u.length){if(u.length+i>t.length)return!1;let I=t.length-u.length;if(this.#n(t,u,n,I,0))f=u.length;else{if(t[t.length-1]!==""||i+u.length===t.length||(I--,!this.#n(t,u,n,I,0)))return!1;f=u.length+1}}if(!c.length){let I=!!f;for(let T=i;T<t.length-f;T++){let D=String(t[T]);if(I=!0,D==="."||D===".."||!this.options.dot&&D.startsWith("."))return!1}return n||I}let g=[[[],0]],m=g[0],A=0,h=[0];for(let I of c)I===xc?(h.push(A),m=[[],0],g.push(m)):(m[0].push(I),A++);let y=g.length-1,C=t.length-f;for(let I of g)I[1]=C-(h[y--]+I[0].length);return!!this.#t(t,g,i,0,n,0,!!f)}#t(t,r,n,i,o,s,a){let l=r[i];if(!l){for(let f=n;f<t.length;f++){a=!0;let g=t[f];if(g==="."||g===".."||!this.options.dot&&g.startsWith("."))return!1}return a}let[c,u]=l;for(;n<=u;){if(this.#n(t.slice(0,n+c.length),c,o,n,0)&&s<this.maxGlobstarRecursion){let m=this.#t(t,r,n+c.length,i+1,o,s+1,a);if(m!==!1)return m}let g=t[n];if(g==="."||g===".."||!this.options.dot&&g.startsWith("."))return!1;n++}return o||null}#n(t,r,n,i,o){let s,a,l,c;for(s=i,a=o,c=t.length,l=r.length;s<c&&a<l;s++,a++){this.debug("matchOne loop");let u=r[a],f=t[s];if(this.debug(r,u,f),u===!1||u===xc)return!1;let g;if(typeof u=="string"?(g=f===u,this.debug("string match",u,f,g)):(g=u.test(f),this.debug("pattern match",u,f,g)),!g)return!1}if(s===c&&a===l)return!0;if(s===c)return n;if(a===l)return s===c-1&&t[s]==="";throw new Error("wtf?")}braceExpand(){return _At(this.pattern,this.options)}parse(t){kU(t);let r=this.options;if(t==="**")return xc;if(t==="")return"";let n,i=null;(n=t.match(Bnn))?i=r.dot?knn:Onn:(n=t.match(Cnn))?i=(r.nocase?r.dot?vnn:Tnn:r.dot?Inn:Snn)(n[1]):(n=t.match(Mnn))?i=(r.nocase?r.dot?Pnn:Qnn:r.dot?Lnn:Fnn)(n):(n=t.match(xnn))?i=r.dot?Dnn:wnn:(n=t.match(Rnn))&&(i=Nnn);let o=xT.fromGlob(t,this.options).toMMPattern();return i&&typeof o=="object"&&Reflect.defineProperty(o,"test",{value:i}),o}makeRe(){if(this.regexp||this.regexp===!1)return this.regexp;let t=this.set;if(!t.length)return this.regexp=!1,this.regexp;let r=this.options,n=r.noglobstar?$nn:r.dot?qnn:Gnn,i=new Set(r.nocase?["i"]:[]),o=t.map(l=>{let c=l.map(f=>{if(f instanceof RegExp)for(let g of f.flags.split(""))i.add(g);return typeof f=="string"?Wnn(f):f===xc?xc:f._src});c.forEach((f,g)=>{let m=c[g+1],A=c[g-1];f!==xc||A===xc||(A===void 0?m!==void 0&&m!==xc?c[g+1]="(?:\\/|"+n+"\\/)?"+m:c[g]=n:m===void 0?c[g-1]=A+"(?:\\/|\\/"+n+")?":m!==xc&&(c[g-1]=A+"(?:\\/|\\/"+n+"\\/)"+m,c[g+1]=xc))});let u=c.filter(f=>f!==xc);if(this.partial&&u.length>=1){let f=[];for(let g=1;g<=u.length;g++)f.push(u.slice(0,g).join("/"));return"(?:"+f.join("|")+")"}return u.join("/")}).join("|"),[s,a]=t.length>1?["(?:",")"]:["",""];o="^"+s+o+a+"$",this.partial&&(o="^(?:\\/|"+s+o.slice(1,-1)+a+")$"),this.negate&&(o="^(?!"+o+").+$");try{this.regexp=new RegExp(o,[...i].join(""))}catch{this.regexp=!1}return this.regexp}slashSplit(t){return this.preserveMultipleSlashes?t.split("/"):this.isWindows&&/^\/\/[^/]+/.test(t)?["",...t.split(/\/+/)]:t.split(/\/+/)}match(t,r=this.partial){if(this.debug("match",t,this.pattern),this.comment)return!1;if(this.empty)return t==="";if(t==="/"&&r)return!0;let n=this.options;this.isWindows&&(t=t.split("\\").join("/"));let i=this.slashSplit(t);this.debug(this.pattern,"split",i);let o=this.set;this.debug(this.pattern,"set",o);let s=i[i.length-1];if(!s)for(let a=i.length-2;!s&&a>=0;a--)s=i[a];for(let a of o){let l=i;if(n.matchBase&&a.length===1&&(l=[s]),this.matchOne(l,a,r))return n.flipNegate?!0:!this.negate}return n.flipNegate?!1:this.negate}static defaults(t){return Yl.defaults(t).Minimatch}};Yl.AST=xT;Yl.Minimatch=DB;Yl.escape=q1e;Yl.unescape=nC;var CAt=we(BU(),1);Sr();$e();De();Xc();import{readFile as yAt}from"fs/promises";import{existsSync as G1e,readdirSync as Knn,statSync as Jnn}from"fs";import{join as z1e,relative as SAt}from"path";import{homedir as Znn}from"os";function bAt(e){try{let t=(0,CAt.default)(e),r=t.data.paths,n=[];return typeof r=="string"?n=r.split(",").map(i=>i.trim()).filter(Boolean):Array.isArray(r)&&(n=r.filter(i=>typeof i=="string")),{paths:n,content:t.content.trim()}}catch(t){return Te(t),{paths:[],content:e.trim()}}}function Xnn(e,t){return t.length===0?!0:t.some(r=>{try{return Yl(e,r,{matchBase:!0,dot:!0})}catch(n){return Te(n),!1}})}function j1e(e){let t=[];try{if(!G1e(e))return t;let r=Knn(e);for(let n of r){let i=z1e(e,n),o=Jnn(i);o.isDirectory()?t.push(...j1e(i)):o.isFile()&&n.endsWith(".md")&&t.push(i)}}catch(r){Te(r)}return t}async function jJ(){let e=[];try{let t=z1e(Znn(),Kr,"rules");if(G1e(t)){let r=j1e(t);for(let n of r)try{let i=await yAt(n,"utf-8"),{paths:o,content:s}=bAt(i);o.length>0&&e.push({filePath:n,content:s,paths:o,isProjectRule:!1})}catch(i){Te(i)}}}catch(t){Te(t)}try{let t=z1e(Ne(),Kr,"rules");if(G1e(t)){let r=j1e(t);for(let n of r)try{let i=await yAt(n,"utf-8"),{paths:o,content:s}=bAt(i);o.length>0&&e.push({filePath:SAt(Ne(),n),content:s,paths:o,isProjectRule:!0})}catch(i){Te(i)}}}catch(t){Te(t)}return e}function IAt(e,t){e=dY(e);let r=dY(Ne()),n=e.startsWith(r)?SAt(r,e):e;return t.filter(i=>Xnn(n,i.paths))}function TAt(e){return e.length===0?"":e.map(r=>{let n=r.isProjectRule?"project instructions, checked into the codebase":"user's private global instructions for all projects";return`Contents of ${r.filePath} (${n}):
625
+ Stack trace: `+f.stack)),new Response(l.body,{status:a.status,statusText:a.statusText,headers:a.headers})}}var TJ=null,A1e=!1;function yXr(){TJ=null,A1e=!1}Yt.on("proxy:changed",yXr);function bXr(){if(A1e)return TJ;if(A1e=!0,Ze().proxy!==!0)return null;let e=process.env.HTTPS_PROXY||process.env.HTTP_PROXY||process.env.https_proxy||process.env.http_proxy;return e&&(TJ=new Rpt.ProxyAgent({uri:e}),yt(`[proxy] using proxy: ${e}`)),TJ}function CXr(){let e=bXr();return e?((t,r={})=>global.fetch(t,{...r,dispatcher:e})):global.fetch}function xJ(e){let t=e||process.env.API_TYPE,r=CXr();switch(t){case"openai":return AXr(r);case"openai-responses":return hXr(r);case"gemini":return EXr(r);default:return _Xr(r)}}SA();var vXr=we(et(),1);function Npt(e,t){let r=[],n=Math.max(1,Math.floor(t)),i="",o=0;for(let s of e){let a=SXr(s);i&&o+a>n?(r.push(i),i=s,o=a):(i+=s,o+=a)}return i&&r.push(i),r}function SXr(e){if(e===" ")return 4;let t=e.codePointAt(0);return t===void 0||t===0||t<32||t>=127&&t<160||IXr(t)?0:TXr(t)?2:1}function IXr(e){return e>=768&&e<=879||e>=6832&&e<=6911||e>=7616&&e<=7679||e>=8400&&e<=8447||e>=65056&&e<=65071}function TXr(e){return e>=4352&&(e<=4447||e===9001||e===9002||e>=11904&&e<=42191&&e!==12351||e>=44032&&e<=55203||e>=63744&&e<=64255||e>=65040&&e<=65049||e>=65072&&e<=65135||e>=65280&&e<=65376||e>=65504&&e<=65510||e>=127744&&e<=128591||e>=129280&&e<=129535||e>=131072&&e<=262141)}function SU(e){if(e<6e4)return`${(e/1e3).toFixed(1)}s`;let t=Math.floor(e/36e5),r=Math.floor(e%36e5/6e4),n=(e%6e4/1e3).toFixed(1);return t>0?`${t}h ${r}m ${n}s`:r>0?`${r}m ${n}s`:`${n}s`}function wJ(e){return new Intl.NumberFormat("en",{notation:"compact",maximumFractionDigits:1}).format(e).toLowerCase()}De();rs();var zl={totalCost:0,totalAPIDuration:0,startTime:Date.now(),inputTokens:0,outputTokens:0,cacheCreationTokens:0,cacheReadTokens:0,currentContextTokens:0};function DJ(e,t){zl.totalCost+=e,zl.totalAPIDuration+=t}function RJ(e,t){zl.inputTokens+=e,zl.outputTokens+=t,Yt.emit("token:change",{inputTokens:zl.inputTokens,outputTokens:zl.outputTokens})}function NJ(e,t){zl.cacheCreationTokens+=e,zl.cacheReadTokens+=t}function _1e(){return{inputTokens:zl.inputTokens,outputTokens:zl.outputTokens,cacheCreationTokens:zl.cacheCreationTokens,cacheReadTokens:zl.cacheReadTokens}}function Bpt(){return zl.totalCost}function Opt(){return Date.now()-zl.startTime}function kpt(){return zl.totalAPIDuration}function Mpt(e){zl.currentContextTokens=e}function Qpt(){return zl.currentContextTokens}De();$e();$e();var y1e="2.8.10";globalThis.MACRO={VERSION:y1e,PACKAGE_URL:`@dahawa/${qi}`,README_URL:"https://github.com/italking/hawa-code",ISSUES_EXPLAINER:"report the issue at https://github.com/italking/hawa-code/issues"};var BJ=process.env.HAWA_CODE_USER_AGENT||`${qi}/${y1e} (${process.env.USER_TYPE})`;import{randomUUID as kh}from"crypto";rs();De();sr();Sr();De();$e();import{existsSync as w0,readdirSync as ein,statSync as tin}from"fs";import{join as iC,relative as rin}from"path";import{homedir as xAt}from"os";import{platform as nin}from"process";import{readFile as oC}from"fs/promises";Sr();Up();Zt();import{join as NXr,sep as BXr}from"path";function Hp(){if(!au())return!1;try{let e=Ze();if(e.autoMemory?.teamMemoryEnabled!==void 0)return e.autoMemory.teamMemoryEnabled}catch{}return!1}function bf(){return(NXr(Ne(),".hcode","team-memory")+BXr).normalize("NFC")}function T0(e){let t=e.normalize("NFC"),r=bf();return t.startsWith(r)}Up();var wAt=we(BU(),1);vi();var P1e=(e,t,r)=>{let n=e instanceof RegExp?tAt(e,r):e,i=t instanceof RegExp?tAt(t,r):t,o=n!==null&&i!=null&&Grn(n,i,r);return o&&{start:o[0],end:o[1],pre:r.slice(0,o[0]),body:r.slice(o[0]+n.length,o[1]),post:r.slice(o[1]+i.length)}},tAt=(e,t)=>{let r=t.match(e);return r?r[0]:null},Grn=(e,t,r)=>{let n,i,o,s,a,l=r.indexOf(e),c=r.indexOf(t,l+1),u=l;if(l>=0&&c>0){if(e===t)return[l,c];for(n=[],o=r.length;u>=0&&!a;){if(u===l)n.push(u),l=r.indexOf(e,u+1);else if(n.length===1){let f=n.pop();f!==void 0&&(a=[f,c])}else i=n.pop(),i!==void 0&&i<o&&(o=i,s=c),c=r.indexOf(t,u+1);u=l<c&&l>=0?l:c}n.length&&s!==void 0&&(a=[o,s])}return a};var rAt="\0SLASH"+Math.random()+"\0",nAt="\0OPEN"+Math.random()+"\0",U1e="\0CLOSE"+Math.random()+"\0",iAt="\0COMMA"+Math.random()+"\0",oAt="\0PERIOD"+Math.random()+"\0",zrn=new RegExp(rAt,"g"),jrn=new RegExp(nAt,"g"),Yrn=new RegExp(U1e,"g"),Vrn=new RegExp(iAt,"g"),Wrn=new RegExp(oAt,"g"),Krn=/\\\\/g,Jrn=/\\{/g,Zrn=/\\}/g,Xrn=/\\,/g,enn=/\\\./g,tnn=1e5,rnn=4e6;function L1e(e){return isNaN(e)?e.charCodeAt(0):parseInt(e,10)}function nnn(e){return e.replace(Krn,rAt).replace(Jrn,nAt).replace(Zrn,U1e).replace(Xrn,iAt).replace(enn,oAt)}function inn(e){return e.replace(zrn,"\\").replace(jrn,"{").replace(Yrn,"}").replace(Vrn,",").replace(Wrn,".")}function sAt(e){if(!e)return[""];let t=[],r=P1e("{","}",e);if(!r)return e.split(",");let{pre:n,body:i,post:o}=r,s=n.split(",");s[s.length-1]+="{"+i+"}";let a=sAt(o);return o.length&&(s[s.length-1]+=a.shift(),s.push.apply(s,a)),t.push.apply(t,s),t}function aAt(e,t={}){if(!e)return[];let{max:r=tnn,maxLength:n=rnn}=t;return e.slice(0,2)==="{}"&&(e="\\{\\}"+e.slice(2)),F1e(nnn(e),r,n,!0).map(inn)}function onn(e){return"{"+e+"}"}function snn(e){return/^-?0\d/.test(e)}function ann(e,t){return e<=t}function lnn(e,t){return e>=t}function OU(e,t,r,n,i,o){let s=[],a=0;for(let l=0;l<e.length;l++)for(let c=0;c<r.length;c++){if(s.length>=n)return s;let u=e[l]+t+r[c];if(!(o&&!u)){if(a+u.length>i)return s;s.push(u),a+=u.length}}return s}function cnn(e,t,r,n){let i=e.split(/\.\./),o=[];if(i[0]===void 0||i[1]===void 0)return o;let s=L1e(i[0]),a=L1e(i[1]),l=Math.max(i[0].length,i[1].length),c=i.length===3&&i[2]!==void 0?Math.max(Math.abs(L1e(i[2])),1):1,u=ann;a<s&&(c*=-1,u=lnn);let g=i.some(snn),m=0;for(let A=s;u(A,a)&&o.length<r;A+=c){let h;if(t)h=String.fromCharCode(A),h==="\\"&&(h="");else if(h=String(A),g){let y=l-h.length;if(y>0){let C=new Array(y+1).join("0");A<0?h="-"+C+h.slice(1):h=C+h}}if(m+h.length>n)break;o.push(h),m+=h.length}return o}function F1e(e,t,r,n){let i=[""],o=!1,s=!0;for(;;){let a=P1e("{","}",e);if(!a)return OU(i,e,[""],t,r,o);let l=a.pre;if(/\$$/.test(l)){if(i=OU(i,l+"{"+a.body+"}",[""],t,r,o&&!a.post.length),s=!1,!a.post.length)break;e=a.post;continue}let c=/^-?\d+\.\.-?\d+(?:\.\.-?\d+)?$/.test(a.body),u=/^[a-zA-Z]\.\.[a-zA-Z](?:\.\.-?\d+)?$/.test(a.body),f=c||u,g=a.body.indexOf(",")>=0;if(!f&&!g){if(a.post.match(/,(?!,).*\}/)){e=a.pre+"{"+a.body+U1e+a.post,n=!0;continue}return OU(i,l+"{"+a.body+"}"+a.post,[""],t,r,o)}s&&(o=n&&!f,s=!1);let m;if(f)m=cnn(a.body,u,t,r);else{let A=sAt(a.body);if(A.length===1&&A[0]!==void 0&&(A=F1e(A[0],t,r,!1).map(onn),A.length===1)){if(i=OU(i,l+A[0],[""],t,r,o&&!a.post.length),!a.post.length)break;e=a.post;continue}let h=o&&!a.post.length&&!l;for(let C=0;h&&C<i.length;C++)i[C]&&(h=!1);m=[];let y=0;e:for(let C=0;C<A.length;C++){let I=F1e(A[C],t,r,!1);for(let T=0;T<I.length;T++){let D=I[T];if(!(h&&!D)){if(m.length>=t||y+D.length>r)break e;m.push(D),y+=D.length}}}}if(i=OU(i,l,m,t,r,o&&!a.post.length),!a.post.length)break;e=a.post}return i}var kU=e=>{if(typeof e!="string")throw new TypeError("invalid pattern");if(e.length>65536)throw new TypeError("pattern is too long")};var unn={"[:alnum:]":["\\p{L}\\p{Nl}\\p{Nd}",!0],"[:alpha:]":["\\p{L}\\p{Nl}",!0],"[:ascii:]":["\\x00-\\x7f",!1],"[:blank:]":["\\p{Zs}\\t",!0],"[:cntrl:]":["\\p{Cc}",!0],"[:digit:]":["\\p{Nd}",!0],"[:graph:]":["\\p{Z}\\p{C}",!0,!0],"[:lower:]":["\\p{Ll}",!0],"[:print:]":["\\p{C}",!0],"[:punct:]":["\\p{P}",!0],"[:space:]":["\\p{Z}\\t\\r\\n\\v\\f",!0],"[:upper:]":["\\p{Lu}",!0],"[:word:]":["\\p{L}\\p{Nl}\\p{Nd}\\p{Pc}",!0],"[:xdigit:]":["A-Fa-f0-9",!1]},MU=e=>e.replace(/[[\]\\-]/g,"\\$&"),dnn=e=>e.replace(/[-[\]{}()*+?.,\\^$|#\s]/g,"\\$&"),lAt=e=>e.join(""),cAt=(e,t)=>{let r=t;if(e.charAt(r)!=="[")throw new Error("not in a brace expression");let n=[],i=[],o=r+1,s=!1,a=!1,l=!1,c=!1,u=r,f="";e:for(;o<e.length;){let h=e.charAt(o);if((h==="!"||h==="^")&&o===r+1){c=!0,o++;continue}if(h==="]"&&s&&!l){u=o+1;break}if(s=!0,h==="\\"&&!l){l=!0,o++;continue}if(h==="["&&!l){for(let[y,[C,I,T]]of Object.entries(unn))if(e.startsWith(y,o)){if(f)return["$.",!1,e.length-r,!0];o+=y.length,T?i.push(C):n.push(C),a=a||I;continue e}}if(l=!1,f){h>f?n.push(MU(f)+"-"+MU(h)):h===f&&n.push(MU(h)),f="",o++;continue}if(e.startsWith("-]",o+1)){n.push(MU(h+"-")),o+=2;continue}if(e.startsWith("-",o+1)){f=h,o+=2;continue}n.push(MU(h)),o++}if(u<o)return["",!1,0,!1];if(!n.length&&!i.length)return["$.",!1,e.length-r,!0];if(i.length===0&&n.length===1&&/^\\?.$/.test(n[0])&&!c){let h=n[0].length===2?n[0].slice(-1):n[0];return[dnn(h),!1,u-r,!1]}let g="["+(c?"^":"")+lAt(n)+"]",m="["+(c?"":"^")+lAt(i)+"]";return[n.length&&i.length?"("+g+"|"+m+")":n.length?g:m,a,u-r,!0]};var nC=(e,{windowsPathsNoEscape:t=!1,magicalBraces:r=!0}={})=>r?t?e.replace(/\[([^/\\])\]/g,"$1"):e.replace(/((?!\\).|^)\[([^/\\])\]/g,"$1$2").replace(/\\([^/])/g,"$1"):t?e.replace(/\[([^/\\{}])\]/g,"$1"):e.replace(/((?!\\).|^)\[([^/\\{}])\]/g,"$1$2").replace(/\\([^/{}])/g,"$1");var dd,fnn=new Set(["!","?","+","*","@"]),H1e=e=>fnn.has(e),uAt=e=>H1e(e.type),pnn=new Map([["!",["@"]],["?",["?","@"]],["@",["@"]],["*",["*","+","?","@"]],["+",["+","@"]]]),mnn=new Map([["!",["?"]],["@",["?"]],["+",["?","*"]]]),gnn=new Map([["!",["?","@"]],["?",["?","@"]],["@",["?","@"]],["*",["*","+","?","@"]],["+",["+","@","?","*"]]]),dAt=new Map([["!",new Map([["!","@"]])],["?",new Map([["*","*"],["+","*"]])],["@",new Map([["!","!"],["?","?"],["@","@"],["*","*"],["+","+"]])],["+",new Map([["?","*"],["*","*"]])]]),Ann="(?!(?:^|/)\\.\\.?(?:$|/))",zJ="(?!\\.)",hnn=new Set(["[","."]),Enn=new Set(["..","."]),_nn=new Set("().*{}+?[]^$\\!"),ynn=e=>e.replace(/[-[\]{}()*+?.,\\^$|#\s]/g,"\\$&"),$1e="[^/]",fAt=$1e+"*?",pAt=$1e+"+?",bnn=0,xT=class{type;#e;#t;#n=!1;#r=[];#o;#i;#l;#s=!1;#a;#d;#p=!1;id=++bnn;get depth(){return(this.#o?.depth??-1)+1}[Symbol.for("nodejs.util.inspect.custom")](){return{"@@type":"AST",id:this.id,type:this.type,root:this.#e.id,parent:this.#o?.id,depth:this.depth,partsLength:this.#r.length,parts:this.#r}}constructor(t,r,n={}){this.type=t,t&&(this.#t=!0),this.#o=r,this.#e=this.#o?this.#o.#e:this,this.#a=this.#e===this?n:this.#e.#a,this.#l=this.#e===this?[]:this.#e.#l,t==="!"&&!this.#e.#s&&this.#l.push(this),this.#i=this.#o?this.#o.#r.length:0}get hasMagic(){if(this.#t!==void 0)return this.#t;for(let t of this.#r)if(typeof t!="string"&&(t.type||t.hasMagic))return this.#t=!0;return this.#t}toString(){return this.#d!==void 0?this.#d:this.type?this.#d=this.type+"("+this.#r.map(t=>String(t)).join("|")+")":this.#d=this.#r.map(t=>String(t)).join("")}#f(){if(this!==this.#e)throw new Error("should only call on root");if(this.#s)return this;this.toString(),this.#s=!0;let t;for(;t=this.#l.pop();){if(t.type!=="!")continue;let r=t,n=r.#o;for(;n;){for(let i=r.#i+1;!n.type&&i<n.#r.length;i++)for(let o of t.#r){if(typeof o=="string")throw new Error("string part in extglob AST??");o.copyIn(n.#r[i])}r=n,n=r.#o}}return this}push(...t){for(let r of t)if(r!==""){if(typeof r!="string"&&!(r instanceof dd&&r.#o===this))throw new Error("invalid part: "+r);this.#r.push(r)}}toJSON(){let t=this.type===null?this.#r.slice().map(r=>typeof r=="string"?r:r.toJSON()):[this.type,...this.#r.map(r=>r.toJSON())];return this.isStart()&&!this.type&&t.unshift([]),this.isEnd()&&(this===this.#e||this.#e.#s&&this.#o?.type==="!")&&t.push({}),t}isStart(){if(this.#e===this)return!0;if(!this.#o?.isStart())return!1;if(this.#i===0)return!0;let t=this.#o;for(let r=0;r<this.#i;r++){let n=t.#r[r];if(!(n instanceof dd&&n.type==="!"))return!1}return!0}isEnd(){if(this.#e===this||this.#o?.type==="!")return!0;if(!this.#o?.isEnd())return!1;if(!this.type)return this.#o?.isEnd();let t=this.#o?this.#o.#r.length:0;return this.#i===t-1}copyIn(t){typeof t=="string"?this.push(t):this.push(t.clone(this))}clone(t){let r=new dd(this.type,t);for(let n of this.#r)r.copyIn(n);return r}static#c(t,r,n,i,o){let s=i.maxExtglobRecursion??2,a=!1,l=!1,c=-1,u=!1;if(r.type===null){let h=n,y="";for(;h<t.length;){let C=t.charAt(h++);if(a||C==="\\"){a=!a,y+=C;continue}if(l){h===c+1?(C==="^"||C==="!")&&(u=!0):C==="]"&&!(h===c+2&&u)&&(l=!1),y+=C;continue}else if(C==="["){l=!0,c=h,u=!1,y+=C;continue}if(!i.noext&&H1e(C)&&t.charAt(h)==="("&&o<=s){r.push(y),y="";let T=new dd(C,r);h=dd.#c(t,T,h,i,o+1),r.push(T);continue}y+=C}return r.push(y),h}let f=n+1,g=new dd(null,r),m=[],A="";for(;f<t.length;){let h=t.charAt(f++);if(a||h==="\\"){a=!a,A+=h;continue}if(l){f===c+1?(h==="^"||h==="!")&&(u=!0):h==="]"&&!(f===c+2&&u)&&(l=!1),A+=h;continue}else if(h==="["){l=!0,c=f,u=!1,A+=h;continue}if(!i.noext&&H1e(h)&&t.charAt(f)==="("&&(o<=s||r&&r.#E(h))){let C=r&&r.#E(h)?0:1;g.push(A),A="";let I=new dd(h,g);g.push(I),f=dd.#c(t,I,f,i,o+C);continue}if(h==="|"){g.push(A),A="",m.push(g),g=new dd(null,r);continue}if(h===")")return A===""&&r.#r.length===0&&(r.#p=!0),g.push(A),A="",r.push(...m,g),f;A+=h}return r.type=null,r.#t=void 0,r.#r=[t.substring(n-1)],f}#g(t){return this.#h(t,mnn)}#h(t,r=pnn){if(!t||typeof t!="object"||t.type!==null||t.#r.length!==1||this.type===null)return!1;let n=t.#r[0];return!n||typeof n!="object"||n.type===null?!1:this.#E(n.type,r)}#E(t,r=gnn){return!!r.get(this.type)?.includes(t)}#A(t,r){let n=t.#r[0],i=new dd(null,n,this.options);i.#r.push(""),n.push(i),this.#v(t,r)}#v(t,r){let n=t.#r[0];this.#r.splice(r,1,...n.#r);for(let i of n.#r)typeof i=="object"&&(i.#o=this);this.#d=void 0}#y(t){return!!dAt.get(this.type)?.has(t)}#S(t){if(!t||typeof t!="object"||t.type!==null||t.#r.length!==1||this.type===null||this.#r.length!==1)return!1;let r=t.#r[0];return!r||typeof r!="object"||r.type===null?!1:this.#y(r.type)}#I(t){let r=dAt.get(this.type),n=t.#r[0],i=r?.get(n.type);if(!i)return!1;this.#r=n.#r;for(let o of this.#r)typeof o=="object"&&(o.#o=this);this.type=i,this.#d=void 0,this.#p=!1}static fromGlob(t,r={}){let n=new dd(null,void 0,r);return dd.#c(t,n,0,r,0),n}toMMPattern(){if(this!==this.#e)return this.#e.toMMPattern();let t=this.toString(),[r,n,i,o]=this.toRegExpSource();if(!(i||this.#t||this.#a.nocase&&!this.#a.nocaseMagicOnly&&t.toUpperCase()!==t.toLowerCase()))return n;let a=(this.#a.nocase?"i":"")+(o?"u":"");return Object.assign(new RegExp(`^${r}$`,a),{_src:r,_glob:t})}get options(){return this.#a}toRegExpSource(t){let r=t??!!this.#a.dot;if(this.#e===this&&(this.#_(),this.#f()),!uAt(this)){let l=this.isStart()&&this.isEnd()&&!this.#r.some(m=>typeof m!="string"),c=this.#r.map(m=>{let[A,h,y,C]=typeof m=="string"?dd.#C(m,this.#t,l):m.toRegExpSource(t);return this.#t=this.#t||y,this.#n=this.#n||C,A}).join(""),u="";if(this.isStart()&&typeof this.#r[0]=="string"&&!(this.#r.length===1&&Enn.has(this.#r[0]))){let A=hnn,h=r&&A.has(c.charAt(0))||c.startsWith("\\.")&&A.has(c.charAt(2))||c.startsWith("\\.\\.")&&A.has(c.charAt(4)),y=!r&&!t&&A.has(c.charAt(0));u=h?Ann:y?zJ:""}let f="";return this.isEnd()&&this.#e.#s&&this.#o?.type==="!"&&(f="(?:$|\\/)"),[u+c+f,nC(c),this.#t=!!this.#t,this.#n]}let n=this.type==="*"||this.type==="+",i=this.type==="!"?"(?:(?!(?:":"(?:",o=this.#b(r);if(this.isStart()&&this.isEnd()&&!o&&this.type!=="!"){let l=this.toString(),c=this;return c.#r=[l],c.type=null,c.#t=void 0,[l,nC(this.toString()),!1,!1]}let s=!n||t||r||!zJ?"":this.#b(!0);s===o&&(s=""),s&&(o=`(?:${o})(?:${s})*?`);let a="";if(this.type==="!"&&this.#p)a=(this.isStart()&&!r?zJ:"")+pAt;else{let l=this.type==="!"?"))"+(this.isStart()&&!r&&!t?zJ:"")+fAt+")":this.type==="@"?")":this.type==="?"?")?":this.type==="+"&&s?")":this.type==="*"&&s?")?":`)${this.type}`;a=i+o+l}return[a,nC(o),this.#t=!!this.#t,this.#n]}#_(){if(uAt(this)){let t=0,r=!1;do{r=!0;for(let n=0;n<this.#r.length;n++){let i=this.#r[n];typeof i=="object"&&(i.#_(),this.#h(i)?(r=!1,this.#v(i,n)):this.#g(i)?(r=!1,this.#A(i,n)):this.#S(i)&&(r=!1,this.#I(i)))}}while(!r&&++t<10)}else for(let t of this.#r)typeof t=="object"&&t.#_();this.#d=void 0}#b(t){return this.#r.map(r=>{if(typeof r=="string")throw new Error("string type in extglob ast??");let[n,i,o,s]=r.toRegExpSource(t);return this.#n=this.#n||s,n}).filter(r=>!(this.isStart()&&this.isEnd())||!!r).join("|")}static#C(t,r,n=!1){let i=!1,o="",s=!1,a=!1;for(let l=0;l<t.length;l++){let c=t.charAt(l);if(i){i=!1,o+=(_nn.has(c)?"\\":"")+c;continue}if(c==="*"){if(a)continue;a=!0,o+=n&&/^[*]+$/.test(t)?pAt:fAt,r=!0;continue}else a=!1;if(c==="\\"){l===t.length-1?o+="\\\\":i=!0;continue}if(c==="["){let[u,f,g,m]=cAt(t,l);if(g){o+=u,s=s||f,l+=g-1,r=r||m;continue}}if(c==="?"){o+=$1e,r=!0;continue}o+=ynn(c)}return[o,nC(t),!!r,s]}};dd=xT;var q1e=(e,{windowsPathsNoEscape:t=!1,magicalBraces:r=!1}={})=>r?t?e.replace(/[?*()[\]{}]/g,"[$&]"):e.replace(/[?*()[\]\\{}]/g,"\\$&"):t?e.replace(/[?*()[\]]/g,"[$&]"):e.replace(/[?*()[\]\\]/g,"\\$&");var Yl=(e,t,r={})=>(kU(t),!r.nocomment&&t.charAt(0)==="#"?!1:new DB(t,r).match(e)),Cnn=/^\*+([^+@!?*[(]*)$/,Snn=e=>t=>!t.startsWith(".")&&t.endsWith(e),Inn=e=>t=>t.endsWith(e),Tnn=e=>(e=e.toLowerCase(),t=>!t.startsWith(".")&&t.toLowerCase().endsWith(e)),vnn=e=>(e=e.toLowerCase(),t=>t.toLowerCase().endsWith(e)),xnn=/^\*+\.\*+$/,wnn=e=>!e.startsWith(".")&&e.includes("."),Dnn=e=>e!=="."&&e!==".."&&e.includes("."),Rnn=/^\.\*+$/,Nnn=e=>e!=="."&&e!==".."&&e.startsWith("."),Bnn=/^\*+$/,Onn=e=>e.length!==0&&!e.startsWith("."),knn=e=>e.length!==0&&e!=="."&&e!=="..",Mnn=/^\?+([^+@!?*[(]*)?$/,Qnn=([e,t=""])=>{let r=AAt([e]);return t?(t=t.toLowerCase(),n=>r(n)&&n.toLowerCase().endsWith(t)):r},Pnn=([e,t=""])=>{let r=hAt([e]);return t?(t=t.toLowerCase(),n=>r(n)&&n.toLowerCase().endsWith(t)):r},Lnn=([e,t=""])=>{let r=hAt([e]);return t?n=>r(n)&&n.endsWith(t):r},Fnn=([e,t=""])=>{let r=AAt([e]);return t?n=>r(n)&&n.endsWith(t):r},AAt=([e])=>{let t=e.length;return r=>r.length===t&&!r.startsWith(".")},hAt=([e])=>{let t=e.length;return r=>r.length===t&&r!=="."&&r!==".."},EAt=typeof process=="object"&&process?typeof process.env=="object"&&process.env&&process.env.__MINIMATCH_TESTING_PLATFORM__||process.platform:"posix",mAt={win32:{sep:"\\"},posix:{sep:"/"}},Unn=EAt==="win32"?mAt.win32.sep:mAt.posix.sep;Yl.sep=Unn;var xc=Symbol("globstar **");Yl.GLOBSTAR=xc;var Hnn="[^/]",$nn=Hnn+"*?",qnn="(?:(?!(?:\\/|^)(?:\\.{1,2})($|\\/)).)*?",Gnn="(?:(?!(?:\\/|^)\\.).)*?",znn=(e,t={})=>r=>Yl(r,e,t);Yl.filter=znn;var $p=(e,t={})=>Object.assign({},e,t),jnn=e=>{if(!e||typeof e!="object"||!Object.keys(e).length)return Yl;let t=Yl;return Object.assign((n,i,o={})=>t(n,i,$p(e,o)),{Minimatch:class extends t.Minimatch{constructor(i,o={}){super(i,$p(e,o))}static defaults(i){return t.defaults($p(e,i)).Minimatch}},AST:class extends t.AST{constructor(i,o,s={}){super(i,o,$p(e,s))}static fromGlob(i,o={}){return t.AST.fromGlob(i,$p(e,o))}},unescape:(n,i={})=>t.unescape(n,$p(e,i)),escape:(n,i={})=>t.escape(n,$p(e,i)),filter:(n,i={})=>t.filter(n,$p(e,i)),defaults:n=>t.defaults($p(e,n)),makeRe:(n,i={})=>t.makeRe(n,$p(e,i)),braceExpand:(n,i={})=>t.braceExpand(n,$p(e,i)),match:(n,i,o={})=>t.match(n,i,$p(e,o)),sep:t.sep,GLOBSTAR:xc})};Yl.defaults=jnn;var _At=(e,t={})=>(kU(e),t.nobrace||!/\{(?:(?!\{).)*\}/.test(e)?[e]:aAt(e,{max:t.braceExpandMax}));Yl.braceExpand=_At;var Ynn=(e,t={})=>new DB(e,t).makeRe();Yl.makeRe=Ynn;var Vnn=(e,t,r={})=>{let n=new DB(t,r);return e=e.filter(i=>n.match(i)),n.options.nonull&&!e.length&&e.push(t),e};Yl.match=Vnn;var gAt=/[?*]|[+@!]\(.*?\)|\[|\]/,Wnn=e=>e.replace(/[-[\]{}()*+?.,\\^$|#\s]/g,"\\$&"),DB=class{options;set;pattern;windowsPathsNoEscape;nonegate;negate;comment;empty;preserveMultipleSlashes;partial;globSet;globParts;nocase;isWindows;platform;windowsNoMagicRoot;maxGlobstarRecursion;regexp;constructor(t,r={}){kU(t),r=r||{},this.options=r,this.maxGlobstarRecursion=r.maxGlobstarRecursion??200,this.pattern=t,this.platform=r.platform||EAt,this.isWindows=this.platform==="win32";let n="allowWindowsEscape";this.windowsPathsNoEscape=!!r.windowsPathsNoEscape||r[n]===!1,this.windowsPathsNoEscape&&(this.pattern=this.pattern.replace(/\\/g,"/")),this.preserveMultipleSlashes=!!r.preserveMultipleSlashes,this.regexp=null,this.negate=!1,this.nonegate=!!r.nonegate,this.comment=!1,this.empty=!1,this.partial=!!r.partial,this.nocase=!!this.options.nocase,this.windowsNoMagicRoot=r.windowsNoMagicRoot!==void 0?r.windowsNoMagicRoot:!!(this.isWindows&&this.nocase),this.globSet=[],this.globParts=[],this.set=[],this.make()}hasMagic(){if(this.options.magicalBraces&&this.set.length>1)return!0;for(let t of this.set)for(let r of t)if(typeof r!="string")return!0;return!1}debug(...t){}make(){let t=this.pattern,r=this.options;if(!r.nocomment&&t.charAt(0)==="#"){this.comment=!0;return}if(!t){this.empty=!0;return}this.parseNegate(),this.globSet=[...new Set(this.braceExpand())],r.debug&&(this.debug=(...o)=>console.error(...o)),this.debug(this.pattern,this.globSet);let n=this.globSet.map(o=>this.slashSplit(o));this.globParts=this.preprocess(n),this.debug(this.pattern,this.globParts);let i=this.globParts.map((o,s,a)=>{if(this.isWindows&&this.windowsNoMagicRoot){let l=o[0]===""&&o[1]===""&&(o[2]==="?"||!gAt.test(o[2]))&&!gAt.test(o[3]),c=/^[a-z]:/i.test(o[0]);if(l)return[...o.slice(0,4),...o.slice(4).map(u=>this.parse(u))];if(c)return[o[0],...o.slice(1).map(u=>this.parse(u))]}return o.map(l=>this.parse(l))});if(this.debug(this.pattern,i),this.set=i.filter(o=>o.indexOf(!1)===-1),this.isWindows)for(let o=0;o<this.set.length;o++){let s=this.set[o];s[0]===""&&s[1]===""&&this.globParts[o][2]==="?"&&typeof s[3]=="string"&&/^[a-z]:$/i.test(s[3])&&(s[2]="?")}this.debug(this.pattern,this.set)}preprocess(t){if(this.options.noglobstar)for(let n of t)for(let i=0;i<n.length;i++)n[i]==="**"&&(n[i]="*");let{optimizationLevel:r=1}=this.options;return r>=2?(t=this.firstPhasePreProcess(t),t=this.secondPhasePreProcess(t)):r>=1?t=this.levelOneOptimize(t):t=this.adjascentGlobstarOptimize(t),t}adjascentGlobstarOptimize(t){return t.map(r=>{let n=-1;for(;(n=r.indexOf("**",n+1))!==-1;){let i=n;for(;r[i+1]==="**";)i++;i!==n&&r.splice(n,i-n)}return r})}levelOneOptimize(t){return t.map(r=>(r=r.reduce((n,i)=>{let o=n[n.length-1];return i==="**"&&o==="**"?n:i===".."&&o&&o!==".."&&o!=="."&&o!=="**"?(n.pop(),n):(n.push(i),n)},[]),r.length===0?[""]:r))}levelTwoFileOptimize(t){Array.isArray(t)||(t=this.slashSplit(t));let r=!1;do{if(r=!1,!this.preserveMultipleSlashes){for(let i=1;i<t.length-1;i++){let o=t[i];i===1&&o===""&&t[0]===""||(o==="."||o==="")&&(r=!0,t.splice(i,1),i--)}t[0]==="."&&t.length===2&&(t[1]==="."||t[1]==="")&&(r=!0,t.pop())}let n=0;for(;(n=t.indexOf("..",n+1))!==-1;){let i=t[n-1];i&&i!=="."&&i!==".."&&i!=="**"&&!(this.isWindows&&/^[a-z]:$/i.test(i))&&(r=!0,t.splice(n-1,2),n-=2)}}while(r);return t.length===0?[""]:t}firstPhasePreProcess(t){let r=!1;do{r=!1;for(let n of t){let i=-1;for(;(i=n.indexOf("**",i+1))!==-1;){let s=i;for(;n[s+1]==="**";)s++;s>i&&n.splice(i+1,s-i);let a=n[i+1],l=n[i+2],c=n[i+3];if(a!==".."||!l||l==="."||l===".."||!c||c==="."||c==="..")continue;r=!0,n.splice(i,1);let u=n.slice(0);u[i]="**",t.push(u),i--}if(!this.preserveMultipleSlashes){for(let s=1;s<n.length-1;s++){let a=n[s];s===1&&a===""&&n[0]===""||(a==="."||a==="")&&(r=!0,n.splice(s,1),s--)}n[0]==="."&&n.length===2&&(n[1]==="."||n[1]==="")&&(r=!0,n.pop())}let o=0;for(;(o=n.indexOf("..",o+1))!==-1;){let s=n[o-1];if(s&&s!=="."&&s!==".."&&s!=="**"){r=!0;let l=o===1&&n[o+1]==="**"?["."]:[];n.splice(o-1,2,...l),n.length===0&&n.push(""),o-=2}}}}while(r);return t}secondPhasePreProcess(t){for(let r=0;r<t.length-1;r++)for(let n=r+1;n<t.length;n++){let i=this.partsMatch(t[r],t[n],!this.preserveMultipleSlashes);if(i){t[r]=[],t[n]=i;break}}return t.filter(r=>r.length)}partsMatch(t,r,n=!1){let i=0,o=0,s=[],a="";for(;i<t.length&&o<r.length;)if(t[i]===r[o])s.push(a==="b"?r[o]:t[i]),i++,o++;else if(n&&t[i]==="**"&&r[o]===t[i+1])s.push(t[i]),i++;else if(n&&r[o]==="**"&&t[i]===r[o+1])s.push(r[o]),o++;else if(t[i]==="*"&&r[o]&&(this.options.dot||!r[o].startsWith("."))&&r[o]!=="**"){if(a==="b")return!1;a="a",s.push(t[i]),i++,o++}else if(r[o]==="*"&&t[i]&&(this.options.dot||!t[i].startsWith("."))&&t[i]!=="**"){if(a==="a")return!1;a="b",s.push(r[o]),i++,o++}else return!1;return t.length===r.length&&s}parseNegate(){if(this.nonegate)return;let t=this.pattern,r=!1,n=0;for(let i=0;i<t.length&&t.charAt(i)==="!";i++)r=!r,n++;n&&(this.pattern=t.slice(n)),this.negate=r}matchOne(t,r,n=!1){let i=0,o=0;if(this.isWindows){let a=typeof t[0]=="string"&&/^[a-z]:$/i.test(t[0]),l=!a&&t[0]===""&&t[1]===""&&t[2]==="?"&&/^[a-z]:$/i.test(t[3]),c=typeof r[0]=="string"&&/^[a-z]:$/i.test(r[0]),u=!c&&r[0]===""&&r[1]===""&&r[2]==="?"&&typeof r[3]=="string"&&/^[a-z]:$/i.test(r[3]),f=l?3:a?0:void 0,g=u?3:c?0:void 0;if(typeof f=="number"&&typeof g=="number"){let[m,A]=[t[f],r[g]];m.toLowerCase()===A.toLowerCase()&&(r[g]=m,o=g,i=f)}}let{optimizationLevel:s=1}=this.options;return s>=2&&(t=this.levelTwoFileOptimize(t)),r.includes(xc)?this.#e(t,r,n,i,o):this.#n(t,r,n,i,o)}#e(t,r,n,i,o){let s=r.indexOf(xc,o),a=r.lastIndexOf(xc),[l,c,u]=n?[r.slice(o,s),r.slice(s+1),[]]:[r.slice(o,s),r.slice(s+1,a),r.slice(a+1)];if(l.length){let I=t.slice(i,i+l.length);if(!this.#n(I,l,n,0,0))return!1;i+=l.length,o+=l.length}let f=0;if(u.length){if(u.length+i>t.length)return!1;let I=t.length-u.length;if(this.#n(t,u,n,I,0))f=u.length;else{if(t[t.length-1]!==""||i+u.length===t.length||(I--,!this.#n(t,u,n,I,0)))return!1;f=u.length+1}}if(!c.length){let I=!!f;for(let T=i;T<t.length-f;T++){let D=String(t[T]);if(I=!0,D==="."||D===".."||!this.options.dot&&D.startsWith("."))return!1}return n||I}let g=[[[],0]],m=g[0],A=0,h=[0];for(let I of c)I===xc?(h.push(A),m=[[],0],g.push(m)):(m[0].push(I),A++);let y=g.length-1,C=t.length-f;for(let I of g)I[1]=C-(h[y--]+I[0].length);return!!this.#t(t,g,i,0,n,0,!!f)}#t(t,r,n,i,o,s,a){let l=r[i];if(!l){for(let f=n;f<t.length;f++){a=!0;let g=t[f];if(g==="."||g===".."||!this.options.dot&&g.startsWith("."))return!1}return a}let[c,u]=l;for(;n<=u;){if(this.#n(t.slice(0,n+c.length),c,o,n,0)&&s<this.maxGlobstarRecursion){let m=this.#t(t,r,n+c.length,i+1,o,s+1,a);if(m!==!1)return m}let g=t[n];if(g==="."||g===".."||!this.options.dot&&g.startsWith("."))return!1;n++}return o||null}#n(t,r,n,i,o){let s,a,l,c;for(s=i,a=o,c=t.length,l=r.length;s<c&&a<l;s++,a++){this.debug("matchOne loop");let u=r[a],f=t[s];if(this.debug(r,u,f),u===!1||u===xc)return!1;let g;if(typeof u=="string"?(g=f===u,this.debug("string match",u,f,g)):(g=u.test(f),this.debug("pattern match",u,f,g)),!g)return!1}if(s===c&&a===l)return!0;if(s===c)return n;if(a===l)return s===c-1&&t[s]==="";throw new Error("wtf?")}braceExpand(){return _At(this.pattern,this.options)}parse(t){kU(t);let r=this.options;if(t==="**")return xc;if(t==="")return"";let n,i=null;(n=t.match(Bnn))?i=r.dot?knn:Onn:(n=t.match(Cnn))?i=(r.nocase?r.dot?vnn:Tnn:r.dot?Inn:Snn)(n[1]):(n=t.match(Mnn))?i=(r.nocase?r.dot?Pnn:Qnn:r.dot?Lnn:Fnn)(n):(n=t.match(xnn))?i=r.dot?Dnn:wnn:(n=t.match(Rnn))&&(i=Nnn);let o=xT.fromGlob(t,this.options).toMMPattern();return i&&typeof o=="object"&&Reflect.defineProperty(o,"test",{value:i}),o}makeRe(){if(this.regexp||this.regexp===!1)return this.regexp;let t=this.set;if(!t.length)return this.regexp=!1,this.regexp;let r=this.options,n=r.noglobstar?$nn:r.dot?qnn:Gnn,i=new Set(r.nocase?["i"]:[]),o=t.map(l=>{let c=l.map(f=>{if(f instanceof RegExp)for(let g of f.flags.split(""))i.add(g);return typeof f=="string"?Wnn(f):f===xc?xc:f._src});c.forEach((f,g)=>{let m=c[g+1],A=c[g-1];f!==xc||A===xc||(A===void 0?m!==void 0&&m!==xc?c[g+1]="(?:\\/|"+n+"\\/)?"+m:c[g]=n:m===void 0?c[g-1]=A+"(?:\\/|\\/"+n+")?":m!==xc&&(c[g-1]=A+"(?:\\/|\\/"+n+"\\/)"+m,c[g+1]=xc))});let u=c.filter(f=>f!==xc);if(this.partial&&u.length>=1){let f=[];for(let g=1;g<=u.length;g++)f.push(u.slice(0,g).join("/"));return"(?:"+f.join("|")+")"}return u.join("/")}).join("|"),[s,a]=t.length>1?["(?:",")"]:["",""];o="^"+s+o+a+"$",this.partial&&(o="^(?:\\/|"+s+o.slice(1,-1)+a+")$"),this.negate&&(o="^(?!"+o+").+$");try{this.regexp=new RegExp(o,[...i].join(""))}catch{this.regexp=!1}return this.regexp}slashSplit(t){return this.preserveMultipleSlashes?t.split("/"):this.isWindows&&/^\/\/[^/]+/.test(t)?["",...t.split(/\/+/)]:t.split(/\/+/)}match(t,r=this.partial){if(this.debug("match",t,this.pattern),this.comment)return!1;if(this.empty)return t==="";if(t==="/"&&r)return!0;let n=this.options;this.isWindows&&(t=t.split("\\").join("/"));let i=this.slashSplit(t);this.debug(this.pattern,"split",i);let o=this.set;this.debug(this.pattern,"set",o);let s=i[i.length-1];if(!s)for(let a=i.length-2;!s&&a>=0;a--)s=i[a];for(let a of o){let l=i;if(n.matchBase&&a.length===1&&(l=[s]),this.matchOne(l,a,r))return n.flipNegate?!0:!this.negate}return n.flipNegate?!1:this.negate}static defaults(t){return Yl.defaults(t).Minimatch}};Yl.AST=xT;Yl.Minimatch=DB;Yl.escape=q1e;Yl.unescape=nC;var CAt=we(BU(),1);Sr();$e();De();Xc();import{readFile as yAt}from"fs/promises";import{existsSync as G1e,readdirSync as Knn,statSync as Jnn}from"fs";import{join as z1e,relative as SAt}from"path";import{homedir as Znn}from"os";function bAt(e){try{let t=(0,CAt.default)(e),r=t.data.paths,n=[];return typeof r=="string"?n=r.split(",").map(i=>i.trim()).filter(Boolean):Array.isArray(r)&&(n=r.filter(i=>typeof i=="string")),{paths:n,content:t.content.trim()}}catch(t){return Te(t),{paths:[],content:e.trim()}}}function Xnn(e,t){return t.length===0?!0:t.some(r=>{try{return Yl(e,r,{matchBase:!0,dot:!0})}catch(n){return Te(n),!1}})}function j1e(e){let t=[];try{if(!G1e(e))return t;let r=Knn(e);for(let n of r){let i=z1e(e,n),o=Jnn(i);o.isDirectory()?t.push(...j1e(i)):o.isFile()&&n.endsWith(".md")&&t.push(i)}}catch(r){Te(r)}return t}async function jJ(){let e=[];try{let t=z1e(Znn(),Kr,"rules");if(G1e(t)){let r=j1e(t);for(let n of r)try{let i=await yAt(n,"utf-8"),{paths:o,content:s}=bAt(i);o.length>0&&e.push({filePath:n,content:s,paths:o,isProjectRule:!1})}catch(i){Te(i)}}}catch(t){Te(t)}try{let t=z1e(Ne(),Kr,"rules");if(G1e(t)){let r=j1e(t);for(let n of r)try{let i=await yAt(n,"utf-8"),{paths:o,content:s}=bAt(i);o.length>0&&e.push({filePath:SAt(Ne(),n),content:s,paths:o,isProjectRule:!0})}catch(i){Te(i)}}}catch(t){Te(t)}return e}function IAt(e,t){e=dY(e);let r=dY(Ne()),n=e.startsWith(r)?SAt(r,e):e;return t.filter(i=>Xnn(n,i.paths))}function TAt(e){return e.length===0?"":e.map(r=>{let n=r.isProjectRule?"project instructions, checked into the codebase":"user's private global instructions for all projects";return`Contents of ${r.filePath} (${n}):
626
626
 
627
627
  ${r.content}`}).join(`
628
628
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@dahawa/hawa-code",
3
- "version": "2.8.9",
3
+ "version": "2.8.10",
4
4
  "bin": {
5
5
  "hcode": "hawa.js"
6
6
  },
package/server.js CHANGED
@@ -599,7 +599,7 @@ data: ${JSON.stringify(z)}
599
599
  `);a=M.pop()||"";for(let z of M){let Y=z.trim();if(!(!Y||Y==="data: [DONE]"))if(Y.startsWith("data: ")){let q=Y.slice(6);try{let K=JSON.parse(q);D(K)}catch(K){this.logger&&this.logger.error({err:K,line:Y},"Failed to parse Gemini SSE chunk")}}else try{let q=JSON.parse(Y);D(q)}catch{}}};(async()=>{try{for(;;){let{value:M,done:z}=await s.read();if(z)break;a+=n.decode(M,{stream:!0}),B()}T()}catch(M){o.error(M)}})()}})}convertGeminiResponseToAnthropic(t){this.logger&&this.logger.debug({response:t},"Original Gemini response");try{if(!t.candidates||!t.candidates[0])throw new Error("No candidates found in Gemini response");let r=t.candidates[0],n=[];r.content&&r.content.parts&&r.content.parts.forEach(o=>{if(o.text&&n.push({type:"text",text:o.text}),o.functionCall){let s=`toolu_${nN()}`,a=o.functionCall.thoughtSignature||o.functionCall.thought_signature||null;n.push({type:"tool_use",id:s,name:o.functionCall.name,input:o.functionCall.args||{},thought_signature:a})}}),r.groundingMetadata&&(this.logger&&this.logger.debug({groundingMetadata:r.groundingMetadata},"Processing grounding metadata"),r.groundingMetadata.webSearchQueries&&n.push({type:"text",text:`
600
600
 
601
601
  [Search queries used: ${r.groundingMetadata.webSearchQueries.join(", ")}]`}));let i={id:`msg_${Math.random().toString(36).slice(2)}`,type:"message",role:"assistant",model:t.modelVersion||"gemini",content:n,stop_reason:r.finishReason?r.finishReason==="STOP"&&n.some(o=>o.type==="tool_use")?"tool_use":this.mapGeminiFinishReason(r.finishReason):"end_turn",stop_sequence:null,usage:{input_tokens:t.usageMetadata?.promptTokenCount||0,output_tokens:t.usageMetadata?.candidatesTokenCount||0}};return this.logger&&this.logger.debug({result:i},"Conversion complete, final Anthropic response"),i}catch{throw XMr(`Provider error: ${JSON.stringify(t)}`,500,"provider_error")}}mapGeminiFinishReason(t){switch(t){case"STOP":return"end_turn";case"MAX_TOKENS":return"max_tokens";case"SAFETY":case"RECITATION":return"stop_sequence";default:return"end_turn"}}},Bme=new Nme;var Ist=De(bst(),1);jt();Mo();function Ym(e){return e?typeof e.entries=="function"?Object.fromEntries(e.entries()):{...e}:{}}function Cst(e){let t=String(e?.["x-thinking-level"]??"medium").toLowerCase();return["off","low","medium","high"].includes(t)?t:"medium"}function p7r(e,t){if(t==="off"){delete e.reasoning;return}e.reasoning={effort:t}}function m7r(e,t){if(t==="off"){delete e.reasoning;return}e.reasoning={effort:t,summary:"auto"}}function g7r(e,t="chat"){let r={request:{},response:{},openai:{request:{},response:{}}};return r.request.model=e.request.body.model,r.request.messages=e.request.body.messages,r.request.system=e.request.body.system,r.response.content=e.response.body.content,r.response.usage=e.response.body?.usage,t==="responses"?(r.openai.request.model=e.openai.request.body.model,r.openai.request.input=e.openai.request.body.input,r.openai.response.output=e.openai.response.body?.output,r.openai.response.usage=e.openai.response.body?.usage):(r.openai.request.model=e.openai.request.body.model,r.openai.request.messages=e.openai.request.body.messages,r.openai.response.choices=e.openai.response.body.choices,r.openai.response.usage=e.openai.response.body?.usage),r}function eF(e,t,r){I8(t,e),T8(t,g7r(e,r),r)}function zN(e){let t=[],r=e.getReader(),n,i=new Promise(l=>n=l),o=!1,s=()=>{o||(o=!0,n(Buffer.concat(t).toString("utf8")))};return{stream:new ReadableStream({async pull(l){try{let{done:c,value:u}=await r.read();if(c){l.close(),s();return}t.push(u),l.enqueue(u)}catch(c){l.error(c),s()}},cancel(l){r.cancel(l).catch(()=>{}),s()}}),done:i}}function tF(e){let t=new Headers(e);return t.delete("content-encoding"),t.delete("content-length"),t.delete("transfer-encoding"),t}function s0e(e,t,r,n,i){let o;try{o={type:"error",error:{type:"api_error",message:JSON.parse(i).error?.message??`${e}: ${n}`,code:`${t}_${r}_ERROR`}}}catch{o={type:"error",error:{type:"api_error",message:`${e}: ${n}`,code:`${t}_${r}_ERROR`}}}return new Response(JSON.stringify(o),{status:r,statusText:n,headers:{"Content-Type":"application/json"}})}var Sst=["/v1/messages"];function a0e(e){let t;try{typeof e=="string"?t=new uT(e):e instanceof uT?t=e:t=new uT(e.url)}catch{return""}let r=t.pathname;for(let n of Sst){let i=r.indexOf(n);if(i!==-1)return t.origin+r.slice(0,i)}return t.origin}function jV(e,t){let r=typeof e=="string"?e:e instanceof uT?e.toString():e.url,n;try{n=new uT(r).pathname}catch{return!1}return Sst.some(i=>n.includes(i))&&(t.method==="POST"||t.method==="post")}function A7r(e){return async(t,r)=>{if(!jV(t,r))return e(t,r);let n=JSON.parse(r.body),i=await Yj.transformRequestOut(n),o=a0e(t)+"/chat/completions",s=Ym(r.headers),a=s.authorization??s.Authorization??"";p7r(i,Cst(s));let l=await e(o,{method:"POST",headers:{"Content-Type":"application/json",Authorization:a},body:JSON.stringify(i),signal:r.signal});if(!l.ok){let y=await l.text();return V(`OpenAI Chat Completions API error: ${l.status}`,{url:o,errorResponse:y}),s0e("OpenAI Chat Completions API error","OPENROUTER",l.status,l.statusText,y)}let c=n.stream===!0,u=s["x-agent-id"],f={request:{url:o,method:r.method,headers:s,body:n},response:{status:l.status,statusText:l.statusText,headers:Ym(l.headers)},openai:{request:{body:i},response:{}}};if(!c){let y=await l.text(),C=new Response(y,{status:l.status,statusText:l.statusText,headers:tF(l.headers)}),I=await Yj.transformResponseIn(C,n),T=await I.text();try{eF({...f,openai:{...f.openai,response:{body:JSON.parse(y)}},response:{...f.response,body:JSON.parse(T)}},u)}catch(D){V("\u65E5\u5FD7\u89E3\u6790\u9519\u8BEF(Chat \u975E\u6D41\u5F0F):",D)}return new Response(T,{status:I.status,statusText:I.statusText,headers:I.headers})}let g=zN(l.body),m=new Response(g.stream,{status:l.status,statusText:l.statusText,headers:tF(l.headers)}),A=await Yj.transformResponseIn(m,n),E=zN(A.body);return Promise.all([g.done,E.done]).then(async([y,C])=>{try{eF({...f,openai:{...f.openai,response:{body:await WKe(y)}},response:{...f.response,body:await jP(C)}},u)}catch(I){V("\u65E5\u5FD7\u89E3\u6790\u9519\u8BEF(Chat \u6D41\u5F0F):"+I?.stack)}}).catch(y=>V("\u65E5\u5FD7\u805A\u5408\u9519\u8BEF(Chat):"+y)),new Response(E.stream,{status:A.status,statusText:A.statusText,headers:A.headers})}}function h7r(e){return async(t,r)=>{if(!jV(t,r))return e(t,r);let n=JSON.parse(r.body),i=await Vj.transformRequestOut(n),o=Ym(r.headers);m7r(i,Cst(o));let s=JSON.stringify(i),l=a0e(t)+"/responses",c=o.authorization??o.Authorization??"";if(!c)return new Response(JSON.stringify({type:"error",error:{type:"api_error",message:"Missing Authorization header",code:"RESPONSES_AUTH_MISSING"}}),{status:401,headers:{"Content-Type":"application/json"}});let u=await e(l,{method:"POST",headers:{"Content-Type":"application/json",Authorization:c,"x-api-key":c.replace(/^Bearer\s+/i,"").trim()},body:s,signal:r.signal});if(!u.ok){let I=await u.text();return V(`OpenAI Responses API error: ${u.status} ${u.statusText}`,{url:l,status:u.status,errorResponse:I}),s0e("OpenAI Responses API error","RESPONSES",u.status,u.statusText,I)}let f=n.stream===!0,g=o["x-agent-id"],m={request:{url:l,method:r.method,headers:o,body:n},response:{status:u.status,statusText:u.statusText,headers:Ym(u.headers)},openai:{request:{body:i},response:{}}};if(!f){let I=await u.text(),T=new Response(I,{status:u.status,statusText:u.statusText,headers:tF(u.headers)}),D=await Vj.transformResponseIn(T,n),B=await D.text();try{eF({...m,openai:{...m.openai,response:{body:JSON.parse(I)}},response:{...m.response,body:JSON.parse(B)}},g,"responses")}catch(M){V("\u65E5\u5FD7\u89E3\u6790\u9519\u8BEF(Responses \u975E\u6D41\u5F0F):",M)}return new Response(B,{status:D.status,statusText:D.statusText,headers:D.headers})}let A=zN(u.body),E=new Response(A.stream,{status:u.status,statusText:u.statusText,headers:tF(u.headers)}),y=await Vj.transformResponseIn(E,n),C=zN(y.body);return Promise.all([A.done,C.done]).then(async([I,T])=>{try{eF({...m,openai:{...m.openai,response:{body:await VKe(I)}},response:{...m.response,body:await jP(T)}},g,"responses")}catch(D){V("\u65E5\u5FD7\u89E3\u6790\u9519\u8BEF(Responses \u6D41\u5F0F):"+D?.stack)}}).catch(I=>V("\u65E5\u5FD7\u805A\u5408\u9519\u8BEF(Responses):"+I)),new Response(C.stream,{status:y.status,statusText:y.statusText,headers:y.headers})}}function E7r(e){return async(t,r)=>{if(!jV(t,r))return e(t,r);let n=JSON.parse(r.body),i=Ym(r.headers),o=await Bme.transformRequestOut(n),s=JSON.stringify(o),a=a0e(t)+`/models/${n.model}:streamGenerateContent?alt=sse`,l=i.authorization??i.Authorization??"",c;try{c=await e(a,{method:"POST",headers:{"Content-Type":"application/json","x-goog-api-key":String(l).replace(/^Bearer\s+/i,"").trim()},body:s,signal:r.signal})}catch(C){throw V("gemini request error:",C),C}if(!c.ok){let C=await c.text();return V(`Gemini API error response: ${c.status} ${c.statusText}`,{url:a,status:c.status,errorResponse:C}),s0e("Gemini API error","Gemini",c.status,c.statusText,C)}let u=n.stream===!0,f=i["x-agent-id"],g={request:{url:a,method:r.method,headers:Ym(r.headers),body:n},response:{status:c.status,statusText:c.statusText,headers:Ym(c.headers)},openai:{request:{body:o},response:{}}},m=zN(c.body),A=new Response(m.stream,{status:c.status,statusText:c.statusText,headers:tF(c.headers)}),E=await Bme.transformResponseIn(A),y=zN(E.body);return Promise.all([m.done,y.done]).then(async([C,I])=>{try{let T=u?KKe(C):JSON.parse(C),D=u?await jP(I):JSON.parse(I);eF({...g,openai:{...g.openai,response:{body:T}},response:{...g.response,body:D}},f)}catch(T){V("\u65E5\u5FD7\u89E3\u6790\u9519\u8BEF(Gemini):"+T?.stack)}}).catch(C=>V("\u65E5\u5FD7\u805A\u5408\u9519\u8BEF(Gemini):"+C)),new Response(y.stream,{status:E.status,statusText:E.statusText,headers:E.headers})}}function _7r(e){return async(t,r)=>{if(!jV(t,r))return e(t,r);let n=r.body;if(r.body)try{let f=JSON.parse(r.body);n=JSON.stringify(f)}catch{}let i=Ym(r.headers);["1","true"].includes(String(process.env.HAWA_CODE_X_API_KEY_DISABLED??"").toLowerCase())&&(delete i["x-api-key"],delete i["X-API-Key"]),["1","true"].includes(String(process.env.HAWA_CODE_AUTH_DISABLED??"").toLowerCase())&&(delete i.authorization,delete i.Authorization),delete i["content-length"];let a=await e(t,{method:r.method,headers:i,body:n,signal:r.signal});if(!a.ok){let f=await a.text();V(`API error response: ${a.status} ${a.statusText}`,{url:typeof t=="string"?t:t instanceof uT?t.toString():t.url,status:a.status,errorResponse:f});let g;try{let m=JSON.parse(f);g={type:"error",error:{type:"api_error",message:m.error?.message||m.message||`API error: ${a.statusText}`,code:m.error?.code||m.code||`API_${a.status}_ERROR`}},m.error?.details&&(g.error.details=m.error.details)}catch{g={type:"error",error:{type:"api_error",message:`API error: ${a.statusText}`,code:`API_${a.status}_ERROR`}}}return new Response(JSON.stringify(g),{status:a.status,statusText:a.statusText,headers:{"Content-Type":"application/json"}})}let l=a.clone(),c=!(Object.hasOwn(JSON.parse(n),"stream")&&!JSON.parse(n).stream),u={request:{url:typeof t=="string"?t:t instanceof uT?t.toString():t.url,method:r.method,headers:Ym(r.headers),body:JSON.parse(n)},response:{status:a.status,statusText:a.statusText,headers:Ym(a.headers)}};return(async()=>{if(c){let m=await a.text();u.response.body=await jP(m)}else u.response.body=await a.json();let g=Ym(r.headers)["x-agent-id"];I8(g,u),T8(g,{request:u.request.body.messages,response:u.response.body.content,usage:u.response.body?.usage})})().catch(f=>V(`\u65E5\u5FD7\u89E3\u6790\u9519\u8BEF:
602
- Stack trace: `+f.stack)),new Response(l.body,{status:a.status,statusText:a.statusText,headers:a.headers})}}var zV=null,o0e=!1;function y7r(){zV=null,o0e=!1}It.on("proxy:changed",y7r);function b7r(){if(o0e)return zV;if(o0e=!0,je().proxy!==!0)return null;let e=process.env.HTTPS_PROXY||process.env.HTTP_PROXY||process.env.https_proxy||process.env.http_proxy;return e&&(zV=new Ist.ProxyAgent({uri:e}),Et(`[proxy] using proxy: ${e}`)),zV}function C7r(){let e=b7r();return e?((t,r={})=>global.fetch(t,{...r,dispatcher:e})):global.fetch}function YV(e){let t=e||process.env.API_TYPE,r=C7r();switch(t){case"openai":return A7r(r);case"openai-responses":return h7r(r);case"gemini":return E7r(r);default:return _7r(r)}}PA();var w7r=De(tt(),1);function xst(e,t){let r=[],n=Math.max(1,Math.floor(t)),i="",o=0;for(let s of e){let a=T7r(s);i&&o+a>n?(r.push(i),i=s,o=a):(i+=s,o+=a)}return i&&r.push(i),r}function T7r(e){if(e===" ")return 4;let t=e.codePointAt(0);return t===void 0||t===0||t<32||t>=127&&t<160||v7r(t)?0:x7r(t)?2:1}function v7r(e){return e>=768&&e<=879||e>=6832&&e<=6911||e>=7616&&e<=7679||e>=8400&&e<=8447||e>=65056&&e<=65071}function x7r(e){return e>=4352&&(e<=4447||e===9001||e===9002||e>=11904&&e<=42191&&e!==12351||e>=44032&&e<=55203||e>=63744&&e<=64255||e>=65040&&e<=65049||e>=65072&&e<=65135||e>=65280&&e<=65376||e>=65504&&e<=65510||e>=127744&&e<=128591||e>=129280&&e<=129535||e>=131072&&e<=262141)}function rF(e){if(e<6e4)return`${(e/1e3).toFixed(1)}s`;let t=Math.floor(e/36e5),r=Math.floor(e%36e5/6e4),n=(e%6e4/1e3).toFixed(1);return t>0?`${t}h ${r}m ${n}s`:r>0?`${r}m ${n}s`:`${n}s`}function VV(e){return new Intl.NumberFormat("en",{notation:"compact",maximumFractionDigits:1}).format(e).toLowerCase()}we();Mo();var ql={totalCost:0,totalAPIDuration:0,startTime:Date.now(),inputTokens:0,outputTokens:0,cacheCreationTokens:0,cacheReadTokens:0,currentContextTokens:0};function WV(e,t){ql.totalCost+=e,ql.totalAPIDuration+=t}function KV(e,t){ql.inputTokens+=e,ql.outputTokens+=t,It.emit("token:change",{inputTokens:ql.inputTokens,outputTokens:ql.outputTokens})}function JV(e,t){ql.cacheCreationTokens+=e,ql.cacheReadTokens+=t}function nF(){return{inputTokens:ql.inputTokens,outputTokens:ql.outputTokens,cacheCreationTokens:ql.cacheCreationTokens,cacheReadTokens:ql.cacheReadTokens}}function wst(){return ql.totalCost}function Dst(){return Date.now()-ql.startTime}function Rst(){return ql.totalAPIDuration}function Nst(e){ql.currentContextTokens=e}function Bst(){return ql.currentContextTokens}we();He();He();var u0e="2.8.9";globalThis.MACRO={VERSION:u0e,PACKAGE_URL:`@dahawa/${Hi}`,README_URL:"https://github.com/italking/hawa-code",ISSUES_EXPLAINER:"report the issue at https://github.com/italking/hawa-code/issues"};var ZV=process.env.HAWA_CODE_USER_AGENT||`${Hi}/${u0e} (${process.env.USER_TYPE})`;we();we();ir();function od(e,t){let r=[],n=new Set;return e.filter(i=>i.type!=="progress"&&i.type!=="reminder").forEach(i=>{switch(i.type){case"user":{let o=dE(r);if(o?.type==="user"){r[r.length-1]=Ost(o,i);return}r.push(i);return}case"assistant":r.push(i);return;case"insert":{let o=dE(r);o?.type==="user"&&(r[r.length-1]=D7r(o,i));return}case"path_rules":{let o=t?.pathRules;if(!o)return;let s=i.content.paths.filter(u=>!n.has(u));if(s.length===0)return;let a=s.map(u=>o.get(u)).filter(u=>u!==void 0);if(s.forEach(u=>n.add(u)),a.length===0)return;let l=Ct([{type:"text",text:`<system-rules>
602
+ Stack trace: `+f.stack)),new Response(l.body,{status:a.status,statusText:a.statusText,headers:a.headers})}}var zV=null,o0e=!1;function y7r(){zV=null,o0e=!1}It.on("proxy:changed",y7r);function b7r(){if(o0e)return zV;if(o0e=!0,je().proxy!==!0)return null;let e=process.env.HTTPS_PROXY||process.env.HTTP_PROXY||process.env.https_proxy||process.env.http_proxy;return e&&(zV=new Ist.ProxyAgent({uri:e}),Et(`[proxy] using proxy: ${e}`)),zV}function C7r(){let e=b7r();return e?((t,r={})=>global.fetch(t,{...r,dispatcher:e})):global.fetch}function YV(e){let t=e||process.env.API_TYPE,r=C7r();switch(t){case"openai":return A7r(r);case"openai-responses":return h7r(r);case"gemini":return E7r(r);default:return _7r(r)}}PA();var w7r=De(tt(),1);function xst(e,t){let r=[],n=Math.max(1,Math.floor(t)),i="",o=0;for(let s of e){let a=T7r(s);i&&o+a>n?(r.push(i),i=s,o=a):(i+=s,o+=a)}return i&&r.push(i),r}function T7r(e){if(e===" ")return 4;let t=e.codePointAt(0);return t===void 0||t===0||t<32||t>=127&&t<160||v7r(t)?0:x7r(t)?2:1}function v7r(e){return e>=768&&e<=879||e>=6832&&e<=6911||e>=7616&&e<=7679||e>=8400&&e<=8447||e>=65056&&e<=65071}function x7r(e){return e>=4352&&(e<=4447||e===9001||e===9002||e>=11904&&e<=42191&&e!==12351||e>=44032&&e<=55203||e>=63744&&e<=64255||e>=65040&&e<=65049||e>=65072&&e<=65135||e>=65280&&e<=65376||e>=65504&&e<=65510||e>=127744&&e<=128591||e>=129280&&e<=129535||e>=131072&&e<=262141)}function rF(e){if(e<6e4)return`${(e/1e3).toFixed(1)}s`;let t=Math.floor(e/36e5),r=Math.floor(e%36e5/6e4),n=(e%6e4/1e3).toFixed(1);return t>0?`${t}h ${r}m ${n}s`:r>0?`${r}m ${n}s`:`${n}s`}function VV(e){return new Intl.NumberFormat("en",{notation:"compact",maximumFractionDigits:1}).format(e).toLowerCase()}we();Mo();var ql={totalCost:0,totalAPIDuration:0,startTime:Date.now(),inputTokens:0,outputTokens:0,cacheCreationTokens:0,cacheReadTokens:0,currentContextTokens:0};function WV(e,t){ql.totalCost+=e,ql.totalAPIDuration+=t}function KV(e,t){ql.inputTokens+=e,ql.outputTokens+=t,It.emit("token:change",{inputTokens:ql.inputTokens,outputTokens:ql.outputTokens})}function JV(e,t){ql.cacheCreationTokens+=e,ql.cacheReadTokens+=t}function nF(){return{inputTokens:ql.inputTokens,outputTokens:ql.outputTokens,cacheCreationTokens:ql.cacheCreationTokens,cacheReadTokens:ql.cacheReadTokens}}function wst(){return ql.totalCost}function Dst(){return Date.now()-ql.startTime}function Rst(){return ql.totalAPIDuration}function Nst(e){ql.currentContextTokens=e}function Bst(){return ql.currentContextTokens}we();He();He();var u0e="2.8.10";globalThis.MACRO={VERSION:u0e,PACKAGE_URL:`@dahawa/${Hi}`,README_URL:"https://github.com/italking/hawa-code",ISSUES_EXPLAINER:"report the issue at https://github.com/italking/hawa-code/issues"};var ZV=process.env.HAWA_CODE_USER_AGENT||`${Hi}/${u0e} (${process.env.USER_TYPE})`;we();we();ir();function od(e,t){let r=[],n=new Set;return e.filter(i=>i.type!=="progress"&&i.type!=="reminder").forEach(i=>{switch(i.type){case"user":{let o=dE(r);if(o?.type==="user"){r[r.length-1]=Ost(o,i);return}r.push(i);return}case"assistant":r.push(i);return;case"insert":{let o=dE(r);o?.type==="user"&&(r[r.length-1]=D7r(o,i));return}case"path_rules":{let o=t?.pathRules;if(!o)return;let s=i.content.paths.filter(u=>!n.has(u));if(s.length===0)return;let a=s.map(u=>o.get(u)).filter(u=>u!==void 0);if(s.forEach(u=>n.add(u)),a.length===0)return;let l=Ct([{type:"text",text:`<system-rules>
603
603
  ${Ize(a)}
604
604
  </system-rules>`}]),c=dE(r);c?.type==="user"?r[r.length-1]=Ost(c,l,{skipTrailingSystemReminders:!0}):r.push(l);return}}}),r}function D7r(e,t){return{...e,message:{...e.message,content:N7r(e.message.content,R7r(t.content.content))}}}function R7r(e){return`
605
605
  <system-reminder>