@dahawa/hawa-code 2.9.6 → 2.9.8

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
@@ -751,7 +751,7 @@ globstar while`,e,d,t,f,p),this.matchOne(e.slice(d),t.slice(f),r))return this.de
751
751
  `)),zWr(e,i,{encoding:r,flush:!0})}var Xst=new cK.default({fetchMethod:e=>XWr(e),ttl:300*1e3,ttlAutopurge:!1,max:1e3});async function sat(e){let t=QU(e);return Xst.get(t)||Xst.fetchMethod?.(t)}async function XWr(e){let t=new AbortController;setTimeout(()=>{t.abort()},1e3);let r=await Ert(e,t.signal,15),n=0;for(let i of r)U1(i)==="CRLF"&&n++;return n>3?"CRLF":"LF"}function aat(e,t,r){if(e.has(t))return e.get(t);let n=r();return e.set(t,n),n}var e7r=new cK.default({fetchMethod:e=>lat(e),ttl:300*1e3,ttlAutopurge:!1,max:1e3});function jd(e){let t=QU(e);return aat(e7r,t,()=>lat(t))}function lat(e){let r=Buffer.alloc(4096),n;try{n=eat(e,"r");let i=tat(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 me(`Error detecting encoding for file ${e}: ${i}`),"utf8"}finally{n&&rat(n)}}var t7r=new cK.default({fetchMethod:e=>cat(e),ttl:300*1e3,ttlAutopurge:!1,max:1e3});function U1(e){let t=QU(e);return aat(t7r,t,()=>cat(t))}function cat(e,t="utf8"){try{if(!nat(e).isFile())return"LF";let n=Buffer.alloc(4096),i=eat(e,"r"),o=tat(i,n,0,4096,0);rat(i);let s=n.toString(t,0,o),a=0,l=0;for(let c=0;c<s.length;c++)s[c]===`
752
752
  `&&(c>0&&s[c-1]==="\r"?a++:l++);return a>l?"CRLF":"LF"}catch(r){return me(`Error detecting line endings for file ${e}: ${r}`),"LF"}}function yB(e){let t=iat(e)?e:QU(Ne(),e);return t.endsWith(" AM.png")?t.replace(" AM.png","\u202FAM.png"):t.endsWith(" PM.png")?t.replace(" PM.png","\u202FPM.png"):t}function DEe(e){return e?iat(e)?e:QU(Ne(),e):void 0}function uat(e){try{let t=DEe(e),r=t?KWr(Ne(),t):void 0;return{absolutePath:t,relativePath:r}}catch(t){return Z("getAbsoluteAndRelativePaths error ",t),{absolutePath:null,relativePath:null}}}function dK(e){try{let t=JWr(e),r=Kst(e,Jst(e));if(!VWr(t))return;let o=WWr(t).filter(s=>Kst(s,Jst(s))===r&&ZWr(t,s)!==e)[0];return o||void 0}catch(t){me(`Error finding similar file for ${e}: ${t}`);return}}function OEe(){let e=process.env.HAWA_CODE_COMPACT_LINE_PREFIX;return!(e==="0"||e==="false")}function uC({content:e,startLine:t}){if(!e)return"";let r=e.split(/\r?\n/);return OEe()?r.map((n,i)=>`${i+t} ${n}`).join(`
753
753
  `):r.map((n,i)=>{let o=String(i+t);return o.length>=6?`${o}\u2192${n}`:`${o.padStart(6," ")}\u2192${n}`}).join(`
754
- `)}function dat(e){try{let t=jWr(e),r=t.readSync();return t.closeSync(),r===null}catch(t){return me(`Error checking directory: ${t}`),!1}}Fe();function sC(){let e=Rn();e.hasCompletedProjectOnboarding||Xi({...e,hasCompletedProjectOnboarding:!0})}function BEe({workspaceDir:e}){let r=!Rn().hasCompletedProjectOnboarding;if(!r)return null;let n=r7r(n7r(e,Hi)),i=dat(e),o=!n&&!i,s=gB.isEnabled&&!zr().shiftEnterKeyBindingInstalled,a=ne();return(0,A.jsxs)(w,{flexDirection:"column",gap:1,padding:1,paddingBottom:0,children:[r&&(0,A.jsxs)(A.Fragment,{children:[(0,A.jsx)(v,{color:a.secondaryText,children:"Tips for getting started:"}),(0,A.jsx)(Ic,{children:(()=>{let l=[];return i&&l.push((0,A.jsx)(Ic.Item,{children:(0,A.jsxs)(v,{color:a.secondaryText,children:["Ask ",nt," to create a new app or clone a repository."]})},"workspace")),o&&l.push((0,A.jsx)(Ic.Item,{children:(0,A.jsxs)(v,{color:a.secondaryText,children:["Run ",(0,A.jsx)(v,{color:a.text,children:"/init"})," to create a",Hi," file with instructions for Hawa code."]})},"claudemd")),s&&l.push((0,A.jsx)(Ic.Item,{children:(0,A.jsxs)(v,{color:a.secondaryText,children:["Run ",(0,A.jsx)(v,{color:a.text,children:"/terminal-setup"}),(0,A.jsx)(v,{bold:!1,children:" to set up terminal integration"})]})},"terminal")),l.push((0,A.jsx)(Ic.Item,{children:(0,A.jsxs)(v,{color:a.secondaryText,children:["Ask ",nt," questions about your codebase."]})},"questions")),l.push((0,A.jsx)(Ic.Item,{children:(0,A.jsxs)(v,{color:a.secondaryText,children:["Ask ",nt," to implement changes to your codebase."]})},"changes")),l})()})]}),e===i7r()&&(0,A.jsxs)(v,{color:ne().warning,children:["Note: You have launched ",(0,A.jsx)(v,{bold:!0,children:nt})," in your home directory. For the best experience, launch it in a project directory instead."]})]})}function MEe({isFocused:e,isSelected:t,smallPointer:r,children:n}){let{styles:i}=yo("Select");return(0,A.jsxs)(w,{...i.option({isFocused:e}),children:[e&&(0,A.jsx)(v,{...i.focusIndicator(),children:r?nr.triangleDownSmall:nr.pointer}),(0,A.jsx)(v,{...i.label({isFocused:e,isSelected:t}),children:n}),t&&(0,A.jsx)(v,{...i.selectedIndicator(),children:nr.tick})]})}var Kd=Ce(He(),1);import{isDeepStrictEqual as o7r}from"node:util";var GU=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:kEe(s);r.push([l,a]),o++,i=a}super(r),this.first=n}};var s7r=(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}}},LEe=e=>e.flatMap(t=>{if("options"in t){let r=LEe(t.options),n=r.flatMap(o=>"value"in o?o.value:[]);return[...t.header!==void 0?[{header:t.header,optionValues:n}]:[],...r]}return t}),pat=({visibleOptionCount:e,defaultValue:t,options:r})=>{let n=LEe(r),i=typeof e=="number"?Math.min(e,n.length):n.length,o=new GU(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}},PEe=({visibleOptionCount:e=5,options:t,defaultValue:r,onChange:n,onFocus:i,focusValue:o})=>{let s=LEe(t),[a,l]=(0,Kd.useReducer)(s7r,{visibleOptionCount:e,defaultValue:r,options:t},pat),[c,u]=(0,Kd.useState)(s);s!==c&&!o7r(s,c)&&(l({type:"reset",state:pat({visibleOptionCount:e,defaultValue:r,options:t})}),u(s));let d=(0,Kd.useCallback)(()=>{l({type:"focus-next-option"})},[]),f=(0,Kd.useCallback)(()=>{l({type:"focus-previous-option"})},[]),p=(0,Kd.useCallback)(()=>{l({type:"select-focused-option"})},[]),h=(0,Kd.useMemo)(()=>s.map((_,E)=>({..._,index:E})).slice(a.visibleFromIndex,a.visibleToIndex),[s,a.visibleFromIndex,a.visibleToIndex]);return(0,Kd.useEffect)(()=>{a.value&&a.previousValue!==a.value&&n?.(a.value)},[a.previousValue,a.value,t,n]),(0,Kd.useEffect)(()=>{a.focusedValue&&i?.(a.focusedValue)},[a.focusedValue,i]),(0,Kd.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 FEe=({isDisabled:e=!1,state:t})=>{Et((r,n)=>{n.downArrow&&t.focusNextOption(),n.upArrow&&t.focusPreviousOption(),n.return&&t.selectFocusedOption()},{isActive:!e})};var kEe=e=>`HEADER-${e.optionValues.join(",")}`;function QS({isDisabled:e=!1,visibleOptionCount:t=5,highlightText:r,options:n,defaultValue:i,onChange:o,onFocus:s,focusValue:a}){let l=PEe({visibleOptionCount:t,options:n,defaultValue:i,onChange:o,onFocus:s,focusValue:a});FEe({isDisabled:e,state:l});let{styles:c}=yo("Select");return(0,A.jsx)(w,{...c.container(),children:l.visibleOptions.map(u=>{let d="value"in u?u.value:kEe(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)(v,{...c.highlightedText(),children:r}),_.slice(b+r.length)]})}return(0,A.jsx)(MEe,{isFocused:f,isSelected:p,smallPointer:h,children:E},d)})})}function mat({onDone:e}){return Et((t,r)=>{(r.ctrl&&(t==="c"||t==="d")||r.escape)&&e()}),(0,A.jsxs)(w,{flexDirection:"column",borderStyle:"round",padding:1,borderColor:ne().secondaryBorder,children:[(0,A.jsx)(w,{marginBottom:1,flexDirection:"column",children:(0,A.jsx)(v,{bold:!0,children:"You've spent $5 this session."})}),(0,A.jsx)(w,{children:(0,A.jsx)(QS,{options:[{value:"ok",label:"Got it, thanks!"}],onChange:e})})]})}var vr=Ce(He(),1);Fe();ur();r_();var c7r="2.9.6",US={VERSION:c7r,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 GEe=46,hat=["(\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 pK({isDefaultModel:e=!1}){let t=Math.max(GEe,Ne().length+12),r=ne(),n=hat[Math.floor(Math.random()*hat.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)(v,{children:[(0,A.jsx)(v,{children:n})," Welcome to"," ",(0,A.jsx)(v,{bold:!0,children:nt}),(0,A.jsxs)(v,{color:r.secondaryText,children:[" v",US.VERSION]})]}),(0,A.jsx)(A.Fragment,{children:(0,A.jsxs)(w,{paddingLeft:2,flexDirection:"column",gap:1,children:[(0,A.jsx)(v,{color:r.secondaryText,italic:!0,children:"/help for help"}),(0,A.jsxs)(v,{color:r.secondaryText,children:["cwd: ",Ne()]}),(0,A.jsxs)(v,{color:r.secondaryText,children:["model: ",Wn.getConfig().routing.MODEL?.map(i=>`${i.source}__${i.model}`).join(", ")??"N/A"]}),(0,A.jsxs)(v,{color:r.secondaryText,children:["small fast model: ",Wn.getConfig().routing.SMALL_FAST_MODEL?.map(i=>`${i.source}__${i.model}`).join(", ")??"N/A"]})]})})]})})}be();Oo();be();cr();ur();be();Fe();import{existsSync as $S,readdirSync as FZr,statSync as QZr}from"fs";import{join as gC,relative as UZr}from"path";import{homedir as cut}from"os";import{platform as GZr}from"process";import{readFile as hC}from"fs/promises";ur();Zd();Jt();import{join as g7r,sep as h7r}from"path";function Xu(){if(!vc())return!1;try{let e=ze();if(e.autoMemory?.teamMemoryEnabled!==void 0)return e.autoMemory.teamMemoryEnabled}catch{}return!1}function _u(){return(g7r(Ne(),".hcode","team-memory")+h7r).normalize("NFC")}function Xd(e){let t=e.normalize("NFC"),r=_u();return t.startsWith(r)}Zd();var uut=Ce(BB(),1);li();var oSe=(e,t,r)=>{let n=e instanceof RegExp?Pct(e,r):e,i=t instanceof RegExp?Pct(t,r):t,o=n!==null&&i!=null&&wJr(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)}},Pct=(e,t)=>{let r=t.match(e);return r?r[0]:null},wJr=(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 Fct="\0SLASH"+Math.random()+"\0",Qct="\0OPEN"+Math.random()+"\0",lSe="\0CLOSE"+Math.random()+"\0",Uct="\0COMMA"+Math.random()+"\0",Gct="\0PERIOD"+Math.random()+"\0",RJr=new RegExp(Fct,"g"),NJr=new RegExp(Qct,"g"),DJr=new RegExp(lSe,"g"),OJr=new RegExp(Uct,"g"),BJr=new RegExp(Gct,"g"),MJr=/\\\\/g,kJr=/\\{/g,LJr=/\\}/g,PJr=/\\,/g,FJr=/\\\./g,QJr=1e5,UJr=4e6;function sSe(e){return isNaN(e)?e.charCodeAt(0):parseInt(e,10)}function GJr(e){return e.replace(MJr,Fct).replace(kJr,Qct).replace(LJr,lSe).replace(PJr,Uct).replace(FJr,Gct)}function HJr(e){return e.replace(RJr,"\\").replace(NJr,"{").replace(DJr,"}").replace(OJr,",").replace(BJr,".")}function Hct(e){if(!e)return[""];let t=[],r=oSe("{","}",e);if(!r)return e.split(",");let{pre:n,body:i,post:o}=r,s=n.split(",");s[s.length-1]+="{"+i+"}";let a=Hct(o);return o.length&&(s[s.length-1]+=a.shift(),s.push.apply(s,a)),t.push.apply(t,s),t}function $ct(e,t={}){if(!e)return[];let{max:r=QJr,maxLength:n=UJr}=t;return e.slice(0,2)==="{}"&&(e="\\{\\}"+e.slice(2)),aSe(GJr(e),r,n,!0).map(HJr)}function $Jr(e){return"{"+e+"}"}function qJr(e){return/^-?0\d/.test(e)}function YJr(e,t){return e<=t}function zJr(e,t){return e>=t}function KU(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 VJr(e,t,r,n){let i=e.split(/\.\./),o=[];if(i[0]===void 0||i[1]===void 0)return o;let s=sSe(i[0]),a=sSe(i[1]),l=Math.max(i[0].length,i[1].length),c=i.length===3&&i[2]!==void 0?Math.max(Math.abs(sSe(i[2])),1):1,u=YJr;a<s&&(c*=-1,u=zJr);let f=i.some(qJr),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 aSe(e,t,r,n){let i=[""],o=!1,s=!0;for(;;){let a=oSe("{","}",e);if(!a)return KU(i,e,[""],t,r,o);let l=a.pre;if(/\$$/.test(l)){if(i=KU(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+lSe+a.post,n=!0;continue}return KU(i,l+"{"+a.body+"}"+a.post,[""],t,r,o)}s&&(o=n&&!d,s=!1);let p;if(d)p=VJr(a.body,u,t,r);else{let h=Hct(a.body);if(h.length===1&&h[0]!==void 0&&(h=aSe(h[0],t,r,!1).map($Jr),h.length===1)){if(i=KU(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=aSe(h[b],t,r,!1);for(let I=0;I<C.length;I++){let R=C[I];if(!(_&&!R)){if(p.length>=t||E+R.length>r)break e;p.push(R),E+=R.length}}}}if(i=KU(i,l,p,t,r,o&&!a.post.length),!a.post.length)break;e=a.post}return i}var JU=e=>{if(typeof e!="string")throw new TypeError("invalid pattern");if(e.length>65536)throw new TypeError("pattern is too long")};var WJr={"[: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]},ZU=e=>e.replace(/[[\]\\-]/g,"\\$&"),jJr=e=>e.replace(/[-[\]{}()*+?.,\\^$|#\s]/g,"\\$&"),qct=e=>e.join(""),Yct=(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,I]]of Object.entries(WJr))if(e.startsWith(E,o)){if(d)return["$.",!1,e.length-r,!0];o+=E.length,I?i.push(b):n.push(b),a=a||C;continue e}}if(l=!1,d){_>d?n.push(ZU(d)+"-"+ZU(_)):_===d&&n.push(ZU(_)),d="",o++;continue}if(e.startsWith("-]",o+1)){n.push(ZU(_+"-")),o+=2;continue}if(e.startsWith("-",o+1)){d=_,o+=2;continue}n.push(ZU(_)),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[jJr(_),!1,u-r,!1]}let f="["+(c?"^":"")+qct(n)+"]",p="["+(c?"":"^")+qct(i)+"]";return[n.length&&i.length?"("+f+"|"+p+")":n.length?f:p,a,u-r,!0]};var fC=(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 tp,KJr=new Set(["!","?","+","*","@"]),cSe=e=>KJr.has(e),zct=e=>cSe(e.type),JJr=new Map([["!",["@"]],["?",["?","@"]],["@",["@"]],["*",["*","+","?","@"]],["+",["+","@"]]]),ZJr=new Map([["!",["?"]],["@",["?"]],["+",["?","*"]]]),XJr=new Map([["!",["?","@"]],["?",["?","@"]],["@",["?","@"]],["*",["*","+","?","@"]],["+",["+","@","?","*"]]]),Vct=new Map([["!",new Map([["!","@"]])],["?",new Map([["*","*"],["+","*"]])],["@",new Map([["!","!"],["?","?"],["@","@"],["*","*"],["+","+"]])],["+",new Map([["?","*"],["*","*"]])]]),eZr="(?!(?:^|/)\\.\\.?(?:$|/))",TK="(?!\\.)",tZr=new Set(["[","."]),rZr=new Set(["..","."]),nZr=new Set("().*{}+?[]^$\\!"),iZr=e=>e.replace(/[-[\]{}()*+?.,\\^$|#\s]/g,"\\$&"),uSe="[^/]",Wct=uSe+"*?",jct=uSe+"+?",oZr=0,W1=class{type;#e;#t;#n=!1;#r=[];#o;#i;#l;#s=!1;#a;#d;#m=!1;id=++oZr;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 tp&&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 tp&&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 tp(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&&cSe(b)&&t.charAt(_)==="("&&o<=s){r.push(E),E="";let I=new tp(b,r);_=tp.#c(t,I,_,i,o+1),r.push(I);continue}E+=b}return r.push(E),_}let d=n+1,f=new tp(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&&cSe(_)&&t.charAt(d)==="("&&(o<=s||r&&r.#_(_))){let b=r&&r.#_(_)?0:1;f.push(h),h="";let C=new tp(_,f);f.push(C),d=tp.#c(t,C,d,i,o+b);continue}if(_==="|"){f.push(h),h="",p.push(f),f=new tp(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,ZJr)}#A(t,r=JJr){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=XJr){return!!r.get(this.type)?.includes(t)}#h(t,r){let n=t.#r[0],i=new tp(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!!Vct.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=Vct.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 tp(null,void 0,r);return tp.#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()),!zct(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"?tp.#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&&rZr.has(this.#r[0]))){let h=tZr,_=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=_?eZr:E?TK:""}let d="";return this.isEnd()&&this.#e.#s&&this.#o?.type==="!"&&(d="(?:$|\\/)"),[u+c+d,fC(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,fC(this.toString()),!1,!1]}let s=!n||t||r||!TK?"":this.#b(!0);s===o&&(s=""),s&&(o=`(?:${o})(?:${s})*?`);let a="";if(this.type==="!"&&this.#m)a=(this.isStart()&&!r?TK:"")+jct;else{let l=this.type==="!"?"))"+(this.isStart()&&!r&&!t?TK:"")+Wct+")":this.type==="@"?")":this.type==="?"?")?":this.type==="+"&&s?")":this.type==="*"&&s?")?":`)${this.type}`;a=i+o+l}return[a,fC(o),this.#t=!!this.#t,this.#n]}#E(){if(zct(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+=(nZr.has(c)?"\\":"")+c;continue}if(c==="*"){if(a)continue;a=!0,o+=n&&/^[*]+$/.test(t)?jct:Wct,r=!0;continue}else a=!1;if(c==="\\"){l===t.length-1?o+="\\\\":i=!0;continue}if(c==="["){let[u,d,f,p]=Yct(t,l);if(f){o+=u,s=s||d,l+=f-1,r=r||p;continue}}if(c==="?"){o+=uSe,r=!0;continue}o+=iZr(c)}return[o,fC(t),!!r,s]}};tp=W1;var dSe=(e,{windowsPathsNoEscape:t=!1,magicalBraces:r=!1}={})=>r?t?e.replace(/[?*()[\]{}]/g,"[$&]"):e.replace(/[?*()[\]\\{}]/g,"\\$&"):t?e.replace(/[?*()[\]]/g,"[$&]"):e.replace(/[?*()[\]\\]/g,"\\$&");var xc=(e,t,r={})=>(JU(t),!r.nocomment&&t.charAt(0)==="#"?!1:new MB(t,r).match(e)),sZr=/^\*+([^+@!?*[(]*)$/,aZr=e=>t=>!t.startsWith(".")&&t.endsWith(e),lZr=e=>t=>t.endsWith(e),cZr=e=>(e=e.toLowerCase(),t=>!t.startsWith(".")&&t.toLowerCase().endsWith(e)),uZr=e=>(e=e.toLowerCase(),t=>t.toLowerCase().endsWith(e)),dZr=/^\*+\.\*+$/,pZr=e=>!e.startsWith(".")&&e.includes("."),mZr=e=>e!=="."&&e!==".."&&e.includes("."),fZr=/^\.\*+$/,gZr=e=>e!=="."&&e!==".."&&e.startsWith("."),hZr=/^\*+$/,AZr=e=>e.length!==0&&!e.startsWith("."),_Zr=e=>e.length!==0&&e!=="."&&e!=="..",EZr=/^\?+([^+@!?*[(]*)?$/,SZr=([e,t=""])=>{let r=Zct([e]);return t?(t=t.toLowerCase(),n=>r(n)&&n.toLowerCase().endsWith(t)):r},bZr=([e,t=""])=>{let r=Xct([e]);return t?(t=t.toLowerCase(),n=>r(n)&&n.toLowerCase().endsWith(t)):r},yZr=([e,t=""])=>{let r=Xct([e]);return t?n=>r(n)&&n.endsWith(t):r},CZr=([e,t=""])=>{let r=Zct([e]);return t?n=>r(n)&&n.endsWith(t):r},Zct=([e])=>{let t=e.length;return r=>r.length===t&&!r.startsWith(".")},Xct=([e])=>{let t=e.length;return r=>r.length===t&&r!=="."&&r!==".."},eut=typeof process=="object"&&process?typeof process.env=="object"&&process.env&&process.env.__MINIMATCH_TESTING_PLATFORM__||process.platform:"posix",Kct={win32:{sep:"\\"},posix:{sep:"/"}},TZr=eut==="win32"?Kct.win32.sep:Kct.posix.sep;xc.sep=TZr;var Su=Symbol("globstar **");xc.GLOBSTAR=Su;var IZr="[^/]",vZr=IZr+"*?",xZr="(?:(?!(?:\\/|^)(?:\\.{1,2})($|\\/)).)*?",wZr="(?:(?!(?:\\/|^)\\.).)*?",RZr=(e,t={})=>r=>xc(r,e,t);xc.filter=RZr;var Uf=(e,t={})=>Object.assign({},e,t),NZr=e=>{if(!e||typeof e!="object"||!Object.keys(e).length)return xc;let t=xc;return Object.assign((n,i,o={})=>t(n,i,Uf(e,o)),{Minimatch:class extends t.Minimatch{constructor(i,o={}){super(i,Uf(e,o))}static defaults(i){return t.defaults(Uf(e,i)).Minimatch}},AST:class extends t.AST{constructor(i,o,s={}){super(i,o,Uf(e,s))}static fromGlob(i,o={}){return t.AST.fromGlob(i,Uf(e,o))}},unescape:(n,i={})=>t.unescape(n,Uf(e,i)),escape:(n,i={})=>t.escape(n,Uf(e,i)),filter:(n,i={})=>t.filter(n,Uf(e,i)),defaults:n=>t.defaults(Uf(e,n)),makeRe:(n,i={})=>t.makeRe(n,Uf(e,i)),braceExpand:(n,i={})=>t.braceExpand(n,Uf(e,i)),match:(n,i,o={})=>t.match(n,i,Uf(e,o)),sep:t.sep,GLOBSTAR:Su})};xc.defaults=NZr;var tut=(e,t={})=>(JU(e),t.nobrace||!/\{(?:(?!\{).)*\}/.test(e)?[e]:$ct(e,{max:t.braceExpandMax}));xc.braceExpand=tut;var DZr=(e,t={})=>new MB(e,t).makeRe();xc.makeRe=DZr;var OZr=(e,t,r={})=>{let n=new MB(t,r);return e=e.filter(i=>n.match(i)),n.options.nonull&&!e.length&&e.push(t),e};xc.match=OZr;var Jct=/[?*]|[+@!]\(.*?\)|\[|\]/,BZr=e=>e.replace(/[-[\]{}()*+?.,\\^$|#\s]/g,"\\$&"),MB=class{options;set;pattern;windowsPathsNoEscape;nonegate;negate;comment;empty;preserveMultipleSlashes;partial;globSet;globParts;nocase;isWindows;platform;windowsNoMagicRoot;maxGlobstarRecursion;regexp;constructor(t,r={}){JU(t),r=r||{},this.options=r,this.maxGlobstarRecursion=r.maxGlobstarRecursion??200,this.pattern=t,this.platform=r.platform||eut,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]==="?"||!Jct.test(o[2]))&&!Jct.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(Su)?this.#e(t,r,n,i,o):this.#n(t,r,n,i,o)}#e(t,r,n,i,o){let s=r.indexOf(Su,o),a=r.lastIndexOf(Su),[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 I=i;I<t.length-d;I++){let R=String(t[I]);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===Su?(_.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===Su)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 tut(this.pattern,this.options)}parse(t){JU(t);let r=this.options;if(t==="**")return Su;if(t==="")return"";let n,i=null;(n=t.match(hZr))?i=r.dot?_Zr:AZr:(n=t.match(sZr))?i=(r.nocase?r.dot?uZr:cZr:r.dot?lZr:aZr)(n[1]):(n=t.match(EZr))?i=(r.nocase?r.dot?bZr:SZr:r.dot?yZr:CZr)(n):(n=t.match(dZr))?i=r.dot?mZr:pZr:(n=t.match(fZr))&&(i=gZr);let o=W1.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?vZr:r.dot?xZr:wZr,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"?BZr(d):d===Su?Su:d._src});c.forEach((d,f)=>{let p=c[f+1],h=c[f-1];d!==Su||h===Su||(h===void 0?p!==void 0&&p!==Su?c[f+1]="(?:\\/|"+n+"\\/)?"+p:c[f]=n:p===void 0?c[f-1]=h+"(?:\\/|\\/"+n+")?":p!==Su&&(c[f-1]=h+"(?:\\/|\\/"+n+"\\/)"+p,c[f+1]=Su))});let u=c.filter(d=>d!==Su);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 xc.defaults(t).Minimatch}};xc.AST=W1;xc.Minimatch=MB;xc.escape=dSe;xc.unescape=fC;var iut=Ce(BB(),1);ur();Fe();be();ju();import{readFile as rut}from"fs/promises";import{existsSync as pSe,readdirSync as MZr,statSync as kZr}from"fs";import{join as mSe,relative as out}from"path";import{homedir as LZr}from"os";function nut(e){try{let t=(0,iut.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 me(t),{paths:[],content:e.trim()}}}function PZr(e,t){return t.length===0?!0:t.some(r=>{try{return xc(e,r,{matchBase:!0,dot:!0})}catch(n){return me(n),!1}})}function fSe(e){let t=[];try{if(!pSe(e))return t;let r=MZr(e);for(let n of r){let i=mSe(e,n),o=kZr(i);o.isDirectory()?t.push(...fSe(i)):o.isFile()&&n.endsWith(".md")&&t.push(i)}}catch(r){me(r)}return t}async function IK(){let e=[];try{let t=mSe(LZr(),yn,"rules");if(pSe(t)){let r=fSe(t);for(let n of r)try{let i=await rut(n,"utf-8"),{paths:o,content:s}=nut(i);o.length>0&&e.push({filePath:n,content:s,paths:o,isProjectRule:!1})}catch(i){me(i)}}}catch(t){me(t)}try{let t=mSe(Ne(),yn,"rules");if(pSe(t)){let r=fSe(t);for(let n of r)try{let i=await rut(n,"utf-8"),{paths:o,content:s}=nut(i);o.length>0&&e.push({filePath:out(Ne(),n),content:s,paths:o,isProjectRule:!0})}catch(i){me(i)}}}catch(t){me(t)}return e}function sut(e,t){e=oj(e);let r=oj(Ne()),n=e.startsWith(r)?out(r,e):e;return t.filter(i=>PZr(n,i.paths))}function aut(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}):
754
+ `)}function dat(e){try{let t=jWr(e),r=t.readSync();return t.closeSync(),r===null}catch(t){return me(`Error checking directory: ${t}`),!1}}Fe();function sC(){let e=Rn();e.hasCompletedProjectOnboarding||Xi({...e,hasCompletedProjectOnboarding:!0})}function BEe({workspaceDir:e}){let r=!Rn().hasCompletedProjectOnboarding;if(!r)return null;let n=r7r(n7r(e,Hi)),i=dat(e),o=!n&&!i,s=gB.isEnabled&&!zr().shiftEnterKeyBindingInstalled,a=ne();return(0,A.jsxs)(w,{flexDirection:"column",gap:1,padding:1,paddingBottom:0,children:[r&&(0,A.jsxs)(A.Fragment,{children:[(0,A.jsx)(v,{color:a.secondaryText,children:"Tips for getting started:"}),(0,A.jsx)(Ic,{children:(()=>{let l=[];return i&&l.push((0,A.jsx)(Ic.Item,{children:(0,A.jsxs)(v,{color:a.secondaryText,children:["Ask ",nt," to create a new app or clone a repository."]})},"workspace")),o&&l.push((0,A.jsx)(Ic.Item,{children:(0,A.jsxs)(v,{color:a.secondaryText,children:["Run ",(0,A.jsx)(v,{color:a.text,children:"/init"})," to create a",Hi," file with instructions for Hawa code."]})},"claudemd")),s&&l.push((0,A.jsx)(Ic.Item,{children:(0,A.jsxs)(v,{color:a.secondaryText,children:["Run ",(0,A.jsx)(v,{color:a.text,children:"/terminal-setup"}),(0,A.jsx)(v,{bold:!1,children:" to set up terminal integration"})]})},"terminal")),l.push((0,A.jsx)(Ic.Item,{children:(0,A.jsxs)(v,{color:a.secondaryText,children:["Ask ",nt," questions about your codebase."]})},"questions")),l.push((0,A.jsx)(Ic.Item,{children:(0,A.jsxs)(v,{color:a.secondaryText,children:["Ask ",nt," to implement changes to your codebase."]})},"changes")),l})()})]}),e===i7r()&&(0,A.jsxs)(v,{color:ne().warning,children:["Note: You have launched ",(0,A.jsx)(v,{bold:!0,children:nt})," in your home directory. For the best experience, launch it in a project directory instead."]})]})}function MEe({isFocused:e,isSelected:t,smallPointer:r,children:n}){let{styles:i}=yo("Select");return(0,A.jsxs)(w,{...i.option({isFocused:e}),children:[e&&(0,A.jsx)(v,{...i.focusIndicator(),children:r?nr.triangleDownSmall:nr.pointer}),(0,A.jsx)(v,{...i.label({isFocused:e,isSelected:t}),children:n}),t&&(0,A.jsx)(v,{...i.selectedIndicator(),children:nr.tick})]})}var Kd=Ce(He(),1);import{isDeepStrictEqual as o7r}from"node:util";var GU=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:kEe(s);r.push([l,a]),o++,i=a}super(r),this.first=n}};var s7r=(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}}},LEe=e=>e.flatMap(t=>{if("options"in t){let r=LEe(t.options),n=r.flatMap(o=>"value"in o?o.value:[]);return[...t.header!==void 0?[{header:t.header,optionValues:n}]:[],...r]}return t}),pat=({visibleOptionCount:e,defaultValue:t,options:r})=>{let n=LEe(r),i=typeof e=="number"?Math.min(e,n.length):n.length,o=new GU(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}},PEe=({visibleOptionCount:e=5,options:t,defaultValue:r,onChange:n,onFocus:i,focusValue:o})=>{let s=LEe(t),[a,l]=(0,Kd.useReducer)(s7r,{visibleOptionCount:e,defaultValue:r,options:t},pat),[c,u]=(0,Kd.useState)(s);s!==c&&!o7r(s,c)&&(l({type:"reset",state:pat({visibleOptionCount:e,defaultValue:r,options:t})}),u(s));let d=(0,Kd.useCallback)(()=>{l({type:"focus-next-option"})},[]),f=(0,Kd.useCallback)(()=>{l({type:"focus-previous-option"})},[]),p=(0,Kd.useCallback)(()=>{l({type:"select-focused-option"})},[]),h=(0,Kd.useMemo)(()=>s.map((_,E)=>({..._,index:E})).slice(a.visibleFromIndex,a.visibleToIndex),[s,a.visibleFromIndex,a.visibleToIndex]);return(0,Kd.useEffect)(()=>{a.value&&a.previousValue!==a.value&&n?.(a.value)},[a.previousValue,a.value,t,n]),(0,Kd.useEffect)(()=>{a.focusedValue&&i?.(a.focusedValue)},[a.focusedValue,i]),(0,Kd.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 FEe=({isDisabled:e=!1,state:t})=>{Et((r,n)=>{n.downArrow&&t.focusNextOption(),n.upArrow&&t.focusPreviousOption(),n.return&&t.selectFocusedOption()},{isActive:!e})};var kEe=e=>`HEADER-${e.optionValues.join(",")}`;function QS({isDisabled:e=!1,visibleOptionCount:t=5,highlightText:r,options:n,defaultValue:i,onChange:o,onFocus:s,focusValue:a}){let l=PEe({visibleOptionCount:t,options:n,defaultValue:i,onChange:o,onFocus:s,focusValue:a});FEe({isDisabled:e,state:l});let{styles:c}=yo("Select");return(0,A.jsx)(w,{...c.container(),children:l.visibleOptions.map(u=>{let d="value"in u?u.value:kEe(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)(v,{...c.highlightedText(),children:r}),_.slice(b+r.length)]})}return(0,A.jsx)(MEe,{isFocused:f,isSelected:p,smallPointer:h,children:E},d)})})}function mat({onDone:e}){return Et((t,r)=>{(r.ctrl&&(t==="c"||t==="d")||r.escape)&&e()}),(0,A.jsxs)(w,{flexDirection:"column",borderStyle:"round",padding:1,borderColor:ne().secondaryBorder,children:[(0,A.jsx)(w,{marginBottom:1,flexDirection:"column",children:(0,A.jsx)(v,{bold:!0,children:"You've spent $5 this session."})}),(0,A.jsx)(w,{children:(0,A.jsx)(QS,{options:[{value:"ok",label:"Got it, thanks!"}],onChange:e})})]})}var vr=Ce(He(),1);Fe();ur();r_();var c7r="2.9.8",US={VERSION:c7r,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 GEe=46,hat=["(\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 pK({isDefaultModel:e=!1}){let t=Math.max(GEe,Ne().length+12),r=ne(),n=hat[Math.floor(Math.random()*hat.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)(v,{children:[(0,A.jsx)(v,{children:n})," Welcome to"," ",(0,A.jsx)(v,{bold:!0,children:nt}),(0,A.jsxs)(v,{color:r.secondaryText,children:[" v",US.VERSION]})]}),(0,A.jsx)(A.Fragment,{children:(0,A.jsxs)(w,{paddingLeft:2,flexDirection:"column",gap:1,children:[(0,A.jsx)(v,{color:r.secondaryText,italic:!0,children:"/help for help"}),(0,A.jsxs)(v,{color:r.secondaryText,children:["cwd: ",Ne()]}),(0,A.jsxs)(v,{color:r.secondaryText,children:["model: ",Wn.getConfig().routing.MODEL?.map(i=>`${i.source}__${i.model}`).join(", ")??"N/A"]}),(0,A.jsxs)(v,{color:r.secondaryText,children:["small fast model: ",Wn.getConfig().routing.SMALL_FAST_MODEL?.map(i=>`${i.source}__${i.model}`).join(", ")??"N/A"]})]})})]})})}be();Oo();be();cr();ur();be();Fe();import{existsSync as $S,readdirSync as FZr,statSync as QZr}from"fs";import{join as gC,relative as UZr}from"path";import{homedir as cut}from"os";import{platform as GZr}from"process";import{readFile as hC}from"fs/promises";ur();Zd();Jt();import{join as g7r,sep as h7r}from"path";function Xu(){if(!vc())return!1;try{let e=ze();if(e.autoMemory?.teamMemoryEnabled!==void 0)return e.autoMemory.teamMemoryEnabled}catch{}return!1}function _u(){return(g7r(Ne(),".hcode","team-memory")+h7r).normalize("NFC")}function Xd(e){let t=e.normalize("NFC"),r=_u();return t.startsWith(r)}Zd();var uut=Ce(BB(),1);li();var oSe=(e,t,r)=>{let n=e instanceof RegExp?Pct(e,r):e,i=t instanceof RegExp?Pct(t,r):t,o=n!==null&&i!=null&&wJr(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)}},Pct=(e,t)=>{let r=t.match(e);return r?r[0]:null},wJr=(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 Fct="\0SLASH"+Math.random()+"\0",Qct="\0OPEN"+Math.random()+"\0",lSe="\0CLOSE"+Math.random()+"\0",Uct="\0COMMA"+Math.random()+"\0",Gct="\0PERIOD"+Math.random()+"\0",RJr=new RegExp(Fct,"g"),NJr=new RegExp(Qct,"g"),DJr=new RegExp(lSe,"g"),OJr=new RegExp(Uct,"g"),BJr=new RegExp(Gct,"g"),MJr=/\\\\/g,kJr=/\\{/g,LJr=/\\}/g,PJr=/\\,/g,FJr=/\\\./g,QJr=1e5,UJr=4e6;function sSe(e){return isNaN(e)?e.charCodeAt(0):parseInt(e,10)}function GJr(e){return e.replace(MJr,Fct).replace(kJr,Qct).replace(LJr,lSe).replace(PJr,Uct).replace(FJr,Gct)}function HJr(e){return e.replace(RJr,"\\").replace(NJr,"{").replace(DJr,"}").replace(OJr,",").replace(BJr,".")}function Hct(e){if(!e)return[""];let t=[],r=oSe("{","}",e);if(!r)return e.split(",");let{pre:n,body:i,post:o}=r,s=n.split(",");s[s.length-1]+="{"+i+"}";let a=Hct(o);return o.length&&(s[s.length-1]+=a.shift(),s.push.apply(s,a)),t.push.apply(t,s),t}function $ct(e,t={}){if(!e)return[];let{max:r=QJr,maxLength:n=UJr}=t;return e.slice(0,2)==="{}"&&(e="\\{\\}"+e.slice(2)),aSe(GJr(e),r,n,!0).map(HJr)}function $Jr(e){return"{"+e+"}"}function qJr(e){return/^-?0\d/.test(e)}function YJr(e,t){return e<=t}function zJr(e,t){return e>=t}function KU(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 VJr(e,t,r,n){let i=e.split(/\.\./),o=[];if(i[0]===void 0||i[1]===void 0)return o;let s=sSe(i[0]),a=sSe(i[1]),l=Math.max(i[0].length,i[1].length),c=i.length===3&&i[2]!==void 0?Math.max(Math.abs(sSe(i[2])),1):1,u=YJr;a<s&&(c*=-1,u=zJr);let f=i.some(qJr),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 aSe(e,t,r,n){let i=[""],o=!1,s=!0;for(;;){let a=oSe("{","}",e);if(!a)return KU(i,e,[""],t,r,o);let l=a.pre;if(/\$$/.test(l)){if(i=KU(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+lSe+a.post,n=!0;continue}return KU(i,l+"{"+a.body+"}"+a.post,[""],t,r,o)}s&&(o=n&&!d,s=!1);let p;if(d)p=VJr(a.body,u,t,r);else{let h=Hct(a.body);if(h.length===1&&h[0]!==void 0&&(h=aSe(h[0],t,r,!1).map($Jr),h.length===1)){if(i=KU(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=aSe(h[b],t,r,!1);for(let I=0;I<C.length;I++){let R=C[I];if(!(_&&!R)){if(p.length>=t||E+R.length>r)break e;p.push(R),E+=R.length}}}}if(i=KU(i,l,p,t,r,o&&!a.post.length),!a.post.length)break;e=a.post}return i}var JU=e=>{if(typeof e!="string")throw new TypeError("invalid pattern");if(e.length>65536)throw new TypeError("pattern is too long")};var WJr={"[: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]},ZU=e=>e.replace(/[[\]\\-]/g,"\\$&"),jJr=e=>e.replace(/[-[\]{}()*+?.,\\^$|#\s]/g,"\\$&"),qct=e=>e.join(""),Yct=(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,I]]of Object.entries(WJr))if(e.startsWith(E,o)){if(d)return["$.",!1,e.length-r,!0];o+=E.length,I?i.push(b):n.push(b),a=a||C;continue e}}if(l=!1,d){_>d?n.push(ZU(d)+"-"+ZU(_)):_===d&&n.push(ZU(_)),d="",o++;continue}if(e.startsWith("-]",o+1)){n.push(ZU(_+"-")),o+=2;continue}if(e.startsWith("-",o+1)){d=_,o+=2;continue}n.push(ZU(_)),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[jJr(_),!1,u-r,!1]}let f="["+(c?"^":"")+qct(n)+"]",p="["+(c?"":"^")+qct(i)+"]";return[n.length&&i.length?"("+f+"|"+p+")":n.length?f:p,a,u-r,!0]};var fC=(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 tp,KJr=new Set(["!","?","+","*","@"]),cSe=e=>KJr.has(e),zct=e=>cSe(e.type),JJr=new Map([["!",["@"]],["?",["?","@"]],["@",["@"]],["*",["*","+","?","@"]],["+",["+","@"]]]),ZJr=new Map([["!",["?"]],["@",["?"]],["+",["?","*"]]]),XJr=new Map([["!",["?","@"]],["?",["?","@"]],["@",["?","@"]],["*",["*","+","?","@"]],["+",["+","@","?","*"]]]),Vct=new Map([["!",new Map([["!","@"]])],["?",new Map([["*","*"],["+","*"]])],["@",new Map([["!","!"],["?","?"],["@","@"],["*","*"],["+","+"]])],["+",new Map([["?","*"],["*","*"]])]]),eZr="(?!(?:^|/)\\.\\.?(?:$|/))",TK="(?!\\.)",tZr=new Set(["[","."]),rZr=new Set(["..","."]),nZr=new Set("().*{}+?[]^$\\!"),iZr=e=>e.replace(/[-[\]{}()*+?.,\\^$|#\s]/g,"\\$&"),uSe="[^/]",Wct=uSe+"*?",jct=uSe+"+?",oZr=0,W1=class{type;#e;#t;#n=!1;#r=[];#o;#i;#l;#s=!1;#a;#d;#m=!1;id=++oZr;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 tp&&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 tp&&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 tp(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&&cSe(b)&&t.charAt(_)==="("&&o<=s){r.push(E),E="";let I=new tp(b,r);_=tp.#c(t,I,_,i,o+1),r.push(I);continue}E+=b}return r.push(E),_}let d=n+1,f=new tp(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&&cSe(_)&&t.charAt(d)==="("&&(o<=s||r&&r.#_(_))){let b=r&&r.#_(_)?0:1;f.push(h),h="";let C=new tp(_,f);f.push(C),d=tp.#c(t,C,d,i,o+b);continue}if(_==="|"){f.push(h),h="",p.push(f),f=new tp(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,ZJr)}#A(t,r=JJr){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=XJr){return!!r.get(this.type)?.includes(t)}#h(t,r){let n=t.#r[0],i=new tp(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!!Vct.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=Vct.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 tp(null,void 0,r);return tp.#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()),!zct(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"?tp.#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&&rZr.has(this.#r[0]))){let h=tZr,_=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=_?eZr:E?TK:""}let d="";return this.isEnd()&&this.#e.#s&&this.#o?.type==="!"&&(d="(?:$|\\/)"),[u+c+d,fC(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,fC(this.toString()),!1,!1]}let s=!n||t||r||!TK?"":this.#b(!0);s===o&&(s=""),s&&(o=`(?:${o})(?:${s})*?`);let a="";if(this.type==="!"&&this.#m)a=(this.isStart()&&!r?TK:"")+jct;else{let l=this.type==="!"?"))"+(this.isStart()&&!r&&!t?TK:"")+Wct+")":this.type==="@"?")":this.type==="?"?")?":this.type==="+"&&s?")":this.type==="*"&&s?")?":`)${this.type}`;a=i+o+l}return[a,fC(o),this.#t=!!this.#t,this.#n]}#E(){if(zct(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+=(nZr.has(c)?"\\":"")+c;continue}if(c==="*"){if(a)continue;a=!0,o+=n&&/^[*]+$/.test(t)?jct:Wct,r=!0;continue}else a=!1;if(c==="\\"){l===t.length-1?o+="\\\\":i=!0;continue}if(c==="["){let[u,d,f,p]=Yct(t,l);if(f){o+=u,s=s||d,l+=f-1,r=r||p;continue}}if(c==="?"){o+=uSe,r=!0;continue}o+=iZr(c)}return[o,fC(t),!!r,s]}};tp=W1;var dSe=(e,{windowsPathsNoEscape:t=!1,magicalBraces:r=!1}={})=>r?t?e.replace(/[?*()[\]{}]/g,"[$&]"):e.replace(/[?*()[\]\\{}]/g,"\\$&"):t?e.replace(/[?*()[\]]/g,"[$&]"):e.replace(/[?*()[\]\\]/g,"\\$&");var xc=(e,t,r={})=>(JU(t),!r.nocomment&&t.charAt(0)==="#"?!1:new MB(t,r).match(e)),sZr=/^\*+([^+@!?*[(]*)$/,aZr=e=>t=>!t.startsWith(".")&&t.endsWith(e),lZr=e=>t=>t.endsWith(e),cZr=e=>(e=e.toLowerCase(),t=>!t.startsWith(".")&&t.toLowerCase().endsWith(e)),uZr=e=>(e=e.toLowerCase(),t=>t.toLowerCase().endsWith(e)),dZr=/^\*+\.\*+$/,pZr=e=>!e.startsWith(".")&&e.includes("."),mZr=e=>e!=="."&&e!==".."&&e.includes("."),fZr=/^\.\*+$/,gZr=e=>e!=="."&&e!==".."&&e.startsWith("."),hZr=/^\*+$/,AZr=e=>e.length!==0&&!e.startsWith("."),_Zr=e=>e.length!==0&&e!=="."&&e!=="..",EZr=/^\?+([^+@!?*[(]*)?$/,SZr=([e,t=""])=>{let r=Zct([e]);return t?(t=t.toLowerCase(),n=>r(n)&&n.toLowerCase().endsWith(t)):r},bZr=([e,t=""])=>{let r=Xct([e]);return t?(t=t.toLowerCase(),n=>r(n)&&n.toLowerCase().endsWith(t)):r},yZr=([e,t=""])=>{let r=Xct([e]);return t?n=>r(n)&&n.endsWith(t):r},CZr=([e,t=""])=>{let r=Zct([e]);return t?n=>r(n)&&n.endsWith(t):r},Zct=([e])=>{let t=e.length;return r=>r.length===t&&!r.startsWith(".")},Xct=([e])=>{let t=e.length;return r=>r.length===t&&r!=="."&&r!==".."},eut=typeof process=="object"&&process?typeof process.env=="object"&&process.env&&process.env.__MINIMATCH_TESTING_PLATFORM__||process.platform:"posix",Kct={win32:{sep:"\\"},posix:{sep:"/"}},TZr=eut==="win32"?Kct.win32.sep:Kct.posix.sep;xc.sep=TZr;var Su=Symbol("globstar **");xc.GLOBSTAR=Su;var IZr="[^/]",vZr=IZr+"*?",xZr="(?:(?!(?:\\/|^)(?:\\.{1,2})($|\\/)).)*?",wZr="(?:(?!(?:\\/|^)\\.).)*?",RZr=(e,t={})=>r=>xc(r,e,t);xc.filter=RZr;var Uf=(e,t={})=>Object.assign({},e,t),NZr=e=>{if(!e||typeof e!="object"||!Object.keys(e).length)return xc;let t=xc;return Object.assign((n,i,o={})=>t(n,i,Uf(e,o)),{Minimatch:class extends t.Minimatch{constructor(i,o={}){super(i,Uf(e,o))}static defaults(i){return t.defaults(Uf(e,i)).Minimatch}},AST:class extends t.AST{constructor(i,o,s={}){super(i,o,Uf(e,s))}static fromGlob(i,o={}){return t.AST.fromGlob(i,Uf(e,o))}},unescape:(n,i={})=>t.unescape(n,Uf(e,i)),escape:(n,i={})=>t.escape(n,Uf(e,i)),filter:(n,i={})=>t.filter(n,Uf(e,i)),defaults:n=>t.defaults(Uf(e,n)),makeRe:(n,i={})=>t.makeRe(n,Uf(e,i)),braceExpand:(n,i={})=>t.braceExpand(n,Uf(e,i)),match:(n,i,o={})=>t.match(n,i,Uf(e,o)),sep:t.sep,GLOBSTAR:Su})};xc.defaults=NZr;var tut=(e,t={})=>(JU(e),t.nobrace||!/\{(?:(?!\{).)*\}/.test(e)?[e]:$ct(e,{max:t.braceExpandMax}));xc.braceExpand=tut;var DZr=(e,t={})=>new MB(e,t).makeRe();xc.makeRe=DZr;var OZr=(e,t,r={})=>{let n=new MB(t,r);return e=e.filter(i=>n.match(i)),n.options.nonull&&!e.length&&e.push(t),e};xc.match=OZr;var Jct=/[?*]|[+@!]\(.*?\)|\[|\]/,BZr=e=>e.replace(/[-[\]{}()*+?.,\\^$|#\s]/g,"\\$&"),MB=class{options;set;pattern;windowsPathsNoEscape;nonegate;negate;comment;empty;preserveMultipleSlashes;partial;globSet;globParts;nocase;isWindows;platform;windowsNoMagicRoot;maxGlobstarRecursion;regexp;constructor(t,r={}){JU(t),r=r||{},this.options=r,this.maxGlobstarRecursion=r.maxGlobstarRecursion??200,this.pattern=t,this.platform=r.platform||eut,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]==="?"||!Jct.test(o[2]))&&!Jct.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(Su)?this.#e(t,r,n,i,o):this.#n(t,r,n,i,o)}#e(t,r,n,i,o){let s=r.indexOf(Su,o),a=r.lastIndexOf(Su),[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 I=i;I<t.length-d;I++){let R=String(t[I]);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===Su?(_.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===Su)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 tut(this.pattern,this.options)}parse(t){JU(t);let r=this.options;if(t==="**")return Su;if(t==="")return"";let n,i=null;(n=t.match(hZr))?i=r.dot?_Zr:AZr:(n=t.match(sZr))?i=(r.nocase?r.dot?uZr:cZr:r.dot?lZr:aZr)(n[1]):(n=t.match(EZr))?i=(r.nocase?r.dot?bZr:SZr:r.dot?yZr:CZr)(n):(n=t.match(dZr))?i=r.dot?mZr:pZr:(n=t.match(fZr))&&(i=gZr);let o=W1.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?vZr:r.dot?xZr:wZr,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"?BZr(d):d===Su?Su:d._src});c.forEach((d,f)=>{let p=c[f+1],h=c[f-1];d!==Su||h===Su||(h===void 0?p!==void 0&&p!==Su?c[f+1]="(?:\\/|"+n+"\\/)?"+p:c[f]=n:p===void 0?c[f-1]=h+"(?:\\/|\\/"+n+")?":p!==Su&&(c[f-1]=h+"(?:\\/|\\/"+n+"\\/)"+p,c[f+1]=Su))});let u=c.filter(d=>d!==Su);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 xc.defaults(t).Minimatch}};xc.AST=W1;xc.Minimatch=MB;xc.escape=dSe;xc.unescape=fC;var iut=Ce(BB(),1);ur();Fe();be();ju();import{readFile as rut}from"fs/promises";import{existsSync as pSe,readdirSync as MZr,statSync as kZr}from"fs";import{join as mSe,relative as out}from"path";import{homedir as LZr}from"os";function nut(e){try{let t=(0,iut.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 me(t),{paths:[],content:e.trim()}}}function PZr(e,t){return t.length===0?!0:t.some(r=>{try{return xc(e,r,{matchBase:!0,dot:!0})}catch(n){return me(n),!1}})}function fSe(e){let t=[];try{if(!pSe(e))return t;let r=MZr(e);for(let n of r){let i=mSe(e,n),o=kZr(i);o.isDirectory()?t.push(...fSe(i)):o.isFile()&&n.endsWith(".md")&&t.push(i)}}catch(r){me(r)}return t}async function IK(){let e=[];try{let t=mSe(LZr(),yn,"rules");if(pSe(t)){let r=fSe(t);for(let n of r)try{let i=await rut(n,"utf-8"),{paths:o,content:s}=nut(i);o.length>0&&e.push({filePath:n,content:s,paths:o,isProjectRule:!1})}catch(i){me(i)}}}catch(t){me(t)}try{let t=mSe(Ne(),yn,"rules");if(pSe(t)){let r=fSe(t);for(let n of r)try{let i=await rut(n,"utf-8"),{paths:o,content:s}=nut(i);o.length>0&&e.push({filePath:out(Ne(),n),content:s,paths:o,isProjectRule:!0})}catch(i){me(i)}}}catch(t){me(t)}return e}function sut(e,t){e=oj(e);let r=oj(Ne()),n=e.startsWith(r)?out(r,e):e;return t.filter(i=>PZr(n,i.paths))}function aut(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}):
755
755
 
756
756
  ${r.content}`}).join(`
757
757
 
@@ -852,7 +852,7 @@ data: ${JSON.stringify(L)}
852
852
  `);a=B.pop()||"";for(let L of B){let G=L.trim();if(!(!G||G==="data: [DONE]"))if(G.startsWith("data: ")){let U=G.slice(6);try{let V=JSON.parse(U);R(V)}catch(V){this.logger&&this.logger.error({err:V,line:G},"Failed to parse Gemini SSE chunk")}}else try{let U=JSON.parse(G);R(U)}catch{}}};(async()=>{try{for(;;){let{value:B,done:L}=await s.read();if(L)break;a+=n.decode(B,{stream:!0}),D()}I()}catch(B){o.error(B)}})()}})}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_${nM()}`,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:`
853
853
 
854
854
  [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 oin(`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"}}},Iye=new Tye;var Tbt=Ce(bbt(),1);Jt();Oo();function xh(e){return e?typeof e.entries=="function"?Object.fromEntries(e.entries()):{...e}:{}}function ybt(e){let t=String(e?.["x-thinking-level"]??"medium").toLowerCase();return["off","low","medium","high"].includes(t)?t:"medium"}function ESn(e,t){if(t==="off"){delete e.reasoning;return}e.reasoning={effort:t}}function SSn(e,t){if(t==="off"){delete e.reasoning;return}e.reasoning={effort:t,summary:"auto"}}function bSn(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 W5(e,t,r){tz(t,e),rz(t,bSn(e,r),r)}function YM(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 j5(e){let t=new Headers(e);return t.delete("content-encoding"),t.delete("content-length"),t.delete("transfer-encoding"),t}function XIe(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 Cbt=["/v1/messages"];function eve(e){let t;try{typeof e=="string"?t=new Px(e):e instanceof Px?t=e:t=new Px(e.url)}catch{return""}let r=t.pathname;for(let n of Cbt){let i=r.indexOf(n);if(i!==-1)return t.origin+r.slice(0,i)}return t.origin}function see(e,t){let r=typeof e=="string"?e:e instanceof Px?e.toString():e.url,n;try{n=new Px(r).pathname}catch{return!1}return Cbt.some(i=>n.includes(i))&&(t.method==="POST"||t.method==="post")}function ySn(e){return async(t,r)=>{if(!see(t,r))return e(t,r);let n=JSON.parse(r.body),i=await aZ.transformRequestOut(n),o=eve(t)+"/chat/completions",s=xh(r.headers),a=s.authorization??s.Authorization??"";ESn(i,ybt(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 Z(`OpenAI Chat Completions API error: ${l.status}`,{url:o,errorResponse:E}),XIe("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:xh(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:j5(l.headers)}),C=await aZ.transformResponseIn(b,n),I=await C.text();try{W5({...d,openai:{...d.openai,response:{body:JSON.parse(E)}},response:{...d.response,body:JSON.parse(I)}},u)}catch(R){Z("\u65E5\u5FD7\u89E3\u6790\u9519\u8BEF(Chat \u975E\u6D41\u5F0F):",R)}return new Response(I,{status:C.status,statusText:C.statusText,headers:C.headers})}let f=YM(l.body),p=new Response(f.stream,{status:l.status,statusText:l.statusText,headers:j5(l.headers)}),h=await aZ.transformResponseIn(p,n),_=YM(h.body);return Promise.all([f.done,_.done]).then(async([E,b])=>{try{W5({...d,openai:{...d.openai,response:{body:await Jdt(E)}},response:{...d.response,body:await U9(b)}},u)}catch(C){Z("\u65E5\u5FD7\u89E3\u6790\u9519\u8BEF(Chat \u6D41\u5F0F):"+C?.stack)}}).catch(E=>Z("\u65E5\u5FD7\u805A\u5408\u9519\u8BEF(Chat):"+E)),new Response(_.stream,{status:h.status,statusText:h.statusText,headers:h.headers})}}function CSn(e){return async(t,r)=>{if(!see(t,r))return e(t,r);let n=JSON.parse(r.body),i=await lZ.transformRequestOut(n),o=xh(r.headers);SSn(i,ybt(o));let s=JSON.stringify(i),l=eve(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 Z(`OpenAI Responses API error: ${u.status} ${u.statusText}`,{url:l,status:u.status,errorResponse:C}),XIe("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:xh(u.headers)},openai:{request:{body:i},response:{}}};if(!d){let C=await u.text(),I=new Response(C,{status:u.status,statusText:u.statusText,headers:j5(u.headers)}),R=await lZ.transformResponseIn(I,n),D=await R.text();try{W5({...p,openai:{...p.openai,response:{body:JSON.parse(C)}},response:{...p.response,body:JSON.parse(D)}},f,"responses")}catch(B){Z("\u65E5\u5FD7\u89E3\u6790\u9519\u8BEF(Responses \u975E\u6D41\u5F0F):",B)}return new Response(D,{status:R.status,statusText:R.statusText,headers:R.headers})}let h=YM(u.body),_=new Response(h.stream,{status:u.status,statusText:u.statusText,headers:j5(u.headers)}),E=await lZ.transformResponseIn(_,n),b=YM(E.body);return Promise.all([h.done,b.done]).then(async([C,I])=>{try{W5({...p,openai:{...p.openai,response:{body:await Kdt(C)}},response:{...p.response,body:await U9(I)}},f,"responses")}catch(R){Z("\u65E5\u5FD7\u89E3\u6790\u9519\u8BEF(Responses \u6D41\u5F0F):"+R?.stack)}}).catch(C=>Z("\u65E5\u5FD7\u805A\u5408\u9519\u8BEF(Responses):"+C)),new Response(b.stream,{status:E.status,statusText:E.statusText,headers:E.headers})}}function TSn(e){return async(t,r)=>{if(!see(t,r))return e(t,r);let n=JSON.parse(r.body),i=xh(r.headers),o=await Iye.transformRequestOut(n),s=JSON.stringify(o),a=eve(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 Z("gemini request error:",b),b}if(!c.ok){let b=await c.text();return Z(`Gemini API error response: ${c.status} ${c.statusText}`,{url:a,status:c.status,errorResponse:b}),XIe("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:xh(r.headers),body:n},response:{status:c.status,statusText:c.statusText,headers:xh(c.headers)},openai:{request:{body:o},response:{}}},p=YM(c.body),h=new Response(p.stream,{status:c.status,statusText:c.statusText,headers:j5(c.headers)}),_=await Iye.transformResponseIn(h),E=YM(_.body);return Promise.all([p.done,E.done]).then(async([b,C])=>{try{let I=u?Zdt(b):JSON.parse(b),R=u?await U9(C):JSON.parse(C);W5({...f,openai:{...f.openai,response:{body:I}},response:{...f.response,body:R}},d)}catch(I){Z("\u65E5\u5FD7\u89E3\u6790\u9519\u8BEF(Gemini):"+I?.stack)}}).catch(b=>Z("\u65E5\u5FD7\u805A\u5408\u9519\u8BEF(Gemini):"+b)),new Response(E.stream,{status:_.status,statusText:_.statusText,headers:_.headers})}}function ISn(e){return async(t,r)=>{if(!see(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=xh(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();Z(`API error response: ${a.status} ${a.statusText}`,{url:typeof t=="string"?t:t instanceof Px?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 Px?t.toString():t.url,method:r.method,headers:xh(r.headers),body:JSON.parse(n)},response:{status:a.status,statusText:a.statusText,headers:xh(a.headers)}};return(async()=>{if(c){let p=await a.text();u.response.body=await U9(p)}else u.response.body=await a.json();let f=xh(r.headers)["x-agent-id"];tz(f,u),rz(f,{request:u.request.body.messages,response:u.response.body.content,usage:u.response.body?.usage})})().catch(d=>Z(`\u65E5\u5FD7\u89E3\u6790\u9519\u8BEF:
855
- Stack trace: `+d.stack)),new Response(l.body,{status:a.status,statusText:a.statusText,headers:a.headers})}}var oee=null,ZIe=!1;function vSn(){oee=null,ZIe=!1}Tt.on("proxy:changed",vSn);function xSn(){if(ZIe)return oee;if(ZIe=!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&&(oee=new Tbt.ProxyAgent({uri:e}),lt(`[proxy] using proxy: ${e}`)),oee}function wSn(){let e=xSn();return e?((t,r={})=>global.fetch(t,{...r,dispatcher:e})):global.fetch}function aee(e){let t=e||process.env.API_TYPE,r=wSn();switch(t){case"openai":return ySn(r);case"openai-responses":return CSn(r);case"gemini":return TSn(r);default:return ISn(r)}}r_();be();Fe();Fe();var tve="2.9.6";globalThis.MACRO={VERSION:tve,PACKAGE_URL:`@dahawa/${$i}`,README_URL:"https://github.com/italking/hawa-code",ISSUES_EXPLAINER:"report the issue at https://github.com/italking/hawa-code/issues"};var lee=process.env.HAWA_CODE_USER_AGENT||`${$i}/${tve} (${process.env.USER_TYPE})`;be();be();cr();function Cu(e,t){let r=[],n=new Set,i=new Set;return e.filter(o=>o.type!=="progress"&&o.type!=="reminder").forEach(o=>{switch(o.type){case"user":{let s=Pd(r);if(s?.type==="user"){r[r.length-1]=rve(s,o);return}r.push(o);return}case"assistant":r.push(o);return;case"insert":{let s=Pd(r);s?.type==="user"&&(r[r.length-1]=RSn(s,o));return}case"path_rules":{let s=t?.pathRules;if(!s)return;let a=o.content.paths.filter(d=>!n.has(d));if(a.length===0)return;let l=a.map(d=>s.get(d)).filter(d=>d!==void 0);if(a.forEach(d=>n.add(d)),l.length===0)return;let c=Ot([{type:"text",text:`<system-rules>
855
+ Stack trace: `+d.stack)),new Response(l.body,{status:a.status,statusText:a.statusText,headers:a.headers})}}var oee=null,ZIe=!1;function vSn(){oee=null,ZIe=!1}Tt.on("proxy:changed",vSn);function xSn(){if(ZIe)return oee;if(ZIe=!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&&(oee=new Tbt.ProxyAgent({uri:e}),lt(`[proxy] using proxy: ${e}`)),oee}function wSn(){let e=xSn();return e?((t,r={})=>global.fetch(t,{...r,dispatcher:e})):global.fetch}function aee(e){let t=e||process.env.API_TYPE,r=wSn();switch(t){case"openai":return ySn(r);case"openai-responses":return CSn(r);case"gemini":return TSn(r);default:return ISn(r)}}r_();be();Fe();Fe();var tve="2.9.8";globalThis.MACRO={VERSION:tve,PACKAGE_URL:`@dahawa/${$i}`,README_URL:"https://github.com/italking/hawa-code",ISSUES_EXPLAINER:"report the issue at https://github.com/italking/hawa-code/issues"};var lee=process.env.HAWA_CODE_USER_AGENT||`${$i}/${tve} (${process.env.USER_TYPE})`;be();be();cr();function Cu(e,t){let r=[],n=new Set,i=new Set;return e.filter(o=>o.type!=="progress"&&o.type!=="reminder").forEach(o=>{switch(o.type){case"user":{let s=Pd(r);if(s?.type==="user"){r[r.length-1]=rve(s,o);return}r.push(o);return}case"assistant":r.push(o);return;case"insert":{let s=Pd(r);s?.type==="user"&&(r[r.length-1]=RSn(s,o));return}case"path_rules":{let s=t?.pathRules;if(!s)return;let a=o.content.paths.filter(d=>!n.has(d));if(a.length===0)return;let l=a.map(d=>s.get(d)).filter(d=>d!==void 0);if(a.forEach(d=>n.add(d)),l.length===0)return;let c=Ot([{type:"text",text:`<system-rules>
856
856
  ${aut(l)}
857
857
  </system-rules>`}]),u=Pd(r);u?.type==="user"?r[r.length-1]=rve(u,c,{skipTrailingSystemReminders:!0}):r.push(c);return}case"systemAutoMemory":{let s=t?.autoMemories;if(!s)return;let a=o.content.paths.filter(d=>!i.has(d));a.forEach(d=>i.add(d));let l=a.map(d=>{let f=s.get(d);return f===void 0||f.length===0?null:`## ${d.split(/[\\/]/).pop()||d}
858
858
  ${f}`}).filter(d=>d!==null);if(l.length===0)return;let c=Ot([{type:"text",text:`<system-auto-memory>
@@ -3135,7 +3135,7 @@ ${t}`}function Fsi(e){return[ZXt(e),"","## Arguments (JSON Schema)","```json\n"+
3135
3135
  `)}function Qsi({name:e,detail:t,schema:r}){return[`<tool name="${Psi(e)}">`,` <description>${T3e(t)}</description>`,` <parameters>${T3e(JSON.stringify(r))}</parameters>`,"</tool>"].join(`
3136
3136
  `)}function Usi({name:e,detail:t,schema:r}){let n=kg(r,""),i=Array.isArray(r.required)?r.required:[];return[ZXt({name:e,detail:t,schema:r}),"","## Arguments (TypeScript)",`type ${e}Arguments = ${n};`,...i.length>0?["","## Required arguments",...i.map(o=>`- ${o}`)]:[]].join(`
3137
3137
  `)}async function Gsi(e,t){let r=await e.prompt({dangerouslySkipPermissions:t?.options?.dangerouslySkipPermissions},t),n="inputJSONSchema"in e&&e.inputJSONSchema?e.inputJSONSchema:hb(e.inputSchema),i=ke.getProxyToolSchemaFormat(),o={name:e.name,detail:r,schema:n},s=i==="json"?Fsi(o):i==="xml"?Qsi(o):Usi(o);return{schema:n,message:s}}function Hsi(e,t){let r=e.filter(Sy).map(n=>n.name).join(", ");return`<error>Tool not found: ${t}. Run ${Do} or refer to the list. Available tools: ${r}</error>`}function $si(e){return`<error>Tool ${e} cannot be invoked through the proxy tools. Call it directly.</error>`}var XXt={name:Do,async description(){return VXt(ke.getProxyToolSchemaFormat())},async prompt(e={},t){return`${WXt(ke.getProxyToolSchemaFormat())}
3138
- ${await JXt(t)}`},isReadOnly(){return!0},isConcurrencySafe(){return!0},get inputSchema(){return Lsi()},userFacingName(){return"LoadTool"},async isEnabled(){return ke.isProxyToolEnable()},needsPermissions(){return!1},renderToolUseMessage(e){return e?.toolName},renderToolUseRejectedMessage(){return(0,A.jsx)(w,{children:(0,A.jsx)(v,{children:"tool execution was rejected"})})},renderToolResultMessage(e){let t=e?.error?e.name||e.message:`tool loaded: ${e?.name??""}`;return(0,A.jsxs)(w,{flexDirection:"row",children:[(0,A.jsx)(v,{children:"\xA0\xA0\u23BF \xA0"}),(0,A.jsx)(v,{children:t})]})},renderResultForAssistant(e){return e.message},async*call(e,t){let r=await $$(t),{toolName:n}=e,i=r.find(l=>l.name===n);if(!i){let l=Hsi(r,n);yield{type:"result",resultForAssistant:l,data:{action:"load",name:n,message:l,error:!0}};return}if(!Sy(i)){let l=$si(n);yield{type:"result",resultForAssistant:l,data:{action:"load",name:n,message:l,error:!0}};return}let{schema:o,message:s}=await Gsi(i,t),a={action:"load",name:i.name,schema:o,message:s};yield{type:"result",resultForAssistant:s,data:a}}};Jr();cr();Fe();Jt();var qsi=$e(()=>{let e=ke.getProxyToolSchemaFormat()==="json"?"JSON Schema":ke.getProxyToolSchemaFormat()==="xml"?"parameters inside the XML":"TypeScript arguments type";return F.object({toolName:F.string().describe("Exact target tool name from the load result of "+Do+"; must NOT be "+Bi+" or "+Do+" themselves"),arguments:F.record(F.unknown()).optional().describe("Arguments to forward to the target tool; must match the "+e+" returned by loading the same tool via "+Do+"; omit when the target tool takes no arguments")})}),eer={name:Bi,async description(){return jXt(ke.getProxyToolSchemaFormat())},async prompt(e={},t){return KXt(ke.getProxyToolSchemaFormat())},isReadOnly(){return!1},isConcurrencySafe(){return!1},get inputSchema(){return qsi()},userFacingName(){return Bi},async isEnabled(){return ke.isProxyToolEnable()},needsPermissions(){return!1},renderToolUseMessage(e){return`call ${e?.toolName??""}`.trim()},renderToolUseRejectedMessage(){return(0,A.jsx)(w,{children:(0,A.jsx)(v,{children:"tool execution was rejected"})})},renderToolResultMessage(e){let t=e?.message??"";return(0,A.jsxs)(w,{flexDirection:"row",children:[(0,A.jsx)(v,{children:"\xA0\xA0\u23BF \xA0"}),(0,A.jsx)(v,{children:t})]})},renderResultForAssistant(e){return e.message},async*call(e,t){let r=await $$(t),n=r.find(i=>i.name===e.toolName);if(!n){let i=r.filter(Sy).map(a=>a.name).join(", "),o=`<error>Tool not found: ${e.toolName}. Run ${Do} or refer to the list. Available tools: ${i}</error>`,s={action:"call",name:e.toolName,message:o,error:!0};yield{type:"result",resultForAssistant:o,data:s};return}if(e.toolName===Bi){let i=`<error>toolName cannot be ${Bi}</error>`,o={action:"call",name:e.toolName,message:i,error:!0};yield{type:"result",resultForAssistant:i,data:o};return}if(!Sy(n)){let i=`<error>Tool ${e.toolName} cannot be invoked through ${Bi}. Call it directly.</error>`,o={action:"call",name:e.toolName,message:i,error:!0};yield{type:"result",resultForAssistant:i,data:o};return}for await(let i of n.call(e.arguments??{},t,void 0))yield i}};Jr();var D3e=Ce(He(),1);V$();var N3e="SearchMessages",ger="Search historical conversation messages (full-text)",her=`Search this project's full conversation history (all sessions, including subagent messages and content compacted away from the active context).
3138
+ ${await JXt(t)}`},isReadOnly(){return!0},isConcurrencySafe(){return!0},get inputSchema(){return Lsi()},userFacingName(){return"LoadTool"},async isEnabled(){return ke.isProxyToolEnable()},needsPermissions(){return!1},renderToolUseMessage(e){return e?.toolName},renderToolUseRejectedMessage(){return(0,A.jsx)(w,{children:(0,A.jsx)(v,{children:"tool execution was rejected"})})},renderToolResultMessage(e){let t=e?.error?e.name||e.message:`tool loaded: ${e?.name??""}`;return(0,A.jsxs)(w,{flexDirection:"row",children:[(0,A.jsx)(v,{children:"\xA0\xA0\u23BF \xA0"}),(0,A.jsx)(v,{children:t})]})},renderResultForAssistant(e){return e.message},async*call(e,t){let r=await $$(t),{toolName:n}=e,i=r.find(l=>l.name===n);if(!i){let l=Hsi(r,n);yield{type:"result",resultForAssistant:l,data:{action:"load",name:n,message:l,error:!0}};return}if(!Sy(i)){let l=$si(n);yield{type:"result",resultForAssistant:l,data:{action:"load",name:n,message:l,error:!0}};return}let{schema:o,message:s}=await Gsi(i,t),a={action:"load",name:i.name,schema:o,message:s};yield{type:"result",resultForAssistant:s,data:a}}};Jr();cr();Fe();Jt();var qsi=$e(()=>{let e=ke.getProxyToolSchemaFormat()==="json"?"JSON Schema":ke.getProxyToolSchemaFormat()==="xml"?"parameters inside the XML":"TypeScript arguments type";return F.object({toolName:F.string().describe("Exact target tool name from the load result of "+Do+"; must NOT be "+Bi+" or "+Do+" themselves"),arguments:F.record(F.unknown()).optional().describe("Arguments to forward to the target tool; must match the "+e+" returned by loading the same tool via "+Do+"; omit when the target tool takes no arguments")})}),eer={name:Bi,async description(){return jXt(ke.getProxyToolSchemaFormat())},async prompt(e={},t){return KXt(ke.getProxyToolSchemaFormat())},isReadOnly(){return!1},isConcurrencySafe(){return!1},get inputSchema(){return qsi()},userFacingName(){return Bi},async isEnabled(){return ke.isProxyToolEnable()},needsPermissions(){return!1},renderToolUseMessage(e){return`call ${e?.toolName??""}`.trim()},renderToolUseRejectedMessage(){return(0,A.jsx)(w,{children:(0,A.jsx)(v,{children:"tool execution was rejected"})})},renderToolResultMessage(e){let t=e?.message??"";return(0,A.jsxs)(w,{flexDirection:"row",children:[(0,A.jsx)(v,{children:"\xA0\xA0\u23BF \xA0"}),(0,A.jsx)(v,{children:t})]})},renderResultForAssistant(e){return e.message},async*call(e,t){let r=await $$(t),n=r.find(i=>i.name===e.toolName);if(!n){let i=r.filter(Sy).map(a=>a.name).join(", "),o=`<error>Tool not found: ${e.toolName}. Run ${Do} or refer to the list. Available tools: ${i}</error>`,s={action:"call",name:e.toolName,message:o,error:!0};yield{type:"result",resultForAssistant:o,data:s};return}if(e.toolName===Bi){let i=`<error>toolName cannot be ${Bi}</error>`,o={action:"call",name:e.toolName,message:i,error:!0};yield{type:"result",resultForAssistant:i,data:o};return}if(!Sy(n)){let i=`<error>Tool ${e.toolName} cannot be invoked through ${Bi}. Call it directly.</error>`,o={action:"call",name:e.toolName,message:i,error:!0};yield{type:"result",resultForAssistant:i,data:o};return}for await(let i of n.call(e.arguments??{},t,void 0))yield i}};Jr();var D3e=Ce(He(),1);V$();var N3e="SearchMessages",ger="Search historical conversation messages. Used to recall content that is not in the current context.",her=`Search this project's full conversation history (all sessions, including subagent messages and content compacted away from the active context).
3139
3139
 
3140
3140
  Usage:
3141
3141
  - query: keywords to search. Multiple terms are AND-combined; CJK and English are both supported. Prefer terms of 3+ characters \u2014 very short terms may not match reliably.
package/hands.js CHANGED
@@ -620,7 +620,7 @@ data: ${JSON.stringify(L)}
620
620
  `);a=P.pop()||"";for(let L of P){let j=L.trim();if(!(!j||j==="data: [DONE]"))if(j.startsWith("data: ")){let z=j.slice(6);try{let J=JSON.parse(z);D(J)}catch(J){this.logger&&this.logger.error({err:J,line:j},"Failed to parse Gemini SSE chunk")}}else try{let z=JSON.parse(j);D(z)}catch{}}};(async()=>{try{for(;;){let{value:P,done:L}=await s.read();if(L)break;a+=n.decode(P,{stream:!0}),M()}T()}catch(P){o.error(P)}})()}})}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_${$N()}`,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:`
621
621
 
622
622
  [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 t8r(`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"}}},_ye=new Eye;var zmt=we(Hmt(),1);Zt();os();function og(e){return e?typeof e.entries=="function"?Object.fromEntries(e.entries()):{...e}:{}}function qmt(e){let t=String(e?.["x-thinking-level"]??"medium").toLowerCase();return["off","low","medium","high"].includes(t)?t:"medium"}function gtn(e,t){if(t==="off"){delete e.reasoning;return}e.reasoning={effort:t}}function Atn(e,t){if(t==="off"){delete e.reasoning;return}e.reasoning={effort:t,summary:"auto"}}function htn(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 LU(e,t,r){BG(t,e),OG(t,htn(e,r),r)}function DB(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 FU(e){let t=new Headers(e);return t.delete("content-encoding"),t.delete("content-length"),t.delete("transfer-encoding"),t}function Y1e(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 Gmt=["/v1/messages"];function V1e(e){let t;try{typeof e=="string"?t=new wT(e):e instanceof wT?t=e:t=new wT(e.url)}catch{return""}let r=t.pathname;for(let n of Gmt){let i=r.indexOf(n);if(i!==-1)return t.origin+r.slice(0,i)}return t.origin}function qJ(e,t){let r=typeof e=="string"?e:e instanceof wT?e.toString():e.url,n;try{n=new wT(r).pathname}catch{return!1}return Gmt.some(i=>n.includes(i))&&(t.method==="POST"||t.method==="post")}function Etn(e){return async(t,r)=>{if(!qJ(t,r))return e(t,r);let n=JSON.parse(r.body),i=await GW.transformRequestOut(n),o=V1e(t)+"/chat/completions",s=og(r.headers),a=s.authorization??s.Authorization??"";gtn(i,qmt(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}),Y1e("OpenAI Chat Completions API error","OPENROUTER",l.status,l.statusText,y)}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:og(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:FU(l.headers)}),I=await GW.transformResponseIn(C,n),T=await I.text();try{LU({...d,openai:{...d.openai,response:{body:JSON.parse(y)}},response:{...d.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=DB(l.body),m=new Response(g.stream,{status:l.status,statusText:l.statusText,headers:FU(l.headers)}),A=await GW.transformResponseIn(m,n),h=DB(A.body);return Promise.all([g.done,h.done]).then(async([y,C])=>{try{LU({...d,openai:{...d.openai,response:{body:await Eot(y)}},response:{...d.response,body:await RF(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 _tn(e){return async(t,r)=>{if(!qJ(t,r))return e(t,r);let n=JSON.parse(r.body),i=await zW.transformRequestOut(n),o=og(r.headers);Atn(i,qmt(o));let s=JSON.stringify(i),l=V1e(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}),Y1e("OpenAI Responses API error","RESPONSES",u.status,u.statusText,I)}let d=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:og(u.headers)},openai:{request:{body:i},response:{}}};if(!d){let I=await u.text(),T=new Response(I,{status:u.status,statusText:u.statusText,headers:FU(u.headers)}),D=await zW.transformResponseIn(T,n),M=await D.text();try{LU({...m,openai:{...m.openai,response:{body:JSON.parse(I)}},response:{...m.response,body:JSON.parse(M)}},g,"responses")}catch(P){V("\u65E5\u5FD7\u89E3\u6790\u9519\u8BEF(Responses \u975E\u6D41\u5F0F):",P)}return new Response(M,{status:D.status,statusText:D.statusText,headers:D.headers})}let A=DB(u.body),h=new Response(A.stream,{status:u.status,statusText:u.statusText,headers:FU(u.headers)}),y=await zW.transformResponseIn(h,n),C=DB(y.body);return Promise.all([A.done,C.done]).then(async([I,T])=>{try{LU({...m,openai:{...m.openai,response:{body:await hot(I)}},response:{...m.response,body:await RF(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 ytn(e){return async(t,r)=>{if(!qJ(t,r))return e(t,r);let n=JSON.parse(r.body),i=og(r.headers),o=await _ye.transformRequestOut(n),s=JSON.stringify(o),a=V1e(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}),Y1e("Gemini API error","Gemini",c.status,c.statusText,C)}let u=n.stream===!0,d=i["x-agent-id"],g={request:{url:a,method:r.method,headers:og(r.headers),body:n},response:{status:c.status,statusText:c.statusText,headers:og(c.headers)},openai:{request:{body:o},response:{}}},m=DB(c.body),A=new Response(m.stream,{status:c.status,statusText:c.statusText,headers:FU(c.headers)}),h=await _ye.transformResponseIn(A),y=DB(h.body);return Promise.all([m.done,y.done]).then(async([C,I])=>{try{let T=u?_ot(C):JSON.parse(C),D=u?await RF(I):JSON.parse(I);LU({...g,openai:{...g.openai,response:{body:T}},response:{...g.response,body:D}},d)}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 btn(e){return async(t,r)=>{if(!qJ(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=og(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();V(`API error response: ${a.status} ${a.statusText}`,{url:typeof t=="string"?t:t instanceof wT?t.toString():t.url,status:a.status,errorResponse:d});let g;try{let m=JSON.parse(d);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 wT?t.toString():t.url,method:r.method,headers:og(r.headers),body:JSON.parse(n)},response:{status:a.status,statusText:a.statusText,headers:og(a.headers)}};return(async()=>{if(c){let m=await a.text();u.response.body=await RF(m)}else u.response.body=await a.json();let g=og(r.headers)["x-agent-id"];BG(g,u),OG(g,{request:u.request.body.messages,response:u.response.body.content,usage:u.response.body?.usage})})().catch(d=>V(`\u65E5\u5FD7\u89E3\u6790\u9519\u8BEF:
623
- Stack trace: `+d.stack)),new Response(l.body,{status:a.status,statusText:a.statusText,headers:a.headers})}}var HJ=null,j1e=!1;function Ctn(){HJ=null,j1e=!1}Yt.on("proxy:changed",Ctn);function Stn(){if(j1e)return HJ;if(j1e=!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&&(HJ=new zmt.ProxyAgent({uri:e}),nt(`[proxy] using proxy: ${e}`)),HJ}function Itn(){let e=Stn();return e?((t,r={})=>global.fetch(t,{...r,dispatcher:e})):global.fetch}function GJ(e){let t=e||process.env.API_TYPE,r=Itn();switch(t){case"openai":return Etn(r);case"openai-responses":return _tn(r);case"gemini":return ytn(r);default:return btn(r)}}NA();var wtn=we(Ze(),1);function jmt(e,t){let r=[],n=Math.max(1,Math.floor(t)),i="",o=0;for(let s of e){let a=Ttn(s);i&&o+a>n?(r.push(i),i=s,o=a):(i+=s,o+=a)}return i&&r.push(i),r}function Ttn(e){if(e===" ")return 4;let t=e.codePointAt(0);return t===void 0||t===0||t<32||t>=127&&t<160||vtn(t)?0:xtn(t)?2:1}function vtn(e){return e>=768&&e<=879||e>=6832&&e<=6911||e>=7616&&e<=7679||e>=8400&&e<=8447||e>=65056&&e<=65071}function xtn(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 UU(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 zJ(e){return new Intl.NumberFormat("en",{notation:"compact",maximumFractionDigits:1}).format(e).toLowerCase()}De();os();var Kl={totalCost:0,totalAPIDuration:0,startTime:Date.now(),inputTokens:0,outputTokens:0,cacheCreationTokens:0,cacheReadTokens:0,currentContextTokens:0};function jJ(e,t){Kl.totalCost+=e,Kl.totalAPIDuration+=t}function YJ(e,t){Kl.inputTokens+=e,Kl.outputTokens+=t,Yt.emit("token:change",{inputTokens:Kl.inputTokens,outputTokens:Kl.outputTokens})}function VJ(e,t){Kl.cacheCreationTokens+=e,Kl.cacheReadTokens+=t}function W1e(){return{inputTokens:Kl.inputTokens,outputTokens:Kl.outputTokens,cacheCreationTokens:Kl.cacheCreationTokens,cacheReadTokens:Kl.cacheReadTokens}}function Ymt(){return Kl.totalCost}function Vmt(){return Date.now()-Kl.startTime}function Wmt(){return Kl.totalAPIDuration}function Kmt(e){Kl.currentContextTokens=e}function Jmt(){return Kl.currentContextTokens}De();He();He();var K1e="2.9.6";globalThis.MACRO={VERSION:K1e,PACKAGE_URL:`@dahawa/${zi}`,README_URL:"https://github.com/italking/hawa-code",ISSUES_EXPLAINER:"report the issue at https://github.com/italking/hawa-code/issues"};var WJ=process.env.HAWA_CODE_USER_AGENT||`${zi}/${K1e} (${process.env.USER_TYPE})`;os();De();ar();Cr();De();He();import{existsSync as R0,readdirSync as rsn,statSync as nsn}from"fs";import{join as uC,relative as isn}from"path";import{homedir as Hht}from"os";import{platform as osn}from"process";import{readFile as dC}from"fs/promises";Cr();xf();Zt();import{join as Otn,sep as ktn}from"path";function zp(){if(!fu())return!1;try{let e=Je();if(e.autoMemory?.teamMemoryEnabled!==void 0)return e.autoMemory.teamMemoryEnabled}catch{}return!1}function pu(){return(Otn(Re(),".hcode","team-memory")+ktn).normalize("NFC")}function ag(e){let t=e.normalize("NFC"),r=pu();return t.startsWith(r)}xf();var qht=we(FB(),1);Di();var pIe=(e,t,r)=>{let n=e instanceof RegExp?Aht(e,r):e,i=t instanceof RegExp?Aht(t,r):t,o=n!==null&&i!=null&&jin(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)}},Aht=(e,t)=>{let r=t.match(e);return r?r[0]:null},jin=(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 hht="\0SLASH"+Math.random()+"\0",Eht="\0OPEN"+Math.random()+"\0",AIe="\0CLOSE"+Math.random()+"\0",_ht="\0COMMA"+Math.random()+"\0",yht="\0PERIOD"+Math.random()+"\0",Yin=new RegExp(hht,"g"),Vin=new RegExp(Eht,"g"),Win=new RegExp(AIe,"g"),Kin=new RegExp(_ht,"g"),Jin=new RegExp(yht,"g"),Zin=/\\\\/g,Xin=/\\{/g,eon=/\\}/g,ton=/\\,/g,ron=/\\\./g,non=1e5,ion=4e6;function mIe(e){return isNaN(e)?e.charCodeAt(0):parseInt(e,10)}function oon(e){return e.replace(Zin,hht).replace(Xin,Eht).replace(eon,AIe).replace(ton,_ht).replace(ron,yht)}function son(e){return e.replace(Yin,"\\").replace(Vin,"{").replace(Win,"}").replace(Kin,",").replace(Jin,".")}function bht(e){if(!e)return[""];let t=[],r=pIe("{","}",e);if(!r)return e.split(",");let{pre:n,body:i,post:o}=r,s=n.split(",");s[s.length-1]+="{"+i+"}";let a=bht(o);return o.length&&(s[s.length-1]+=a.shift(),s.push.apply(s,a)),t.push.apply(t,s),t}function Cht(e,t={}){if(!e)return[];let{max:r=non,maxLength:n=ion}=t;return e.slice(0,2)==="{}"&&(e="\\{\\}"+e.slice(2)),gIe(oon(e),r,n,!0).map(son)}function aon(e){return"{"+e+"}"}function lon(e){return/^-?0\d/.test(e)}function con(e,t){return e<=t}function uon(e,t){return e>=t}function WU(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 don(e,t,r,n){let i=e.split(/\.\./),o=[];if(i[0]===void 0||i[1]===void 0)return o;let s=mIe(i[0]),a=mIe(i[1]),l=Math.max(i[0].length,i[1].length),c=i.length===3&&i[2]!==void 0?Math.max(Math.abs(mIe(i[2])),1):1,u=con;a<s&&(c*=-1,u=uon);let g=i.some(lon),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 gIe(e,t,r,n){let i=[""],o=!1,s=!0;for(;;){let a=pIe("{","}",e);if(!a)return WU(i,e,[""],t,r,o);let l=a.pre;if(/\$$/.test(l)){if(i=WU(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,g=a.body.indexOf(",")>=0;if(!d&&!g){if(a.post.match(/,(?!,).*\}/)){e=a.pre+"{"+a.body+AIe+a.post,n=!0;continue}return WU(i,l+"{"+a.body+"}"+a.post,[""],t,r,o)}s&&(o=n&&!d,s=!1);let m;if(d)m=don(a.body,u,t,r);else{let A=bht(a.body);if(A.length===1&&A[0]!==void 0&&(A=gIe(A[0],t,r,!1).map(aon),A.length===1)){if(i=WU(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=gIe(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=WU(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 fon={"[: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]},JU=e=>e.replace(/[[\]\\-]/g,"\\$&"),pon=e=>e.replace(/[-[\]{}()*+?.,\\^$|#\s]/g,"\\$&"),Sht=e=>e.join(""),Iht=(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 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(fon))if(e.startsWith(y,o)){if(d)return["$.",!1,e.length-r,!0];o+=y.length,T?i.push(C):n.push(C),a=a||I;continue e}}if(l=!1,d){h>d?n.push(JU(d)+"-"+JU(h)):h===d&&n.push(JU(h)),d="",o++;continue}if(e.startsWith("-]",o+1)){n.push(JU(h+"-")),o+=2;continue}if(e.startsWith("-",o+1)){d=h,o+=2;continue}n.push(JU(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[pon(h),!1,u-r,!1]}let g="["+(c?"^":"")+Sht(n)+"]",m="["+(c?"":"^")+Sht(i)+"]";return[n.length&&i.length?"("+g+"|"+m+")":n.length?g:m,a,u-r,!0]};var cC=(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 Ed,mon=new Set(["!","?","+","*","@"]),hIe=e=>mon.has(e),Tht=e=>hIe(e.type),gon=new Map([["!",["@"]],["?",["?","@"]],["@",["@"]],["*",["*","+","?","@"]],["+",["+","@"]]]),Aon=new Map([["!",["?"]],["@",["?"]],["+",["?","*"]]]),hon=new Map([["!",["?","@"]],["?",["?","@"]],["@",["?","@"]],["*",["*","+","?","@"]],["+",["+","@","?","*"]]]),vht=new Map([["!",new Map([["!","@"]])],["?",new Map([["*","*"],["+","*"]])],["@",new Map([["!","!"],["?","?"],["@","@"],["*","*"],["+","+"]])],["+",new Map([["?","*"],["*","*"]])]]),Eon="(?!(?:^|/)\\.\\.?(?:$|/))",lZ="(?!\\.)",_on=new Set(["[","."]),yon=new Set(["..","."]),bon=new Set("().*{}+?[]^$\\!"),Con=e=>e.replace(/[-[\]{}()*+?.,\\^$|#\s]/g,"\\$&"),EIe="[^/]",xht=EIe+"*?",wht=EIe+"+?",Son=0,QT=class{type;#e;#t;#n=!1;#r=[];#o;#i;#l;#s=!1;#a;#d;#p=!1;id=++Son;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 Ed&&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 Ed&&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 Ed(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&&hIe(C)&&t.charAt(h)==="("&&o<=s){r.push(y),y="";let T=new Ed(C,r);h=Ed.#c(t,T,h,i,o+1),r.push(T);continue}y+=C}return r.push(y),h}let d=n+1,g=new Ed(null,r),m=[],A="";for(;d<t.length;){let h=t.charAt(d++);if(a||h==="\\"){a=!a,A+=h;continue}if(l){d===c+1?(h==="^"||h==="!")&&(u=!0):h==="]"&&!(d===c+2&&u)&&(l=!1),A+=h;continue}else if(h==="["){l=!0,c=d,u=!1,A+=h;continue}if(!i.noext&&hIe(h)&&t.charAt(d)==="("&&(o<=s||r&&r.#E(h))){let C=r&&r.#E(h)?0:1;g.push(A),A="";let I=new Ed(h,g);g.push(I),d=Ed.#c(t,I,d,i,o+C);continue}if(h==="|"){g.push(A),A="",m.push(g),g=new Ed(null,r);continue}if(h===")")return A===""&&r.#r.length===0&&(r.#p=!0),g.push(A),A="",r.push(...m,g),d;A+=h}return r.type=null,r.#t=void 0,r.#r=[t.substring(n-1)],d}#g(t){return this.#h(t,Aon)}#h(t,r=gon){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=hon){return!!r.get(this.type)?.includes(t)}#A(t,r){let n=t.#r[0],i=new Ed(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!!vht.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=vht.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 Ed(null,void 0,r);return Ed.#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()),!Tht(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"?Ed.#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&&yon.has(this.#r[0]))){let A=_on,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?Eon:y?lZ:""}let d="";return this.isEnd()&&this.#e.#s&&this.#o?.type==="!"&&(d="(?:$|\\/)"),[u+c+d,cC(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,cC(this.toString()),!1,!1]}let s=!n||t||r||!lZ?"":this.#b(!0);s===o&&(s=""),s&&(o=`(?:${o})(?:${s})*?`);let a="";if(this.type==="!"&&this.#p)a=(this.isStart()&&!r?lZ:"")+wht;else{let l=this.type==="!"?"))"+(this.isStart()&&!r&&!t?lZ:"")+xht+")":this.type==="@"?")":this.type==="?"?")?":this.type==="+"&&s?")":this.type==="*"&&s?")?":`)${this.type}`;a=i+o+l}return[a,cC(o),this.#t=!!this.#t,this.#n]}#_(){if(Tht(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+=(bon.has(c)?"\\":"")+c;continue}if(c==="*"){if(a)continue;a=!0,o+=n&&/^[*]+$/.test(t)?wht:xht,r=!0;continue}else a=!1;if(c==="\\"){l===t.length-1?o+="\\\\":i=!0;continue}if(c==="["){let[u,d,g,m]=Iht(t,l);if(g){o+=u,s=s||d,l+=g-1,r=r||m;continue}}if(c==="?"){o+=EIe,r=!0;continue}o+=Con(c)}return[o,cC(t),!!r,s]}};Ed=QT;var _Ie=(e,{windowsPathsNoEscape:t=!1,magicalBraces:r=!1}={})=>r?t?e.replace(/[?*()[\]{}]/g,"[$&]"):e.replace(/[?*()[\]\\{}]/g,"\\$&"):t?e.replace(/[?*()[\]]/g,"[$&]"):e.replace(/[?*()[\]\\]/g,"\\$&");var Jl=(e,t,r={})=>(KU(t),!r.nocomment&&t.charAt(0)==="#"?!1:new UB(t,r).match(e)),Ion=/^\*+([^+@!?*[(]*)$/,Ton=e=>t=>!t.startsWith(".")&&t.endsWith(e),von=e=>t=>t.endsWith(e),xon=e=>(e=e.toLowerCase(),t=>!t.startsWith(".")&&t.toLowerCase().endsWith(e)),won=e=>(e=e.toLowerCase(),t=>t.toLowerCase().endsWith(e)),Don=/^\*+\.\*+$/,Ron=e=>!e.startsWith(".")&&e.includes("."),Non=e=>e!=="."&&e!==".."&&e.includes("."),Bon=/^\.\*+$/,Oon=e=>e!=="."&&e!==".."&&e.startsWith("."),kon=/^\*+$/,Mon=e=>e.length!==0&&!e.startsWith("."),Qon=e=>e.length!==0&&e!=="."&&e!=="..",Pon=/^\?+([^+@!?*[(]*)?$/,Lon=([e,t=""])=>{let r=Nht([e]);return t?(t=t.toLowerCase(),n=>r(n)&&n.toLowerCase().endsWith(t)):r},Fon=([e,t=""])=>{let r=Bht([e]);return t?(t=t.toLowerCase(),n=>r(n)&&n.toLowerCase().endsWith(t)):r},Uon=([e,t=""])=>{let r=Bht([e]);return t?n=>r(n)&&n.endsWith(t):r},$on=([e,t=""])=>{let r=Nht([e]);return t?n=>r(n)&&n.endsWith(t):r},Nht=([e])=>{let t=e.length;return r=>r.length===t&&!r.startsWith(".")},Bht=([e])=>{let t=e.length;return r=>r.length===t&&r!=="."&&r!==".."},Oht=typeof process=="object"&&process?typeof process.env=="object"&&process.env&&process.env.__MINIMATCH_TESTING_PLATFORM__||process.platform:"posix",Dht={win32:{sep:"\\"},posix:{sep:"/"}},Hon=Oht==="win32"?Dht.win32.sep:Dht.posix.sep;Jl.sep=Hon;var Oc=Symbol("globstar **");Jl.GLOBSTAR=Oc;var qon="[^/]",Gon=qon+"*?",zon="(?:(?!(?:\\/|^)(?:\\.{1,2})($|\\/)).)*?",jon="(?:(?!(?:\\/|^)\\.).)*?",Yon=(e,t={})=>r=>Jl(r,e,t);Jl.filter=Yon;var jp=(e,t={})=>Object.assign({},e,t),Von=e=>{if(!e||typeof e!="object"||!Object.keys(e).length)return Jl;let t=Jl;return Object.assign((n,i,o={})=>t(n,i,jp(e,o)),{Minimatch:class extends t.Minimatch{constructor(i,o={}){super(i,jp(e,o))}static defaults(i){return t.defaults(jp(e,i)).Minimatch}},AST:class extends t.AST{constructor(i,o,s={}){super(i,o,jp(e,s))}static fromGlob(i,o={}){return t.AST.fromGlob(i,jp(e,o))}},unescape:(n,i={})=>t.unescape(n,jp(e,i)),escape:(n,i={})=>t.escape(n,jp(e,i)),filter:(n,i={})=>t.filter(n,jp(e,i)),defaults:n=>t.defaults(jp(e,n)),makeRe:(n,i={})=>t.makeRe(n,jp(e,i)),braceExpand:(n,i={})=>t.braceExpand(n,jp(e,i)),match:(n,i,o={})=>t.match(n,i,jp(e,o)),sep:t.sep,GLOBSTAR:Oc})};Jl.defaults=Von;var kht=(e,t={})=>(KU(e),t.nobrace||!/\{(?:(?!\{).)*\}/.test(e)?[e]:Cht(e,{max:t.braceExpandMax}));Jl.braceExpand=kht;var Won=(e,t={})=>new UB(e,t).makeRe();Jl.makeRe=Won;var Kon=(e,t,r={})=>{let n=new UB(t,r);return e=e.filter(i=>n.match(i)),n.options.nonull&&!e.length&&e.push(t),e};Jl.match=Kon;var Rht=/[?*]|[+@!]\(.*?\)|\[|\]/,Jon=e=>e.replace(/[-[\]{}()*+?.,\\^$|#\s]/g,"\\$&"),UB=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||Oht,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]==="?"||!Rht.test(o[2]))&&!Rht.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,g=u?3:c?0:void 0;if(typeof d=="number"&&typeof g=="number"){let[m,A]=[t[d],r[g]];m.toLowerCase()===A.toLowerCase()&&(r[g]=m,o=g,i=d)}}let{optimizationLevel:s=1}=this.options;return s>=2&&(t=this.levelTwoFileOptimize(t)),r.includes(Oc)?this.#e(t,r,n,i,o):this.#n(t,r,n,i,o)}#e(t,r,n,i,o){let s=r.indexOf(Oc,o),a=r.lastIndexOf(Oc),[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 d=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))d=u.length;else{if(t[t.length-1]!==""||i+u.length===t.length||(I--,!this.#n(t,u,n,I,0)))return!1;d=u.length+1}}if(!c.length){let I=!!d;for(let T=i;T<t.length-d;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===Oc?(h.push(A),m=[[],0],g.push(m)):(m[0].push(I),A++);let y=g.length-1,C=t.length-d;for(let I of g)I[1]=C-(h[y--]+I[0].length);return!!this.#t(t,g,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 g=t[d];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],d=t[s];if(this.debug(r,u,d),u===!1||u===Oc)return!1;let g;if(typeof u=="string"?(g=d===u,this.debug("string match",u,d,g)):(g=u.test(d),this.debug("pattern match",u,d,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 kht(this.pattern,this.options)}parse(t){KU(t);let r=this.options;if(t==="**")return Oc;if(t==="")return"";let n,i=null;(n=t.match(kon))?i=r.dot?Qon:Mon:(n=t.match(Ion))?i=(r.nocase?r.dot?won:xon:r.dot?von:Ton)(n[1]):(n=t.match(Pon))?i=(r.nocase?r.dot?Fon:Lon:r.dot?Uon:$on)(n):(n=t.match(Don))?i=r.dot?Non:Ron:(n=t.match(Bon))&&(i=Oon);let o=QT.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?Gon:r.dot?zon:jon,i=new Set(r.nocase?["i"]:[]),o=t.map(l=>{let c=l.map(d=>{if(d instanceof RegExp)for(let g of d.flags.split(""))i.add(g);return typeof d=="string"?Jon(d):d===Oc?Oc:d._src});c.forEach((d,g)=>{let m=c[g+1],A=c[g-1];d!==Oc||A===Oc||(A===void 0?m!==void 0&&m!==Oc?c[g+1]="(?:\\/|"+n+"\\/)?"+m:c[g]=n:m===void 0?c[g-1]=A+"(?:\\/|\\/"+n+")?":m!==Oc&&(c[g-1]=A+"(?:\\/|\\/"+n+"\\/)"+m,c[g+1]=Oc))});let u=c.filter(d=>d!==Oc);if(this.partial&&u.length>=1){let d=[];for(let g=1;g<=u.length;g++)d.push(u.slice(0,g).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 Jl.defaults(t).Minimatch}};Jl.AST=QT;Jl.Minimatch=UB;Jl.escape=_Ie;Jl.unescape=cC;var Pht=we(FB(),1);Cr();He();De();iu();import{readFile as Mht}from"fs/promises";import{existsSync as yIe,readdirSync as Zon,statSync as Xon}from"fs";import{join as bIe,relative as Lht}from"path";import{homedir as esn}from"os";function Qht(e){try{let t=(0,Pht.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 Ie(t),{paths:[],content:e.trim()}}}function tsn(e,t){return t.length===0?!0:t.some(r=>{try{return Jl(e,r,{matchBase:!0,dot:!0})}catch(n){return Ie(n),!1}})}function CIe(e){let t=[];try{if(!yIe(e))return t;let r=Zon(e);for(let n of r){let i=bIe(e,n),o=Xon(i);o.isDirectory()?t.push(...CIe(i)):o.isFile()&&n.endsWith(".md")&&t.push(i)}}catch(r){Ie(r)}return t}async function cZ(){let e=[];try{let t=bIe(esn(),Kr,"rules");if(yIe(t)){let r=CIe(t);for(let n of r)try{let i=await Mht(n,"utf-8"),{paths:o,content:s}=Qht(i);o.length>0&&e.push({filePath:n,content:s,paths:o,isProjectRule:!1})}catch(i){Ie(i)}}}catch(t){Ie(t)}try{let t=bIe(Re(),Kr,"rules");if(yIe(t)){let r=CIe(t);for(let n of r)try{let i=await Mht(n,"utf-8"),{paths:o,content:s}=Qht(i);o.length>0&&e.push({filePath:Lht(Re(),n),content:s,paths:o,isProjectRule:!0})}catch(i){Ie(i)}}}catch(t){Ie(t)}return e}function Fht(e,t){e=xY(e);let r=xY(Re()),n=e.startsWith(r)?Lht(r,e):e;return t.filter(i=>tsn(n,i.paths))}function Uht(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}):
623
+ Stack trace: `+d.stack)),new Response(l.body,{status:a.status,statusText:a.statusText,headers:a.headers})}}var HJ=null,j1e=!1;function Ctn(){HJ=null,j1e=!1}Yt.on("proxy:changed",Ctn);function Stn(){if(j1e)return HJ;if(j1e=!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&&(HJ=new zmt.ProxyAgent({uri:e}),nt(`[proxy] using proxy: ${e}`)),HJ}function Itn(){let e=Stn();return e?((t,r={})=>global.fetch(t,{...r,dispatcher:e})):global.fetch}function GJ(e){let t=e||process.env.API_TYPE,r=Itn();switch(t){case"openai":return Etn(r);case"openai-responses":return _tn(r);case"gemini":return ytn(r);default:return btn(r)}}NA();var wtn=we(Ze(),1);function jmt(e,t){let r=[],n=Math.max(1,Math.floor(t)),i="",o=0;for(let s of e){let a=Ttn(s);i&&o+a>n?(r.push(i),i=s,o=a):(i+=s,o+=a)}return i&&r.push(i),r}function Ttn(e){if(e===" ")return 4;let t=e.codePointAt(0);return t===void 0||t===0||t<32||t>=127&&t<160||vtn(t)?0:xtn(t)?2:1}function vtn(e){return e>=768&&e<=879||e>=6832&&e<=6911||e>=7616&&e<=7679||e>=8400&&e<=8447||e>=65056&&e<=65071}function xtn(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 UU(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 zJ(e){return new Intl.NumberFormat("en",{notation:"compact",maximumFractionDigits:1}).format(e).toLowerCase()}De();os();var Kl={totalCost:0,totalAPIDuration:0,startTime:Date.now(),inputTokens:0,outputTokens:0,cacheCreationTokens:0,cacheReadTokens:0,currentContextTokens:0};function jJ(e,t){Kl.totalCost+=e,Kl.totalAPIDuration+=t}function YJ(e,t){Kl.inputTokens+=e,Kl.outputTokens+=t,Yt.emit("token:change",{inputTokens:Kl.inputTokens,outputTokens:Kl.outputTokens})}function VJ(e,t){Kl.cacheCreationTokens+=e,Kl.cacheReadTokens+=t}function W1e(){return{inputTokens:Kl.inputTokens,outputTokens:Kl.outputTokens,cacheCreationTokens:Kl.cacheCreationTokens,cacheReadTokens:Kl.cacheReadTokens}}function Ymt(){return Kl.totalCost}function Vmt(){return Date.now()-Kl.startTime}function Wmt(){return Kl.totalAPIDuration}function Kmt(e){Kl.currentContextTokens=e}function Jmt(){return Kl.currentContextTokens}De();He();He();var K1e="2.9.8";globalThis.MACRO={VERSION:K1e,PACKAGE_URL:`@dahawa/${zi}`,README_URL:"https://github.com/italking/hawa-code",ISSUES_EXPLAINER:"report the issue at https://github.com/italking/hawa-code/issues"};var WJ=process.env.HAWA_CODE_USER_AGENT||`${zi}/${K1e} (${process.env.USER_TYPE})`;os();De();ar();Cr();De();He();import{existsSync as R0,readdirSync as rsn,statSync as nsn}from"fs";import{join as uC,relative as isn}from"path";import{homedir as Hht}from"os";import{platform as osn}from"process";import{readFile as dC}from"fs/promises";Cr();xf();Zt();import{join as Otn,sep as ktn}from"path";function zp(){if(!fu())return!1;try{let e=Je();if(e.autoMemory?.teamMemoryEnabled!==void 0)return e.autoMemory.teamMemoryEnabled}catch{}return!1}function pu(){return(Otn(Re(),".hcode","team-memory")+ktn).normalize("NFC")}function ag(e){let t=e.normalize("NFC"),r=pu();return t.startsWith(r)}xf();var qht=we(FB(),1);Di();var pIe=(e,t,r)=>{let n=e instanceof RegExp?Aht(e,r):e,i=t instanceof RegExp?Aht(t,r):t,o=n!==null&&i!=null&&jin(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)}},Aht=(e,t)=>{let r=t.match(e);return r?r[0]:null},jin=(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 hht="\0SLASH"+Math.random()+"\0",Eht="\0OPEN"+Math.random()+"\0",AIe="\0CLOSE"+Math.random()+"\0",_ht="\0COMMA"+Math.random()+"\0",yht="\0PERIOD"+Math.random()+"\0",Yin=new RegExp(hht,"g"),Vin=new RegExp(Eht,"g"),Win=new RegExp(AIe,"g"),Kin=new RegExp(_ht,"g"),Jin=new RegExp(yht,"g"),Zin=/\\\\/g,Xin=/\\{/g,eon=/\\}/g,ton=/\\,/g,ron=/\\\./g,non=1e5,ion=4e6;function mIe(e){return isNaN(e)?e.charCodeAt(0):parseInt(e,10)}function oon(e){return e.replace(Zin,hht).replace(Xin,Eht).replace(eon,AIe).replace(ton,_ht).replace(ron,yht)}function son(e){return e.replace(Yin,"\\").replace(Vin,"{").replace(Win,"}").replace(Kin,",").replace(Jin,".")}function bht(e){if(!e)return[""];let t=[],r=pIe("{","}",e);if(!r)return e.split(",");let{pre:n,body:i,post:o}=r,s=n.split(",");s[s.length-1]+="{"+i+"}";let a=bht(o);return o.length&&(s[s.length-1]+=a.shift(),s.push.apply(s,a)),t.push.apply(t,s),t}function Cht(e,t={}){if(!e)return[];let{max:r=non,maxLength:n=ion}=t;return e.slice(0,2)==="{}"&&(e="\\{\\}"+e.slice(2)),gIe(oon(e),r,n,!0).map(son)}function aon(e){return"{"+e+"}"}function lon(e){return/^-?0\d/.test(e)}function con(e,t){return e<=t}function uon(e,t){return e>=t}function WU(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 don(e,t,r,n){let i=e.split(/\.\./),o=[];if(i[0]===void 0||i[1]===void 0)return o;let s=mIe(i[0]),a=mIe(i[1]),l=Math.max(i[0].length,i[1].length),c=i.length===3&&i[2]!==void 0?Math.max(Math.abs(mIe(i[2])),1):1,u=con;a<s&&(c*=-1,u=uon);let g=i.some(lon),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 gIe(e,t,r,n){let i=[""],o=!1,s=!0;for(;;){let a=pIe("{","}",e);if(!a)return WU(i,e,[""],t,r,o);let l=a.pre;if(/\$$/.test(l)){if(i=WU(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,g=a.body.indexOf(",")>=0;if(!d&&!g){if(a.post.match(/,(?!,).*\}/)){e=a.pre+"{"+a.body+AIe+a.post,n=!0;continue}return WU(i,l+"{"+a.body+"}"+a.post,[""],t,r,o)}s&&(o=n&&!d,s=!1);let m;if(d)m=don(a.body,u,t,r);else{let A=bht(a.body);if(A.length===1&&A[0]!==void 0&&(A=gIe(A[0],t,r,!1).map(aon),A.length===1)){if(i=WU(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=gIe(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=WU(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 fon={"[: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]},JU=e=>e.replace(/[[\]\\-]/g,"\\$&"),pon=e=>e.replace(/[-[\]{}()*+?.,\\^$|#\s]/g,"\\$&"),Sht=e=>e.join(""),Iht=(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 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(fon))if(e.startsWith(y,o)){if(d)return["$.",!1,e.length-r,!0];o+=y.length,T?i.push(C):n.push(C),a=a||I;continue e}}if(l=!1,d){h>d?n.push(JU(d)+"-"+JU(h)):h===d&&n.push(JU(h)),d="",o++;continue}if(e.startsWith("-]",o+1)){n.push(JU(h+"-")),o+=2;continue}if(e.startsWith("-",o+1)){d=h,o+=2;continue}n.push(JU(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[pon(h),!1,u-r,!1]}let g="["+(c?"^":"")+Sht(n)+"]",m="["+(c?"":"^")+Sht(i)+"]";return[n.length&&i.length?"("+g+"|"+m+")":n.length?g:m,a,u-r,!0]};var cC=(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 Ed,mon=new Set(["!","?","+","*","@"]),hIe=e=>mon.has(e),Tht=e=>hIe(e.type),gon=new Map([["!",["@"]],["?",["?","@"]],["@",["@"]],["*",["*","+","?","@"]],["+",["+","@"]]]),Aon=new Map([["!",["?"]],["@",["?"]],["+",["?","*"]]]),hon=new Map([["!",["?","@"]],["?",["?","@"]],["@",["?","@"]],["*",["*","+","?","@"]],["+",["+","@","?","*"]]]),vht=new Map([["!",new Map([["!","@"]])],["?",new Map([["*","*"],["+","*"]])],["@",new Map([["!","!"],["?","?"],["@","@"],["*","*"],["+","+"]])],["+",new Map([["?","*"],["*","*"]])]]),Eon="(?!(?:^|/)\\.\\.?(?:$|/))",lZ="(?!\\.)",_on=new Set(["[","."]),yon=new Set(["..","."]),bon=new Set("().*{}+?[]^$\\!"),Con=e=>e.replace(/[-[\]{}()*+?.,\\^$|#\s]/g,"\\$&"),EIe="[^/]",xht=EIe+"*?",wht=EIe+"+?",Son=0,QT=class{type;#e;#t;#n=!1;#r=[];#o;#i;#l;#s=!1;#a;#d;#p=!1;id=++Son;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 Ed&&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 Ed&&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 Ed(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&&hIe(C)&&t.charAt(h)==="("&&o<=s){r.push(y),y="";let T=new Ed(C,r);h=Ed.#c(t,T,h,i,o+1),r.push(T);continue}y+=C}return r.push(y),h}let d=n+1,g=new Ed(null,r),m=[],A="";for(;d<t.length;){let h=t.charAt(d++);if(a||h==="\\"){a=!a,A+=h;continue}if(l){d===c+1?(h==="^"||h==="!")&&(u=!0):h==="]"&&!(d===c+2&&u)&&(l=!1),A+=h;continue}else if(h==="["){l=!0,c=d,u=!1,A+=h;continue}if(!i.noext&&hIe(h)&&t.charAt(d)==="("&&(o<=s||r&&r.#E(h))){let C=r&&r.#E(h)?0:1;g.push(A),A="";let I=new Ed(h,g);g.push(I),d=Ed.#c(t,I,d,i,o+C);continue}if(h==="|"){g.push(A),A="",m.push(g),g=new Ed(null,r);continue}if(h===")")return A===""&&r.#r.length===0&&(r.#p=!0),g.push(A),A="",r.push(...m,g),d;A+=h}return r.type=null,r.#t=void 0,r.#r=[t.substring(n-1)],d}#g(t){return this.#h(t,Aon)}#h(t,r=gon){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=hon){return!!r.get(this.type)?.includes(t)}#A(t,r){let n=t.#r[0],i=new Ed(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!!vht.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=vht.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 Ed(null,void 0,r);return Ed.#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()),!Tht(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"?Ed.#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&&yon.has(this.#r[0]))){let A=_on,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?Eon:y?lZ:""}let d="";return this.isEnd()&&this.#e.#s&&this.#o?.type==="!"&&(d="(?:$|\\/)"),[u+c+d,cC(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,cC(this.toString()),!1,!1]}let s=!n||t||r||!lZ?"":this.#b(!0);s===o&&(s=""),s&&(o=`(?:${o})(?:${s})*?`);let a="";if(this.type==="!"&&this.#p)a=(this.isStart()&&!r?lZ:"")+wht;else{let l=this.type==="!"?"))"+(this.isStart()&&!r&&!t?lZ:"")+xht+")":this.type==="@"?")":this.type==="?"?")?":this.type==="+"&&s?")":this.type==="*"&&s?")?":`)${this.type}`;a=i+o+l}return[a,cC(o),this.#t=!!this.#t,this.#n]}#_(){if(Tht(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+=(bon.has(c)?"\\":"")+c;continue}if(c==="*"){if(a)continue;a=!0,o+=n&&/^[*]+$/.test(t)?wht:xht,r=!0;continue}else a=!1;if(c==="\\"){l===t.length-1?o+="\\\\":i=!0;continue}if(c==="["){let[u,d,g,m]=Iht(t,l);if(g){o+=u,s=s||d,l+=g-1,r=r||m;continue}}if(c==="?"){o+=EIe,r=!0;continue}o+=Con(c)}return[o,cC(t),!!r,s]}};Ed=QT;var _Ie=(e,{windowsPathsNoEscape:t=!1,magicalBraces:r=!1}={})=>r?t?e.replace(/[?*()[\]{}]/g,"[$&]"):e.replace(/[?*()[\]\\{}]/g,"\\$&"):t?e.replace(/[?*()[\]]/g,"[$&]"):e.replace(/[?*()[\]\\]/g,"\\$&");var Jl=(e,t,r={})=>(KU(t),!r.nocomment&&t.charAt(0)==="#"?!1:new UB(t,r).match(e)),Ion=/^\*+([^+@!?*[(]*)$/,Ton=e=>t=>!t.startsWith(".")&&t.endsWith(e),von=e=>t=>t.endsWith(e),xon=e=>(e=e.toLowerCase(),t=>!t.startsWith(".")&&t.toLowerCase().endsWith(e)),won=e=>(e=e.toLowerCase(),t=>t.toLowerCase().endsWith(e)),Don=/^\*+\.\*+$/,Ron=e=>!e.startsWith(".")&&e.includes("."),Non=e=>e!=="."&&e!==".."&&e.includes("."),Bon=/^\.\*+$/,Oon=e=>e!=="."&&e!==".."&&e.startsWith("."),kon=/^\*+$/,Mon=e=>e.length!==0&&!e.startsWith("."),Qon=e=>e.length!==0&&e!=="."&&e!=="..",Pon=/^\?+([^+@!?*[(]*)?$/,Lon=([e,t=""])=>{let r=Nht([e]);return t?(t=t.toLowerCase(),n=>r(n)&&n.toLowerCase().endsWith(t)):r},Fon=([e,t=""])=>{let r=Bht([e]);return t?(t=t.toLowerCase(),n=>r(n)&&n.toLowerCase().endsWith(t)):r},Uon=([e,t=""])=>{let r=Bht([e]);return t?n=>r(n)&&n.endsWith(t):r},$on=([e,t=""])=>{let r=Nht([e]);return t?n=>r(n)&&n.endsWith(t):r},Nht=([e])=>{let t=e.length;return r=>r.length===t&&!r.startsWith(".")},Bht=([e])=>{let t=e.length;return r=>r.length===t&&r!=="."&&r!==".."},Oht=typeof process=="object"&&process?typeof process.env=="object"&&process.env&&process.env.__MINIMATCH_TESTING_PLATFORM__||process.platform:"posix",Dht={win32:{sep:"\\"},posix:{sep:"/"}},Hon=Oht==="win32"?Dht.win32.sep:Dht.posix.sep;Jl.sep=Hon;var Oc=Symbol("globstar **");Jl.GLOBSTAR=Oc;var qon="[^/]",Gon=qon+"*?",zon="(?:(?!(?:\\/|^)(?:\\.{1,2})($|\\/)).)*?",jon="(?:(?!(?:\\/|^)\\.).)*?",Yon=(e,t={})=>r=>Jl(r,e,t);Jl.filter=Yon;var jp=(e,t={})=>Object.assign({},e,t),Von=e=>{if(!e||typeof e!="object"||!Object.keys(e).length)return Jl;let t=Jl;return Object.assign((n,i,o={})=>t(n,i,jp(e,o)),{Minimatch:class extends t.Minimatch{constructor(i,o={}){super(i,jp(e,o))}static defaults(i){return t.defaults(jp(e,i)).Minimatch}},AST:class extends t.AST{constructor(i,o,s={}){super(i,o,jp(e,s))}static fromGlob(i,o={}){return t.AST.fromGlob(i,jp(e,o))}},unescape:(n,i={})=>t.unescape(n,jp(e,i)),escape:(n,i={})=>t.escape(n,jp(e,i)),filter:(n,i={})=>t.filter(n,jp(e,i)),defaults:n=>t.defaults(jp(e,n)),makeRe:(n,i={})=>t.makeRe(n,jp(e,i)),braceExpand:(n,i={})=>t.braceExpand(n,jp(e,i)),match:(n,i,o={})=>t.match(n,i,jp(e,o)),sep:t.sep,GLOBSTAR:Oc})};Jl.defaults=Von;var kht=(e,t={})=>(KU(e),t.nobrace||!/\{(?:(?!\{).)*\}/.test(e)?[e]:Cht(e,{max:t.braceExpandMax}));Jl.braceExpand=kht;var Won=(e,t={})=>new UB(e,t).makeRe();Jl.makeRe=Won;var Kon=(e,t,r={})=>{let n=new UB(t,r);return e=e.filter(i=>n.match(i)),n.options.nonull&&!e.length&&e.push(t),e};Jl.match=Kon;var Rht=/[?*]|[+@!]\(.*?\)|\[|\]/,Jon=e=>e.replace(/[-[\]{}()*+?.,\\^$|#\s]/g,"\\$&"),UB=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||Oht,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]==="?"||!Rht.test(o[2]))&&!Rht.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,g=u?3:c?0:void 0;if(typeof d=="number"&&typeof g=="number"){let[m,A]=[t[d],r[g]];m.toLowerCase()===A.toLowerCase()&&(r[g]=m,o=g,i=d)}}let{optimizationLevel:s=1}=this.options;return s>=2&&(t=this.levelTwoFileOptimize(t)),r.includes(Oc)?this.#e(t,r,n,i,o):this.#n(t,r,n,i,o)}#e(t,r,n,i,o){let s=r.indexOf(Oc,o),a=r.lastIndexOf(Oc),[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 d=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))d=u.length;else{if(t[t.length-1]!==""||i+u.length===t.length||(I--,!this.#n(t,u,n,I,0)))return!1;d=u.length+1}}if(!c.length){let I=!!d;for(let T=i;T<t.length-d;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===Oc?(h.push(A),m=[[],0],g.push(m)):(m[0].push(I),A++);let y=g.length-1,C=t.length-d;for(let I of g)I[1]=C-(h[y--]+I[0].length);return!!this.#t(t,g,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 g=t[d];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],d=t[s];if(this.debug(r,u,d),u===!1||u===Oc)return!1;let g;if(typeof u=="string"?(g=d===u,this.debug("string match",u,d,g)):(g=u.test(d),this.debug("pattern match",u,d,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 kht(this.pattern,this.options)}parse(t){KU(t);let r=this.options;if(t==="**")return Oc;if(t==="")return"";let n,i=null;(n=t.match(kon))?i=r.dot?Qon:Mon:(n=t.match(Ion))?i=(r.nocase?r.dot?won:xon:r.dot?von:Ton)(n[1]):(n=t.match(Pon))?i=(r.nocase?r.dot?Fon:Lon:r.dot?Uon:$on)(n):(n=t.match(Don))?i=r.dot?Non:Ron:(n=t.match(Bon))&&(i=Oon);let o=QT.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?Gon:r.dot?zon:jon,i=new Set(r.nocase?["i"]:[]),o=t.map(l=>{let c=l.map(d=>{if(d instanceof RegExp)for(let g of d.flags.split(""))i.add(g);return typeof d=="string"?Jon(d):d===Oc?Oc:d._src});c.forEach((d,g)=>{let m=c[g+1],A=c[g-1];d!==Oc||A===Oc||(A===void 0?m!==void 0&&m!==Oc?c[g+1]="(?:\\/|"+n+"\\/)?"+m:c[g]=n:m===void 0?c[g-1]=A+"(?:\\/|\\/"+n+")?":m!==Oc&&(c[g-1]=A+"(?:\\/|\\/"+n+"\\/)"+m,c[g+1]=Oc))});let u=c.filter(d=>d!==Oc);if(this.partial&&u.length>=1){let d=[];for(let g=1;g<=u.length;g++)d.push(u.slice(0,g).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 Jl.defaults(t).Minimatch}};Jl.AST=QT;Jl.Minimatch=UB;Jl.escape=_Ie;Jl.unescape=cC;var Pht=we(FB(),1);Cr();He();De();iu();import{readFile as Mht}from"fs/promises";import{existsSync as yIe,readdirSync as Zon,statSync as Xon}from"fs";import{join as bIe,relative as Lht}from"path";import{homedir as esn}from"os";function Qht(e){try{let t=(0,Pht.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 Ie(t),{paths:[],content:e.trim()}}}function tsn(e,t){return t.length===0?!0:t.some(r=>{try{return Jl(e,r,{matchBase:!0,dot:!0})}catch(n){return Ie(n),!1}})}function CIe(e){let t=[];try{if(!yIe(e))return t;let r=Zon(e);for(let n of r){let i=bIe(e,n),o=Xon(i);o.isDirectory()?t.push(...CIe(i)):o.isFile()&&n.endsWith(".md")&&t.push(i)}}catch(r){Ie(r)}return t}async function cZ(){let e=[];try{let t=bIe(esn(),Kr,"rules");if(yIe(t)){let r=CIe(t);for(let n of r)try{let i=await Mht(n,"utf-8"),{paths:o,content:s}=Qht(i);o.length>0&&e.push({filePath:n,content:s,paths:o,isProjectRule:!1})}catch(i){Ie(i)}}}catch(t){Ie(t)}try{let t=bIe(Re(),Kr,"rules");if(yIe(t)){let r=CIe(t);for(let n of r)try{let i=await Mht(n,"utf-8"),{paths:o,content:s}=Qht(i);o.length>0&&e.push({filePath:Lht(Re(),n),content:s,paths:o,isProjectRule:!0})}catch(i){Ie(i)}}}catch(t){Ie(t)}return e}function Fht(e,t){e=xY(e);let r=xY(Re()),n=e.startsWith(r)?Lht(r,e):e;return t.filter(i=>tsn(n,i.paths))}function Uht(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}):
624
624
 
625
625
  ${r.content}`}).join(`
626
626
 
@@ -2937,7 +2937,7 @@ CREATE TABLE IF NOT EXISTS index_state (
2937
2937
  WHERE 1=1${c} AND ${m}
2938
2938
  ORDER BY timestamp DESC, id DESC LIMIT ?`).all(...u,...A,n);d.push(...h.reverse())}if(i>0){let m=l.timestamp===null?"id > ?":"(timestamp > ? OR (timestamp = ? AND id > ?))",A=l.timestamp===null?[l.messageId]:[l.timestamp,l.timestamp,l.messageId],h=r.prepare(`SELECT ${K3} FROM messages m
2939
2939
  WHERE 1=1${c} AND ${m}
2940
- ORDER BY timestamp ASC, id ASC LIMIT ?`).all(...u,...A,i);g.push(...h)}return{anchor:o?l:null,before:d.map(Coe),after:g.map(Coe)}}catch(a){return Ie("hmemory.getMessageContext failed",a),{anchor:null,before:[],after:[]}}}function vLe(e){let t=W3();if(!t||e.length===0)return[];try{let r=e.map(()=>"?").join(","),n=t.prepare(`SELECT ${K3} FROM messages m WHERE m.id IN (${r})`).all(...e),i=new Map(n.map(o=>[o.messageId,Coe(o)]));return e.map(o=>i.get(o)).filter(o=>o!==void 0)}catch(r){return Ie("hmemory.getMessagesByIds failed",r),[]}}var xLe="SearchMessages",Qzt="Search historical conversation messages (full-text)",Pzt=`Search this project's full conversation history (all sessions, including subagent messages and content compacted away from the active context).
2940
+ ORDER BY timestamp ASC, id ASC LIMIT ?`).all(...u,...A,i);g.push(...h)}return{anchor:o?l:null,before:d.map(Coe),after:g.map(Coe)}}catch(a){return Ie("hmemory.getMessageContext failed",a),{anchor:null,before:[],after:[]}}}function vLe(e){let t=W3();if(!t||e.length===0)return[];try{let r=e.map(()=>"?").join(","),n=t.prepare(`SELECT ${K3} FROM messages m WHERE m.id IN (${r})`).all(...e),i=new Map(n.map(o=>[o.messageId,Coe(o)]));return e.map(o=>i.get(o)).filter(o=>o!==void 0)}catch(r){return Ie("hmemory.getMessagesByIds failed",r),[]}}var xLe="SearchMessages",Qzt="Search historical conversation messages. Used to recall content that is not in the current context.",Pzt=`Search this project's full conversation history (all sessions, including subagent messages and content compacted away from the active context).
2941
2941
 
2942
2942
  Usage:
2943
2943
  - query: keywords to search. Multiple terms are AND-combined; CJK and English are both supported. Prefer terms of 3+ characters \u2014 very short terms may not match reliably.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@dahawa/hawa-code",
3
- "version": "2.9.6",
3
+ "version": "2.9.8",
4
4
  "bin": {
5
5
  "hcode": "hawa.js"
6
6
  },
package/server.js CHANGED
@@ -597,7 +597,7 @@ data: ${JSON.stringify(L)}
597
597
  `);a=P.pop()||"";for(let L of P){let j=L.trim();if(!(!j||j==="data: [DONE]"))if(j.startsWith("data: ")){let z=j.slice(6);try{let W=JSON.parse(z);D(W)}catch(W){this.logger&&this.logger.error({err:W,line:j},"Failed to parse Gemini SSE chunk")}}else try{let z=JSON.parse(j);D(z)}catch{}}};(async()=>{try{for(;;){let{value:P,done:L}=await s.read();if(L)break;a+=n.decode(P,{stream:!0}),M()}T()}catch(P){o.error(P)}})()}})}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_${mN()}`,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:`
598
598
 
599
599
  [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 rLr(`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"}}},age=new sge;var Uat=De(Pat(),1);jt();Fo();function Wm(e){return e?typeof e.entries=="function"?Object.fromEntries(e.entries()):{...e}:{}}function Lat(e){let t=String(e?.["x-thinking-level"]??"medium").toLowerCase();return["off","low","medium","high"].includes(t)?t:"medium"}function AYr(e,t){if(t==="off"){delete e.reasoning;return}e.reasoning={effort:t}}function hYr(e,t){if(t==="off"){delete e.reasoning;return}e.reasoning={effort:t,summary:"auto"}}function EYr(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 gF(e,t,r){U8(t,e),$8(t,EYr(e,r),r)}function rB(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 AF(e){let t=new Headers(e);return t.delete("content-encoding"),t.delete("content-length"),t.delete("transfer-encoding"),t}function M0e(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 Fat=["/v1/messages"];function Q0e(e){let t;try{typeof e=="string"?t=new mT(e):e instanceof mT?t=e:t=new mT(e.url)}catch{return""}let r=t.pathname;for(let n of Fat){let i=r.indexOf(n);if(i!==-1)return t.origin+r.slice(0,i)}return t.origin}function oW(e,t){let r=typeof e=="string"?e:e instanceof mT?e.toString():e.url,n;try{n=new mT(r).pathname}catch{return!1}return Fat.some(i=>n.includes(i))&&(t.method==="POST"||t.method==="post")}function _Yr(e){return async(t,r)=>{if(!oW(t,r))return e(t,r);let n=JSON.parse(r.body),i=await sY.transformRequestOut(n),o=Q0e(t)+"/chat/completions",s=Wm(r.headers),a=s.authorization??s.Authorization??"";AYr(i,Lat(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}),M0e("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:Wm(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:AF(l.headers)}),I=await sY.transformResponseIn(C,n),T=await I.text();try{gF({...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=rB(l.body),m=new Response(g.stream,{status:l.status,statusText:l.statusText,headers:AF(l.headers)}),A=await sY.transformResponseIn(m,n),E=rB(A.body);return Promise.all([g.done,E.done]).then(async([y,C])=>{try{gF({...f,openai:{...f.openai,response:{body:await dZe(y)}},response:{...f.response,body:await aL(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 yYr(e){return async(t,r)=>{if(!oW(t,r))return e(t,r);let n=JSON.parse(r.body),i=await aY.transformRequestOut(n),o=Wm(r.headers);hYr(i,Lat(o));let s=JSON.stringify(i),l=Q0e(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}),M0e("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:Wm(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:AF(u.headers)}),D=await aY.transformResponseIn(T,n),M=await D.text();try{gF({...m,openai:{...m.openai,response:{body:JSON.parse(I)}},response:{...m.response,body:JSON.parse(M)}},g,"responses")}catch(P){V("\u65E5\u5FD7\u89E3\u6790\u9519\u8BEF(Responses \u975E\u6D41\u5F0F):",P)}return new Response(M,{status:D.status,statusText:D.statusText,headers:D.headers})}let A=rB(u.body),E=new Response(A.stream,{status:u.status,statusText:u.statusText,headers:AF(u.headers)}),y=await aY.transformResponseIn(E,n),C=rB(y.body);return Promise.all([A.done,C.done]).then(async([I,T])=>{try{gF({...m,openai:{...m.openai,response:{body:await uZe(I)}},response:{...m.response,body:await aL(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 bYr(e){return async(t,r)=>{if(!oW(t,r))return e(t,r);let n=JSON.parse(r.body),i=Wm(r.headers),o=await age.transformRequestOut(n),s=JSON.stringify(o),a=Q0e(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}),M0e("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:Wm(r.headers),body:n},response:{status:c.status,statusText:c.statusText,headers:Wm(c.headers)},openai:{request:{body:o},response:{}}},m=rB(c.body),A=new Response(m.stream,{status:c.status,statusText:c.statusText,headers:AF(c.headers)}),E=await age.transformResponseIn(A),y=rB(E.body);return Promise.all([m.done,y.done]).then(async([C,I])=>{try{let T=u?fZe(C):JSON.parse(C),D=u?await aL(I):JSON.parse(I);gF({...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 CYr(e){return async(t,r)=>{if(!oW(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=Wm(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 mT?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 mT?t.toString():t.url,method:r.method,headers:Wm(r.headers),body:JSON.parse(n)},response:{status:a.status,statusText:a.statusText,headers:Wm(a.headers)}};return(async()=>{if(c){let m=await a.text();u.response.body=await aL(m)}else u.response.body=await a.json();let g=Wm(r.headers)["x-agent-id"];U8(g,u),$8(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:
600
- Stack trace: `+f.stack)),new Response(l.body,{status:a.status,statusText:a.statusText,headers:a.headers})}}var iW=null,k0e=!1;function SYr(){iW=null,k0e=!1}It.on("proxy:changed",SYr);function IYr(){if(k0e)return iW;if(k0e=!0,Ge().proxy!==!0)return null;let e=process.env.HTTPS_PROXY||process.env.HTTP_PROXY||process.env.https_proxy||process.env.http_proxy;return e&&(iW=new Uat.ProxyAgent({uri:e}),rt(`[proxy] using proxy: ${e}`)),iW}function TYr(){let e=IYr();return e?((t,r={})=>global.fetch(t,{...r,dispatcher:e})):global.fetch}function sW(e){let t=e||process.env.API_TYPE,r=TYr();switch(t){case"openai":return _Yr(r);case"openai-responses":return yYr(r);case"gemini":return bYr(r);default:return CYr(r)}}HA();var NYr=De(Xe(),1);function qat(e,t){let r=[],n=Math.max(1,Math.floor(t)),i="",o=0;for(let s of e){let a=wYr(s);i&&o+a>n?(r.push(i),i=s,o=a):(i+=s,o+=a)}return i&&r.push(i),r}function wYr(e){if(e===" ")return 4;let t=e.codePointAt(0);return t===void 0||t===0||t<32||t>=127&&t<160||DYr(t)?0:RYr(t)?2:1}function DYr(e){return e>=768&&e<=879||e>=6832&&e<=6911||e>=7616&&e<=7679||e>=8400&&e<=8447||e>=65056&&e<=65071}function RYr(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 hF(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 aW(e){return new Intl.NumberFormat("en",{notation:"compact",maximumFractionDigits:1}).format(e).toLowerCase()}xe();Fo();var jl={totalCost:0,totalAPIDuration:0,startTime:Date.now(),inputTokens:0,outputTokens:0,cacheCreationTokens:0,cacheReadTokens:0,currentContextTokens:0};function lW(e,t){jl.totalCost+=e,jl.totalAPIDuration+=t}function cW(e,t){jl.inputTokens+=e,jl.outputTokens+=t,It.emit("token:change",{inputTokens:jl.inputTokens,outputTokens:jl.outputTokens})}function uW(e,t){jl.cacheCreationTokens+=e,jl.cacheReadTokens+=t}function EF(){return{inputTokens:jl.inputTokens,outputTokens:jl.outputTokens,cacheCreationTokens:jl.cacheCreationTokens,cacheReadTokens:jl.cacheReadTokens}}function Gat(){return jl.totalCost}function zat(){return Date.now()-jl.startTime}function jat(){return jl.totalAPIDuration}function Yat(e){jl.currentContextTokens=e}function Vat(){return jl.currentContextTokens}xe();He();He();var F0e="2.9.6";globalThis.MACRO={VERSION:F0e,PACKAGE_URL:`@dahawa/${ji}`,README_URL:"https://github.com/italking/hawa-code",ISSUES_EXPLAINER:"report the issue at https://github.com/italking/hawa-code/issues"};var dW=process.env.HAWA_CODE_USER_AGENT||`${ji}/${F0e} (${process.env.USER_TYPE})`;xe();xe();ir();function fd(e,t){let r=[],n=new Set,i=new Set;return e.filter(o=>o.type!=="progress"&&o.type!=="reminder").forEach(o=>{switch(o.type){case"user":{let s=tA(r);if(s?.type==="user"){r[r.length-1]=U0e(s,o);return}r.push(o);return}case"assistant":r.push(o);return;case"insert":{let s=tA(r);s?.type==="user"&&(r[r.length-1]=BYr(s,o));return}case"path_rules":{let s=t?.pathRules;if(!s)return;let a=o.content.paths.filter(f=>!n.has(f));if(a.length===0)return;let l=a.map(f=>s.get(f)).filter(f=>f!==void 0);if(a.forEach(f=>n.add(f)),l.length===0)return;let c=Ct([{type:"text",text:`<system-rules>
600
+ Stack trace: `+f.stack)),new Response(l.body,{status:a.status,statusText:a.statusText,headers:a.headers})}}var iW=null,k0e=!1;function SYr(){iW=null,k0e=!1}It.on("proxy:changed",SYr);function IYr(){if(k0e)return iW;if(k0e=!0,Ge().proxy!==!0)return null;let e=process.env.HTTPS_PROXY||process.env.HTTP_PROXY||process.env.https_proxy||process.env.http_proxy;return e&&(iW=new Uat.ProxyAgent({uri:e}),rt(`[proxy] using proxy: ${e}`)),iW}function TYr(){let e=IYr();return e?((t,r={})=>global.fetch(t,{...r,dispatcher:e})):global.fetch}function sW(e){let t=e||process.env.API_TYPE,r=TYr();switch(t){case"openai":return _Yr(r);case"openai-responses":return yYr(r);case"gemini":return bYr(r);default:return CYr(r)}}HA();var NYr=De(Xe(),1);function qat(e,t){let r=[],n=Math.max(1,Math.floor(t)),i="",o=0;for(let s of e){let a=wYr(s);i&&o+a>n?(r.push(i),i=s,o=a):(i+=s,o+=a)}return i&&r.push(i),r}function wYr(e){if(e===" ")return 4;let t=e.codePointAt(0);return t===void 0||t===0||t<32||t>=127&&t<160||DYr(t)?0:RYr(t)?2:1}function DYr(e){return e>=768&&e<=879||e>=6832&&e<=6911||e>=7616&&e<=7679||e>=8400&&e<=8447||e>=65056&&e<=65071}function RYr(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 hF(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 aW(e){return new Intl.NumberFormat("en",{notation:"compact",maximumFractionDigits:1}).format(e).toLowerCase()}xe();Fo();var jl={totalCost:0,totalAPIDuration:0,startTime:Date.now(),inputTokens:0,outputTokens:0,cacheCreationTokens:0,cacheReadTokens:0,currentContextTokens:0};function lW(e,t){jl.totalCost+=e,jl.totalAPIDuration+=t}function cW(e,t){jl.inputTokens+=e,jl.outputTokens+=t,It.emit("token:change",{inputTokens:jl.inputTokens,outputTokens:jl.outputTokens})}function uW(e,t){jl.cacheCreationTokens+=e,jl.cacheReadTokens+=t}function EF(){return{inputTokens:jl.inputTokens,outputTokens:jl.outputTokens,cacheCreationTokens:jl.cacheCreationTokens,cacheReadTokens:jl.cacheReadTokens}}function Gat(){return jl.totalCost}function zat(){return Date.now()-jl.startTime}function jat(){return jl.totalAPIDuration}function Yat(e){jl.currentContextTokens=e}function Vat(){return jl.currentContextTokens}xe();He();He();var F0e="2.9.8";globalThis.MACRO={VERSION:F0e,PACKAGE_URL:`@dahawa/${ji}`,README_URL:"https://github.com/italking/hawa-code",ISSUES_EXPLAINER:"report the issue at https://github.com/italking/hawa-code/issues"};var dW=process.env.HAWA_CODE_USER_AGENT||`${ji}/${F0e} (${process.env.USER_TYPE})`;xe();xe();ir();function fd(e,t){let r=[],n=new Set,i=new Set;return e.filter(o=>o.type!=="progress"&&o.type!=="reminder").forEach(o=>{switch(o.type){case"user":{let s=tA(r);if(s?.type==="user"){r[r.length-1]=U0e(s,o);return}r.push(o);return}case"assistant":r.push(o);return;case"insert":{let s=tA(r);s?.type==="user"&&(r[r.length-1]=BYr(s,o));return}case"path_rules":{let s=t?.pathRules;if(!s)return;let a=o.content.paths.filter(f=>!n.has(f));if(a.length===0)return;let l=a.map(f=>s.get(f)).filter(f=>f!==void 0);if(a.forEach(f=>n.add(f)),l.length===0)return;let c=Ct([{type:"text",text:`<system-rules>
601
601
  ${U7e(l)}
602
602
  </system-rules>`}]),u=tA(r);u?.type==="user"?r[r.length-1]=U0e(u,c,{skipTrailingSystemReminders:!0}):r.push(c);return}case"systemAutoMemory":{let s=t?.autoMemories;if(!s)return;let a=o.content.paths.filter(f=>!i.has(f));a.forEach(f=>i.add(f));let l=a.map(f=>{let g=s.get(f);return g===void 0||g.length===0?null:`## ${f.split(/[\\/]/).pop()||f}
603
603
  ${g}`}).filter(f=>f!==null);if(l.length===0)return;let c=Ct([{type:"text",text:`<system-auto-memory>
@@ -2990,7 +2990,7 @@ CREATE TABLE IF NOT EXISTS index_state (
2990
2990
  WHERE 1=1${c} AND ${m}
2991
2991
  ORDER BY timestamp DESC, id DESC LIMIT ?`).all(...u,...A,n);f.push(...E.reverse())}if(i>0){let m=l.timestamp===null?"id > ?":"(timestamp > ? OR (timestamp = ? AND id > ?))",A=l.timestamp===null?[l.messageId]:[l.timestamp,l.timestamp,l.messageId],E=r.prepare(`SELECT ${w3} FROM messages m
2992
2992
  WHERE 1=1${c} AND ${m}
2993
- ORDER BY timestamp ASC, id ASC LIMIT ?`).all(...u,...A,i);g.push(...E)}return{anchor:o?l:null,before:f.map(zie),after:g.map(zie)}}catch(a){return Ce("hmemory.getMessageContext failed",a),{anchor:null,before:[],after:[]}}}function UQe(e){let t=x3();if(!t||e.length===0)return[];try{let r=e.map(()=>"?").join(","),n=t.prepare(`SELECT ${w3} FROM messages m WHERE m.id IN (${r})`).all(...e),i=new Map(n.map(o=>[o.messageId,zie(o)]));return e.map(o=>i.get(o)).filter(o=>o!==void 0)}catch(r){return Ce("hmemory.getMessagesByIds failed",r),[]}}var $Qe="SearchMessages",E7t="Search historical conversation messages (full-text)",_7t=`Search this project's full conversation history (all sessions, including subagent messages and content compacted away from the active context).
2993
+ ORDER BY timestamp ASC, id ASC LIMIT ?`).all(...u,...A,i);g.push(...E)}return{anchor:o?l:null,before:f.map(zie),after:g.map(zie)}}catch(a){return Ce("hmemory.getMessageContext failed",a),{anchor:null,before:[],after:[]}}}function UQe(e){let t=x3();if(!t||e.length===0)return[];try{let r=e.map(()=>"?").join(","),n=t.prepare(`SELECT ${w3} FROM messages m WHERE m.id IN (${r})`).all(...e),i=new Map(n.map(o=>[o.messageId,zie(o)]));return e.map(o=>i.get(o)).filter(o=>o!==void 0)}catch(r){return Ce("hmemory.getMessagesByIds failed",r),[]}}var $Qe="SearchMessages",E7t="Search historical conversation messages. Used to recall content that is not in the current context.",_7t=`Search this project's full conversation history (all sessions, including subagent messages and content compacted away from the active context).
2994
2994
 
2995
2995
  Usage:
2996
2996
  - query: keywords to search. Multiple terms are AND-combined; CJK and English are both supported. Prefer terms of 3+ characters \u2014 very short terms may not match reliably.