@texra-ai/cli 1.0.0-preview.3 → 1.0.0-preview.4
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/README.md +1 -1
- package/README.npm.md +1 -1
- package/dist/bin/texra.js +2 -2
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -48,7 +48,7 @@ runs directly from your machine to your chosen provider with no TeXRA account.
|
|
|
48
48
|
Task history, settings (`.texra/config.json` and `~/.texra`), and credentials
|
|
49
49
|
(`~/.texra/secrets/`) are shared with the
|
|
50
50
|
[VS Code extension](https://marketplace.visualstudio.com/items?itemName=texra-ai.texra)
|
|
51
|
-
and the
|
|
51
|
+
and the [Desktop App](https://github.com/texra-ai/texra-desktop-releases/releases).
|
|
52
52
|
|
|
53
53
|
## Documentation & Support
|
|
54
54
|
|
package/README.npm.md
CHANGED
|
@@ -48,7 +48,7 @@ runs directly from your machine to your chosen provider with no TeXRA account.
|
|
|
48
48
|
Task history, settings (`.texra/config.json` and `~/.texra`), and credentials
|
|
49
49
|
(`~/.texra/secrets/`) are shared with the
|
|
50
50
|
[VS Code extension](https://marketplace.visualstudio.com/items?itemName=texra-ai.texra)
|
|
51
|
-
and the
|
|
51
|
+
and the [Desktop App](https://github.com/texra-ai/texra-desktop-releases/releases).
|
|
52
52
|
|
|
53
53
|
## Documentation & Support
|
|
54
54
|
|
package/dist/bin/texra.js
CHANGED
|
@@ -1031,7 +1031,7 @@ ${l}
|
|
|
1031
1031
|
${s}`}).join(`
|
|
1032
1032
|
|
|
1033
1033
|
`)}var ZDo,ePo,YVa,JVa,XVa,ZVa,GPt,WPt=N(()=>{"use strict";de();It();ZDo=A.Struct({line:A.Int,character:A.Int}),ePo=A.Struct({severity:A.Literals([0,1,2,3]),message:A.String,range:A.Struct({start:ZDo,end:ZDo})}),YVa=0,JVa=1,XVa=2,ZVa=3,GPt={[YVa]:{label:"error",countKey:"errors",sectionTitle:"Errors"},[JVa]:{label:"warning",countKey:"warnings",sectionTitle:"Warnings"},[XVa]:{label:"info",countKey:"info",sectionTitle:"Info/Hints"},[ZVa]:{label:"hint",countKey:"hints",sectionTitle:"Info/Hints"}};i(qPt,"countBySeverity");i(zPt,"formatCounts");i(tPo,"formatMessageList");i(LHn,"formatGroupedSections")});var eKa,Nte,Ofe,VPt,nPo,rPo,KPt=N(()=>{"use strict";de();Jz();It();XOe();JOe();WPt();eKa=A.Union([A.Struct({event:A.Literal("openFile"),payload:A.Struct({location:Kw,preserveFocus:A.Boolean})}),...sqe.members,A.Struct({event:A.Literal("requestShowError"),payload:rcn})]),Nte=class extends A.TaggedError()("HostCallFailed",{message:A.String}){static{i(this,"HostCallFailed")}},Ofe=RT.make(Pc.make("readDiagnostics",{payload:{path:A.String},success:A.Array(ePo),error:Nte}),Pc.make("addCriticism",{payload:{entry:KDo},success:A.Boolean,error:Nte}),Pc.make("openPdf",{payload:{location:Kw,preserveFocus:A.Boolean},error:Nte}),Pc.make("notices",{payload:{notice:eKa}}),Pc.make("filesWritten",{payload:{absolutePaths:A.Array(A.String)}})),VPt=A.Literals(["readDiagnostics","addCriticism","openPdf","notices","filesWritten"]),nPo=Object.freeze({readDiagnostics:"2 minutes",addCriticism:"10 seconds",openPdf:"30 seconds"}),rPo=A.Union([A.Struct({kind:A.Literal("attached"),attachment:A.String}),A.Struct({kind:A.Literal("call"),message:HPt})])});import{Buffer as iPo}from"node:buffer";import*as sPo from"node:net";import*as ZOe from"node:tls";var tKa,YPt,nKa,oPo,rKa,oKa,FHn,aPo,UHn=N(()=>{Hd();eo();Yn();Zn();Zn();M2();Tc();HI();dm();Sle();tKa="Deno"in globalThis,YPt=class extends cr()("@effect/platform-node/NodeSocket/NetSocket"){static{i(this,"NetSocket")}},nKa=i((e,t)=>{let n=e.read();if(n===null)return;let r=[n],o;for(;r.length<t&&(o=e.read())!==null;)r.push(o);return r},"readAvailable"),oPo=i(e=>bf(bie(e),t=>iPo.from(t)),"toBuffers"),rKa=i((e,t)=>{e.closed===!1&&(!t||!("destroySoon"in e)?e.destroy():e.destroySoon())},"closeSocket"),oKa=i(e=>FHn(Cf(t=>{let n,r=!1;return ze(Da(Fo(t,Xc),St(()=>{n&&rKa(n,r)})),()=>Su(o=>{n=sPo.createConnection(e),n.once("connect",()=>{r=!0,o(ve(n))}),n.on("error",s=>{o(Ze(new Hu({reason:new kU({kind:"Unknown",cause:s})})))})}))}),e),"makeNet"),FHn=i((e,t)=>Qi(n=>{let r,o=Cd(!1),s=n.context,a=t?.tlsServer===!0,c=t?.chunkSize??4096,l=c===1/0||Number.isSafeInteger(c)&&c>0?c:4096,u=a?"secure":"secureConnect",d=Br(function*(){let y=yield*uh,S=yield*Eu(e,y).pipe(t?.openTimeout!==void 0?m2({duration:t.openTimeout,orElse:i(()=>Ze(new Hu({reason:new kU({kind:"Timeout",cause:new Error("Connection timed out")})})),"orElse")}):en),_,b,v,x=!1,R=!1,O=!0;function T(){if(b===void 0||x)return;let pe=v;if(v=void 0,pe===void 0&&!R){x=!0;try{pe=nKa(S,l)}finally{x=!1}}if(R&&(pe=void 0),b===void 0){v=pe;return}let Ae=pe!==void 0?ve(pe):_!==void 0?Ze(_):void 0;if(Ae===void 0)return;let Ie=b;b=void 0,Ie(Ae)}i(T,"drain");function B(pe){_??=pe,T()}i(B,"end");function D(pe){_??=pe,R=!0,v=void 0,T()}i(D,"close");function M(){B(new Hu({reason:new qP({code:1e3})}))}i(M,"onEnd");function L(pe){D(new Hu({reason:new GP({cause:pe})}))}i(L,"onError");function H(pe){let Ae=new Hu({reason:new qP({code:pe?1006:1e3})});pe?D(Ae):B(Ae)}i(H,"onClose");function V(pe){pe.on("readable",T),pe.on("end",M),pe.on("error",L),pe.on("close",H)}i(V,"attachReadListeners");function $(pe){pe.off("readable",T),pe.off("end",M),pe.off("error",L),pe.off("close",H)}return i($,"detachReadListeners"),tKa||S.pause(),V(S),yield*Da(y,St(()=>{D(new Hu({reason:new qP({code:1006})})),$(S),o.closeUnsafe(),r=void 0,O=!1})),r=S,o.openUnsafe(),{pull:Su(pe=>{if(b=pe,T(),b===pe)return St(()=>{b===pe&&(b=void 0)})}),upgrade:i((pe={})=>wt(()=>{if(!O)return Ze(new Hu({reason:new OU({cause:new Error("socket is already upgraded or closed")})}));let Ae=pe.key!==void 0,Ie=pe.cert!==void 0;return a&&(!Ae||!Ie)||Ae!==Ie?Ze(new Hu({reason:new OU({cause:new Error(a?"server TLS upgrade requires both key and cert":"TLS upgrade credentials must include both key and cert")})})):Su(ge=>{let _e=S;$(_e);let ce;try{let Ue={secureContext:ZOe.createSecureContext({key:pe.key===void 0?void 0:bf(bie(pe.key),oe=>iPo.from(Ey(oe))),cert:pe.cert===void 0?void 0:oPo(pe.cert),ca:pe.ca===void 0?void 0:oPo(pe.ca),passphrase:pe.passphrase===void 0?void 0:Ey(pe.passphrase)}),ALPNProtocols:pe.alpnProtocols===void 0?void 0:[...pe.alpnProtocols],requestCert:pe.requestCert,rejectUnauthorized:pe.rejectUnauthorized};ce=a?new ZOe.TLSSocket(_e,{...Ue,isServer:!0}):ZOe.connect({...Ue,servername:pe.servername,socket:_e})}catch(He){V(_e),ge(Ze(new Hu({reason:new OU({cause:He})})));return}S=ce,r=ce,ce.pause();function se(){ce.off(u,Z),ce.off("error",ue),ce.off("close",we)}i(se,"cleanup");function Z(){se(),O=!1,V(ce),ge(ht)}i(Z,"succeed");function ue(He){se();let Ue=new Hu({reason:new OU({cause:He})});D(Ue),ge(Ze(Ue))}i(ue,"failUpgrade");function we(){ue(new Error("socket closed during TLS upgrade"))}return i(we,"onUpgradeClose"),ce.once(u,Z),ce.once("error",ue),ce.once("close",we),St(()=>{se(),D(new Hu({reason:new qP({code:1006})})),ce.destroy()})})}),"upgrade")}}).pipe(KR(y=>Ed(s,y))),p=i(y=>Su(S=>{function _(){y.off("drain",b),y.off("error",v),y.off("close",x)}i(_,"cleanup");function b(){_(),S(ht)}i(b,"onDrain");function v(R){_(),S(Ze(new Hu({reason:new _N({cause:R})})))}i(v,"onError");function x(){_(),S(Ze(new Hu({reason:new _N({cause:new Error("socket closed")})})))}return i(x,"onClose"),y.on("drain",b),y.on("error",v),y.on("close",x),St(_)}),"awaitDrain"),f=i(y=>wt(()=>{let S=r;if(S===void 0)return o.whenOpen(f(y));if(N0e(y))return S.destroy(y.code>1e3?new Error(`closed with code ${y.code}`):void 0),ht;try{return S.write(y)?ht:p(S)}catch(_){return Ze(new Hu({reason:new _N({cause:_})}))}}),"write"),h=i(y=>wt(()=>{let S=r;if(S===void 0)return o.whenOpen(h(y));let _=!1;try{if(y.length===1)_=!S.write(y[0]);else{S.cork();try{for(let b=0;b<y.length;b++)_=!S.write(y[b])||_}finally{S.uncork()}}}catch(b){return Ze(new Hu({reason:new _N({cause:b})}))}return _?p(S):ht}),"writeAll"),g=Mu(ve({write:f,writeAll:h}),()=>St(()=>{!r||r.writableEnded||r.end()}));return ve(A6e({reader:d,writer:g}))}),"fromDuplex"),aPo=G_(oKa,Ui(pX))});var cPo=N(()=>{UHn()});function JPt(e){return XS(e)?"interrupted":e.approval==="own"?"waitingOnUser":e.outcome!==null?e.outcome:e.position==="running"&&e.turn===null&&gce(e.identity)?e.forkPoint===null?"starting":"resuming":e.position}function QHn(e){return XS(e)?"interrupted":e.approval==="own"?"waiting":e.holder==="here"&&e.position!=="ready"?"running":"recent"}var lPo,XPt=N(()=>{"use strict";de();It();lPo=A.Union([iqe,pN,A.Literals(["starting","resuming","interrupted","waitingOnUser"])]);i(JPt,"runStatusKey");i(QHn,"runSection")});function jHn(e){let t=new Map(e.stages.map(a=>[a.id,[]])),n=[];for(let a of e.rows){let c=a.stageId===void 0?void 0:t.get(a.stageId);c===void 0?n.push(a):c.push(a)}let r=[],o=0,{stages:s}=e;for(let a of n){for(;o<s.length&&s[o].seqNo<a.seqNo;){let c=s[o];r.push({kind:"stage",stage:c,rows:t.get(c.id)??[]}),o+=1}r.push({kind:"row",row:a})}for(let a of s.slice(o))r.push({kind:"stage",stage:a,rows:t.get(a.id)??[]});return r}var HHn=N(()=>{"use strict";i(jHn,"transcriptTimeline")});function pPo(e,t){if(t.approval==="own")return t;if(t.approval==="descendant")for(let n of t.childIds){let r=e.runs.get(n),o=r===void 0?void 0:pPo(e,r);if(o)return o}}function aKa(e,t,n){let{result:r}=e.log;switch(e.model.status){case Bf.COMPLETED:return r?.status==="executed"&&r.reusedFrom!==void 0?"reused":"finished";case Bf.FAILED:return r?.status==="error"&&r.name==="Skipped"?"skipped":e.cutByRunEnd===!0?t&&n===void 0?"not run":"cancelled":"failed";case"interrupted":return"interrupted";default:return t&&n===void 0?"queued":"running"}}function cKa(e,t,n){let r=e.log.toolName.trim(),o=dPo.has(r),s=Ye.isObject(e.log.input)?e.log.input:{},a=t.childIds.map(_=>n.runs.get(_)).findLast(_=>_?.launch?.card===e.id),c=aKa(e,o,a),l=a===void 0?void 0:pPo(n,a),u=l===void 0?void 0:n.requests.find(_=>_.runId===l.id),d=c!=="running"&&c!=="queued"&&a?.outcome!=null?a:void 0,p=[o?uPo(s):void 0,o?a?.modelLabel??GHn(s.model):void 0,e.attempt!==void 0&&e.attempt>1?"retried":void 0,o?Zjr({input:$Hn(s.inputFiles),context:$Hn(s.contextFiles),media:$Hn(s.mediaFiles)}):void 0,d!==void 0?lb(d.lastTimestamp-d.launchedAt):void 0,d!==void 0&&d.treeUsage.cost>0?vk(d.treeUsage.cost):void 0].filter(Ye.isNotUndefined),f=o?GHn(s.label)??uPo(s)??r:[e.model.headerLabel,e.model.headerPreview].filter(_=>_.length>0).join(" "),h;if(u!==void 0)h={kind:"request",payload:u.payload};else if(c==="failed"){let{errorText:_}=A4e(e.log);_.length>0&&(h={kind:"error",text:_})}else c==="not run"?h={kind:"notRun"}:c==="interrupted"&&(h={kind:"interrupted"});let g=KOt(e.log.result),y=o&&(c==="finished"||c==="reused")?g??a?.latestLine:a?.latestLine,S=y==null?void 0:uKa(y);return{id:e.id,toolName:r,label:f,status:c,section:e.section??null,facts:p,...h!==void 0?{detail:h}:{},...a!==void 0?{childRunId:a.id}:{},...l!==void 0?{askingRunId:l.id}:{},needsYou:u!==void 0&&l!==void 0,talkable:o&&l===void 0&&a!==void 0&&z$(a),...S!==void 0&&S.length>0?{summary:S}:{}}}function lKa(e){return[...Map.groupBy(e,t=>t.section)].map(([t,n])=>({title:t,calls:n}))}function uKa(e){return e.split(`
|
|
1034
|
-
`).map(t=>t.trim()).find(t=>t.length>0)??""}function ZPt(e){return e.kind==="tool"&&e.stageId!==void 0}function G7e(e,t){return jHn(e.transcript).flatMap(n=>{if(n.kind!=="stage")return[];let{stage:r}=n,o=n.rows.filter(ZPt).map(c=>cKa(c,e,t));if(o.length===0)return[];let s=new Set(o.map(c=>c.id)),a=0;for(let c of e.childIds){let l=t.runs.get(c);l?.launch?.card!=null&&s.has(l.launch.card)&&(a+=l.treeUsage.cost)}return[{id:r.id,outcome:r.end?.outcome??null,calls:o,sections:lKa(o),agents:o.filter(c=>dPo.has(c.toolName)).length,needsYou:o.filter(c=>c.needsYou).length,costUsd:a}]})}var uPo,dPo,GHn,$Hn,fPo=N(()=>{"use strict";de();vn();W$();wP();DEt();mv();Sc();CMn();HHn();uPo=i(e=>GHn(e.agentName??e.name),"nameOf"),dPo=new Set(["agent",Q$,"self"]);i(pPo,"askingRun");GHn=i(e=>typeof e=="string"&&e.length>0?e:void 0,"stringOf"),$Hn=i(e=>Array.isArray(e)?e.flatMap(t=>typeof t=="string"?[WS(t)]:[]):[],"namesOf");i(aKa,"statusOf");i(cKa,"callView");i(lKa,"sectionsOf");i(uKa,"firstLine");i(ZPt,"isScriptCall");i(G7e,"scriptStages")});var $v=N(()=>{"use strict";C7e();fNt();vn();Fee();F1e();gCe();mKe();SU();fPo();HHn();yMn()});var qHn,q7e,z7e,eMt=N(()=>{"use strict";de();It();qHn=class extends A.TaggedError()("Invalid",{reason:A.String}){static{i(this,"Invalid")}},q7e=class extends A.TaggedError()("Internal",{ref:A.String}){static{i(this,"Internal")}},z7e=Oqe.mapMembers(e=>[...e,qHn,q7e])});var Nfe,mPo,zHn=N(()=>{"use strict";de();Nfe=A.Literals(["input","context","media"]),mPo=A.Union([Nfe,A.Literals(["base","edited"])])});var dKa,pKa,hPo,APo=N(()=>{"use strict";de();dKa=Object.freeze(["general","models","agents","memory","plugins","latex"]),pKa=Object.freeze({models:Object.freeze(["keys","subscriptions","models"]),agents:Object.freeze(["skills","advanced"]),plugins:Object.freeze([]),latex:Object.freeze(["dependencies","compile","formatting","vscode"]),memory:Object.freeze([]),general:Object.freeze(["appearance","approval","privacy","git"])}),hPo=A.Literals(dKa.flatMap(e=>[e,...pKa[e].map(t=>`${e}/${t}`)]))});function gPo(e,t){let n=Bfe(e),r=n===null?void 0:t.runs.get(n);return r===void 0||r.parentId!==null||(WHn(e,r.id).seen??-1/0)>=r.lastTimestamp?e:W7e(e,r.id,o=>({...o,seen:r.lastTimestamp}))}var yPo=N(()=>{"use strict";Dfe();i(gPo,"markShownRunSeen")});function Bfe(e){return e.shown._tag==="Run"?e.shown.runId:null}function WHn(e,t){return e.runs.get(t)??{draft:bPo,expanded:void 0,disclosures:new Map,seen:void 0,rejected:void 0}}function CPo(e,t,n){return dgt(n,t.runs)||e.runs.get(n.id)?.expanded===!0}function VHn(e,t){return Eo(A.Array(A.Tuple([e,t])),[])}function vPo(e){return yKa(e,A.decodeUnknownSync(gKa)({}))}function yKa(e,t){return{session:e,requestError:null,shown:YHn(t.selected),arriving:null,runs:new Map(t.runs.map(([n,r])=>[n,{draft:{...bPo,text:r.draft},expanded:r.expanded,disclosures:new Map(r.groups),seen:r.seen,rejected:void 0}])),polishing:new Set,sending:new Set,deleting:new Set,launch:t.launch,requestDrafts:new Map(t.requestDrafts),drawerOpen:t.drawerOpen,toolsSheetOpen:!1,storageHintDismissed:t.storageHintDismissed,search:"",workbench:t.workbench}}function EKa(e,t){let n=[...e].filter(([r])=>t.runs.has(r));return n.length===e.size?e:new Map(n)}function SKa(e){return t=>t===null||e.runs.has(t)?t:e.order.at(0)??null}function IPo(e,t,n=SKa(t)){let r=e,{arriving:o}=e;o!==null&&t.runs.has(o.runId)?r=JHn(e,{kind:"select",runId:o.runId}):o!==null&&t.cursor>=o.cursor&&(r={...e,arriving:null});let s=EKa(r.runs,t),{shown:a}=r,c=a;if(a._tag==="Proposal")t.requests.some(l=>l.runId===a.runId&&l.requestId===a.requestId)||(c=KHn);else{let l=n(Bfe(r));l!==Bfe(r)&&(c=YHn(l))}return c===a&&s===r.runs?r:{...r,runs:s,shown:c}}function EPo(e,t,n){let r=new Map(e);return n===null?r.delete(t):r.set(t,n),r}function W7e(e,t,n){return{...e,runs:new Map(e.runs).set(t,n(WHn(e,t)))}}function JHn(e,t){switch(t.kind){case"dismissRequestError":return{...e,requestError:null};case"reportError":return{...e,requestError:new as({reason:t.reason})};case"select":return{...e,shown:YHn(t.runId),arriving:null,drawerOpen:!1};case"selectOnArrival":return{...e,arriving:{runId:t.runId,cursor:t.cursor}};case"selectNew":return{...e,shown:KHn,arriving:null,drawerOpen:!1,requestError:null,launch:{...e.launch,instruction:"",skills:[],chat:null}};case"editProposal":return{...e,shown:{_tag:"Proposal",...t.proposal},arriving:null,drawerOpen:!1,requestError:null,launch:{...e.launch,...t.patch}};case"toggleDrawer":return{...e,drawerOpen:!e.drawerOpen};case"drawer":return{...e,drawerOpen:t.open};case"toolsSheet":return{...e,toolsSheetOpen:t.open};case"dismissStorageHint":return{...e,storageHintDismissed:!0};case"search":return{...e,search:t.value};case"draft":return W7e(e,t.runId,n=>({...n,draft:{...n.draft,...t.patch}}));case"launch":return{...e,launch:{...e.launch,...t.patch}};case"requestDraft":return{...e,requestDrafts:EPo(e.requestDrafts,t.key,t.draft)};case"expand":return W7e(e,t.runId,n=>({...n,expanded:t.expanded}));case"group":return W7e(e,t.runId,n=>({...n,disclosures:EPo(n.disclosures,t.key,t.expanded)}));case"workbench":return{...e,workbench:t.layout};case"seen":return gPo(e,t.view)}}var fKa,SPo,mKa,tMt,nMt,hKa,_Po,KHn,YHn,bPo,AKa,gKa,Dfe=N(()=>{"use strict";de();It();gi();P7e();yPo();fKa=Ace.mapFields(In.assign({editedFile:A.optional(A.NullOr(A.String)).pipe(A.decodeTo(A.String,{decode:Ii.transformOptional(e=>at.some(at.getOrUndefined(e)??"")),encode:Ii.transform(e=>e)}))})),SPo=["label","system","tools","toolScope"],mKa=A.Struct(In.pick(gh.fields,SPo)),tMt=i(e=>In.pick(e,SPo),"chatOf"),nMt=fKa.mapFields(In.assign({workingDirectory:Eo(A.String,""),model:Eo(A.String,tHn),commit:Eo(A.String,"HEAD"),instruction:Eo(A.String,""),skills:Eo(A.Array(A.String),[]),chat:Eo(A.NullOr(mKa),null),baseFile:Eo(A.String,""),approval:Eo(A.Literals(["policy","autoApprove"]),"policy")})),hKa=In.lambda(e=>A.optional(A.toType(e))),_Po=nMt.mapFields(In.map(hKa)),KHn=Object.freeze({_tag:"New"}),YHn=i(e=>e===null?KHn:{_tag:"Run",runId:e},"shownOf");i(Bfe,"shownRun");bPo=Object.freeze({text:"",images:Object.freeze([])});i(WHn,"runSurface");i(CPo,"runExpanded");i(VHn,"entries");AKa=A.Struct({note:A.optionalKey(A.String),model:A.optionalKey(A.String),answers:A.optionalKey(A.Array(A.Struct({selected:A.Array(A.String),text:A.String})))}),gKa=A.Struct({selected:Eo(A.NullOr(Cr),null),launch:Eo(nMt,{}),runs:VHn(Cr,A.Struct({draft:Eo(A.String,""),expanded:A.optionalKey(A.Boolean),groups:VHn(A.String,A.Boolean),seen:A.optionalKey(A.Number)})),requestDrafts:VHn(A.String,AKa),drawerOpen:Eo(A.Boolean,!1),storageHintDismissed:Eo(A.Boolean,!1),workbench:Eo(A.NullOr(A.Record(A.String,A.Unknown)),null)});i(vPo,"emptySurface");i(yKa,"loadSurface");i(EKa,"retain");i(SKa,"projectSelection");i(IPo,"pruneSurface");i(EPo,"withEntry");i(W7e,"updateRun");i(JHn,"applySurfaceAction")});var _Ka,wQ,bKa,xPo,wPo=N(()=>{"use strict";de();It();zHn();APo();Dfe();_Ka=A.Literals(["createSampleProject","cloneOverleaf","downloadArxiv"]),wQ={runId:Cr},bKa=A.Literals(["compare","latexdiff","accept"]),xPo=A.Union([A.Struct({kind:A.Literal("openFile"),path:A.NonEmptyString,line:A.optional(A.Int.check(A.isGreaterThan(0)))}),A.Struct({kind:A.Literal("openLabel"),label:A.String}),A.Struct({kind:A.Literal("openRunStorage"),...wQ}),A.Struct({kind:A.Literal("exportTranscript"),...wQ}),A.Struct({kind:A.Literal("resume"),...wQ}),A.Struct({kind:A.Literal("runAgain"),...wQ}),A.Struct({kind:A.Literal("fork"),...wQ,at:A.optional(A.Int.check(A.isGreaterThan(0))),draft:A.optional(A.String),media:A.optional(A.Array(cU))}),A.Struct({kind:A.Literal("runCompileFixer"),...wQ}),A.Struct({kind:A.Literal("useOwnApiKey"),...wQ,requestId:A.NonEmptyString,credentialSwitch:BAt}),A.Struct({kind:A.Literal("latexdiff"),...wQ}),A.Struct({kind:A.Literal("pack"),...wQ}),A.Struct({kind:A.Literal("clean"),...wQ}),A.Struct({kind:A.Literal("latexdiffCommit"),baseFile:A.optional(A.String),commit:A.optional(A.String),action:A.Literals(["latexdiffvc","packLatexdiffvc","cleanLatexdiffvc"])}),A.Struct({kind:A.Literal("record"),action:A.Union([A.Struct({kind:A.Literal("start"),target:A.Union([Cr,A.Literal("launch")])}),A.Struct({kind:A.Literal("stop")})])}),A.Struct({kind:A.Literal("popOut")}),A.Struct({kind:A.Literal("popBack")}),A.Struct({kind:A.Literal("refreshCommits")}),A.Struct({kind:A.Literal("refreshFiles")}),A.Struct({kind:A.Literal("openSettings"),target:A.optional(hPo)}),A.Struct({kind:A.Literal("pickFiles"),fileType:Nfe}),A.Struct({kind:A.Literal("useCurrentFile"),fileType:mPo}),A.Struct({kind:A.Literal("addOpenedFiles"),fileType:Nfe}),A.Struct({kind:A.Literal("attachDroppedFiles"),paths:A.Array(A.String),category:Nfe}),A.Struct({kind:A.Literal("launch"),launch:nMt,instruction:A.String}),A.Struct({kind:A.Literal("polish"),text:A.String}),A.Struct({kind:A.Literal("savePastedImage"),fileName:A.NonEmptyString,base64:A.NonEmptyString}),A.Struct({kind:A.Literal("workspaceFile"),action:A.Union([A.Struct({kind:A.Literal("list"),directory:A.String}),A.Struct({kind:A.Literal("read"),path:A.String}),A.Struct({kind:A.Literal("write"),path:A.String,contents:A.String,base:A.NullOr(A.String)})])}),A.Struct({kind:A.Literal("toolEdit"),requestId:A.NonEmptyString,action:A.Literals(["approve","openDiff","previewProposed","showLatexdiff"]),grant:A.optional(A.Literals(yv))}),A.Struct({kind:A.Literal("fileAction"),action:bKa,file:A.String,base:A.Union([A.Struct({kind:A.Literal("runOutput"),...wQ}),A.Struct({kind:A.Literal("file"),path:A.String})])}),A.Struct({kind:A.Literal("apiKeyBanner"),action:A.Literals(["set","guide"])}),A.Struct({kind:A.Literal("recheckDependencies")}),A.Struct({kind:A.Literal("openInstallGuide")}),A.Struct({kind:A.Literal("dismissBanner"),banner:A.Literals(["gettingStarted","dependency"])}),A.Struct({kind:A.Literal("gettingStarted"),action:_Ka}),A.Struct({kind:A.Literal("onboarding"),action:A.Literals(["signInChatGpt","setApiKey","skip","runSetup","skipSetup","openGettingStarted"])})])});var CKa,TPo,RPo=N(()=>{"use strict";de();It();CKa=A.Struct({availability:Ecn,unavailableReason:A.optional(A.String),usageRoute:A.optional(L$),routeLabel:A.optional(A.String)}),TPo=A.Struct({value:A.String,label:A.String,provider:A.optional(A.String),context:A.optional(A.String),cost:A.optional(A.String),hint:A.optional(A.String),reasoning:A.optional(A.String),...CKa.fields})});function kPo(e){return WS(e)||e}var vKa,IKa,xKa,wKa,TKa,OPo,XHn=N(()=>{"use strict";de();It();RPo();vKa=A.Struct({value:A.String,label:A.String}),IKa=A.Struct({label:A.String,interchangeable:A.Boolean,usedFor:A.String}),xKa=A.Struct({baseFile:A.Array(A.String),editedFile:A.Array(A.String),commit:A.Array(A.String)}),wKa=A.Struct({key:A.NonEmptyString,name:A.String});i(kPo,"projectName");TKa=A.Literals(["needs-credential","setup","done"]),OPo=A.Struct({project:wKa,modelOptions:A.Array(TPo),tools:A.Struct({icons:A.Record(A.String,A.String),terminalOutput:A.Array(A.String)}),workspaceRoots:A.Array(vKa),approvalPolicy:rCe,fileOptions:xKa,isGitRepo:A.Boolean,recording:A.NullOr(A.Struct({session:A.String,target:A.String})),banners:A.Struct({apiKey:A.Boolean,dependency:A.NullOr(A.Array(IKa)),gettingStarted:A.Boolean,service:A.NullOr(A.Union([A.Struct({kind:A.Literal("offline"),reason:A.String}),A.Struct({kind:A.Literal("local"),reason:A.String})]))}),onboarding:TKa})});var ZHn,e$n,RKa,kKa,Lup,NPo,Fup,Uup,BPo=N(()=>{"use strict";de();Jz();It();$v();XOe();eMt();wPo();XHn();Dfe();ZHn=A.Struct({debug:A.Boolean,cursor:sx,aggregates:A.Array(JAt)}),e$n=A.Struct({cursor:sx,inputs:A.Array(Pcn)}),RKa=A.Union([A.Struct({kind:A.Literal("done")}),A.Struct({kind:A.Literal("files"),paths:A.Array(A.String)}),A.Struct({kind:A.Literal("text"),text:A.String}),A.Struct({kind:A.Literal("savedImage"),fileName:A.String}),A.Struct({kind:A.Literal("entries"),entries:A.Array(A.Struct({path:A.String,isDirectory:A.Boolean}))}),A.Struct({kind:A.Literal("contents"),contents:A.String}),A.Struct({kind:A.Literal("changedOnDisk")})]),kKa=A.Union([A.Struct({kind:A.Literal("selectNew")}),A.Struct({kind:A.Literal("select"),runId:Cr}),A.Struct({kind:A.Literal("selectOnArrival"),runId:Cr,cursor:sx}),A.Struct({kind:A.Literal("showSessions"),runId:Cr}),A.Struct({kind:A.Literal("submit")}),A.Struct({kind:A.Literal("draft"),runId:Cr,text:A.String,images:A.Array(A.Struct({fileName:A.String,media:cU}))}),A.Struct({kind:A.Literal("chime")}),A.Struct({kind:A.Literal("launch"),patch:_Po})]),Lup=RT.make(Pc.make("session.frames",{payload:ZHn,success:e$n,stream:!0}),Pc.make("session.host",{success:OPo,stream:!0}),Pc.make("session.actions",{success:kKa,stream:!0}),Pc.make("session.request",{payload:{request:Rqe},success:kqe,error:z7e}),Pc.make("host.request",{payload:{request:xPo},success:RKa,error:z7e})),NPo={session:A.NonEmptyString,client:A.NonEmptyString},Fup=A.Struct({...NPo,message:HPt}),Uup=A.Struct({...NPo,message:$Pt})});import{randomUUID as OKa}from"node:crypto";import t$n from"node:path";var DPo,eNe,V7e=N(()=>{"use strict";de();Rn();Co();It();DPo=A.Union([A.Struct({kind:A.Literal("anything")}),A.Struct({kind:A.Literal("absent")}),A.Struct({kind:A.Literal("holds"),contents:A.String})]),eNe=m.fn("writeFileIfUnchanged")(function*(e,t,n){let r=yield*ot.FileSystem;return yield*m.gen(function*(){let o=yield*Sa(r,e).pipe(m.catchIf(br,()=>m.succeed(null)));if(o===t)return!0;if(o!==null&&(n.kind==="absent"||n.kind==="holds"&&o!==n.contents))return!1;let s=o===null?e:yield*r.realPath(e),a=o===null?void 0:(yield*r.stat(s)).mode&4095,c=t$n.join(t$n.dirname(s),`.${t$n.basename(s)}.${OKa()}.tmp`);return yield*r.writeFileString(c,t).pipe(m.andThen(a===void 0?m.void:r.chmod(c,a)),m.andThen(r.rename(c,s)),m.onError(()=>r.remove(c,{force:!0}).pipe(m.ignore({log:"Warn",message:`A staged project file stays behind: ${c}`}))),m.uninterruptible),!0}).pipe(vQ(e))},m.catchTag("PlatformError",e=>m.fail(new as({reason:e.message}))))});import{hash as NKa}from"node:crypto";var Mfe,rMt,BKa,nNe,DKa,n$n,BT,LPo,PKa,Xq,Pfe,r$n,cL,tNe,MKa,LKa,Lfe,FPo,PPo,MPo,Ffe,Zz=N(()=>{"use strict";de();Jz();xQ();It();XOe();XPt();$v();BPo();eMt();V7e();KPt();Mfe="1.0.0-preview.3",rMt=A.Struct({protocol:A.NonEmptyString,version:A.String,pid:A.Int.check(A.isGreaterThan(0)),socket:A.String,startedAt:A.Int.check(A.isGreaterThan(0)),clients:Jr,running:Jr,draining:A.Boolean}),BKa=rMt.mapFields(In.pick(["pid","startedAt"])).mapFields(In.assign({socket:A.NonEmptyString})),nNe=Object.freeze({name:"texra-service",schema:BKa}),DKa=A.Struct({workspace:A.String,runId:Cr,label:A.String,statusKey:lPo,launchedAt:A.Int.check(A.isGreaterThan(0)),live:A.Boolean}),n$n=A.Struct({runId:Cr,activation:sx}),BT=class extends A.TaggedError()("TaskFailed",{message:A.String}){static{i(this,"TaskFailed")}},LPo=A.Union([BT,Ry,Kz,mB]),PKa=A.Union([...LPo.members,Rfe]),Xq=class extends A.TaggedError()("TaskRecordsFailed",{runId:Cr,message:A.String}){static{i(this,"TaskRecordsFailed")}},Pfe=class extends A.TaggedError()("ProjectStateFailed",{message:A.String}){static{i(this,"ProjectStateFailed")}},r$n=A.Record(A.String,A.Struct({value:A.optional(A.Json)})),cL=A.String,tNe=Object.freeze({exists:A.Boolean,readConfig:A.NullOr(gh),readReport:A.NullOr(A.String),readRunEnd:A.NullOr(dU),readResult:A.NullOr(ocn),readWorkspaceFiles:A.Array(icn),readSkills:A.Array(A.String),readContinues:A.Boolean,readConversation:A.Array(Ucn),readTrace:Lcn}),MKa={workspace:cL,runId:Cr},LKa=In.keys(tNe).map(e=>Pc.make(`records.${e}`,{payload:MKa,success:tNe[e],error:Xq})),Lfe=RT.make(Pc.make("service.hello",{payload:{protocol:A.String},success:rMt}),Pc.make("service.stop",{payload:{drain:A.Boolean}}),Pc.make("tasks.list",{payload:{all:A.Boolean},success:A.Array(DKa)}),Pc.make("task.watch",{payload:{workspace:cL,subscribe:ZHn},success:e$n,error:BT,stream:!0}),Pc.make("task.request",{payload:{workspace:cL,request:Rqe},success:kqe,error:z7e}),Pc.make("task.start",{payload:{workspace:cL,start:eln.members[1]},success:n$n,error:LPo}),Pc.make("task.resume",{payload:{workspace:cL,runId:Cr,apiKeys:A.optional(A.Record(A.String,A.String))},success:n$n,error:PKa}),Pc.make("task.result",{payload:n$n.mapFields(In.assign({workspace:cL})),success:dU.mapFields(In.assign({at:sx})),error:BT}),Pc.make("session.view",{payload:{workspace:cL,runIds:A.Array(Cr)},success:rln,error:BT}),Pc.make("session.listRuns",{payload:{workspace:cL},success:A.Array(scn),error:BT}),Pc.make("session.deleteRuns",{payload:{workspace:cL,target:A.Union([Cr,A.Literal("all")])},success:A.Struct({deleted:A.Array(Cr),active:A.Array(Cr),failed:A.Array(A.Struct({runId:Cr,error:Oqe}))}),error:BT}),...LKa,Pc.make("host.attach",{payload:{workspace:cL,capabilities:A.Array(VPt)},success:rPo,error:BT,stream:!0}),Pc.make("state.get",{payload:{workspace:cL,keys:A.Array(A.String)},success:r$n,error:Pfe}),Pc.make("state.set",{payload:{workspace:cL,next:r$n,ifCurrent:A.NullOr(r$n)},success:A.Boolean,error:Pfe}),Pc.make("file.write",{payload:{path:A.String,contents:A.String,expected:DPo},success:A.Boolean,error:as}),Pc.make("host.focus",{payload:{attachment:A.String}}),Pc.make("host.answer",{payload:{attachment:A.String,message:$Pt}})),FPo=i(e=>NKa("sha256",JSON.stringify(e),"hex").slice(0,12),"digest12"),PPo=i(e=>{let t=e.successSchema,n=ofe.isStreamSchema(t)?[e.payloadSchema,t.success,t.error,e.errorSchema]:[e.payloadSchema,t,e.errorSchema];return FPo(n.map(r=>A.toJsonSchemaDocument(r)))},"shapeOf"),MPo=Object.freeze(Object.fromEntries([...[...Lfe.requests].map(([e,t])=>[e,PPo(t)]),...[...Ofe.requests].map(([e,t])=>[`window.${e}`,PPo(t)])])),Ffe=Object.freeze({digest:FPo([FRt,Object.entries(MPo).toSorted(([e],[t])=>e.localeCompare(t))]),shapes:MPo})});import{hash as FKa}from"node:crypto";import{lstatSync as UKa}from"node:fs";import*as Zq from"node:path";function Bte(e){let t=Zq.join(e,"run"),n=Zq.join(t,"serve.log"),r=FKa("sha256",Zq.resolve(e),"hex").slice(0,16),o=Zq.join(t,o$n(4294967295));if(Buffer.byteLength(o)<=QKa)return{runDirectory:t,log:n,socketDirectory:t,socketFor:i(a=>Zq.join(t,o$n(a)),"socketFor")};let s=Zq.join("/tmp",`texra-${process.getuid?.()??0}-${r}`);return{runDirectory:t,log:n,socketDirectory:s,socketFor:i(a=>Zq.join(s,o$n(a)),"socketFor")}}function HKa(e){let t=i((n,r)=>YI.badArgument({module:"TexraService",method:"prepareServiceDirectories",description:n,cause:r}),"failure");return m.try({try:i(()=>UKa(e),"try"),catch:i(n=>t(et(n),n),"catch")}).pipe(m.filterOrFail(n=>{let r=process.getuid?.();return n.isDirectory()&&(r===void 0||n.uid===r)},()=>t(`${e} is not a directory this user owns; remove it and start the service again`)),m.asVoid)}function $Ka(e){try{return process.kill(e,0),!0}catch(t){return Ye.hasProperty(t,"code")&&t.code==="EPERM"}}var UPo,QKa,jKa,o$n,Y7e,oMt,K7e,QPo,jPo,HPo,$Po,GPo,qPo,J7e=N(()=>{"use strict";de();Rn();It();Zz();UPo="service",QKa=100,jKa=/^serve-(\d+)\.sock$/,o$n=i(e=>`serve-${e}.sock`,"socketName"),Y7e="serve";i(Bte,"servicePaths");oMt=m.fn("prepareServiceDirectories")(function*(e){let t=yield*ot.FileSystem;for(let n of new Set([e.runDirectory,e.socketDirectory]))yield*t.makeDirectory(n,{recursive:!0,mode:448}),yield*HKa(n),yield*t.chmod(n,448)});i(HKa,"ownDirectory");K7e="current",QPo=i((e,t)=>e?.pid===t?.pid&&e?.startedAt===t?.startedAt,"sameService"),jPo=De.unwrap(m.map(jg,e=>e.changes(nNe,[K7e]))),HPo=m.flatMap(jg,e=>m.map(e.get(nNe,K7e),t=>t??null)),$Po=m.fn("claimServiceRecord")(function*(e,t){let n=yield*jg;for(;;){let r=yield*n.get(nNe,K7e),o=r===void 0?null:yield*t(r);if(o!==null)return o;if(yield*n.modify(nNe,[K7e],({current:a})=>Re.succeed(QPo(a,r)?[!0,{current:e}]:[!1])))return null}}),GPo=m.fn("releaseServiceRecord")(function*(e,t){yield*(yield*jg).modify(nNe,[K7e],({current:o})=>Re.succeed(QPo(o,t)?[void 0,{current:void 0}]:[void 0])),yield*(yield*ot.FileSystem).remove(e.socketFor(t.pid),{force:!0})},m.catch(Ir(UPo,"Could not remove the service files"))),qPo=m.fn("removeDeadSockets")(function*(e){let t=yield*ot.FileSystem,n=(yield*t.readDirectory(e.socketDirectory)).filter(r=>{let o=Number(jKa.exec(r)?.[1]);return Number.isInteger(o)&&!$Ka(o)});yield*m.forEach(n,r=>t.remove(Zq.join(e.socketDirectory,r),{force:!0}),{concurrency:8,discard:!0})},m.catch(Ir(UPo,"Could not remove dead services' sockets")));i($Ka,"processAlive")});import{spawn as GKa}from"node:child_process";import{closeSync as qKa,existsSync as ydp,openSync as zKa}from"node:fs";import{join as WKa}from"node:path";function p$n(e){return m.scoped(m.flatMap(d$n(e),t=>t["service.hello"]({protocol:Ffe.digest}))).pipe(m.timeout(YKa),m.map(t=>t),m.catch(t=>JPo(t)?m.succeed(null):t._tag==="TimeoutError"?m.fail(new df({reason:`The TeXRA service on ${e} accepts connections but did not answer (${t.message}). Stop it with \`texra service stop\`, or end its process.`,failure:{kind:"unanswered"}})):m.fail(new df({reason:`The TeXRA service on ${e} speaks a protocol this build cannot read (${t.message}).`,failure:{kind:"unreadable",socket:e}}))))}function XPo(e,t,n,r={}){let o=Bte(e),s=m.gen(function*(){yield*oMt(o);let a=yield*m.try({try:i(()=>zKa(o.log,"a",384),"try"),catch:s$n});return yield*m.callback(c=>{let l=GKa(t,[...n],{cwd:o.runDirectory,detached:!0,stdio:["ignore",a,a],env:{...Zi.filter(process.env,(d,p)=>p==="HOME"||p.startsWith("TEXRA_")),NODE_COMPILE_CACHE:WKa(o.runDirectory,"compile-cache"),...r}});l.once("error",d=>c(m.fail(s$n(d))));let u=Nn.makeUnsafe();l.once("exit",(d,p)=>{d!==0&&Nn.doneUnsafe(u,m.succeed(p===null?`exited with code ${d}`:`was ended by ${p}`))}),l.once("spawn",()=>{l.unref(),c(m.succeed(Nn.await(u)))})}).pipe(m.ensuring(m.sync(()=>qKa(a))))}).pipe(m.catchTag("PlatformError",a=>m.fail(s$n(a))),m.provide(zw));return{storageRoot:e,start:s}}var sMt,rNe,VPo,VKa,df,u$n,i$n,KKa,a$n,YKa,iMt,KPo,YPo,zPo,d$n,JPo,aMt,c$n,s$n,l$n,WPo,f$n,JKa,XKa,X7e,ZPo,ZKa,m$n,Dte,eMo,cMt,tMo,nMo,eYa,rMo,e4=N(()=>{"use strict";cPo();de();Jz();gi();xQ();It();Co();J7e();Zz();sMt=i(()=>Object.fromEntries(RGe.flatMap(e=>{let t=process.env[e]?.trim();return t?[[e,t]]:[]})),"environmentApiKeys"),rNe=i((e,t,n)=>e["task.request"]({workspace:t,request:n.kind==="followUp.send"?{...n,apiKeys:n.apiKeys??sMt()}:n}).pipe(m.filterOrFail(r=>Zcn(n.kind,r),r=>new as({reason:`The TeXRA service answered a ${n.kind} with ${r.kind}.`}))),"requestOnService"),VPo=i((e,t)=>m.map(e["tasks.list"]({all:!0}),n=>{let r=n.find(s=>s.runId===t),o=r?[r]:n.filter(s=>s.runId.startsWith(t));return o.length===1?{task:o[0]}:{matches:o}}),"findTask"),VKa=A.Union([A.Struct({kind:A.Literal("failed")}),A.Struct({kind:A.Literal("none")}),A.Struct({kind:A.Literal("incompatible")}),A.Struct({kind:A.Literal("unreadable"),socket:A.String}),A.Struct({kind:A.Literal("unanswered")}),A.Struct({kind:A.Literal("startFailed")})]),df=class extends A.TaggedError()("ServiceUnavailable",{reason:A.String,failure:VKa.pipe(A.withConstructorDefault(m.succeed({kind:"failed"})))}){static{i(this,"ServiceUnavailable")}get message(){return this.reason}},u$n="The TeXRA service does not run on Windows yet.",i$n="TEXRA_NO_SERVICE",KKa="no TeXRA service is running",a$n="60 seconds",YKa="10 seconds",iMt=i(e=>e.protocol===Ffe.digest,"compatible"),KPo=i((e,t)=>{let n=dk.parse(e.version),r=dk.parse(Mfe);return Re.isSuccess(n)&&Re.isSuccess(r)&&t(n.success,r.success)},"builds"),YPo=i(e=>!iMt(e)&&KPo(e,dk.isGreaterThan),"isNewer"),zPo=i(e=>KPo(e,dk.isLessThan)||!iMt(e)&&!YPo(e),"isOlder"),d$n=m.fn("connectService")(function*(e,t=m.void){let n=yield*gt.build(lB.layerProtocolSocket().pipe(gt.provide(aPo({path:e})),gt.provide(Xee.layerNdjson),gt.provide(gt.succeed(lB.ConnectionHooks,{onConnect:m.void,onDisconnect:t}))));return yield*lB.make(Lfe).pipe(m.provideContext(n))}),JPo=i(e=>(e._tag==="RpcClientError"||e._tag==="SocketError")&&e.reason?._tag==="SocketOpenError","nobodyListens");i(p$n,"probeService");aMt=HPo.pipe(m.mapError(e=>new df({reason:`The service record could not be read: ${e.message}`})),m.flatMap(e=>e===null?m.succeed(null):p$n(e.socket))),c$n=class extends A.TaggedError()("ServiceStartFailed",{message:A.String,cause:A.Defect()}){static{i(this,"ServiceStartFailed")}},s$n=i(e=>new c$n({message:jo(e).message,cause:e}),"startFailed");i(XPo,"spawnService");l$n=i((e,t)=>m.scoped(m.gen(function*(){let n=yield*Nn.make();yield*(yield*d$n(e,m.asVoid(Nn.succeed(n,void 0))))["service.stop"]({drain:t},{discard:!0}),yield*Nn.await(n)})).pipe(m.catchIf(JPo,()=>m.void)),"stopService"),WPo="30 seconds",f$n=m.gen(function*(){let e=yield*aMt.pipe(m.catch(n=>{let{failure:r}=n;return r.kind==="unreadable"?m.succeed({socket:r.socket}):m.fail(n)}));if(e===null)return null;let t=e.pid===void 0?"the TeXRA service":`the TeXRA service (pid ${e.pid})`;return yield*l$n(e.socket,!1).pipe(m.timeoutOrElse({duration:WPo,orElse:i(()=>m.fail(new df({reason:`it did not exit within ${WPo}`})),"orElse")}),m.mapError(n=>new df({reason:`Could not stop ${t}: ${n.message}`}))),e.pid===void 0?{}:{pid:e.pid}}),JKa=i(e=>new df({reason:`The running TeXRA service (${e.version}, pid ${e.pid}) is newer than this TeXRA (${Mfe}) and speaks another protocol. Update TeXRA, or stop the service with \`texra service stop\`.`,failure:{kind:"incompatible"}}),"newerService"),XKa=m.fn("server.ensureService")(function*({storageRoot:e,start:t},n,r,o){let s=aMt.pipe(m.tap(p=>p===null||iMt(p)?m.void:YPo(p)?m.fail(JKa(p)):o?m.void:m.fail(new df({reason:ZPo,failure:{kind:"incompatible"}})))),a=yield*s.pipe(m.map(p=>({found:p,replaced:!1})),m.catch(p=>{let{failure:f}=p;return!o||f.kind!=="unreadable"?m.fail(p):o("Stopping an incompatible TeXRA service after its active tasks finish, then starting this version.").pipe(m.andThen(l$n(f.socket,!0).pipe(m.mapError(h=>new df({reason:`Could not stop the older TeXRA service: ${h.message}`})))),m.as({found:null,replaced:!0}))})),c=a.found,{replaced:l}=a;if(!o&&c?.draining)return yield*new df({reason:X7e});if(o&&c!==null&&(zPo(c)||c.draining)){let p=c;l=zPo(p);let f=yr(p.running,"running task");yield*(p.running>0?o:m.logInfo)(p.draining?`Waiting for TeXRA service ${p.version} (pid ${p.pid}) to finish ${f} and exit.`:`Updating TeXRA service ${p.version}: waiting for ${f} to finish before restarting.`),yield*l$n(p.socket,!0).pipe(m.mapError(h=>new df({reason:`Could not stop the older TeXRA service (pid ${p.pid}): ${h.message}`}))),c=null}if(c===null&&!l&&!n)return yield*new df({reason:KKa,failure:{kind:"none"}});if(c===null){let{log:p}=Bte(e),f=yield*t.pipe(m.mapError(S=>new df({reason:`The TeXRA service could not be started: ${S.message}`,failure:{kind:"startFailed"}}))),h=new df({reason:`TeXRA service did not respond within ${a$n} (log: ${p}).`,failure:{kind:"startFailed"}}),g=yield*ui.make(h),y=s.pipe(m.retry({while:i(S=>S.failure.kind==="unanswered","while")}),m.flatMap(S=>S!==null&&iMt(S)&&!S.draining?m.succeed(S):m.fail(h)),m.tapError(S=>ui.set(g,S)),m.catchIf(S=>S.failure.kind!=="incompatible"&&(o!==void 0||S.failure.kind!=="unreadable"),()=>m.succeed(null)));c=yield*jPo.pipe(De.mapEffect(()=>y),De.filter(Ye.isNotNull),De.runHead,m.flatMap(at.match({onNone:i(()=>m.flatMap(ui.get(g),m.fail),"onNone"),onSome:m.succeed})),m.timeoutOrElse({duration:a$n,orElse:i(()=>m.flatMap(ui.get(g),m.fail),"orElse")}),m.raceFirst(m.flatMap(f,S=>m.fail(new df({reason:`TeXRA service ${S} before responding (log: ${p}).`,failure:{kind:"startFailed"}})))))}let{socket:u}=c,d=yield*d$n(u,r).pipe(m.mapError(p=>new df({reason:`The TeXRA service on ${u} could not be reached: ${p.message}`})));return{info:c,client:d}}),X7e="The TeXRA service is offline; TeXRA is reconnecting to it.",ZPo="The running TeXRA service uses a different protocol. Reopen this terminal session or reload the window using the updated build.",ZKa=i(e=>({get:An.get(e),changes:An.changes(e)}),"followed"),m$n=i((e,t)=>({state:ZKa(e),client:{get:m.map(An.get(e),({client:n})=>n),changes:An.changes(e).pipe(De.map(({client:n})=>n),De.changes)},refusalTold:t}),"linkOver"),Dte=i(e=>m.flatMap(e.state.get,t=>"away"in t?m.fail(new df({reason:t.away})):m.succeed(t.client)),"linkedClient"),eMo=i(e=>e.state.changes.pipe(De.map(t=>"away"in t?t.away:null),De.changes),"linkOutage"),cMt=i(e=>e.state.changes.pipe(De.map(t=>"away"in t&&t.lasting?t.away:null),De.changes,De.filter(Ye.isNotNull)),"linkRefusals"),tMo=Xo.min([Xo.exponential("500 millis"),Xo.spaced("10 seconds")]),nMo=3,eYa=tMo.pipe(Xo.upTo({times:nMo-1})),rMo=m.fn("server.linkService")(function*(e,t){if(yield*mq(i$n))return yield*new df({reason:`${i$n} is set`,failure:{kind:"none"}});if(ru)return yield*new df({reason:u$n,failure:{kind:"none"}});let n=m.fn("connect")(function*(d,p,f){let h=yield*Dn.make(),g=yield*Nn.make();return{connection:yield*XKa(d,p,m.asVoid(Nn.succeed(g,void 0)),f).pipe(Dn.provide(h),m.onError(()=>Dn.close(h,zt.void))),lost:g,scope:h}}),r=yield*n(e,t.startsService,t.waiting),o=r,s=yield*An.make({client:r.connection.client}),a=i((d,p=!1)=>An.set(s,{client:null,away:d,lasting:p}),"awayFor"),c=yield*ui.make(!1);yield*m.addFinalizer(()=>m.suspend(()=>Dn.close(r.scope,zt.void)));let l=m.suspend(()=>{let d="";return n({storageRoot:e.storageRoot,start:m.succeed(m.never)},!0).pipe(m.catchIf(p=>p.failure.kind==="startFailed",()=>n(e,t.startsService)),m.tapError(p=>m.suspend(()=>p.message===d?m.void:(d=p.message,(p.failure.kind==="incompatible"||p.failure.kind==="unreadable"?a(ZPo,!0):a(X7e)).pipe(m.andThen(m.logWarning(`The TeXRA service is not back yet: ${p.message}`)))))),m.retry({schedule:tMo,while:i(p=>p.failure.kind!=="startFailed","while")}),m.tap(p=>m.logInfo(`Reconnected to the TeXRA service ${p.connection.info.version} (pid ${p.connection.info.pid}).`)))}),u=m.gen(function*(){let d=o??(yield*l);o=null,r=d,yield*ui.set(c,!1),yield*An.set(s,{client:d.connection.client}),yield*Nn.await(d.lost),yield*a(X7e),yield*Dn.close(d.scope,zt.void);let{pid:p,startedAt:f}=d.connection.info,h=(yield*Ar.currentTimeMillis)-f;if(yield*m.logWarning(`The TeXRA service (pid ${p}) went away; reconnecting.`),h<Zt.toMillis(a$n))return yield*new df({reason:`The TeXRA service (pid ${p}) went away ${Math.max(0,Math.round(h/1e3))} seconds after it started.`,failure:{kind:"startFailed"}})});return yield*m.forkScoped(m.forever(m.retry(u,eYa)).pipe(m.catch(d=>{let p=`The TeXRA service failed to start ${nMo} times in a row, so TeXRA stopped restarting it. The last failure: ${d.reason.replace(/\.$/,"")}. Its log is ${Bte(e.storageRoot).log}. Fix what the log names, then restart TeXRA (in VS Code, reload the window); with ${i$n}=1 set, TeXRA runs tasks without the service.`;return a(p,!0).pipe(m.andThen(m.logError(p)))}))),m$n(s,c)})});import{randomUUID as tYa}from"node:crypto";var oMo,nYa,Ufe,rYa,oYa,iMo,iYa,Pte,lMt=N(()=>{"use strict";Co();de();Jz();JOe();KPt();Rn();XOe();e4();oMo="service",nYa={openFile:i(e=>({event:"openFile",payload:e}),"openFile"),requestShowInstruction:i(e=>({event:"requestShowInstruction",payload:e}),"requestShowInstruction"),requestShowError:i(e=>({event:"requestShowError",payload:e}),"requestShowError")},Ufe=class extends A.TaggedError()("WindowCallFailed",{reason:A.Literals(["detached","no-answer","failed"]),message:A.String}){static{i(this,"WindowCallFailed")}},rYa=64,oYa=i(e=>e.roots.workspace??e.roots.storage,"projectOf"),iMo=i(()=>{let e=new Set,t=i((d,p)=>{let f;for(let h of e)h.key===d&&h.capabilities.has(p)&&(f===void 0||h.focusedAt>f.focusedAt)&&(f=h);return f},"target"),n=i((d,p)=>t(d,p)!==void 0,"offers"),r=i(d=>d.pipe(m.catchCause(Ir(oMo,"A TeXRA window did not take a host call"))),"tell"),o=i((d,p,f)=>m.suspend(()=>{let h=t(d,p);if(h===void 0)return m.fail(new Ufe({reason:"detached",message:"No TeXRA window is open for this project."}));let g=nPo[p];return f(h.calls).pipe(m.mapError(y=>new Ufe({reason:"failed",message:y.message})),m.timeoutOrElse({duration:g,orElse:i(()=>m.fail(new Ufe({reason:"no-answer",message:`The TeXRA window did not respond within ${g}.`})),"orElse")}),m.catchCause(y=>Qt.hasFails(y)?m.failCause(y):m.fail(Qt.hasDies(y)?new Ufe({reason:"failed",message:`The TeXRA window returned an unexpected response for ${p}.`}):new Ufe({reason:"detached",message:"The TeXRA window closed before responding."}))))}),"ask"),s=m.fn("detach")(function*(d){e.delete(d),[...e].some(p=>p.key===d.key)||(yield*m.logWarning(`No TeXRA window of ${d.project} is attached: its tasks run without diagnostics, inline criticism or PDF opening until one attaches.`))});return{windows:e,detach:s,interactionsOf:i(d=>{let p=d.roots.storage;return{emit:i((f,h)=>{let g=t(p,"notices"),y=nYa[f](h);return g===void 0?Ir(oMo,`Host notice ${f}`)(h):r(g.calls.notices({notice:y},{discard:!0}))},"emit")}},"interactionsOf"),answer:i((d,p)=>m.suspend(()=>{for(let f of e)if(f.id===d)return f.reply(p);return m.logWarning(`A TeXRA window answered a host call after its attachment ${d} ended`)}),"answer"),focus:i(d=>m.map(Ar.currentTimeMillis,p=>{for(let f of e)f.id===d&&(f.focusedAt=p)}),"focus"),filesWritten:i(d=>m.forEach([...e].filter(p=>p.capabilities.has("filesWritten")&&d.some(f=>Zp(p.project,f))),p=>r(p.calls.filesWritten({absolutePaths:d},{discard:!0})),{discard:!0}),"filesWritten"),editors:jPt(i(d=>({get readDiagnostics(){if(n(d,"readDiagnostics"))return p=>o(d,"readDiagnostics",f=>f.readDiagnostics({path:p})).pipe(m.mapError(f=>new UPt({reason:f.reason==="failed"?"read-failed":f.reason,path:p,message:f.message})))},get addCriticism(){if(n(d,"addCriticism"))return p=>o(d,"addCriticism",f=>f.addCriticism({entry:p}))},get openPdf(){if(n(d,"openPdf"))return({location:p,preserveFocus:f})=>o(d,"openPdf",h=>h.openPdf({location:p,preserveFocus:f})).pipe(m.mapError(h=>new QPt({path:p.absolutePath,message:h.message})))}}),"editorOf"))}},"makeWindowTable"),iYa=m.fn("make")(function*(e){let{windows:t,detach:n,interactionsOf:r,answer:o,focus:s}=e,a=yield*Ma.make({lookup:i(l=>l.attach(r(l)),"lookup")}),c=i((l,u)=>De.unwrap(m.gen(function*(){let d=yield*vi.bounded(rYa),{protocol:p,receive:f}=yield*XDo(y=>vi.offer(d,{kind:"call",message:y}).pipe(m.asVoid)),h=yield*lB.make(Ofe).pipe(m.provideService(lB.Protocol,p)),g={id:tYa(),key:l.roots.storage,project:oYa(l),capabilities:new Set(u),focusedAt:yield*Ar.currentTimeMillis,calls:h,reply:f};return t.add(g),yield*m.addFinalizer(()=>n(g)),yield*Ma.get(a,Gs.byReferenceUnsafe(l)),De.concat(De.succeed({kind:"attached",attachment:g.id}),De.fromQueue(d))})),"attach");return{attach:c,filesWritten:e.filesWritten,focus:s,answer:o,localLink:i(l=>m.zipWith(An.make({client:{"host.attach":i(({capabilities:u})=>c(l,u),"host.attach"),"host.answer":i(u=>o(u.attachment,u.message),"host.answer"),"host.focus":i(({attachment:u})=>s(u),"host.focus")}}),ui.make(!1),m$n),"localLink")}}),Pte=class e extends Ve.Service()("@texra-ai/texra/server/HostWindows"){static{i(this,"HostWindows")}static{this.layer=i(t=>gt.effect(e,iYa(t)),"layer")}}});import{fileURLToPath as r7a}from"node:url";import{tracingChannel as o7a,channel as i7a}from"node:diagnostics_channel";import{posix as u7a,win32 as F$n}from"node:path";import{fileURLToPath as d7a}from"node:url";import{lstatSync as p7a,readdir as f7a,readdirSync as m7a,readlinkSync as h7a,realpathSync as A7a}from"fs";import*as g7a from"node:fs";import{lstat as y7a,readdir as E7a,readlink as S7a,realpath as _7a}from"node:fs/promises";import{EventEmitter as $$n}from"node:events";import JMo from"node:stream";import{StringDecoder as b7a}from"node:string_decoder";function h$n(e){return isNaN(e)?e.charCodeAt(0):parseInt(e,10)}function _Ya(e){return e.replace(pYa,DMo).replace(fYa,PMo).replace(mYa,Q$n).replace(hYa,MMo).replace(AYa,LMo)}function bYa(e){return e.replace(aYa,"\\").replace(cYa,"{").replace(lYa,"}").replace(uYa,",").replace(dYa,".")}function A$n(e,t){for(let n=0;n<t.length;n++)e.push(t[n])}function CYa(e){let t=[],n="";for(;;){let r=BMo("{","}",e);if(!r){let l=e.split(",");return l[0]=n+l[0],A$n(t,l),t}let{pre:o,body:s,post:a}=r,c=o.split(",");if(c[0]=n+c[0],c[c.length-1]+="{"+s+"}",!a.length)return A$n(t,c),t;n=c.pop(),A$n(t,c),e=a}}function vYa(e,t={}){if(!e)return[];let{max:n=gYa,maxLength:r=yYa,maxDepth:o=EYa,maxRewrites:s=SYa}=t;return e.slice(0,2)==="{}"&&(e="\\{\\}"+e.slice(2)),O$n(_Ya(e),n,r,o,0,s,!0).map(bYa)}function IYa(e){return"{"+e+"}"}function xYa(e){return/^-?0\d/.test(e)}function wYa(e,t){return e<=t}function TYa(e,t){return e>=t}function Z7e(e,t,n,r,o,s){let a=[],c=0;for(let l=0;l<e.length;l++)for(let u=0;u<n.length;u++){if(a.length>=r)return a;let d=e[l]+t+n[u];if(!(s&&!d)){if(c+d.length>o)return a;a.push(d),c+=d.length}}return a}function RYa(e,t,n,r){let o=e.split(/\.\./),s=[];if(o[0]===void 0||o[1]===void 0)return s;let a=h$n(o[0]),c=h$n(o[1]),l=Math.max(o[0].length,o[1].length),u=o.length===3&&o[2]!==void 0?Math.max(Math.abs(h$n(o[2])),1):1,d=wYa;c<a&&(u*=-1,d=TYa);let p=o.some(xYa),f=0;for(let h=a;d(h,c)&&s.length<n;h+=u){let g;if(t)g=String.fromCharCode(h),g==="\\"&&(g="");else if(g=String(h),p){let y=l-g.length;if(y>0){let S=new Array(y+1).join("0");h<0?g="-"+S+g.slice(1):g=S+g}}if(f+g.length>r)break;s.push(g),f+=g.length}return s}function O$n(e,t,n,r,o,s,a){if(o>r)return[e];let c=[""],l=0,u=!1,d=!0;for(;;){let p=BMo("{","}",e);if(!p)return Z7e(c,e,[""],t,n,u);let f=p.pre;if(/\$$/.test(f)){if(c=Z7e(c,f+"{"+p.body+"}",[""],t,n,u&&!p.post.length),d=!1,!p.post.length)break;e=p.post;continue}let h=/^-?\d+\.\.-?\d+(?:\.\.-?\d+)?$/.test(p.body),g=/^[a-zA-Z]\.\.[a-zA-Z](?:\.\.-?\d+)?$/.test(p.body),y=h||g,S=p.body.indexOf(",")>=0;if(!y&&!S){if(l<s&&p.post.match(/,(?!,).*\}/)){l++,e=p.pre+"{"+p.body+Q$n+p.post,a=!0;continue}return Z7e(c,f+"{"+p.body+"}"+p.post,[""],t,n,u)}d&&(u=a&&!y,d=!1);let _;if(y)_=RYa(p.body,g,t,n);else{let b=CYa(p.body);if(b.length===1&&b[0]!==void 0&&(b=O$n(b[0],t,n,r,o+1,s,!1).map(IYa),b.length===1)){if(c=Z7e(c,f+b[0],[""],t,n,u&&!p.post.length),!p.post.length)break;e=p.post;continue}let v=u&&!p.post.length&&!f;for(let R=0;v&&R<c.length;R++)c[R]&&(v=!1);_=[];let x=0;e:for(let R=0;R<b.length;R++){let O=O$n(b[R],t,n,r,o+1,s,!1);for(let T=0;T<O.length;T++){let B=O[T];if(!(v&&!B)){if(_.length>=t||x+B.length>n)break e;_.push(B),x+=B.length}}}}if(c=Z7e(c,f,_,t,n,u&&!p.post.length),!p.post.length)break;e=p.post}return c}function kMt(e,t={}){return new rW(e,t).streamSync()}function yLo(e,t={}){return new rW(e,t).stream()}function OMt(e,t={}){return new rW(e,t).walkSync()}async function NMo(e,t={}){return new rW(e,t).walk()}function NMt(e,t={}){return new rW(e,t).iterateSync()}function ELo(e,t={}){return new rW(e,t).iterate()}var BMo,sMo,sYa,DMo,PMo,Q$n,MMo,LMo,aYa,cYa,lYa,uYa,dYa,pYa,fYa,mYa,hYa,AYa,gYa,yYa,EYa,SYa,N$n,g$n,pJe,aMo,kYa,OYa,eJe,y$n,NYa,B$n,BYa,Hfe,DYa,FMo,uMt,UMo,j$n,PYa,MYa,QMo,jMo,LYa,FYa,UYa,HMo,cMo,D$n,$Mo,QYa,jYa,HYa,$Ya,GMo,GYa,lMo,qYa,zYa,dMt,uMo,dMo,IMt,H$n,qMo,gB,oNe,WYa,VYa,zMo,pMo,KYa,qy,YYa,eW,JYa,P$n,XYa,ZYa,e7a,fMo,WMo,t7a,n7a,E$n,mMo,Fte,hMo,M$n,S$n,bMt,_$n,pMt,tJe,xMt,L$n,AMo,b$n,$fe,Gv,aJe,s7a,C$n,VMo,gMo,a7a,c7a,Lte,KMo,CMt,l7a,RMt,yMo,C7a,v7a,I7a,tW,nW,Mte,fMt,nJe,mMt,EMo,hMt,SMo,TQ,iNe,l0,rJe,sNe,u0,DT,d0,v$n,AMt,Fx,oS,I$n,x$n,_Mo,w$n,t4,T$n,gMt,oJe,Qfe,AB,iJe,x7a,w7a,T7a,R7a,XMo,k7a,O7a,N7a,wMt,B7a,lJe,ZMo,D7a,P7a,M7a,bMo,L7a,F7a,U7a,Q7a,uL,eLo,tLo,n4,nLo,rLo,jfe,oLo,lL,sJe,R$n,CMo,uJe,RQ,yMt,vMt,vMo,j7a,k$n,IMo,dJe,xMo,EMt,wMo,H7a,iLo,E1,sLo,cLo,uLo,G$n,q$n,dLo,Ydp,$7a,G7a,q7a,z7a,pLo,W7a,TMo,V7a,hLo,K7a,RMo,SMt,_Mt,Y7a,gLo,kMo,OMo,J7a,rW,z$n,X7a,Z7a,eJa,tJa,nJa,TMt,BMt=N(()=>{BMo=i((e,t,n)=>{let r=e instanceof RegExp?sMo(e,n):e,o=t instanceof RegExp?sMo(t,n):t,s=r!==null&&o!=null&&sYa(r,o,n);return s&&{start:s[0],end:s[1],pre:n.slice(0,s[0]),body:n.slice(s[0]+r.length,s[1]),post:n.slice(s[1]+o.length)}},"re"),sMo=i((e,t)=>{let n=t.match(e);return n?n[0]:null},"We"),sYa=i((e,t,n)=>{let r,o,s,a,c,l=n.indexOf(e),u=n.indexOf(t,l+1),d=l;if(l>=0&&u>0){if(e===t)return[l,u];for(r=[],s=n.length;d>=0&&!c;){if(d===l)r.push(d),l=n.indexOf(e,d+1);else if(r.length===1){let p=r.pop();p!==void 0&&(c=[p,u])}else o=r.pop(),o!==void 0&&o<s&&(s=o,a=u),u=n.indexOf(t,d+1);d=l<u&&l>=0?l:u}r.length&&a!==void 0&&(c=[s,a])}return c},"js"),DMo="\0SLASH"+Math.random()+"\0",PMo="\0OPEN"+Math.random()+"\0",Q$n="\0CLOSE"+Math.random()+"\0",MMo="\0COMMA"+Math.random()+"\0",LMo="\0PERIOD"+Math.random()+"\0",aYa=new RegExp(DMo,"g"),cYa=new RegExp(PMo,"g"),lYa=new RegExp(Q$n,"g"),uYa=new RegExp(MMo,"g"),dYa=new RegExp(LMo,"g"),pYa=/\\\\/g,fYa=/\\{/g,mYa=/\\}/g,hYa=/\\,/g,AYa=/\\\./g,gYa=1e5,yYa=4e6,EYa=1e3,SYa=1e3;i(h$n,"oe");i(_Ya,"Qs");i(bYa,"ti");i(A$n,"he");i(CYa,"ei");i(vYa,"Ge");i(IYa,"si");i(xYa,"ii");i(wYa,"ni");i(TYa,"ri");i(Z7e,"ct");i(RYa,"oi");i(O$n,"ae");N$n=i((e,t)=>e===t?{t:"lit",ch:String(e)}:{t:"class",re:new RegExp(`^[${e}-${t}]$`)},"fe"),g$n=i((e,t)=>t.map(n=>[N$n(e,e),...n]),"ce"),pJe=i((e,t)=>{if(!e)return[[]];let n=+e[0],r=+t[0],o=e.slice(1),s=t.slice(1);if(n===r)return g$n(n,pJe(o,s));let a="0".repeat(o.length),c="9".repeat(o.length),l=[];o!==a&&l.push(...g$n(n++,pJe(o,c)));let u=s===c?[]:g$n(r--,pJe(a,s));return n<=r&&l.push([N$n(n,r),...Array.from(o,()=>N$n(0,9))]),l.push(...u),l},"ft"),aMo=i((e,t,n)=>{if(n)return pJe(String(e).padStart(n,"0"),String(t).padStart(n,"0"));let r=[];for(let o=String(e).length;o<=String(t).length;o++){let s=Math.max(e,o===1?0:10**(o-1)),a=Math.min(t,10**o-1);r.push(...pJe(String(s),String(a)))}return r},"He"),kYa=i((e,t)=>{let n=Number(e),r=Number(t);if(!Number.isSafeInteger(n)||!Number.isSafeInteger(r))return;n>r&&([n,r]=[r,n]);let o=/^-?0\d/.test(e)||/^-?0\d/.test(t)?Math.max(e.length,t.length):0,s=[];if(n<0){let a=aMo(Math.max(-r,1),-n,o&&o-1);s.push(...a.map(c=>[{t:"lit",ch:"-"},...c]))}return r>=0&&s.push(...aMo(Math.max(n,0),r,o)),s},"qe"),OYa={"[:alnum:]":["\\p{L}\\p{Nl}\\p{Nd}"],"[:alpha:]":["\\p{L}\\p{Nl}"],"[:ascii:]":["\\x00-\\x7f"],"[:blank:]":["\\p{Zs}\\t"],"[:cntrl:]":["\\p{Cc}"],"[:digit:]":["\\p{Nd}"],"[:graph:]":["\\p{Z}\\p{C}",!0],"[:lower:]":["\\p{Ll}"],"[:print:]":["\\p{C}",!0],"[:punct:]":["\\p{P}\\p{S}"],"[:space:]":["\\p{Z}\\t\\r\\n\\v\\f"],"[:upper:]":["\\p{Lu}"],"[:word:]":["\\p{L}\\p{Nl}\\p{Nd}\\p{Pc}"],"[:xdigit:]":["A-Fa-f0-9"]},eJe=i(e=>e.replace(/[[\]\\-]/g,"\\$&"),"ut"),y$n=/$./,NYa=i((e,t,n=!1,r)=>{let o=i(_=>{let b=r?_.normalize(r):_;return[...b].length===1?b:_},"i"),s=t;if(e.charAt(s)!=="[")throw new Error("not in a brace expression");let a=[],c=[],l=s+1,u=!1,d=!1,p=!1,f=s,h="";e:for(;l<e.length;){let _=String.fromCodePoint(e.codePointAt(l));if((_==="!"||_==="^")&&l===s+1){p=!0,l++;continue}if(_==="]"&&u&&!d){f=l+1;break}if(u=!0,_==="\\"&&!d){d=!0,l++;continue}if(_==="["&&!d){for(let[v,[x,R]]of Object.entries(OYa))if(e.startsWith(v,l)){if(h)return[y$n,e.length-s];l+=v.length,R?c.push(x):a.push(x);continue e}}d=!1;let b=o(_);if(h){b.codePointAt(0)>h.codePointAt(0)?a.push(eJe(h)+"-"+eJe(b)):b===h&&a.push(eJe(b)),h="",l+=_.length;continue}if(e.startsWith("-]",l+_.length)){a.push(eJe(b+"-")),l+=_.length+1;continue}if(e.startsWith("-",l+_.length)){h=b,l+=_.length+1;continue}a.push(eJe(b)),l+=_.length}if(f<l)return[y$n,0];if(!a.length&&!c.length)return[y$n,e.length-s];let g="["+(p?"^":"")+a.join("")+"]",y="["+(p?"":"^")+c.join("")+"]",S="^"+(a.length&&c.length?"("+g+"|"+y+")":a.length?g:y);return[new RegExp(S,n?"iu":"u"),f-s]},"Ke"),B$n={t:"match",id:0},BYa="!?+*@",Hfe=i(e=>({t:"lit",ch:e}),"Z"),DYa=i(e=>e.replace(/[\\^$.*+?()[\]{}|/]/g,"\\$&"),"li"),FMo=i(e=>new RegExp(`^${DYa(e)}$`,"iu"),"Je"),uMt=new Map,UMo=i(e=>{let t=uMt.get(e);return t||(t=FMo(e),uMt.size>=1e3&&uMt.clear(),uMt.set(e,t)),t},"Ze"),j$n=i((e,t)=>{if(t===e.ch)return!0;if(!e.re)return!1;let n=t.charCodeAt(0);if(n>=128)return e.re.test(t);let r=e.ascii??=new Uint8Array(128);return r[n]||=e.re.test(t)?1:2,r[n]===1},"ge"),PYa=i((e,t,n,r,o)=>{let s=[];for(let a=0;a<e.length;){let c=String.fromCodePoint(e.codePointAt(a));if(o){let l=c==="\\"&&e.startsWith(o,a+1)?1:0;if(l||c===o){let u=a+l+o.length,d=e.indexOf(o,u),p=/^(-?\d+)\.\.(-?\d+)$/.exec(e.slice(u,d)),f=d!==-1&&p&&kYa(p[1],p[2]);if(f){s.push({t:"ext",type:"@",alts:f}),a=d+o.length;continue}}}if(c==="\\"){let l=e.codePointAt(a+1),u=l===void 0?c:String.fromCodePoint(l);s.push(Hfe(u)),a+=1+u.length;continue}if(c==="["){let[l,u]=NYa(e,a,t,r);if(u){s.push({t:"class",re:l}),a+=u;continue}}if(!n&&BYa.includes(c)&&e[a+1]==="("){s.push({t:"open",type:c}),a+=2;continue}s.push(!n&&c==="|"?{t:"bar"}:!n&&c===")"?{t:"close"}:c==="*"?{t:"star"}:c==="?"?{t:"any"}:Hfe(c)),a+=c.length}return s},"ci"),MYa=i(e=>{let t=new Map,n=[];return e.forEach((r,o)=>{r.t==="open"?n.push(o):r.t==="close"&&n.length&&t.set(n.pop(),o)}),t},"fi"),QMo=i((e,t,n,r,o)=>{let s=[],a=[s];for(let c=n;c<r;c++){let l=e[c],u=t.get(c);if(l.t==="open"&&u!==void 0){let d=QMo(e,t,c+1,u,!1);s.push({t:"ext",type:l.type,alts:d}),c=u}else l.t==="bar"&&!o?a.push(s=[]):l.t==="open"?s.push(Hfe(l.type),Hfe("(")):l.t==="bar"?s.push(Hfe("|")):l.t==="close"?s.push(Hfe(")")):s.push(l)}return a},"Qe"),jMo=i((e,t)=>{let n=[],r="",o=i(()=>{for(let s of r.normalize(t))n.push(Hfe(s));r=""},"i");for(let s of e){if(s.t==="lit"){r+=s.ch;continue}o(),n.push(s.t==="ext"?{...s,alts:s.alts.map(a=>jMo(a,t))}:s)}return o(),n},"ts"),LYa=i((e,t)=>{let n=1,r=i(a=>({t:"split",id:n++,out:a}),"s"),o=i((a,c)=>a.reduceRight((l,u)=>s(u,l),c),"i"),s=i((a,c)=>{switch(a.t){case"lit":let p=t?UMo(a.ch):void 0;return{t:"lit",id:n++,ch:a.ch,re:p,next:c};case"any":case"star":return{t:a.t,id:n++,next:c};case"class":return{t:"class",id:n++,re:a.re,next:c}}let l=i(p=>a.alts.map(f=>o(f,p)),"l");switch(a.type){case"@":return r(l(c));case"?":return r([c,...l(c)]);case"!":return{t:"neg",id:n++,sub:r(l(B$n)),next:c}}let u=r([]),d=r(l(u));return u.out.push(c,d),a.type==="*"?u:d},"n");return[o(e,B$n),n]},"ui"),FYa=i(e=>{let t=[],n=new Set,r=i(s=>s.t==="match"?"match":String(s.id),"s"),o=i((s,a)=>{if(s.t==="match"||n.has(s))return;n.add(s);let c=i(l=>t.push(`${a}${s.id}: ${l}`),"h");switch(s.t){case"split":c(`split -> ${s.out.map(r).join(", ")}`);for(let l of s.out)o(l,a);return;case"neg":return c(`!(${r(s.sub)}) -> ${r(s.next)}`),o(s.sub,a+" "),o(s.next,a);case"lit":c(`${JSON.stringify(s.ch)} -> ${r(s.next)}`);break;case"class":c(`${s.re} -> ${r(s.next)}`);break;default:c(`${s.t==="any"?"?":"*"} -> ${r(s.next)}`)}o(s.next,a)},"i");return o(e,""),[`start -> ${r(e)}`,...t].join(`
|
|
1034
|
+
`).map(t=>t.trim()).find(t=>t.length>0)??""}function ZPt(e){return e.kind==="tool"&&e.stageId!==void 0}function G7e(e,t){return jHn(e.transcript).flatMap(n=>{if(n.kind!=="stage")return[];let{stage:r}=n,o=n.rows.filter(ZPt).map(c=>cKa(c,e,t));if(o.length===0)return[];let s=new Set(o.map(c=>c.id)),a=0;for(let c of e.childIds){let l=t.runs.get(c);l?.launch?.card!=null&&s.has(l.launch.card)&&(a+=l.treeUsage.cost)}return[{id:r.id,outcome:r.end?.outcome??null,calls:o,sections:lKa(o),agents:o.filter(c=>dPo.has(c.toolName)).length,needsYou:o.filter(c=>c.needsYou).length,costUsd:a}]})}var uPo,dPo,GHn,$Hn,fPo=N(()=>{"use strict";de();vn();W$();wP();DEt();mv();Sc();CMn();HHn();uPo=i(e=>GHn(e.agentName??e.name),"nameOf"),dPo=new Set(["agent",Q$,"self"]);i(pPo,"askingRun");GHn=i(e=>typeof e=="string"&&e.length>0?e:void 0,"stringOf"),$Hn=i(e=>Array.isArray(e)?e.flatMap(t=>typeof t=="string"?[WS(t)]:[]):[],"namesOf");i(aKa,"statusOf");i(cKa,"callView");i(lKa,"sectionsOf");i(uKa,"firstLine");i(ZPt,"isScriptCall");i(G7e,"scriptStages")});var $v=N(()=>{"use strict";C7e();fNt();vn();Fee();F1e();gCe();mKe();SU();fPo();HHn();yMn()});var qHn,q7e,z7e,eMt=N(()=>{"use strict";de();It();qHn=class extends A.TaggedError()("Invalid",{reason:A.String}){static{i(this,"Invalid")}},q7e=class extends A.TaggedError()("Internal",{ref:A.String}){static{i(this,"Internal")}},z7e=Oqe.mapMembers(e=>[...e,qHn,q7e])});var Nfe,mPo,zHn=N(()=>{"use strict";de();Nfe=A.Literals(["input","context","media"]),mPo=A.Union([Nfe,A.Literals(["base","edited"])])});var dKa,pKa,hPo,APo=N(()=>{"use strict";de();dKa=Object.freeze(["general","models","agents","memory","plugins","latex"]),pKa=Object.freeze({models:Object.freeze(["keys","subscriptions","models"]),agents:Object.freeze(["skills","advanced"]),plugins:Object.freeze([]),latex:Object.freeze(["dependencies","compile","formatting","vscode"]),memory:Object.freeze([]),general:Object.freeze(["appearance","approval","privacy","git"])}),hPo=A.Literals(dKa.flatMap(e=>[e,...pKa[e].map(t=>`${e}/${t}`)]))});function gPo(e,t){let n=Bfe(e),r=n===null?void 0:t.runs.get(n);return r===void 0||r.parentId!==null||(WHn(e,r.id).seen??-1/0)>=r.lastTimestamp?e:W7e(e,r.id,o=>({...o,seen:r.lastTimestamp}))}var yPo=N(()=>{"use strict";Dfe();i(gPo,"markShownRunSeen")});function Bfe(e){return e.shown._tag==="Run"?e.shown.runId:null}function WHn(e,t){return e.runs.get(t)??{draft:bPo,expanded:void 0,disclosures:new Map,seen:void 0,rejected:void 0}}function CPo(e,t,n){return dgt(n,t.runs)||e.runs.get(n.id)?.expanded===!0}function VHn(e,t){return Eo(A.Array(A.Tuple([e,t])),[])}function vPo(e){return yKa(e,A.decodeUnknownSync(gKa)({}))}function yKa(e,t){return{session:e,requestError:null,shown:YHn(t.selected),arriving:null,runs:new Map(t.runs.map(([n,r])=>[n,{draft:{...bPo,text:r.draft},expanded:r.expanded,disclosures:new Map(r.groups),seen:r.seen,rejected:void 0}])),polishing:new Set,sending:new Set,deleting:new Set,launch:t.launch,requestDrafts:new Map(t.requestDrafts),drawerOpen:t.drawerOpen,toolsSheetOpen:!1,storageHintDismissed:t.storageHintDismissed,search:"",workbench:t.workbench}}function EKa(e,t){let n=[...e].filter(([r])=>t.runs.has(r));return n.length===e.size?e:new Map(n)}function SKa(e){return t=>t===null||e.runs.has(t)?t:e.order.at(0)??null}function IPo(e,t,n=SKa(t)){let r=e,{arriving:o}=e;o!==null&&t.runs.has(o.runId)?r=JHn(e,{kind:"select",runId:o.runId}):o!==null&&t.cursor>=o.cursor&&(r={...e,arriving:null});let s=EKa(r.runs,t),{shown:a}=r,c=a;if(a._tag==="Proposal")t.requests.some(l=>l.runId===a.runId&&l.requestId===a.requestId)||(c=KHn);else{let l=n(Bfe(r));l!==Bfe(r)&&(c=YHn(l))}return c===a&&s===r.runs?r:{...r,runs:s,shown:c}}function EPo(e,t,n){let r=new Map(e);return n===null?r.delete(t):r.set(t,n),r}function W7e(e,t,n){return{...e,runs:new Map(e.runs).set(t,n(WHn(e,t)))}}function JHn(e,t){switch(t.kind){case"dismissRequestError":return{...e,requestError:null};case"reportError":return{...e,requestError:new as({reason:t.reason})};case"select":return{...e,shown:YHn(t.runId),arriving:null,drawerOpen:!1};case"selectOnArrival":return{...e,arriving:{runId:t.runId,cursor:t.cursor}};case"selectNew":return{...e,shown:KHn,arriving:null,drawerOpen:!1,requestError:null,launch:{...e.launch,instruction:"",skills:[],chat:null}};case"editProposal":return{...e,shown:{_tag:"Proposal",...t.proposal},arriving:null,drawerOpen:!1,requestError:null,launch:{...e.launch,...t.patch}};case"toggleDrawer":return{...e,drawerOpen:!e.drawerOpen};case"drawer":return{...e,drawerOpen:t.open};case"toolsSheet":return{...e,toolsSheetOpen:t.open};case"dismissStorageHint":return{...e,storageHintDismissed:!0};case"search":return{...e,search:t.value};case"draft":return W7e(e,t.runId,n=>({...n,draft:{...n.draft,...t.patch}}));case"launch":return{...e,launch:{...e.launch,...t.patch}};case"requestDraft":return{...e,requestDrafts:EPo(e.requestDrafts,t.key,t.draft)};case"expand":return W7e(e,t.runId,n=>({...n,expanded:t.expanded}));case"group":return W7e(e,t.runId,n=>({...n,disclosures:EPo(n.disclosures,t.key,t.expanded)}));case"workbench":return{...e,workbench:t.layout};case"seen":return gPo(e,t.view)}}var fKa,SPo,mKa,tMt,nMt,hKa,_Po,KHn,YHn,bPo,AKa,gKa,Dfe=N(()=>{"use strict";de();It();gi();P7e();yPo();fKa=Ace.mapFields(In.assign({editedFile:A.optional(A.NullOr(A.String)).pipe(A.decodeTo(A.String,{decode:Ii.transformOptional(e=>at.some(at.getOrUndefined(e)??"")),encode:Ii.transform(e=>e)}))})),SPo=["label","system","tools","toolScope"],mKa=A.Struct(In.pick(gh.fields,SPo)),tMt=i(e=>In.pick(e,SPo),"chatOf"),nMt=fKa.mapFields(In.assign({workingDirectory:Eo(A.String,""),model:Eo(A.String,tHn),commit:Eo(A.String,"HEAD"),instruction:Eo(A.String,""),skills:Eo(A.Array(A.String),[]),chat:Eo(A.NullOr(mKa),null),baseFile:Eo(A.String,""),approval:Eo(A.Literals(["policy","autoApprove"]),"policy")})),hKa=In.lambda(e=>A.optional(A.toType(e))),_Po=nMt.mapFields(In.map(hKa)),KHn=Object.freeze({_tag:"New"}),YHn=i(e=>e===null?KHn:{_tag:"Run",runId:e},"shownOf");i(Bfe,"shownRun");bPo=Object.freeze({text:"",images:Object.freeze([])});i(WHn,"runSurface");i(CPo,"runExpanded");i(VHn,"entries");AKa=A.Struct({note:A.optionalKey(A.String),model:A.optionalKey(A.String),answers:A.optionalKey(A.Array(A.Struct({selected:A.Array(A.String),text:A.String})))}),gKa=A.Struct({selected:Eo(A.NullOr(Cr),null),launch:Eo(nMt,{}),runs:VHn(Cr,A.Struct({draft:Eo(A.String,""),expanded:A.optionalKey(A.Boolean),groups:VHn(A.String,A.Boolean),seen:A.optionalKey(A.Number)})),requestDrafts:VHn(A.String,AKa),drawerOpen:Eo(A.Boolean,!1),storageHintDismissed:Eo(A.Boolean,!1),workbench:Eo(A.NullOr(A.Record(A.String,A.Unknown)),null)});i(vPo,"emptySurface");i(yKa,"loadSurface");i(EKa,"retain");i(SKa,"projectSelection");i(IPo,"pruneSurface");i(EPo,"withEntry");i(W7e,"updateRun");i(JHn,"applySurfaceAction")});var _Ka,wQ,bKa,xPo,wPo=N(()=>{"use strict";de();It();zHn();APo();Dfe();_Ka=A.Literals(["createSampleProject","cloneOverleaf","downloadArxiv"]),wQ={runId:Cr},bKa=A.Literals(["compare","latexdiff","accept"]),xPo=A.Union([A.Struct({kind:A.Literal("openFile"),path:A.NonEmptyString,line:A.optional(A.Int.check(A.isGreaterThan(0)))}),A.Struct({kind:A.Literal("openLabel"),label:A.String}),A.Struct({kind:A.Literal("openRunStorage"),...wQ}),A.Struct({kind:A.Literal("exportTranscript"),...wQ}),A.Struct({kind:A.Literal("resume"),...wQ}),A.Struct({kind:A.Literal("runAgain"),...wQ}),A.Struct({kind:A.Literal("fork"),...wQ,at:A.optional(A.Int.check(A.isGreaterThan(0))),draft:A.optional(A.String),media:A.optional(A.Array(cU))}),A.Struct({kind:A.Literal("runCompileFixer"),...wQ}),A.Struct({kind:A.Literal("useOwnApiKey"),...wQ,requestId:A.NonEmptyString,credentialSwitch:BAt}),A.Struct({kind:A.Literal("latexdiff"),...wQ}),A.Struct({kind:A.Literal("pack"),...wQ}),A.Struct({kind:A.Literal("clean"),...wQ}),A.Struct({kind:A.Literal("latexdiffCommit"),baseFile:A.optional(A.String),commit:A.optional(A.String),action:A.Literals(["latexdiffvc","packLatexdiffvc","cleanLatexdiffvc"])}),A.Struct({kind:A.Literal("record"),action:A.Union([A.Struct({kind:A.Literal("start"),target:A.Union([Cr,A.Literal("launch")])}),A.Struct({kind:A.Literal("stop")})])}),A.Struct({kind:A.Literal("popOut")}),A.Struct({kind:A.Literal("popBack")}),A.Struct({kind:A.Literal("refreshCommits")}),A.Struct({kind:A.Literal("refreshFiles")}),A.Struct({kind:A.Literal("openSettings"),target:A.optional(hPo)}),A.Struct({kind:A.Literal("pickFiles"),fileType:Nfe}),A.Struct({kind:A.Literal("useCurrentFile"),fileType:mPo}),A.Struct({kind:A.Literal("addOpenedFiles"),fileType:Nfe}),A.Struct({kind:A.Literal("attachDroppedFiles"),paths:A.Array(A.String),category:Nfe}),A.Struct({kind:A.Literal("launch"),launch:nMt,instruction:A.String}),A.Struct({kind:A.Literal("polish"),text:A.String}),A.Struct({kind:A.Literal("savePastedImage"),fileName:A.NonEmptyString,base64:A.NonEmptyString}),A.Struct({kind:A.Literal("workspaceFile"),action:A.Union([A.Struct({kind:A.Literal("list"),directory:A.String}),A.Struct({kind:A.Literal("read"),path:A.String}),A.Struct({kind:A.Literal("write"),path:A.String,contents:A.String,base:A.NullOr(A.String)})])}),A.Struct({kind:A.Literal("toolEdit"),requestId:A.NonEmptyString,action:A.Literals(["approve","openDiff","previewProposed","showLatexdiff"]),grant:A.optional(A.Literals(yv))}),A.Struct({kind:A.Literal("fileAction"),action:bKa,file:A.String,base:A.Union([A.Struct({kind:A.Literal("runOutput"),...wQ}),A.Struct({kind:A.Literal("file"),path:A.String})])}),A.Struct({kind:A.Literal("apiKeyBanner"),action:A.Literals(["set","guide"])}),A.Struct({kind:A.Literal("recheckDependencies")}),A.Struct({kind:A.Literal("openInstallGuide")}),A.Struct({kind:A.Literal("dismissBanner"),banner:A.Literals(["gettingStarted","dependency"])}),A.Struct({kind:A.Literal("gettingStarted"),action:_Ka}),A.Struct({kind:A.Literal("onboarding"),action:A.Literals(["signInChatGpt","setApiKey","skip","runSetup","skipSetup","openGettingStarted"])})])});var CKa,TPo,RPo=N(()=>{"use strict";de();It();CKa=A.Struct({availability:Ecn,unavailableReason:A.optional(A.String),usageRoute:A.optional(L$),routeLabel:A.optional(A.String)}),TPo=A.Struct({value:A.String,label:A.String,provider:A.optional(A.String),context:A.optional(A.String),cost:A.optional(A.String),hint:A.optional(A.String),reasoning:A.optional(A.String),...CKa.fields})});function kPo(e){return WS(e)||e}var vKa,IKa,xKa,wKa,TKa,OPo,XHn=N(()=>{"use strict";de();It();RPo();vKa=A.Struct({value:A.String,label:A.String}),IKa=A.Struct({label:A.String,interchangeable:A.Boolean,usedFor:A.String}),xKa=A.Struct({baseFile:A.Array(A.String),editedFile:A.Array(A.String),commit:A.Array(A.String)}),wKa=A.Struct({key:A.NonEmptyString,name:A.String});i(kPo,"projectName");TKa=A.Literals(["needs-credential","setup","done"]),OPo=A.Struct({project:wKa,modelOptions:A.Array(TPo),tools:A.Struct({icons:A.Record(A.String,A.String),terminalOutput:A.Array(A.String)}),workspaceRoots:A.Array(vKa),approvalPolicy:rCe,fileOptions:xKa,isGitRepo:A.Boolean,recording:A.NullOr(A.Struct({session:A.String,target:A.String})),banners:A.Struct({apiKey:A.Boolean,dependency:A.NullOr(A.Array(IKa)),gettingStarted:A.Boolean,service:A.NullOr(A.Union([A.Struct({kind:A.Literal("offline"),reason:A.String}),A.Struct({kind:A.Literal("local"),reason:A.String})]))}),onboarding:TKa})});var ZHn,e$n,RKa,kKa,Lup,NPo,Fup,Uup,BPo=N(()=>{"use strict";de();Jz();It();$v();XOe();eMt();wPo();XHn();Dfe();ZHn=A.Struct({debug:A.Boolean,cursor:sx,aggregates:A.Array(JAt)}),e$n=A.Struct({cursor:sx,inputs:A.Array(Pcn)}),RKa=A.Union([A.Struct({kind:A.Literal("done")}),A.Struct({kind:A.Literal("files"),paths:A.Array(A.String)}),A.Struct({kind:A.Literal("text"),text:A.String}),A.Struct({kind:A.Literal("savedImage"),fileName:A.String}),A.Struct({kind:A.Literal("entries"),entries:A.Array(A.Struct({path:A.String,isDirectory:A.Boolean}))}),A.Struct({kind:A.Literal("contents"),contents:A.String}),A.Struct({kind:A.Literal("changedOnDisk")})]),kKa=A.Union([A.Struct({kind:A.Literal("selectNew")}),A.Struct({kind:A.Literal("select"),runId:Cr}),A.Struct({kind:A.Literal("selectOnArrival"),runId:Cr,cursor:sx}),A.Struct({kind:A.Literal("showSessions"),runId:Cr}),A.Struct({kind:A.Literal("submit")}),A.Struct({kind:A.Literal("draft"),runId:Cr,text:A.String,images:A.Array(A.Struct({fileName:A.String,media:cU}))}),A.Struct({kind:A.Literal("chime")}),A.Struct({kind:A.Literal("launch"),patch:_Po})]),Lup=RT.make(Pc.make("session.frames",{payload:ZHn,success:e$n,stream:!0}),Pc.make("session.host",{success:OPo,stream:!0}),Pc.make("session.actions",{success:kKa,stream:!0}),Pc.make("session.request",{payload:{request:Rqe},success:kqe,error:z7e}),Pc.make("host.request",{payload:{request:xPo},success:RKa,error:z7e})),NPo={session:A.NonEmptyString,client:A.NonEmptyString},Fup=A.Struct({...NPo,message:HPt}),Uup=A.Struct({...NPo,message:$Pt})});import{randomUUID as OKa}from"node:crypto";import t$n from"node:path";var DPo,eNe,V7e=N(()=>{"use strict";de();Rn();Co();It();DPo=A.Union([A.Struct({kind:A.Literal("anything")}),A.Struct({kind:A.Literal("absent")}),A.Struct({kind:A.Literal("holds"),contents:A.String})]),eNe=m.fn("writeFileIfUnchanged")(function*(e,t,n){let r=yield*ot.FileSystem;return yield*m.gen(function*(){let o=yield*Sa(r,e).pipe(m.catchIf(br,()=>m.succeed(null)));if(o===t)return!0;if(o!==null&&(n.kind==="absent"||n.kind==="holds"&&o!==n.contents))return!1;let s=o===null?e:yield*r.realPath(e),a=o===null?void 0:(yield*r.stat(s)).mode&4095,c=t$n.join(t$n.dirname(s),`.${t$n.basename(s)}.${OKa()}.tmp`);return yield*r.writeFileString(c,t).pipe(m.andThen(a===void 0?m.void:r.chmod(c,a)),m.andThen(r.rename(c,s)),m.onError(()=>r.remove(c,{force:!0}).pipe(m.ignore({log:"Warn",message:`A staged project file stays behind: ${c}`}))),m.uninterruptible),!0}).pipe(vQ(e))},m.catchTag("PlatformError",e=>m.fail(new as({reason:e.message}))))});import{hash as NKa}from"node:crypto";var Mfe,rMt,BKa,nNe,DKa,n$n,BT,LPo,PKa,Xq,Pfe,r$n,cL,tNe,MKa,LKa,Lfe,FPo,PPo,MPo,Ffe,Zz=N(()=>{"use strict";de();Jz();xQ();It();XOe();XPt();$v();BPo();eMt();V7e();KPt();Mfe="1.0.0-preview.4",rMt=A.Struct({protocol:A.NonEmptyString,version:A.String,pid:A.Int.check(A.isGreaterThan(0)),socket:A.String,startedAt:A.Int.check(A.isGreaterThan(0)),clients:Jr,running:Jr,draining:A.Boolean}),BKa=rMt.mapFields(In.pick(["pid","startedAt"])).mapFields(In.assign({socket:A.NonEmptyString})),nNe=Object.freeze({name:"texra-service",schema:BKa}),DKa=A.Struct({workspace:A.String,runId:Cr,label:A.String,statusKey:lPo,launchedAt:A.Int.check(A.isGreaterThan(0)),live:A.Boolean}),n$n=A.Struct({runId:Cr,activation:sx}),BT=class extends A.TaggedError()("TaskFailed",{message:A.String}){static{i(this,"TaskFailed")}},LPo=A.Union([BT,Ry,Kz,mB]),PKa=A.Union([...LPo.members,Rfe]),Xq=class extends A.TaggedError()("TaskRecordsFailed",{runId:Cr,message:A.String}){static{i(this,"TaskRecordsFailed")}},Pfe=class extends A.TaggedError()("ProjectStateFailed",{message:A.String}){static{i(this,"ProjectStateFailed")}},r$n=A.Record(A.String,A.Struct({value:A.optional(A.Json)})),cL=A.String,tNe=Object.freeze({exists:A.Boolean,readConfig:A.NullOr(gh),readReport:A.NullOr(A.String),readRunEnd:A.NullOr(dU),readResult:A.NullOr(ocn),readWorkspaceFiles:A.Array(icn),readSkills:A.Array(A.String),readContinues:A.Boolean,readConversation:A.Array(Ucn),readTrace:Lcn}),MKa={workspace:cL,runId:Cr},LKa=In.keys(tNe).map(e=>Pc.make(`records.${e}`,{payload:MKa,success:tNe[e],error:Xq})),Lfe=RT.make(Pc.make("service.hello",{payload:{protocol:A.String},success:rMt}),Pc.make("service.stop",{payload:{drain:A.Boolean}}),Pc.make("tasks.list",{payload:{all:A.Boolean},success:A.Array(DKa)}),Pc.make("task.watch",{payload:{workspace:cL,subscribe:ZHn},success:e$n,error:BT,stream:!0}),Pc.make("task.request",{payload:{workspace:cL,request:Rqe},success:kqe,error:z7e}),Pc.make("task.start",{payload:{workspace:cL,start:eln.members[1]},success:n$n,error:LPo}),Pc.make("task.resume",{payload:{workspace:cL,runId:Cr,apiKeys:A.optional(A.Record(A.String,A.String))},success:n$n,error:PKa}),Pc.make("task.result",{payload:n$n.mapFields(In.assign({workspace:cL})),success:dU.mapFields(In.assign({at:sx})),error:BT}),Pc.make("session.view",{payload:{workspace:cL,runIds:A.Array(Cr)},success:rln,error:BT}),Pc.make("session.listRuns",{payload:{workspace:cL},success:A.Array(scn),error:BT}),Pc.make("session.deleteRuns",{payload:{workspace:cL,target:A.Union([Cr,A.Literal("all")])},success:A.Struct({deleted:A.Array(Cr),active:A.Array(Cr),failed:A.Array(A.Struct({runId:Cr,error:Oqe}))}),error:BT}),...LKa,Pc.make("host.attach",{payload:{workspace:cL,capabilities:A.Array(VPt)},success:rPo,error:BT,stream:!0}),Pc.make("state.get",{payload:{workspace:cL,keys:A.Array(A.String)},success:r$n,error:Pfe}),Pc.make("state.set",{payload:{workspace:cL,next:r$n,ifCurrent:A.NullOr(r$n)},success:A.Boolean,error:Pfe}),Pc.make("file.write",{payload:{path:A.String,contents:A.String,expected:DPo},success:A.Boolean,error:as}),Pc.make("host.focus",{payload:{attachment:A.String}}),Pc.make("host.answer",{payload:{attachment:A.String,message:$Pt}})),FPo=i(e=>NKa("sha256",JSON.stringify(e),"hex").slice(0,12),"digest12"),PPo=i(e=>{let t=e.successSchema,n=ofe.isStreamSchema(t)?[e.payloadSchema,t.success,t.error,e.errorSchema]:[e.payloadSchema,t,e.errorSchema];return FPo(n.map(r=>A.toJsonSchemaDocument(r)))},"shapeOf"),MPo=Object.freeze(Object.fromEntries([...[...Lfe.requests].map(([e,t])=>[e,PPo(t)]),...[...Ofe.requests].map(([e,t])=>[`window.${e}`,PPo(t)])])),Ffe=Object.freeze({digest:FPo([FRt,Object.entries(MPo).toSorted(([e],[t])=>e.localeCompare(t))]),shapes:MPo})});import{hash as FKa}from"node:crypto";import{lstatSync as UKa}from"node:fs";import*as Zq from"node:path";function Bte(e){let t=Zq.join(e,"run"),n=Zq.join(t,"serve.log"),r=FKa("sha256",Zq.resolve(e),"hex").slice(0,16),o=Zq.join(t,o$n(4294967295));if(Buffer.byteLength(o)<=QKa)return{runDirectory:t,log:n,socketDirectory:t,socketFor:i(a=>Zq.join(t,o$n(a)),"socketFor")};let s=Zq.join("/tmp",`texra-${process.getuid?.()??0}-${r}`);return{runDirectory:t,log:n,socketDirectory:s,socketFor:i(a=>Zq.join(s,o$n(a)),"socketFor")}}function HKa(e){let t=i((n,r)=>YI.badArgument({module:"TexraService",method:"prepareServiceDirectories",description:n,cause:r}),"failure");return m.try({try:i(()=>UKa(e),"try"),catch:i(n=>t(et(n),n),"catch")}).pipe(m.filterOrFail(n=>{let r=process.getuid?.();return n.isDirectory()&&(r===void 0||n.uid===r)},()=>t(`${e} is not a directory this user owns; remove it and start the service again`)),m.asVoid)}function $Ka(e){try{return process.kill(e,0),!0}catch(t){return Ye.hasProperty(t,"code")&&t.code==="EPERM"}}var UPo,QKa,jKa,o$n,Y7e,oMt,K7e,QPo,jPo,HPo,$Po,GPo,qPo,J7e=N(()=>{"use strict";de();Rn();It();Zz();UPo="service",QKa=100,jKa=/^serve-(\d+)\.sock$/,o$n=i(e=>`serve-${e}.sock`,"socketName"),Y7e="serve";i(Bte,"servicePaths");oMt=m.fn("prepareServiceDirectories")(function*(e){let t=yield*ot.FileSystem;for(let n of new Set([e.runDirectory,e.socketDirectory]))yield*t.makeDirectory(n,{recursive:!0,mode:448}),yield*HKa(n),yield*t.chmod(n,448)});i(HKa,"ownDirectory");K7e="current",QPo=i((e,t)=>e?.pid===t?.pid&&e?.startedAt===t?.startedAt,"sameService"),jPo=De.unwrap(m.map(jg,e=>e.changes(nNe,[K7e]))),HPo=m.flatMap(jg,e=>m.map(e.get(nNe,K7e),t=>t??null)),$Po=m.fn("claimServiceRecord")(function*(e,t){let n=yield*jg;for(;;){let r=yield*n.get(nNe,K7e),o=r===void 0?null:yield*t(r);if(o!==null)return o;if(yield*n.modify(nNe,[K7e],({current:a})=>Re.succeed(QPo(a,r)?[!0,{current:e}]:[!1])))return null}}),GPo=m.fn("releaseServiceRecord")(function*(e,t){yield*(yield*jg).modify(nNe,[K7e],({current:o})=>Re.succeed(QPo(o,t)?[void 0,{current:void 0}]:[void 0])),yield*(yield*ot.FileSystem).remove(e.socketFor(t.pid),{force:!0})},m.catch(Ir(UPo,"Could not remove the service files"))),qPo=m.fn("removeDeadSockets")(function*(e){let t=yield*ot.FileSystem,n=(yield*t.readDirectory(e.socketDirectory)).filter(r=>{let o=Number(jKa.exec(r)?.[1]);return Number.isInteger(o)&&!$Ka(o)});yield*m.forEach(n,r=>t.remove(Zq.join(e.socketDirectory,r),{force:!0}),{concurrency:8,discard:!0})},m.catch(Ir(UPo,"Could not remove dead services' sockets")));i($Ka,"processAlive")});import{spawn as GKa}from"node:child_process";import{closeSync as qKa,existsSync as ydp,openSync as zKa}from"node:fs";import{join as WKa}from"node:path";function p$n(e){return m.scoped(m.flatMap(d$n(e),t=>t["service.hello"]({protocol:Ffe.digest}))).pipe(m.timeout(YKa),m.map(t=>t),m.catch(t=>JPo(t)?m.succeed(null):t._tag==="TimeoutError"?m.fail(new df({reason:`The TeXRA service on ${e} accepts connections but did not answer (${t.message}). Stop it with \`texra service stop\`, or end its process.`,failure:{kind:"unanswered"}})):m.fail(new df({reason:`The TeXRA service on ${e} speaks a protocol this build cannot read (${t.message}).`,failure:{kind:"unreadable",socket:e}}))))}function XPo(e,t,n,r={}){let o=Bte(e),s=m.gen(function*(){yield*oMt(o);let a=yield*m.try({try:i(()=>zKa(o.log,"a",384),"try"),catch:s$n});return yield*m.callback(c=>{let l=GKa(t,[...n],{cwd:o.runDirectory,detached:!0,stdio:["ignore",a,a],env:{...Zi.filter(process.env,(d,p)=>p==="HOME"||p.startsWith("TEXRA_")),NODE_COMPILE_CACHE:WKa(o.runDirectory,"compile-cache"),...r}});l.once("error",d=>c(m.fail(s$n(d))));let u=Nn.makeUnsafe();l.once("exit",(d,p)=>{d!==0&&Nn.doneUnsafe(u,m.succeed(p===null?`exited with code ${d}`:`was ended by ${p}`))}),l.once("spawn",()=>{l.unref(),c(m.succeed(Nn.await(u)))})}).pipe(m.ensuring(m.sync(()=>qKa(a))))}).pipe(m.catchTag("PlatformError",a=>m.fail(s$n(a))),m.provide(zw));return{storageRoot:e,start:s}}var sMt,rNe,VPo,VKa,df,u$n,i$n,KKa,a$n,YKa,iMt,KPo,YPo,zPo,d$n,JPo,aMt,c$n,s$n,l$n,WPo,f$n,JKa,XKa,X7e,ZPo,ZKa,m$n,Dte,eMo,cMt,tMo,nMo,eYa,rMo,e4=N(()=>{"use strict";cPo();de();Jz();gi();xQ();It();Co();J7e();Zz();sMt=i(()=>Object.fromEntries(RGe.flatMap(e=>{let t=process.env[e]?.trim();return t?[[e,t]]:[]})),"environmentApiKeys"),rNe=i((e,t,n)=>e["task.request"]({workspace:t,request:n.kind==="followUp.send"?{...n,apiKeys:n.apiKeys??sMt()}:n}).pipe(m.filterOrFail(r=>Zcn(n.kind,r),r=>new as({reason:`The TeXRA service answered a ${n.kind} with ${r.kind}.`}))),"requestOnService"),VPo=i((e,t)=>m.map(e["tasks.list"]({all:!0}),n=>{let r=n.find(s=>s.runId===t),o=r?[r]:n.filter(s=>s.runId.startsWith(t));return o.length===1?{task:o[0]}:{matches:o}}),"findTask"),VKa=A.Union([A.Struct({kind:A.Literal("failed")}),A.Struct({kind:A.Literal("none")}),A.Struct({kind:A.Literal("incompatible")}),A.Struct({kind:A.Literal("unreadable"),socket:A.String}),A.Struct({kind:A.Literal("unanswered")}),A.Struct({kind:A.Literal("startFailed")})]),df=class extends A.TaggedError()("ServiceUnavailable",{reason:A.String,failure:VKa.pipe(A.withConstructorDefault(m.succeed({kind:"failed"})))}){static{i(this,"ServiceUnavailable")}get message(){return this.reason}},u$n="The TeXRA service does not run on Windows yet.",i$n="TEXRA_NO_SERVICE",KKa="no TeXRA service is running",a$n="60 seconds",YKa="10 seconds",iMt=i(e=>e.protocol===Ffe.digest,"compatible"),KPo=i((e,t)=>{let n=dk.parse(e.version),r=dk.parse(Mfe);return Re.isSuccess(n)&&Re.isSuccess(r)&&t(n.success,r.success)},"builds"),YPo=i(e=>!iMt(e)&&KPo(e,dk.isGreaterThan),"isNewer"),zPo=i(e=>KPo(e,dk.isLessThan)||!iMt(e)&&!YPo(e),"isOlder"),d$n=m.fn("connectService")(function*(e,t=m.void){let n=yield*gt.build(lB.layerProtocolSocket().pipe(gt.provide(aPo({path:e})),gt.provide(Xee.layerNdjson),gt.provide(gt.succeed(lB.ConnectionHooks,{onConnect:m.void,onDisconnect:t}))));return yield*lB.make(Lfe).pipe(m.provideContext(n))}),JPo=i(e=>(e._tag==="RpcClientError"||e._tag==="SocketError")&&e.reason?._tag==="SocketOpenError","nobodyListens");i(p$n,"probeService");aMt=HPo.pipe(m.mapError(e=>new df({reason:`The service record could not be read: ${e.message}`})),m.flatMap(e=>e===null?m.succeed(null):p$n(e.socket))),c$n=class extends A.TaggedError()("ServiceStartFailed",{message:A.String,cause:A.Defect()}){static{i(this,"ServiceStartFailed")}},s$n=i(e=>new c$n({message:jo(e).message,cause:e}),"startFailed");i(XPo,"spawnService");l$n=i((e,t)=>m.scoped(m.gen(function*(){let n=yield*Nn.make();yield*(yield*d$n(e,m.asVoid(Nn.succeed(n,void 0))))["service.stop"]({drain:t},{discard:!0}),yield*Nn.await(n)})).pipe(m.catchIf(JPo,()=>m.void)),"stopService"),WPo="30 seconds",f$n=m.gen(function*(){let e=yield*aMt.pipe(m.catch(n=>{let{failure:r}=n;return r.kind==="unreadable"?m.succeed({socket:r.socket}):m.fail(n)}));if(e===null)return null;let t=e.pid===void 0?"the TeXRA service":`the TeXRA service (pid ${e.pid})`;return yield*l$n(e.socket,!1).pipe(m.timeoutOrElse({duration:WPo,orElse:i(()=>m.fail(new df({reason:`it did not exit within ${WPo}`})),"orElse")}),m.mapError(n=>new df({reason:`Could not stop ${t}: ${n.message}`}))),e.pid===void 0?{}:{pid:e.pid}}),JKa=i(e=>new df({reason:`The running TeXRA service (${e.version}, pid ${e.pid}) is newer than this TeXRA (${Mfe}) and speaks another protocol. Update TeXRA, or stop the service with \`texra service stop\`.`,failure:{kind:"incompatible"}}),"newerService"),XKa=m.fn("server.ensureService")(function*({storageRoot:e,start:t},n,r,o){let s=aMt.pipe(m.tap(p=>p===null||iMt(p)?m.void:YPo(p)?m.fail(JKa(p)):o?m.void:m.fail(new df({reason:ZPo,failure:{kind:"incompatible"}})))),a=yield*s.pipe(m.map(p=>({found:p,replaced:!1})),m.catch(p=>{let{failure:f}=p;return!o||f.kind!=="unreadable"?m.fail(p):o("Stopping an incompatible TeXRA service after its active tasks finish, then starting this version.").pipe(m.andThen(l$n(f.socket,!0).pipe(m.mapError(h=>new df({reason:`Could not stop the older TeXRA service: ${h.message}`})))),m.as({found:null,replaced:!0}))})),c=a.found,{replaced:l}=a;if(!o&&c?.draining)return yield*new df({reason:X7e});if(o&&c!==null&&(zPo(c)||c.draining)){let p=c;l=zPo(p);let f=yr(p.running,"running task");yield*(p.running>0?o:m.logInfo)(p.draining?`Waiting for TeXRA service ${p.version} (pid ${p.pid}) to finish ${f} and exit.`:`Updating TeXRA service ${p.version}: waiting for ${f} to finish before restarting.`),yield*l$n(p.socket,!0).pipe(m.mapError(h=>new df({reason:`Could not stop the older TeXRA service (pid ${p.pid}): ${h.message}`}))),c=null}if(c===null&&!l&&!n)return yield*new df({reason:KKa,failure:{kind:"none"}});if(c===null){let{log:p}=Bte(e),f=yield*t.pipe(m.mapError(S=>new df({reason:`The TeXRA service could not be started: ${S.message}`,failure:{kind:"startFailed"}}))),h=new df({reason:`TeXRA service did not respond within ${a$n} (log: ${p}).`,failure:{kind:"startFailed"}}),g=yield*ui.make(h),y=s.pipe(m.retry({while:i(S=>S.failure.kind==="unanswered","while")}),m.flatMap(S=>S!==null&&iMt(S)&&!S.draining?m.succeed(S):m.fail(h)),m.tapError(S=>ui.set(g,S)),m.catchIf(S=>S.failure.kind!=="incompatible"&&(o!==void 0||S.failure.kind!=="unreadable"),()=>m.succeed(null)));c=yield*jPo.pipe(De.mapEffect(()=>y),De.filter(Ye.isNotNull),De.runHead,m.flatMap(at.match({onNone:i(()=>m.flatMap(ui.get(g),m.fail),"onNone"),onSome:m.succeed})),m.timeoutOrElse({duration:a$n,orElse:i(()=>m.flatMap(ui.get(g),m.fail),"orElse")}),m.raceFirst(m.flatMap(f,S=>m.fail(new df({reason:`TeXRA service ${S} before responding (log: ${p}).`,failure:{kind:"startFailed"}})))))}let{socket:u}=c,d=yield*d$n(u,r).pipe(m.mapError(p=>new df({reason:`The TeXRA service on ${u} could not be reached: ${p.message}`})));return{info:c,client:d}}),X7e="The TeXRA service is offline; TeXRA is reconnecting to it.",ZPo="The running TeXRA service uses a different protocol. Reopen this terminal session or reload the window using the updated build.",ZKa=i(e=>({get:An.get(e),changes:An.changes(e)}),"followed"),m$n=i((e,t)=>({state:ZKa(e),client:{get:m.map(An.get(e),({client:n})=>n),changes:An.changes(e).pipe(De.map(({client:n})=>n),De.changes)},refusalTold:t}),"linkOver"),Dte=i(e=>m.flatMap(e.state.get,t=>"away"in t?m.fail(new df({reason:t.away})):m.succeed(t.client)),"linkedClient"),eMo=i(e=>e.state.changes.pipe(De.map(t=>"away"in t?t.away:null),De.changes),"linkOutage"),cMt=i(e=>e.state.changes.pipe(De.map(t=>"away"in t&&t.lasting?t.away:null),De.changes,De.filter(Ye.isNotNull)),"linkRefusals"),tMo=Xo.min([Xo.exponential("500 millis"),Xo.spaced("10 seconds")]),nMo=3,eYa=tMo.pipe(Xo.upTo({times:nMo-1})),rMo=m.fn("server.linkService")(function*(e,t){if(yield*mq(i$n))return yield*new df({reason:`${i$n} is set`,failure:{kind:"none"}});if(ru)return yield*new df({reason:u$n,failure:{kind:"none"}});let n=m.fn("connect")(function*(d,p,f){let h=yield*Dn.make(),g=yield*Nn.make();return{connection:yield*XKa(d,p,m.asVoid(Nn.succeed(g,void 0)),f).pipe(Dn.provide(h),m.onError(()=>Dn.close(h,zt.void))),lost:g,scope:h}}),r=yield*n(e,t.startsService,t.waiting),o=r,s=yield*An.make({client:r.connection.client}),a=i((d,p=!1)=>An.set(s,{client:null,away:d,lasting:p}),"awayFor"),c=yield*ui.make(!1);yield*m.addFinalizer(()=>m.suspend(()=>Dn.close(r.scope,zt.void)));let l=m.suspend(()=>{let d="";return n({storageRoot:e.storageRoot,start:m.succeed(m.never)},!0).pipe(m.catchIf(p=>p.failure.kind==="startFailed",()=>n(e,t.startsService)),m.tapError(p=>m.suspend(()=>p.message===d?m.void:(d=p.message,(p.failure.kind==="incompatible"||p.failure.kind==="unreadable"?a(ZPo,!0):a(X7e)).pipe(m.andThen(m.logWarning(`The TeXRA service is not back yet: ${p.message}`)))))),m.retry({schedule:tMo,while:i(p=>p.failure.kind!=="startFailed","while")}),m.tap(p=>m.logInfo(`Reconnected to the TeXRA service ${p.connection.info.version} (pid ${p.connection.info.pid}).`)))}),u=m.gen(function*(){let d=o??(yield*l);o=null,r=d,yield*ui.set(c,!1),yield*An.set(s,{client:d.connection.client}),yield*Nn.await(d.lost),yield*a(X7e),yield*Dn.close(d.scope,zt.void);let{pid:p,startedAt:f}=d.connection.info,h=(yield*Ar.currentTimeMillis)-f;if(yield*m.logWarning(`The TeXRA service (pid ${p}) went away; reconnecting.`),h<Zt.toMillis(a$n))return yield*new df({reason:`The TeXRA service (pid ${p}) went away ${Math.max(0,Math.round(h/1e3))} seconds after it started.`,failure:{kind:"startFailed"}})});return yield*m.forkScoped(m.forever(m.retry(u,eYa)).pipe(m.catch(d=>{let p=`The TeXRA service failed to start ${nMo} times in a row, so TeXRA stopped restarting it. The last failure: ${d.reason.replace(/\.$/,"")}. Its log is ${Bte(e.storageRoot).log}. Fix what the log names, then restart TeXRA (in VS Code, reload the window); with ${i$n}=1 set, TeXRA runs tasks without the service.`;return a(p,!0).pipe(m.andThen(m.logError(p)))}))),m$n(s,c)})});import{randomUUID as tYa}from"node:crypto";var oMo,nYa,Ufe,rYa,oYa,iMo,iYa,Pte,lMt=N(()=>{"use strict";Co();de();Jz();JOe();KPt();Rn();XOe();e4();oMo="service",nYa={openFile:i(e=>({event:"openFile",payload:e}),"openFile"),requestShowInstruction:i(e=>({event:"requestShowInstruction",payload:e}),"requestShowInstruction"),requestShowError:i(e=>({event:"requestShowError",payload:e}),"requestShowError")},Ufe=class extends A.TaggedError()("WindowCallFailed",{reason:A.Literals(["detached","no-answer","failed"]),message:A.String}){static{i(this,"WindowCallFailed")}},rYa=64,oYa=i(e=>e.roots.workspace??e.roots.storage,"projectOf"),iMo=i(()=>{let e=new Set,t=i((d,p)=>{let f;for(let h of e)h.key===d&&h.capabilities.has(p)&&(f===void 0||h.focusedAt>f.focusedAt)&&(f=h);return f},"target"),n=i((d,p)=>t(d,p)!==void 0,"offers"),r=i(d=>d.pipe(m.catchCause(Ir(oMo,"A TeXRA window did not take a host call"))),"tell"),o=i((d,p,f)=>m.suspend(()=>{let h=t(d,p);if(h===void 0)return m.fail(new Ufe({reason:"detached",message:"No TeXRA window is open for this project."}));let g=nPo[p];return f(h.calls).pipe(m.mapError(y=>new Ufe({reason:"failed",message:y.message})),m.timeoutOrElse({duration:g,orElse:i(()=>m.fail(new Ufe({reason:"no-answer",message:`The TeXRA window did not respond within ${g}.`})),"orElse")}),m.catchCause(y=>Qt.hasFails(y)?m.failCause(y):m.fail(Qt.hasDies(y)?new Ufe({reason:"failed",message:`The TeXRA window returned an unexpected response for ${p}.`}):new Ufe({reason:"detached",message:"The TeXRA window closed before responding."}))))}),"ask"),s=m.fn("detach")(function*(d){e.delete(d),[...e].some(p=>p.key===d.key)||(yield*m.logWarning(`No TeXRA window of ${d.project} is attached: its tasks run without diagnostics, inline criticism or PDF opening until one attaches.`))});return{windows:e,detach:s,interactionsOf:i(d=>{let p=d.roots.storage;return{emit:i((f,h)=>{let g=t(p,"notices"),y=nYa[f](h);return g===void 0?Ir(oMo,`Host notice ${f}`)(h):r(g.calls.notices({notice:y},{discard:!0}))},"emit")}},"interactionsOf"),answer:i((d,p)=>m.suspend(()=>{for(let f of e)if(f.id===d)return f.reply(p);return m.logWarning(`A TeXRA window answered a host call after its attachment ${d} ended`)}),"answer"),focus:i(d=>m.map(Ar.currentTimeMillis,p=>{for(let f of e)f.id===d&&(f.focusedAt=p)}),"focus"),filesWritten:i(d=>m.forEach([...e].filter(p=>p.capabilities.has("filesWritten")&&d.some(f=>Zp(p.project,f))),p=>r(p.calls.filesWritten({absolutePaths:d},{discard:!0})),{discard:!0}),"filesWritten"),editors:jPt(i(d=>({get readDiagnostics(){if(n(d,"readDiagnostics"))return p=>o(d,"readDiagnostics",f=>f.readDiagnostics({path:p})).pipe(m.mapError(f=>new UPt({reason:f.reason==="failed"?"read-failed":f.reason,path:p,message:f.message})))},get addCriticism(){if(n(d,"addCriticism"))return p=>o(d,"addCriticism",f=>f.addCriticism({entry:p}))},get openPdf(){if(n(d,"openPdf"))return({location:p,preserveFocus:f})=>o(d,"openPdf",h=>h.openPdf({location:p,preserveFocus:f})).pipe(m.mapError(h=>new QPt({path:p.absolutePath,message:h.message})))}}),"editorOf"))}},"makeWindowTable"),iYa=m.fn("make")(function*(e){let{windows:t,detach:n,interactionsOf:r,answer:o,focus:s}=e,a=yield*Ma.make({lookup:i(l=>l.attach(r(l)),"lookup")}),c=i((l,u)=>De.unwrap(m.gen(function*(){let d=yield*vi.bounded(rYa),{protocol:p,receive:f}=yield*XDo(y=>vi.offer(d,{kind:"call",message:y}).pipe(m.asVoid)),h=yield*lB.make(Ofe).pipe(m.provideService(lB.Protocol,p)),g={id:tYa(),key:l.roots.storage,project:oYa(l),capabilities:new Set(u),focusedAt:yield*Ar.currentTimeMillis,calls:h,reply:f};return t.add(g),yield*m.addFinalizer(()=>n(g)),yield*Ma.get(a,Gs.byReferenceUnsafe(l)),De.concat(De.succeed({kind:"attached",attachment:g.id}),De.fromQueue(d))})),"attach");return{attach:c,filesWritten:e.filesWritten,focus:s,answer:o,localLink:i(l=>m.zipWith(An.make({client:{"host.attach":i(({capabilities:u})=>c(l,u),"host.attach"),"host.answer":i(u=>o(u.attachment,u.message),"host.answer"),"host.focus":i(({attachment:u})=>s(u),"host.focus")}}),ui.make(!1),m$n),"localLink")}}),Pte=class e extends Ve.Service()("@texra-ai/texra/server/HostWindows"){static{i(this,"HostWindows")}static{this.layer=i(t=>gt.effect(e,iYa(t)),"layer")}}});import{fileURLToPath as r7a}from"node:url";import{tracingChannel as o7a,channel as i7a}from"node:diagnostics_channel";import{posix as u7a,win32 as F$n}from"node:path";import{fileURLToPath as d7a}from"node:url";import{lstatSync as p7a,readdir as f7a,readdirSync as m7a,readlinkSync as h7a,realpathSync as A7a}from"fs";import*as g7a from"node:fs";import{lstat as y7a,readdir as E7a,readlink as S7a,realpath as _7a}from"node:fs/promises";import{EventEmitter as $$n}from"node:events";import JMo from"node:stream";import{StringDecoder as b7a}from"node:string_decoder";function h$n(e){return isNaN(e)?e.charCodeAt(0):parseInt(e,10)}function _Ya(e){return e.replace(pYa,DMo).replace(fYa,PMo).replace(mYa,Q$n).replace(hYa,MMo).replace(AYa,LMo)}function bYa(e){return e.replace(aYa,"\\").replace(cYa,"{").replace(lYa,"}").replace(uYa,",").replace(dYa,".")}function A$n(e,t){for(let n=0;n<t.length;n++)e.push(t[n])}function CYa(e){let t=[],n="";for(;;){let r=BMo("{","}",e);if(!r){let l=e.split(",");return l[0]=n+l[0],A$n(t,l),t}let{pre:o,body:s,post:a}=r,c=o.split(",");if(c[0]=n+c[0],c[c.length-1]+="{"+s+"}",!a.length)return A$n(t,c),t;n=c.pop(),A$n(t,c),e=a}}function vYa(e,t={}){if(!e)return[];let{max:n=gYa,maxLength:r=yYa,maxDepth:o=EYa,maxRewrites:s=SYa}=t;return e.slice(0,2)==="{}"&&(e="\\{\\}"+e.slice(2)),O$n(_Ya(e),n,r,o,0,s,!0).map(bYa)}function IYa(e){return"{"+e+"}"}function xYa(e){return/^-?0\d/.test(e)}function wYa(e,t){return e<=t}function TYa(e,t){return e>=t}function Z7e(e,t,n,r,o,s){let a=[],c=0;for(let l=0;l<e.length;l++)for(let u=0;u<n.length;u++){if(a.length>=r)return a;let d=e[l]+t+n[u];if(!(s&&!d)){if(c+d.length>o)return a;a.push(d),c+=d.length}}return a}function RYa(e,t,n,r){let o=e.split(/\.\./),s=[];if(o[0]===void 0||o[1]===void 0)return s;let a=h$n(o[0]),c=h$n(o[1]),l=Math.max(o[0].length,o[1].length),u=o.length===3&&o[2]!==void 0?Math.max(Math.abs(h$n(o[2])),1):1,d=wYa;c<a&&(u*=-1,d=TYa);let p=o.some(xYa),f=0;for(let h=a;d(h,c)&&s.length<n;h+=u){let g;if(t)g=String.fromCharCode(h),g==="\\"&&(g="");else if(g=String(h),p){let y=l-g.length;if(y>0){let S=new Array(y+1).join("0");h<0?g="-"+S+g.slice(1):g=S+g}}if(f+g.length>r)break;s.push(g),f+=g.length}return s}function O$n(e,t,n,r,o,s,a){if(o>r)return[e];let c=[""],l=0,u=!1,d=!0;for(;;){let p=BMo("{","}",e);if(!p)return Z7e(c,e,[""],t,n,u);let f=p.pre;if(/\$$/.test(f)){if(c=Z7e(c,f+"{"+p.body+"}",[""],t,n,u&&!p.post.length),d=!1,!p.post.length)break;e=p.post;continue}let h=/^-?\d+\.\.-?\d+(?:\.\.-?\d+)?$/.test(p.body),g=/^[a-zA-Z]\.\.[a-zA-Z](?:\.\.-?\d+)?$/.test(p.body),y=h||g,S=p.body.indexOf(",")>=0;if(!y&&!S){if(l<s&&p.post.match(/,(?!,).*\}/)){l++,e=p.pre+"{"+p.body+Q$n+p.post,a=!0;continue}return Z7e(c,f+"{"+p.body+"}"+p.post,[""],t,n,u)}d&&(u=a&&!y,d=!1);let _;if(y)_=RYa(p.body,g,t,n);else{let b=CYa(p.body);if(b.length===1&&b[0]!==void 0&&(b=O$n(b[0],t,n,r,o+1,s,!1).map(IYa),b.length===1)){if(c=Z7e(c,f+b[0],[""],t,n,u&&!p.post.length),!p.post.length)break;e=p.post;continue}let v=u&&!p.post.length&&!f;for(let R=0;v&&R<c.length;R++)c[R]&&(v=!1);_=[];let x=0;e:for(let R=0;R<b.length;R++){let O=O$n(b[R],t,n,r,o+1,s,!1);for(let T=0;T<O.length;T++){let B=O[T];if(!(v&&!B)){if(_.length>=t||x+B.length>n)break e;_.push(B),x+=B.length}}}}if(c=Z7e(c,f,_,t,n,u&&!p.post.length),!p.post.length)break;e=p.post}return c}function kMt(e,t={}){return new rW(e,t).streamSync()}function yLo(e,t={}){return new rW(e,t).stream()}function OMt(e,t={}){return new rW(e,t).walkSync()}async function NMo(e,t={}){return new rW(e,t).walk()}function NMt(e,t={}){return new rW(e,t).iterateSync()}function ELo(e,t={}){return new rW(e,t).iterate()}var BMo,sMo,sYa,DMo,PMo,Q$n,MMo,LMo,aYa,cYa,lYa,uYa,dYa,pYa,fYa,mYa,hYa,AYa,gYa,yYa,EYa,SYa,N$n,g$n,pJe,aMo,kYa,OYa,eJe,y$n,NYa,B$n,BYa,Hfe,DYa,FMo,uMt,UMo,j$n,PYa,MYa,QMo,jMo,LYa,FYa,UYa,HMo,cMo,D$n,$Mo,QYa,jYa,HYa,$Ya,GMo,GYa,lMo,qYa,zYa,dMt,uMo,dMo,IMt,H$n,qMo,gB,oNe,WYa,VYa,zMo,pMo,KYa,qy,YYa,eW,JYa,P$n,XYa,ZYa,e7a,fMo,WMo,t7a,n7a,E$n,mMo,Fte,hMo,M$n,S$n,bMt,_$n,pMt,tJe,xMt,L$n,AMo,b$n,$fe,Gv,aJe,s7a,C$n,VMo,gMo,a7a,c7a,Lte,KMo,CMt,l7a,RMt,yMo,C7a,v7a,I7a,tW,nW,Mte,fMt,nJe,mMt,EMo,hMt,SMo,TQ,iNe,l0,rJe,sNe,u0,DT,d0,v$n,AMt,Fx,oS,I$n,x$n,_Mo,w$n,t4,T$n,gMt,oJe,Qfe,AB,iJe,x7a,w7a,T7a,R7a,XMo,k7a,O7a,N7a,wMt,B7a,lJe,ZMo,D7a,P7a,M7a,bMo,L7a,F7a,U7a,Q7a,uL,eLo,tLo,n4,nLo,rLo,jfe,oLo,lL,sJe,R$n,CMo,uJe,RQ,yMt,vMt,vMo,j7a,k$n,IMo,dJe,xMo,EMt,wMo,H7a,iLo,E1,sLo,cLo,uLo,G$n,q$n,dLo,Ydp,$7a,G7a,q7a,z7a,pLo,W7a,TMo,V7a,hLo,K7a,RMo,SMt,_Mt,Y7a,gLo,kMo,OMo,J7a,rW,z$n,X7a,Z7a,eJa,tJa,nJa,TMt,BMt=N(()=>{BMo=i((e,t,n)=>{let r=e instanceof RegExp?sMo(e,n):e,o=t instanceof RegExp?sMo(t,n):t,s=r!==null&&o!=null&&sYa(r,o,n);return s&&{start:s[0],end:s[1],pre:n.slice(0,s[0]),body:n.slice(s[0]+r.length,s[1]),post:n.slice(s[1]+o.length)}},"re"),sMo=i((e,t)=>{let n=t.match(e);return n?n[0]:null},"We"),sYa=i((e,t,n)=>{let r,o,s,a,c,l=n.indexOf(e),u=n.indexOf(t,l+1),d=l;if(l>=0&&u>0){if(e===t)return[l,u];for(r=[],s=n.length;d>=0&&!c;){if(d===l)r.push(d),l=n.indexOf(e,d+1);else if(r.length===1){let p=r.pop();p!==void 0&&(c=[p,u])}else o=r.pop(),o!==void 0&&o<s&&(s=o,a=u),u=n.indexOf(t,d+1);d=l<u&&l>=0?l:u}r.length&&a!==void 0&&(c=[s,a])}return c},"js"),DMo="\0SLASH"+Math.random()+"\0",PMo="\0OPEN"+Math.random()+"\0",Q$n="\0CLOSE"+Math.random()+"\0",MMo="\0COMMA"+Math.random()+"\0",LMo="\0PERIOD"+Math.random()+"\0",aYa=new RegExp(DMo,"g"),cYa=new RegExp(PMo,"g"),lYa=new RegExp(Q$n,"g"),uYa=new RegExp(MMo,"g"),dYa=new RegExp(LMo,"g"),pYa=/\\\\/g,fYa=/\\{/g,mYa=/\\}/g,hYa=/\\,/g,AYa=/\\\./g,gYa=1e5,yYa=4e6,EYa=1e3,SYa=1e3;i(h$n,"oe");i(_Ya,"Qs");i(bYa,"ti");i(A$n,"he");i(CYa,"ei");i(vYa,"Ge");i(IYa,"si");i(xYa,"ii");i(wYa,"ni");i(TYa,"ri");i(Z7e,"ct");i(RYa,"oi");i(O$n,"ae");N$n=i((e,t)=>e===t?{t:"lit",ch:String(e)}:{t:"class",re:new RegExp(`^[${e}-${t}]$`)},"fe"),g$n=i((e,t)=>t.map(n=>[N$n(e,e),...n]),"ce"),pJe=i((e,t)=>{if(!e)return[[]];let n=+e[0],r=+t[0],o=e.slice(1),s=t.slice(1);if(n===r)return g$n(n,pJe(o,s));let a="0".repeat(o.length),c="9".repeat(o.length),l=[];o!==a&&l.push(...g$n(n++,pJe(o,c)));let u=s===c?[]:g$n(r--,pJe(a,s));return n<=r&&l.push([N$n(n,r),...Array.from(o,()=>N$n(0,9))]),l.push(...u),l},"ft"),aMo=i((e,t,n)=>{if(n)return pJe(String(e).padStart(n,"0"),String(t).padStart(n,"0"));let r=[];for(let o=String(e).length;o<=String(t).length;o++){let s=Math.max(e,o===1?0:10**(o-1)),a=Math.min(t,10**o-1);r.push(...pJe(String(s),String(a)))}return r},"He"),kYa=i((e,t)=>{let n=Number(e),r=Number(t);if(!Number.isSafeInteger(n)||!Number.isSafeInteger(r))return;n>r&&([n,r]=[r,n]);let o=/^-?0\d/.test(e)||/^-?0\d/.test(t)?Math.max(e.length,t.length):0,s=[];if(n<0){let a=aMo(Math.max(-r,1),-n,o&&o-1);s.push(...a.map(c=>[{t:"lit",ch:"-"},...c]))}return r>=0&&s.push(...aMo(Math.max(n,0),r,o)),s},"qe"),OYa={"[:alnum:]":["\\p{L}\\p{Nl}\\p{Nd}"],"[:alpha:]":["\\p{L}\\p{Nl}"],"[:ascii:]":["\\x00-\\x7f"],"[:blank:]":["\\p{Zs}\\t"],"[:cntrl:]":["\\p{Cc}"],"[:digit:]":["\\p{Nd}"],"[:graph:]":["\\p{Z}\\p{C}",!0],"[:lower:]":["\\p{Ll}"],"[:print:]":["\\p{C}",!0],"[:punct:]":["\\p{P}\\p{S}"],"[:space:]":["\\p{Z}\\t\\r\\n\\v\\f"],"[:upper:]":["\\p{Lu}"],"[:word:]":["\\p{L}\\p{Nl}\\p{Nd}\\p{Pc}"],"[:xdigit:]":["A-Fa-f0-9"]},eJe=i(e=>e.replace(/[[\]\\-]/g,"\\$&"),"ut"),y$n=/$./,NYa=i((e,t,n=!1,r)=>{let o=i(_=>{let b=r?_.normalize(r):_;return[...b].length===1?b:_},"i"),s=t;if(e.charAt(s)!=="[")throw new Error("not in a brace expression");let a=[],c=[],l=s+1,u=!1,d=!1,p=!1,f=s,h="";e:for(;l<e.length;){let _=String.fromCodePoint(e.codePointAt(l));if((_==="!"||_==="^")&&l===s+1){p=!0,l++;continue}if(_==="]"&&u&&!d){f=l+1;break}if(u=!0,_==="\\"&&!d){d=!0,l++;continue}if(_==="["&&!d){for(let[v,[x,R]]of Object.entries(OYa))if(e.startsWith(v,l)){if(h)return[y$n,e.length-s];l+=v.length,R?c.push(x):a.push(x);continue e}}d=!1;let b=o(_);if(h){b.codePointAt(0)>h.codePointAt(0)?a.push(eJe(h)+"-"+eJe(b)):b===h&&a.push(eJe(b)),h="",l+=_.length;continue}if(e.startsWith("-]",l+_.length)){a.push(eJe(b+"-")),l+=_.length+1;continue}if(e.startsWith("-",l+_.length)){h=b,l+=_.length+1;continue}a.push(eJe(b)),l+=_.length}if(f<l)return[y$n,0];if(!a.length&&!c.length)return[y$n,e.length-s];let g="["+(p?"^":"")+a.join("")+"]",y="["+(p?"":"^")+c.join("")+"]",S="^"+(a.length&&c.length?"("+g+"|"+y+")":a.length?g:y);return[new RegExp(S,n?"iu":"u"),f-s]},"Ke"),B$n={t:"match",id:0},BYa="!?+*@",Hfe=i(e=>({t:"lit",ch:e}),"Z"),DYa=i(e=>e.replace(/[\\^$.*+?()[\]{}|/]/g,"\\$&"),"li"),FMo=i(e=>new RegExp(`^${DYa(e)}$`,"iu"),"Je"),uMt=new Map,UMo=i(e=>{let t=uMt.get(e);return t||(t=FMo(e),uMt.size>=1e3&&uMt.clear(),uMt.set(e,t)),t},"Ze"),j$n=i((e,t)=>{if(t===e.ch)return!0;if(!e.re)return!1;let n=t.charCodeAt(0);if(n>=128)return e.re.test(t);let r=e.ascii??=new Uint8Array(128);return r[n]||=e.re.test(t)?1:2,r[n]===1},"ge"),PYa=i((e,t,n,r,o)=>{let s=[];for(let a=0;a<e.length;){let c=String.fromCodePoint(e.codePointAt(a));if(o){let l=c==="\\"&&e.startsWith(o,a+1)?1:0;if(l||c===o){let u=a+l+o.length,d=e.indexOf(o,u),p=/^(-?\d+)\.\.(-?\d+)$/.exec(e.slice(u,d)),f=d!==-1&&p&&kYa(p[1],p[2]);if(f){s.push({t:"ext",type:"@",alts:f}),a=d+o.length;continue}}}if(c==="\\"){let l=e.codePointAt(a+1),u=l===void 0?c:String.fromCodePoint(l);s.push(Hfe(u)),a+=1+u.length;continue}if(c==="["){let[l,u]=NYa(e,a,t,r);if(u){s.push({t:"class",re:l}),a+=u;continue}}if(!n&&BYa.includes(c)&&e[a+1]==="("){s.push({t:"open",type:c}),a+=2;continue}s.push(!n&&c==="|"?{t:"bar"}:!n&&c===")"?{t:"close"}:c==="*"?{t:"star"}:c==="?"?{t:"any"}:Hfe(c)),a+=c.length}return s},"ci"),MYa=i(e=>{let t=new Map,n=[];return e.forEach((r,o)=>{r.t==="open"?n.push(o):r.t==="close"&&n.length&&t.set(n.pop(),o)}),t},"fi"),QMo=i((e,t,n,r,o)=>{let s=[],a=[s];for(let c=n;c<r;c++){let l=e[c],u=t.get(c);if(l.t==="open"&&u!==void 0){let d=QMo(e,t,c+1,u,!1);s.push({t:"ext",type:l.type,alts:d}),c=u}else l.t==="bar"&&!o?a.push(s=[]):l.t==="open"?s.push(Hfe(l.type),Hfe("(")):l.t==="bar"?s.push(Hfe("|")):l.t==="close"?s.push(Hfe(")")):s.push(l)}return a},"Qe"),jMo=i((e,t)=>{let n=[],r="",o=i(()=>{for(let s of r.normalize(t))n.push(Hfe(s));r=""},"i");for(let s of e){if(s.t==="lit"){r+=s.ch;continue}o(),n.push(s.t==="ext"?{...s,alts:s.alts.map(a=>jMo(a,t))}:s)}return o(),n},"ts"),LYa=i((e,t)=>{let n=1,r=i(a=>({t:"split",id:n++,out:a}),"s"),o=i((a,c)=>a.reduceRight((l,u)=>s(u,l),c),"i"),s=i((a,c)=>{switch(a.t){case"lit":let p=t?UMo(a.ch):void 0;return{t:"lit",id:n++,ch:a.ch,re:p,next:c};case"any":case"star":return{t:a.t,id:n++,next:c};case"class":return{t:"class",id:n++,re:a.re,next:c}}let l=i(p=>a.alts.map(f=>o(f,p)),"l");switch(a.type){case"@":return r(l(c));case"?":return r([c,...l(c)]);case"!":return{t:"neg",id:n++,sub:r(l(B$n)),next:c}}let u=r([]),d=r(l(u));return u.out.push(c,d),a.type==="*"?u:d},"n");return[o(e,B$n),n]},"ui"),FYa=i(e=>{let t=[],n=new Set,r=i(s=>s.t==="match"?"match":String(s.id),"s"),o=i((s,a)=>{if(s.t==="match"||n.has(s))return;n.add(s);let c=i(l=>t.push(`${a}${s.id}: ${l}`),"h");switch(s.t){case"split":c(`split -> ${s.out.map(r).join(", ")}`);for(let l of s.out)o(l,a);return;case"neg":return c(`!(${r(s.sub)}) -> ${r(s.next)}`),o(s.sub,a+" "),o(s.next,a);case"lit":c(`${JSON.stringify(s.ch)} -> ${r(s.next)}`);break;case"class":c(`${s.re} -> ${r(s.next)}`);break;default:c(`${s.t==="any"?"?":"*"} -> ${r(s.next)}`)}o(s.next,a)},"i");return o(e,""),[`start -> ${r(e)}`,...t].join(`
|
|
1035
1035
|
`)},"di"),UYa=class{static{i(this,"pe")}gen;threads=[];match=!1;runs=[];ids=[];constructor(e){this.gen=e}get dead(){return!this.threads.length&&!this.match&&!this.runs.length}},HMo=i((e,t)=>e.ids.length!==t.ids.length||e.runs.length!==t.runs.length||e.ids.some((n,r)=>n!==t.ids[r])?!1:e.runs.every(n=>t.runs.some(r=>r.neg===n.neg&&HMo(r.state,n.state))),"es"),cMo=i(e=>({has:new Float64Array(e),seen:new Float64Array(e),gen:0}),"Xe"),D$n=class{static{i(this,"dt")}dots;dotStart;#e;constructor(e,t,n){this.dots=e,this.dotStart=t,this.#e=n}state(){return new UYa(++this.#e.gen)}done(e){return e.ids=e.threads.map(t=>t.id).sort((t,n)=>t-n),e.match&&e.ids.unshift(B$n.id),e}#t(e,t){let{seen:n}=this.#e;return n[t.id]===e.gen?!1:(n[t.id]=e.gen,!0)}#n(e,t){let{has:n}=this.#e;return n[t.id]===e.gen?!1:(n[t.id]=e.gen,e.threads.push(t),!0)}restricted(e,t){return t&&(this.dots||this.dotStart&&e===0)}add(e,t,n,r){switch(t.t){case"split":if(!this.#t(e,t))return;for(let s of t.out)this.add(e,s,n,r);return;case"neg":if(!this.#t(e,t))return;let o=this.state();return this.add(o,t.sub,n,!1),this.done(o),this.addRun(e,{t:"run",neg:t,state:o},n,r);case"star":if(this.restricted(n,r))return;this.#n(e,t)&&this.add(e,t.next,n,r);return;case"match":e.match=!0;return;default:this.#n(e,t)}}addRun(e,t,n,r){for(let o of e.runs)if(o.neg===t.neg&&HMo(o.state,t.state))return;e.runs.push(t),t.state.match||this.add(e,t.neg.next,n,r)}step(e,t,n,r){let o=this.state();for(let s of e.threads)switch(s.t){case"lit":j$n(s,t)&&this.add(o,s.next,n+1,r);break;case"any":this.restricted(n,r)||this.add(o,s.next,n+1,r);break;case"class":!this.restricted(n,r)&&s.re.test(t)&&this.add(o,s.next,n+1,r);break;case"star":this.restricted(n,r)||this.add(o,s,n+1,r)}if(!this.restricted(n,r))for(let s of e.runs){if(s.state.dead){this.addRun(o,s,n+1,r);continue}let a=this.step(s.state,t,n,!1);this.addRun(o,{t:"run",neg:s.neg,state:a},n+1,r)}return this.done(o)}},$Mo=i(e=>{let t=e.ids.join();if(!e.runs.length)return t;let n=e.runs.map(r=>`${r.neg.id}(${$Mo(r.state)})`);return`${t}|${n.sort().join("|")}`},"ss"),QYa=1<<18,jYa=class{static{i(this,"me")}#e;#t=new Map;#n=0;#r;#o;#s;#i;constructor(e,t){this.#e=e,this.#s=new D$n(!1,!1,t),this.#i=new D$n(!1,!0,t)}#a(e){return{state:e,match:e.match,dead:e.dead,next:new Map}}#c(e){let t=$Mo(e),n=this.#t.get(t);if(n)return n;this.#n>QYa&&this.#p();let r=this.#a(e);return this.#t.set(t,r),this.#n+=t.length+1,r}#p(){this.#t.clear(),this.#n=0,this.#r=void 0,this.#o=void 0}start(e){if(e){if(this.#o)return this.#o;let n=this.#i.state();return this.#i.add(n,this.#e,0,!0),this.#o=this.#a(this.#i.done(n))}if(this.#r)return this.#r;let t=this.#s.state();return this.#s.add(t,this.#e,0,!0),this.#r=this.#c(this.#s.done(t))}next(e,t){let n=t.charCodeAt(0),r=n<128?void 0:e.next.get(t);if(r)return r;let o=e===this.#o?this.#c(this.#i.step(e.state,t,0,!0)):this.#c(this.#s.step(e.state,t,1,!0));return n<128?(e.ascii||(e.ascii=new Array(128),this.#n+=128),e.ascii[n]=o):e.next.set(t,o),this.#n++,o}},HYa=i(e=>{let t=[];for(let n=e;n.t!=="match";n=n.next){if(n.t==="split"||n.t==="neg")return;t.push(n)}return t},"mi"),$Ya=i((e,t,n,r)=>{let o=0,s=n,a=-1,c=0;for(;s<r;){let l=e[o];if(l?.t==="star"){a=o++,c=s;continue}let u=t[s];if(l&&(l.t==="any"||l.t==="lit"&&j$n(l,u)||l.t==="class"&&l.re.test(u))){o++,s++;continue}if(a===-1)return!1;o=a+1,s=++c}for(;e[o]?.t==="star";)o++;return o===e.length},"gi"),GMo=i(e=>{let t=0,n=0;for(let r of e){let[o,s]=GYa(r);t+=o,n+=s}return[t,n]},"is"),GYa=i(e=>{if(e.t==="star")return[0,1/0];if(e.t!=="ext")return[1,1];if(e.type==="!")return[0,1/0];let t=e.alts.map(GMo),n=Math.min(...t.map(s=>s[0])),r=Math.max(...t.map(s=>s[1])),o=r===0?0:1/0;return e.type==="@"?[n,r]:e.type==="?"?[0,r]:e.type==="*"?[0,o]:[n,o]},"wi"),lMo=i((e,t,n)=>{for(let r=0;r<e.length;r++)if(!j$n(e[r],t[n+r]))return!1;return!0},"Ve"),qYa=/[/\ud800-\udfff]/,zYa=/[\ud800-\udfff]/,dMt=i(e=>zYa.test(e)?[...e]:e,"Nt"),uMo=i(e=>{if(e.includes("/"))throw new Error("can only match a single path portion, got: "+e)},"Ye"),dMo=class{static{i(this,"pt")}pattern;options;#e;#t;#n;#r;#o;#s=!1;#i;#a;#c=!1;#p=0;#d=1/0;#u=[];#l=[];#f;#m;#y=!1;#A;#E;constructor(e,t={}){if(e.includes("/"))throw new Error("can only match a single path portion, got pattern: "+e);this.pattern=e,this.options=t;let{nocase:n=!1,noext:r=!1,normalize:o}=t;this.#E=o===!0?"NFC":o||void 0;let s=/^[?*+@]\(\)$/.test(e),a=PYa(e,n,r||s,this.#E,t.rangeMark),[c]=QMo(a,MYa(a),0,a.length,!0);this.#E&&(c=jMo(c,this.#E));let[l,u]=LYa(c,n);if(this.#e=l,this.#t=u,c.every(d=>d.t==="lit"))this.#o=c.map(d=>d.ch).join(""),this.#s=n;else{let d=i(h=>h.t!=="lit"?void 0:n?{ch:h.ch,re:UMo(h.ch)}:{ch:h.ch},"f");for(let h of c){let g=d(h);if(!g)break;this.#u.push(g)}for(let h=c.length-1;h>=0;h--){let g=d(c[h]);if(!g)break;this.#l.unshift(g)}this.#y=!!(this.#u.length||this.#l.length),n||(this.#f=this.#u.map(h=>h.ch).join(""),this.#m=this.#l.map(h=>h.ch).join("")),this.#a=HYa(this.#e)?.slice(this.#u.length,-this.#l.length||void 0),this.#c=!!this.#a?.every(h=>h.t==="star"||h.t==="any");let[p,f]=GMo(c);this.#p=p,this.#d=f}}test(e){return this.#E?(uMo(e),this.#g(e.normalize(this.#E))):qYa.test(e)?(uMo(e),this.#g(e,[...e])):this.#g(e,e)}testUnchecked(e){return this.#g(this.#E?e.normalize(this.#E):e)}#g(e,t){if(this.#o!==void 0)return this.#s?(this.#i??=FMo(this.#o)).test(e):e===this.#o;let n=this.#p,r=this.#d;if(t===void 0){let u=e.length,d=u+1>>1;if(u<n||d>r)return!1;(d<n||u>r)&&(t=dMt(e))}if(t!==void 0&&(t.length<n||t.length>r))return!1;let o=this.#u.length;if(this.#y)if(this.#f!==void 0&&this.#m!==void 0){if(!e.startsWith(this.#f)||!e.endsWith(this.#m))return!1}else{t??=dMt(e);let u=t.length-this.#l.length;if(!lMo(this.#u,t,0)||!lMo(this.#l,t,u))return!1}let s=!this.options.dot&&e.startsWith(".");if(this.#a){if(e==="."||e===".."||s&&!o)return!1;if(this.#c)return!0;t??=dMt(e);let u=t.length-this.#l.length;return $Ya(this.#a,t,o,u)}if(t??=dMt(e),e==="."||e===".."){this.#n??=cMo(this.#t);let u=this.#r??=new D$n(!0,!1,this.#n),d=u.state();u.add(d,this.#e,0,!0);let p=u.done(d);for(let f=0;f<t.length;f++)p=u.step(p,t[f],f,!0);return p.match}this.#n??=cMo(this.#t);let a=this.#A??=new jYa(this.#e,this.#n),c=a.start(s),l=t===e;for(let u=0;u<t.length;u++){if(c.dead)return!1;let d=l?e.charCodeAt(u):t[u].charCodeAt(0);c=c.ascii?.[d]??a.next(c,t[u])}return c.match}toString(){return FYa(this.#e)}},IMt=i(e=>{if(typeof e!="string")throw new TypeError("invalid pattern");if(e.length>65536)throw new TypeError("pattern is too long")},"mt"),H$n=i((e,{windowsPathsNoEscape:t=!1,magicalBraces:n=!1}={})=>n?t?e.replace(/[?*()[\]{}]/g,"[$&]"):e.replace(/[?*()[\]\\{}]/g,"\\$&"):t?e.replace(/[?*()[\]]/g,"[$&]"):e.replace(/[?*()[\]\\]/g,"\\$&"),"K"),qMo=i((e,{windowsPathsNoEscape:t=!1,magicalBraces:n=!0}={})=>n?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"),"st"),gB=i((e,t,n={})=>(IMt(t),!n.nocomment&&t.charAt(0)==="#"?!1:VYa(t,n).match(e)),"T"),oNe=new Map,WYa=256,VYa=i((e,t)=>{let n=e+"\0"+JSON.stringify(t),r=oNe.get(n);return r?oNe.delete(n):(r=new $fe(e,{...t}),oNe.size>=WYa&&oNe.delete(oNe.keys().next().value)),oNe.set(n,r),r},"xi"),zMo=typeof process=="object"&&process?process.env?.__MINIMATCH_TESTING_PLATFORM__||process.platform:"posix",pMo={win32:{sep:"\\"},posix:{sep:"/"}},KYa=zMo==="win32"?pMo.win32.sep:pMo.posix.sep;gB.sep=KYa;qy=Symbol("globstar **");gB.GLOBSTAR=qy;YYa=i((e,t={})=>n=>gB(n,e,t),"Ei");gB.filter=YYa;eW=i((e,t={})=>Object.assign({},e,t),"U"),JYa=i(e=>{if(!e||typeof e!="object"||!Object.keys(e).length)return gB;let t=gB;return Object.assign((n,r,o={})=>t(n,r,eW(e,o)),{Minimatch:class extends t.Minimatch{static{i(this,"Minimatch")}constructor(n,r={}){super(n,eW(e,r))}static defaults(n){return t.defaults(eW(e,n)).Minimatch}},unescape:i((n,r={})=>t.unescape(n,eW(e,r)),"unescape"),escape:i((n,r={})=>t.escape(n,eW(e,r)),"escape"),filter:i((n,r={})=>t.filter(n,eW(e,r)),"filter"),defaults:i(n=>t.defaults(eW(e,n)),"defaults"),braceExpand:i((n,r={})=>t.braceExpand(n,eW(e,r)),"braceExpand"),match:i((n,r,o={})=>t.match(n,r,eW(e,o)),"match"),sep:t.sep,GLOBSTAR:qy})},"ki");gB.defaults=JYa;P$n=i((e,t={})=>(IMt(e),t.nobrace||!/\{(?:(?!\{).)*\}/.test(e)?[e]:vYa(e,{max:t.braceExpandMax})),"xe");gB.braceExpand=P$n;XYa=100,ZYa=/(?<![\\$])\{(-?\d+)\.\.(-?\d+)\}/g,e7a=i((e,t,n={})=>{let r=new $fe(t,n);return e=e.filter(o=>r.match(o)),r.options.nonull&&!e.length&&e.push(t),e},"Mi");gB.match=e7a;fMo=/[?*]|[+@!]\(.*?\)|\[|\]/,WMo=i((e,t)=>{let n=t+1;(e.charAt(n)==="!"||e.charAt(n)==="^")&&n++;let r=!1;for(;n<e.length;n++){let o=e.charAt(n);if(o==="]"&&r)return n;r=!0,o==="\\"&&n++}return-1},"cs"),t7a=i((e,t)=>{if(!t&&(e==="+()"||e==="@()"))return e;let n="";for(let r=0;r<e.length;r++){let o=e.charAt(r);if(o==="\\")n+=e.charAt(++r)||o;else{if(o==="*"||o==="?")return;if(o==="["){let s=WMo(e,r);if(s===-1){n+=o;continue}let a=e.slice(r+1,s);if(a.startsWith("\\")&&(a=a.slice(1)),[...a].length!==1||"!^".includes(e.charAt(r+1)))return;n+=a,r=s}else{if(!t&&"+@!".includes(o)&&e.charAt(r+1)==="("&&e.includes(")",r+2))return;n+=o}}}return n},"Ri"),n7a=i(e=>{if(/^[?*+@]\(\)$/.test(e)||e.includes("[:"))return!1;let t=0;for(let n=0;n<e.length;n++){let r=e.charAt(n);if(r==="\\"){if(++n===e.length)return!1}else if(r==="["){let o=WMo(e,n);o!==-1&&(n=o)}else if("+@!?*".includes(r)&&e.charAt(n+1)==="(")t++,n++;else if(r===")"){if(!t--)return!1}else if(r==="|"&&!t)return!1}return!t},"Oi"),Fte=i((e,t)=>typeof e=="string"?t===e:t!==""&&e.testUnchecked(t),"X"),hMo=i((e,t,n,r,o)=>Fte(e,t)?n:r!==void 0&&Fte(e,r)?o:-1,"hs"),M$n=i(e=>e==="."||e==="..","ve"),S$n=i(e=>typeof e=="string"&&/^[a-z]:$/i.test(e),"be"),bMt=i(e=>typeof e=="string"&&/^unc$/i.test(e),"zt"),_$n=i(e=>{if(e[0]!==""||e[1]!=="")return-1;let t=e[2]!=="?"?2:bMt(e[3])?4:-1,n=e[t],r=e[t+1];return t!==-1&&n!==void 0&&n!==""&&n!==qy&&r!==void 0&&r!==""&&r!==qy?t:-1},"ye"),pMt=i((e,t)=>!M$n(e)&&(t||!e.startsWith(".")),"Pt"),tJe=i((e,t,n,r,o)=>{for(let s=t;s<n;){if(e.charCodeAt(s)===46){if(!r)return!0;let c=e.charCodeAt(s+1)===46?s+2:s+1;if(c>=n||xMt(e.charCodeAt(c),o))return!0}let a=L$n(e,s,o);if(a===-1)return!1;for(s=a+1;s<n&&xMt(e.charCodeAt(s),o);)s++}return!1},"gt"),xMt=i((e,t)=>t==="/"?e===47:t==="\\"?e===92:e===47||e===92,"Lt"),L$n=i((e,t,n)=>{if(n!=="both")return e.indexOf(n,t);let r=e.indexOf("/",t),o=e.indexOf("\\",t);return r===-1?o:o===-1?r:Math.min(r,o)},"Ee"),AMo=i((e,t,n)=>n!=="both"?e.lastIndexOf(n,t):Math.max(e.lastIndexOf("/",t),e.lastIndexOf("\\",t)),"as"),b$n={},$fe=class{static{i(this,"D")}options;set;pattern;windowsPathsNoEscape;nonegate;negate;comment;empty;preserveMultipleSlashes;partial;globSet;globParts;nocase;isWindows;platform;windowsNoMagicRoot;maxGlobstarRecursion;#e;#t;#n;#r;#o=[];#s=[];#i=[];#a=new Map;#c=!1;#p;#d=new WeakMap;constructor(e,t={}){IMt(e),t=t||{},this.options=t,this.maxGlobstarRecursion=t.maxGlobstarRecursion??200,this.pattern=e,this.platform=t.platform||zMo,this.isWindows=this.platform==="win32";let n="allowWindowsEscape";this.windowsPathsNoEscape=!!t.windowsPathsNoEscape||t[n]===!1,this.windowsPathsNoEscape&&(this.pattern=this.pattern.replace(/\\/g,"/")),this.preserveMultipleSlashes=!!t.preserveMultipleSlashes,this.negate=!1,this.nonegate=!!t.nonegate,this.comment=!1,this.empty=!1,this.partial=!!t.partial,this.nocase=!!this.options.nocase,this.windowsNoMagicRoot=t.windowsNoMagicRoot!==void 0?t.windowsNoMagicRoot:!!(this.isWindows&&this.nocase),this.globSet=[],this.globParts=[],this.set=[],this.#e=!this.preserveMultipleSlashes,this.#n=(t.optimizationLevel??1)>=2;let r=t.normalize;this.#r=r===!0?"NFC":r||void 0,this.make();let o=this.set.map(s=>this.#l(s));this.#i=this.set.map((s,a)=>this.#e&&s.length-1>o[a]),this.#o=this.set.map((s,a)=>{let c=this.#i[a]?s.length-1:s.length,l=s.slice(o[a]+1,c).filter(u=>typeof u=="string"&&!!u);return[...new Set(l)]}),this.#t=this.#o.some(s=>s.length),this.#s=this.set.map((s,a)=>{let[c,l,u]=s;if(this.#i[a]&&s.length===2&&c===qy&&l!==qy)return"tail";if(this.#i[a]&&t.matchBase&&s.length===1&&c!==qy&&c!=="")return"base";if(!(!this.#e||o[a]!==-1)){if(s.length===3&&c===qy&&u===qy&&l!==qy&&l!==""&&this.maxGlobstarRecursion>0)return"mid";if(s.length===2&&l===qy&&c!==qy&&c!=="")return"head"}})}#u(e){return this.#r?e.normalize(this.#r):e}#l(e){if(!this.isWindows)return-1;if(S$n(e[0]))return 0;if(e[0]===""&&e[1]===""&&e[2]==="?"&&S$n(e[3]))return 3;let t=_$n(e);return t===-1?-1:t+1}hasMagic(){if(this.options.magicalBraces&&this.set.length>1)return!0;for(let e of this.set)for(let t of e)if(typeof t!="string")return!0;return!1}make(){let e=this.pattern,t=this.options;if(!t.nocomment&&e.charAt(0)==="#"){this.comment=!0;return}if(!e){this.empty=!0;return}this.parseNegate(),this.globSet=[...new Set(this.#x())];let n=this.globSet.map(o=>this.#h(o));this.globParts=this.preprocess(n),this.#c=!0;let r=this.globParts.map((o,s,a)=>{if(this.isWindows&&this.windowsNoMagicRoot){let c=o[2]==="?"&&bMt(o[3])?6:4,l=o[0]===""&&o[1]===""&&(o[2]==="?"||!fMo.test(o[2]))&&o.slice(3,c).every(d=>!fMo.test(d)),u=/^[a-z]:/i.test(o[0]);if(l)return[...o.slice(0,c).map(d=>this.#u(d)),...o.slice(c).map(d=>this.parse(d))];if(u)return[this.#u(o[0]),...o.slice(1).map(d=>this.parse(d))]}return o.map(c=>this.parse(c))});if(this.set=r.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]==="?"&&(S$n(s[3])||bMt(this.globParts[o][3]))&&(bMt(this.globParts[o][3])&&(s[3]="UNC"),s[2]="?")}t.noext||this.mergeRows(),this.#c=!1,this.set.forEach((o,s)=>{for(let a=0;a<o.length;a++)o[a]===b$n&&(o[a]=this.parse(this.globParts[s][a]))})}mergeRows(){let e=!0;for(;e;){e=!1;let t=Math.max(0,...this.set.map(n=>n.length));for(let n=0;n<t;n++){let r=new Map;this.set.forEach((s,a)=>{if(!(s[n]instanceof dMo||s[n]===b$n)||!n7a(this.globParts[a][n]))return;let c=[...this.globParts[a]];c[n]="";let l=`${s.length}/${c.join("/")}`,u=r.get(l);u?u.push(a):r.set(l,[a])});let o=new Set;for(let s of r.values()){if(s.length<2)continue;let[a,...c]=s,l=`@(${s.map(u=>this.globParts[u][n]).join("|")})`;this.globParts[a][n]=l,this.set[a][n]=this.parse(l);for(let u of c)o.add(u)}o.size&&(e=!0,this.set=this.set.filter((s,a)=>!o.has(a)),this.globParts=this.globParts.filter((s,a)=>!o.has(a)))}}}preprocess(e){if(this.options.noglobstar)for(let n of e)for(let r=0;r<n.length;r++)n[r]==="**"&&(n[r]="*");let{optimizationLevel:t=1}=this.options;return t>=2?(e=this.firstPhasePreProcess(e),e=this.secondPhasePreProcess(e)):t>=1?e=this.levelOneOptimize(e):e=this.adjascentGlobstarOptimize(e),e}adjascentGlobstarOptimize(e){return e.map(t=>{let n=-1;for(;(n=t.indexOf("**",n+1))!==-1;){let r=n;for(;t[r+1]==="**";)r++;r!==n&&t.splice(n,r-n)}return t})}levelOneOptimize(e){return e.map(t=>{let n=this.#l(t)+1;return t=t.reduce((r,o)=>{let s=r[r.length-1];return o==="**"&&s==="**"?r:o===".."&&r.length>n&&s&&s!==".."&&s!=="."&&s!=="**"?(r.pop(),r):(r.push(o),r)},[]),t.length===0?[""]:t})}#f(e){let t=!this.isWindows||!e.includes("\\")?"/":e.includes("/")?"both":"\\",n=this.#e?0:-1,r="",o=0,s,a=0,c=!!this.options.dot;e:for(let l=0;l<this.set.length;l++){let u=this.set[l],d=u[u.length-1],p=n!==-1&&this.#i[l]&&d!==qy;if(p&&n===0){let g=AMo(e,e.length,t);if(o=g+1,r=e.slice(o),r===""&&g>=0){let S=g;for(;S>0&&xMt(e.charCodeAt(S-1),t);)S--;a=S===0?0:AMo(e,S-1,t)+1,s=e.slice(a,S)}let y=this.#n&&(M$n(r)||r===""&&s!==void 0&&M$n(s));n=y?-1:1,p=!y}let f=-1;if(p&&typeof d=="string"&&(f=hMo(d,r,o,s,a),f===-1))continue;if(this.#t){for(let g of this.#o[l])if(!e.includes(g))continue e}if(p&&typeof d=="object"&&(f=hMo(d,r,o,s,a),f===-1))continue;let h=this.#s[l];if(h==="base"&&p)return"yes";if(h==="tail"&&p){if(this.#n&&tJe(e,0,f,!0,t))return"maybe";if(!tJe(e,0,f,c,t))return"yes";continue}if(h==="mid"||h==="head"){let g=this.#y(e,u,h==="head",c,t);if(g!=="no")return g;continue}return"maybe"}return"no"}#m(e,t,n){let r=!!this.options.dot,o=e.length;if(n==="head"){if(o<2||!Fte(t[0],e[0]))return!1;for(let a=1;a<o;a++)if(!pMt(e[a],r))return!1;return!0}let s=t[1];if(n==="tail"){let a=o-1;if(!Fte(s,e[a])&&(e[a]!==""||o===1||!Fte(s,e[--a])))return!1;for(let c=0;c<a;c++)if(!pMt(e[c],r))return!1;return!0}for(let a=0;a<o;a++){if(Fte(s,e[a])&&a+1<o){let c=a+1;for(;c<o&&pMt(e[c],r);)c++;if(c===o)return!0}if(!pMt(e[a],r))return!1}return!1}#y(e,t,n,r,o){if(this.#n&&tJe(e,0,e.length,!0,o))return"maybe";let s=t[n?0:1],a=0;for(let c=L$n(e,a,o);c!==-1;c=L$n(e,a,o)){let l=c+1;for(;l<e.length&&xMt(e.charCodeAt(l),o);)l++;if((typeof s=="string"?c-a===s.length&&e.startsWith(s,a):c>a&&s.testUnchecked(e.slice(a,c)))&&!tJe(e,l,e.length,r,o))return"yes";if(n||tJe(e,a,l,r,o))return"no";a=l}return"no"}#A(e){let t=E$n;return t?.f===e&&t.isWindows===this.isWindows&&t.preserveMultipleSlashes===this.preserveMultipleSlashes&&t.normalize===this.#r?t:void 0}#E(e){let{isWindows:t,preserveMultipleSlashes:n}=this,r=this.#h(t?e.split("\\").join("/"):e),o=this.#r;return o&&(r=r.map(s=>s.normalize(o))),E$n={f:e,isWindows:t,preserveMultipleSlashes:n,normalize:o,parts:r},E$n}#g(e){let t=[...e],n=!1;do{if(n=!1,!this.preserveMultipleSlashes){for(let s=1;s<t.length-1;s++){let a=t[s];s===1&&a===""&&t[0]===""||(a==="."||a==="")&&(n=!0,t.splice(s,1),s--)}t[0]==="."&&t.length===2&&(t[1]==="."||t[1]==="")&&(n=!0,t.pop())}let r=this.#l(t)+1,o=r;for(;(o=t.indexOf("..",o+1))!==-1;){let s=t[o-1];s&&s!=="."&&s!==".."&&s!=="**"&&(n=!0,t.splice(o-1,2),o=Math.max(o-2,r))}}while(n);return t.length===0?[""]:t}firstPhasePreProcess(e){let{braceExpandMax:t=1e5}=this.options,n=0,r=1e6,o=!1;do{o=!1;for(let s of e){let a=-1;for(;(a=s.indexOf("**",a+1))!==-1;){let u=a;for(;s[u+1]==="**";)u++;u>a&&s.splice(a+1,u-a);let d=s[a+1],p=s[a+2],f=s[a+3];if(d!==".."||!p||p==="."||p===".."||!f||f==="."||f==="..")continue;let h=s.length-1;if(e.length>=t||n+h>r)throw new RangeError("optimizationLevel 2: too many patterns from '**/..'");o=!0,s.splice(a,1);let g=s.slice(0);g[a]="**",n+=h,e.push(g),a--}if(!this.preserveMultipleSlashes){for(let u=1;u<s.length-1;u++){let d=s[u];u===1&&d===""&&s[0]===""||(d==="."||d==="")&&(o=!0,s.splice(u,1),u--)}s[0]==="."&&s.length===2&&(s[1]==="."||s[1]==="")&&(o=!0,s.pop())}let c=this.#l(s)+1,l=c;for(;(l=s.indexOf("..",l+1))!==-1;){let u=s[l-1];if(u&&u!=="."&&u!==".."&&u!=="**"){o=!0;let d=l===1&&s[l+1]==="**"?["."]:[];s.splice(l-1,2,...d),s.length===0&&s.push(""),l=Math.max(l-2,c)}}}}while(o);return e}secondPhasePreProcess(e){let t=new Set,n=e.filter(s=>{let a=s.join("/");return t.has(a)?!1:(t.add(a),!0)}),r=new Map;for(let s of n){let a=[];for(let c=0;c<s.length;c++)s[c]==="*"&&a.push(c);a.length&&r.set(a.join(","),a)}if(!r.size||n.length*r.size>1e5)return n;let{dot:o}=this.options;return n.filter(s=>{for(let a of r.values()){if(a[a.length-1]>=s.length)continue;let c=[...s],l=!0,u=!1;for(let d of a){let p=s[d];if(p!=="*"){if(!p||p==="**"||!o&&p.startsWith(".")){l=!1;break}c[d]="*",u=!0}}if(l&&u&&t.has(c.join("/")))return!1}return!0})}parseNegate(){if(this.nonegate)return;let e=this.pattern,t=!1,n=0;for(let r=0;r<e.length&&e.charAt(r)==="!";r++)t=!t,n++;n&&(this.pattern=e.slice(n)),this.negate=t}#_(e,t,n,r){let o=0,s=0,a=this.isWindows?_$n(t):-1,c=a===-1?-1:_$n(n);if(c!==-1){let l=n[c],u=n[c+1];typeof l!="string"||typeof u!="string"?(o=a,s=c):t[a].toLowerCase()===l.toLowerCase()&&t[a+1].toLowerCase()===u.toLowerCase()&&(o=a+2,s=c+2)}else if(this.isWindows){let l=typeof e[0]=="string"&&/^[a-z]:$/i.test(e[0]),u=!l&&e[0]===""&&e[1]===""&&e[2]==="?"&&/^[a-z]:$/i.test(e[3]),d=typeof n[0]=="string"&&/^[a-z]:$/i.test(n[0]),p=!d&&n[0]===""&&n[1]===""&&n[2]==="?"&&typeof n[3]=="string"&&/^[a-z]:$/i.test(n[3]),f=u?3:l?0:void 0,h=p?3:d?0:void 0;if(typeof f=="number"&&typeof h=="number"){let[g,y]=[e[f],n[h]];g.toLowerCase()===y.toLowerCase()&&(s=h+1,o=f+1)}}return e=t,n.includes(qy)?this.#b(e,n,r,o,s):this.#I(e,n,r,o,s)}#b(e,t,n,r,o){let{head:s,body:a,tail:c,segments:l}=this.#S(t,n,o);if(s.length){let d=r+s.length;if(!this.#I(e,s,n,r,0,d))return!1;r+=s.length,o+=s.length}let u=0;if(c.length){if(c.length+r>e.length)return!1;let d=e.length-c.length;if(this.#I(e,c,n,d,0))u=c.length;else{if(e[e.length-1]!==""||r+c.length===e.length||(d--,!this.#I(e,c,n,d,0)))return!1;u=c.length+1}}if(!a.length){let d=!!u;for(let p=r;p<e.length-u;p++){let f=String(e[p]);if(d=!0,f==="."||f===".."||!this.options.dot&&f.startsWith("."))return!1}return n||d}return!!this.#v(e,l,e.length-u,r,0,n,0,!!u,new Set)}#S(e,t,n){let r=this.#d.get(e);r||(r=[],this.#d.set(e,r));let o=n*2+(t?1:0),s=r[o];if(s)return s;let a=e.indexOf(qy,n),c=e.lastIndexOf(qy),l=e.slice(n,a),u=e.slice(a+1,t?void 0:c),d=t?[]:e.slice(c+1),p=[[[],0]],f=p[0],h=0,g=[0];for(let S of u)S===qy?(g.push(h),f=[[],0],p.push(f)):(f[0].push(S),h++);p.forEach((S,_)=>{S[1]=h-g[_]});let y={head:l,body:u,tail:d,segments:p};return r[o]=y,y}#v(e,t,n,r,o,s,a,c,l){let u=t[o];if(!u){if(s)return r>=n||r===n-1&&e[r]==="";for(let h=r;h<n;h++){c=!0;let g=e[h];if(g==="."||g===".."||!this.options.dot&&g.startsWith("."))return!1}return c}let[d,p]=u,f=s?n:n-p;for(;r<=f;){let h=o*(e.length+1)+r;if(l.has(h))return!1;if(l.add(h),this.#I(e,d,s,r,0,r+d.length)&&a<this.maxGlobstarRecursion){let y=this.#v(e,t,n,r+d.length,o+1,s,a+1,c,l);if(y!==!1)return y}if(r===f)break;let g=e[r];if(g==="."||g===".."||!this.options.dot&&g.startsWith("."))return!1;r++}return s||null}#I(e,t,n,r,o,s=e.length){let a,c,l,u;for(a=r,c=o,u=Math.min(s,e.length),l=t.length;a<u&&c<l;a++,c++){let d=t[c],p=e[a];if(d===!1||d===qy||!Fte(d,p))return!1}if(a===u&&c===l)return!0;if(a===u)return n;if(c===l)return a===u-1&&e[a]==="";throw new Error("wtf?")}braceExpand(){return P$n(this.pattern,this.options)}#x(){let{pattern:e}=this;if(this.options.nobrace)return this.braceExpand();let t=57344;for(;e.includes(String.fromCharCode(t));)if(++t>63743)return this.braceExpand();let n=String.fromCharCode(t),r=!1,o=e.replace(ZYa,(a,c,l)=>{let u=Number(c),d=Number(l);return!Number.isSafeInteger(u)||!Number.isSafeInteger(d)||Math.abs(u-d)+1<XYa?a:(r=!0,`${n}${c}..${l}${n}`)});if(!r)return this.braceExpand();let s=P$n(o,this.options);for(let a of s)for(let c of a.split("/")){let l=c.indexOf("[");if(l!==-1&&l<c.lastIndexOf(n))return this.braceExpand()}return this.#p=n,s}parse(e){IMt(e);let t=this.options;if(e==="**")return qy;if(e==="")return"";let{nocase:n,nocaseMagicOnly:r,noext:o=!1,dot:s,normalize:a}=t,c=this.#p,l=c&&e.includes(c)?void 0:t7a(e,o);if(l!==void 0&&!(n&&!r&&e.toUpperCase()!==e.toLowerCase()))return this.#u(l);if(this.#c)return b$n;let u=this.#a.get(e);return u||(u=new dMo(e,{nocase:n,noext:o,dot:s,normalize:a,...c&&{rangeMark:c}}),this.#a.set(e,u)),u}#h(e){return this.preserveMultipleSlashes?e.split("/"):this.isWindows&&/^\/\/[^/]+/.test(e)?["",...e.split(/\/+/)]:e.split(/\/+/)}match(e,t=this.partial){if(this.comment)return!1;if(this.empty)return e==="";if(e==="/"&&t)return!0;let n=this.options,r=this.#A(e);if(!r){if(!t&&!this.#r&&(this.#e||this.#t)&&mMo!==e){mMo=e;let l=this.#f(e);if(l==="no")return n.flipNegate?!1:this.negate;if(l==="yes")return n.flipNegate?!0:!this.negate}r=this.#E(e)}let o=r.parts,s=this.#n?r.resolved??=this.#g(o):o,a=this.set,c=o[o.length-1];if(!c)for(let l=o.length-2;!c&&l>=0;l--)c=o[l];for(let l=0;l<a.length;l++){let u=a[l],d=t?void 0:this.#s[l];if(d==="base"?Fte(u[0],c):d?this.#m(s,u,d):n.matchBase&&u.length===1?this.#_([c],[c],u,t):this.#_(o,s,u,t))return n.flipNegate?!0:!this.negate}return n.flipNegate?!1:this.negate}static defaults(e){return gB.defaults(e).Minimatch}};gB.Minimatch=$fe;gB.escape=H$n;gB.unescape=qMo;Gv=i7a("lru-cache:metrics"),aJe=o7a("lru-cache"),s7a=typeof performance=="object"&&performance&&typeof performance.now=="function"?performance:Date,C$n=i(()=>Gv.hasSubscribers||aJe.hasSubscribers,"ke"),VMo=new Set,gMo=typeof process=="object"&&process?process:{},a7a=i((e,t,n,r)=>{typeof gMo.emitWarning=="function"?gMo.emitWarning(e,t,n,r):console.error(`[${n}] ${t}: ${e}`)},"Di"),c7a=i(e=>!VMo.has(e),"Ni"),Lte=i(e=>!!e&&e===Math.floor(e)&&e>0&&isFinite(e),"V"),KMo=i(e=>Lte(e)?e<=Math.pow(2,8)?Uint8Array:e<=Math.pow(2,16)?Uint16Array:e<=Math.pow(2,32)?Uint32Array:e<=Number.MAX_SAFE_INTEGER?CMt:null:null,"ds"),CMt=class extends Array{static{i(this,"jt")}constructor(e){super(e),this.fill(0)}},l7a=class cJe{static{i(this,"bt")}heap;length;static#e=!1;static create(t){let n=KMo(t);if(!n)return[];cJe.#e=!0;let r=new cJe(t,n);return cJe.#e=!1,r}constructor(t,n){if(!cJe.#e)throw new TypeError("instantiate Stack using Stack.create(n)");this.heap=new n(t),this.length=0}push(t){this.heap[this.length++]=t}pop(){return this.heap[--this.length]}},RMt=class YMo{static{i(this,"ps")}#e;#t;#n;#r;#o;#s;#i;#a;get perf(){return this.#a}ttl;ttlResolution;ttlAutopurge;updateAgeOnGet;updateAgeOnHas;allowStale;noDisposeOnSet;noUpdateTTL;maxEntrySize;sizeCalculation;noDeleteOnFetchRejection;noDeleteOnStaleGet;allowStaleOnFetchAbort;allowStaleOnFetchRejection;ignoreFetchAbort;backgroundFetchSize;#c;#p;#d;#u;#l;#f;#m;#y;#A;#E;#g;#_;#b;#S;#v;#I;#x;#h;#T;static unsafeExposeInternals(t){return{starts:t.#b,ttls:t.#S,autopurgeTimers:t.#v,sizes:t.#_,keyMap:t.#d,keyList:t.#u,valList:t.#l,next:t.#f,prev:t.#m,get head(){return t.#y},get tail(){return t.#A},free:t.#E,isBackgroundFetch:i(n=>t.#C(n),"isBackgroundFetch"),backgroundFetch:i((n,r,o,s)=>t.#j(n,r,o,s),"backgroundFetch"),moveToTail:i(n=>t.#K(n),"moveToTail"),indexes:i(n=>t.#B(n),"indexes"),rindexes:i(n=>t.#P(n),"rindexes"),isStale:i(n=>t.#w(n),"isStale")}}get max(){return this.#e}get maxSize(){return this.#t}get calculatedSize(){return this.#p}get size(){return this.#c}get fetchMethod(){return this.#s}get memoMethod(){return this.#i}get dispose(){return this.#n}get onInsert(){return this.#r}get disposeAfter(){return this.#o}constructor(t){let{max:n=0,ttl:r,ttlResolution:o=1,ttlAutopurge:s,updateAgeOnGet:a,updateAgeOnHas:c,allowStale:l,dispose:u,onInsert:d,disposeAfter:p,noDisposeOnSet:f,noUpdateTTL:h,maxSize:g=0,maxEntrySize:y=0,sizeCalculation:S,fetchMethod:_,memoMethod:b,noDeleteOnFetchRejection:v,noDeleteOnStaleGet:x,allowStaleOnFetchRejection:R,allowStaleOnFetchAbort:O,ignoreFetchAbort:T,backgroundFetchSize:B=1,perf:D}=t;if(this.backgroundFetchSize=B,D!==void 0&&typeof D?.now!="function")throw new TypeError("perf option must have a now() method if specified");if(this.#a=D??s7a,n!==0&&!Lte(n))throw new TypeError("max option must be a nonnegative integer");let M=n?KMo(n):Array;if(!M)throw new Error("invalid max value: "+n);if(this.#e=n,this.#t=g,this.maxEntrySize=y||this.#t,this.sizeCalculation=S,this.sizeCalculation){if(!this.#t&&!this.maxEntrySize)throw new TypeError("cannot set sizeCalculation without setting maxSize or maxEntrySize");if(typeof this.sizeCalculation!="function")throw new TypeError("sizeCalculation set to non-function")}if(b!==void 0&&typeof b!="function")throw new TypeError("memoMethod must be a function if defined");if(this.#i=b,_!==void 0&&typeof _!="function")throw new TypeError("fetchMethod must be a function if specified");if(this.#s=_,this.#x=!!_,this.#d=new Map,this.#u=Array.from({length:n}).fill(void 0),this.#l=Array.from({length:n}).fill(void 0),this.#f=new M(n),this.#m=new M(n),this.#y=0,this.#A=0,this.#E=l7a.create(n),this.#c=0,this.#p=0,typeof u=="function"&&(this.#n=u),typeof d=="function"&&(this.#r=d),typeof p=="function"?(this.#o=p,this.#g=[]):(this.#o=void 0,this.#g=void 0),this.#I=!!this.#n,this.#T=!!this.#r,this.#h=!!this.#o,this.noDisposeOnSet=!!f,this.noUpdateTTL=!!h,this.noDeleteOnFetchRejection=!!v,this.allowStaleOnFetchRejection=!!R,this.allowStaleOnFetchAbort=!!O,this.ignoreFetchAbort=!!T,this.maxEntrySize!==0){if(this.#t!==0&&!Lte(this.#t))throw new TypeError("maxSize must be a positive integer if specified");if(!Lte(this.maxEntrySize))throw new TypeError("maxEntrySize must be a positive integer if specified");this.#Q()}if(this.allowStale=!!l,this.noDeleteOnStaleGet=!!x,this.updateAgeOnGet=!!a,this.updateAgeOnHas=!!c,this.ttlResolution=Lte(o)||o===0?o:1,this.ttlAutopurge=!!s,this.ttl=r||0,this.ttl){if(!Lte(this.ttl))throw new TypeError("ttl must be a positive integer if specified");this.#k()}if(this.#e===0&&this.ttl===0&&this.#t===0)throw new TypeError("At least one of max, maxSize, or ttl is required");if(!this.ttlAutopurge&&!this.#e&&!this.#t){let L="LRU_CACHE_UNBOUNDED";c7a(L)&&(VMo.add(L),a7a("TTL caching without ttlAutopurge, max, or maxSize can result in unbounded memory consumption.","UnboundedCacheWarning",L,YMo))}}getRemainingTTL(t){return this.#d.has(t)?1/0:0}#k(){let t=new CMt(this.#e),n=new CMt(this.#e);this.#S=t,this.#b=n;let r=this.ttlAutopurge?Array.from({length:this.#e}):void 0;this.#v=r,this.#N=(l,u,d=this.#a.now())=>{n[l]=u!==0?d:0,t[l]=u,o(l,u)},this.#R=l=>{n[l]=t[l]!==0?this.#a.now():0,o(l,t[l])};let o=this.ttlAutopurge?(l,u)=>{if(r?.[l]&&(clearTimeout(r[l]),r[l]=void 0),u&&u!==0&&r){let d=setTimeout(()=>{this.#w(l)?(this.#H(this.#u[l],"expire"),r[l]=void 0):o(l,c(l))},u+1);d.unref&&d.unref(),r[l]=d}}:()=>{};this.#O=(l,u)=>{if(t[u]){let d=t[u],p=n[u];if(!d||!p)return;l.ttl=d,l.start=p,l.now=s||a();let f=l.now-p;l.remainingTTL=d-f}};let s=0,a=i(()=>{let l=this.#a.now();if(this.ttlResolution>0){s=l;let u=setTimeout(()=>s=0,this.ttlResolution);u.unref&&u.unref()}return l},"o");this.getRemainingTTL=l=>{let u=this.#d.get(l);return u===void 0?0:c(u)};let c=i(l=>{let u=t[l],d=n[l];if(!u||!d)return 1/0;let p=(s||a())-d;return u-p},"h");this.#w=l=>{let u=n[l],d=t[l];return!!d&&!!u&&(s||a())-u>d}}#R=i(()=>{},"#R");#O=i(()=>{},"#D");#N=i(()=>{},"#W");#w=i(()=>!1,"#A");#Q(){let t=new CMt(this.#e);this.#p=0,this.#_=t,this.#M=n=>{this.#p-=t[n],t[n]=0},this.#L=(n,r,o,s)=>{if(!Lte(o)){if(this.#C(r))return this.backgroundFetchSize;if(s){if(typeof s!="function")throw new TypeError("sizeCalculation must be a function");if(o=s(r,n),!Lte(o))throw new TypeError("sizeCalculation return invalid (expect positive integer)")}else throw new TypeError("invalid size value (must be positive integer). When maxSize or maxEntrySize is used, sizeCalculation or size must be set.")}return o},this.#D=(n,r,o)=>{if(t[n]=r,this.#t){let s=this.#t-t[n];for(;this.#p>s;)this.#$(!0)}this.#p+=t[n],o&&(o.entrySize=r,o.totalCalculatedSize=this.#p)}}#M=i(t=>{},"#P");#D=i((t,n,r)=>{},"#N");#L=i((t,n,r,o)=>{if(r||o)throw new TypeError("cannot set size without setting maxSize or maxEntrySize on cache");return 0},"#$");*#B({allowStale:t=this.allowStale}={}){if(this.#c)for(let n=this.#A;this.#U(n)&&((t||!this.#w(n))&&(yield n),n!==this.#y);)n=this.#m[n]}*#P({allowStale:t=this.allowStale}={}){if(this.#c)for(let n=this.#y;this.#U(n)&&((t||!this.#w(n))&&(yield n),n!==this.#A);)n=this.#f[n]}#U(t){return t!==void 0&&this.#d.get(this.#u[t])===t}*entries(){for(let t of this.#B())this.#l[t]!==void 0&&this.#u[t]!==void 0&&!this.#C(this.#l[t])&&(yield[this.#u[t],this.#l[t]])}*rentries(){for(let t of this.#P())this.#l[t]!==void 0&&this.#u[t]!==void 0&&!this.#C(this.#l[t])&&(yield[this.#u[t],this.#l[t]])}*keys(){for(let t of this.#B()){let n=this.#u[t];n!==void 0&&!this.#C(this.#l[t])&&(yield n)}}*rkeys(){for(let t of this.#P()){let n=this.#u[t];n!==void 0&&!this.#C(this.#l[t])&&(yield n)}}*values(){for(let t of this.#B())this.#l[t]!==void 0&&!this.#C(this.#l[t])&&(yield this.#l[t])}*rvalues(){for(let t of this.#P())this.#l[t]!==void 0&&!this.#C(this.#l[t])&&(yield this.#l[t])}[Symbol.iterator](){return this.entries()}[Symbol.toStringTag]="LRUCache";find(t,n={}){for(let r of this.#B()){let o=this.#l[r],s=this.#C(o)?o.__staleWhileFetching:o;if(s!==void 0&&t(s,this.#u[r],this))return this.#V(this.#u[r],n)}}forEach(t,n=this){for(let r of this.#B()){let o=this.#l[r],s=this.#C(o)?o.__staleWhileFetching:o;s!==void 0&&t.call(n,s,this.#u[r],this)}}rforEach(t,n=this){for(let r of this.#P()){let o=this.#l[r],s=this.#C(o)?o.__staleWhileFetching:o;s!==void 0&&t.call(n,s,this.#u[r],this)}}purgeStale(){let t=!1;for(let n of this.#P({allowStale:!0}))this.#w(n)&&(this.#H(this.#u[n],"expire"),t=!0);return t}info(t){let n=this.#d.get(t);if(n===void 0)return;let r=this.#l[n],o=this.#C(r)?r.__staleWhileFetching:r;if(o===void 0)return;let s={value:o};if(this.#S&&this.#b){let a=this.#S[n],c=this.#b[n];if(a&&c){let l=a-(this.#a.now()-c);s.ttl=l,s.start=Date.now()}}return this.#_&&(s.size=this.#_[n]),s}dump(){let t=[];for(let n of this.#B({allowStale:!0})){let r=this.#u[n],o=this.#l[n],s=this.#C(o)?o.__staleWhileFetching:o;if(s===void 0||r===void 0)continue;let a={value:s};if(this.#S&&this.#b){a.ttl=this.#S[n];let c=this.#a.now()-this.#b[n];a.start=Math.floor(Date.now()-c)}this.#_&&(a.size=this.#_[n]),t.unshift([r,a])}return t}load(t){this.clear();for(let[n,r]of t){if(r.start){let o=Date.now()-r.start;r.start=this.#a.now()-o}this.#F(n,r.value,r)}}set(t,n,r={}){let{status:o=Gv.hasSubscribers?{}:void 0}=r;r.status=o,o&&(o.op="set",o.key=t,n!==void 0&&(o.value=n),o.cache=this);let s=this.#F(t,n,r);return o&&Gv.hasSubscribers&&Gv.publish(o),s}#F(t,n,r,o){let{ttl:s=this.ttl,start:a,noDisposeOnSet:c=this.noDisposeOnSet,sizeCalculation:l=this.sizeCalculation,status:u}=r,d=this.#C(n);if(n===void 0)return u&&(u.set="deleted"),this.delete(t),this;let{noUpdateTTL:p=this.noUpdateTTL}=r;u&&!d&&(u.value=n);let f=this.#L(t,n,r.size||0,l,u);if(this.maxEntrySize&&f>this.maxEntrySize)return this.#H(t,"set"),u&&(u.set="miss",u.maxEntrySizeExceeded=!0),this;let h=this.#c===0?void 0:this.#d.get(t);if(h===void 0)h=this.#c===0?this.#A:this.#E.length!==0?this.#E.pop():this.#c===this.#e?this.#$(!1):this.#c,this.#u[h]=t,this.#l[h]=n,this.#d.set(t,h),this.#f[this.#A]=h,this.#m[h]=this.#A,this.#A=h,this.#c++,this.#D(h,f,u),u&&(u.set="add"),p=!1,this.#T&&!d&&this.#r?.(n,t,"add");else{this.#K(h);let g=this.#l[h];if(n!==g){if(!c)if(this.#C(g)){g!==o&&g.__abortController.abort(new Error("replaced"));let{__staleWhileFetching:y}=g;y!==void 0&&y!==n&&(this.#I&&this.#n?.(y,t,"set"),this.#h&&this.#g?.push([y,t,"set"]))}else this.#I&&this.#n?.(g,t,"set"),this.#h&&this.#g?.push([g,t,"set"]);if(this.#M(h),this.#D(h,f,u),this.#l[h]=n,!d){let y=g&&this.#C(g)?g.__staleWhileFetching:g,S=y===void 0?"add":n!==y?"replace":"update";u&&(u.set=S,y!==void 0&&(u.oldValue=y)),this.#T&&this.onInsert?.(n,t,S)}}else d||(u&&(u.set="update"),this.#T&&this.onInsert?.(n,t,"update"))}if(s!==0&&!this.#S&&this.#k(),this.#S&&(p||this.#N(h,s,a),u&&this.#O(u,h)),!c&&this.#h&&this.#g){let g=this.#g,y;for(;y=g?.shift();)this.#o?.(...y)}return this}pop(){try{for(;this.#c;){let t=this.#l[this.#y];if(this.#$(!0),this.#C(t)){if(t.__staleWhileFetching)return t.__staleWhileFetching}else if(t!==void 0)return t}}finally{if(this.#h&&this.#g){let t=this.#g,n;for(;n=t?.shift();)this.#o?.(...n)}}}#$(t){let n=this.#y,r=this.#u[n],o=this.#l[n],s=this.#C(o);s&&o.__abortController.abort(new Error("evicted"));let a=s?o.__staleWhileFetching:o;return(this.#I||this.#h)&&a!==void 0&&(this.#I&&this.#n?.(a,r,"evict"),this.#h&&this.#g?.push([a,r,"evict"])),this.#M(n),this.#v?.[n]&&(clearTimeout(this.#v[n]),this.#v[n]=void 0),t&&(this.#u[n]=void 0,this.#l[n]=void 0,this.#E.push(n)),this.#c===1?(this.#y=this.#A=0,this.#E.length=0):this.#y=this.#f[n],this.#d.delete(r),this.#c--,n}has(t,n={}){let{status:r=Gv.hasSubscribers?{}:void 0}=n;n.status=r,r&&(r.op="has",r.key=t,r.cache=this);let o=this.#W(t,n);return Gv.hasSubscribers&&Gv.publish(r),o}#W(t,n={}){let{updateAgeOnHas:r=this.updateAgeOnHas,status:o}=n,s=this.#d.get(t);if(s!==void 0){let a=this.#l[s];if(this.#C(a)&&a.__staleWhileFetching===void 0)return!1;if(this.#w(s))o&&(o.has="stale",this.#O(o,s));else return r&&this.#R(s),o&&(o.has="hit",this.#O(o,s)),!0}else o&&(o.has="miss");return!1}peek(t,n={}){let{status:r=C$n()?{}:void 0}=n;r&&(r.op="peek",r.key=t,r.cache=this),n.status=r;let o=this.#G(t,n);return Gv.hasSubscribers&&Gv.publish(r),o}#G(t,n){let{status:r,allowStale:o=this.allowStale}=n,s=this.#d.get(t);if(s===void 0||!o&&this.#w(s)){r&&(r.peek=s===void 0?"miss":"stale");return}let a=this.#l[s],c=this.#C(a)?a.__staleWhileFetching:a;return r&&(c!==void 0?(r.peek="hit",r.value=c):r.peek="miss"),c}#j(t,n,r,o){let s=n===void 0?void 0:this.#l[n];if(this.#C(s))return s;let a=new AbortController,{signal:c}=r;c?.addEventListener("abort",()=>a.abort(c.reason),{signal:a.signal});let l={signal:a.signal,options:r,context:o},u=i((y,S=!1)=>{let{aborted:_}=a.signal,b=r.ignoreFetchAbort&&y!==void 0,v=r.ignoreFetchAbort||!!(r.allowStaleOnFetchAbort&&y!==void 0);if(r.status&&(_&&!S?(r.status.fetchAborted=!0,r.status.fetchError=a.signal.reason,b&&(r.status.fetchAbortIgnored=!0)):r.status.fetchResolved=!0),_&&!b&&!S)return p(a.signal.reason,v);let x=h,R=this.#l[n];return(R===h||R===void 0&&b&&S)&&(y===void 0?x.__staleWhileFetching!==void 0?this.#l[n]=x.__staleWhileFetching:this.#H(t,"fetch"):(r.status&&(r.status.fetchUpdated=!0),this.#F(t,y,l.options,x))),y},"l"),d=i(y=>(r.status&&(r.status.fetchRejected=!0,r.status.fetchError=y),p(y,!1)),"c"),p=i((y,S)=>{let{aborted:_}=a.signal,b=_&&r.allowStaleOnFetchAbort,v=b||r.allowStaleOnFetchRejection,x=v||r.noDeleteOnFetchRejection,R=h;if(this.#l[n]===h&&(!x||!S&&R.__staleWhileFetching===void 0?this.#H(t,"fetch"):b||(this.#l[n]=R.__staleWhileFetching)),v)return r.status&&R.__staleWhileFetching!==void 0&&(r.status.returnedStale=!0),R.__staleWhileFetching;if(R.__returned===R)throw y},"f"),f=i((y,S)=>{let _=this.#s?.(t,s,l);a.signal.addEventListener("abort",()=>{(!r.ignoreFetchAbort||r.allowStaleOnFetchAbort)&&(y(void 0),r.allowStaleOnFetchAbort&&(y=i(b=>u(b,!0),"d")))}),_&&_ instanceof Promise?_.then(b=>y(b===void 0?void 0:b),S):_!==void 0&&y(_)},"u");r.status&&(r.status.fetchDispatched=!0);let h=new Promise(f).then(u,d),g=Object.assign(h,{__abortController:a,__staleWhileFetching:s,__returned:void 0});return n===void 0?(this.#F(t,g,{...l.options,status:void 0}),n=this.#d.get(t)):this.#l[n]=g,g}#C(t){if(!this.#x)return!1;let n=t;return!!n&&n instanceof Promise&&n.hasOwnProperty("__staleWhileFetching")&&n.__abortController instanceof AbortController}fetch(t,n={}){let r=aJe.hasSubscribers,{status:o=C$n()?{}:void 0}=n;n.status=o,o&&n.context&&(o.context=n.context);let s=this.#q(t,n);return o&&r&&(o.trace=!0,aJe.tracePromise(()=>s,o).catch(()=>{})),s}async#q(t,n={}){let{allowStale:r=this.allowStale,updateAgeOnGet:o=this.updateAgeOnGet,noDeleteOnStaleGet:s=this.noDeleteOnStaleGet,ttl:a=this.ttl,noDisposeOnSet:c=this.noDisposeOnSet,size:l=0,sizeCalculation:u=this.sizeCalculation,noUpdateTTL:d=this.noUpdateTTL,noDeleteOnFetchRejection:p=this.noDeleteOnFetchRejection,allowStaleOnFetchRejection:f=this.allowStaleOnFetchRejection,ignoreFetchAbort:h=this.ignoreFetchAbort,allowStaleOnFetchAbort:g=this.allowStaleOnFetchAbort,context:y,forceRefresh:S=!1,status:_,signal:b}=n;if(_&&(_.op="fetch",_.key=t,S&&(_.forceRefresh=!0),_.cache=this),!this.#x)return _&&(_.fetch="get"),this.#V(t,{allowStale:r,updateAgeOnGet:o,noDeleteOnStaleGet:s,status:_});let v={allowStale:r,updateAgeOnGet:o,noDeleteOnStaleGet:s,ttl:a,noDisposeOnSet:c,size:l,sizeCalculation:u,noUpdateTTL:d,noDeleteOnFetchRejection:p,allowStaleOnFetchRejection:f,allowStaleOnFetchAbort:g,ignoreFetchAbort:h,status:_,signal:b},x=this.#d.get(t);if(x===void 0){_&&(_.fetch="miss");let R=this.#j(t,x,v,y);return R.__returned=R}else{let R=this.#l[x];if(this.#C(R)){let D=r&&R.__staleWhileFetching!==void 0;return _&&(_.fetch="inflight",D&&(_.returnedStale=!0)),D?R.__staleWhileFetching:R.__returned=R}let O=this.#w(x);if(!S&&!O)return _&&(_.fetch="hit"),this.#K(x),o&&this.#R(x),_&&this.#O(_,x),R;let T=this.#j(t,x,v,y),B=T.__staleWhileFetching!==void 0&&r;return _&&(_.fetch=O?"stale":"refresh",B&&O&&(_.returnedStale=!0)),B?T.__staleWhileFetching:T.__returned=T}}forceFetch(t,n={}){let r=aJe.hasSubscribers,{status:o=C$n()?{}:void 0}=n;n.status=o,o&&n.context&&(o.context=n.context);let s=this.#z(t,n);return o&&r&&(o.trace=!0,aJe.tracePromise(()=>s,o).catch(()=>{})),s}async#z(t,n={}){let r=await this.#q(t,n);if(r===void 0)throw new Error("fetch() returned undefined");return r}memo(t,n={}){let{status:r=Gv.hasSubscribers?{}:void 0}=n;n.status=r,r&&(r.op="memo",r.key=t,n.context&&(r.context=n.context),r.cache=this);let o=this.#X(t,n);return r&&(r.value=o),Gv.hasSubscribers&&Gv.publish(r),o}#X(t,n={}){let r=this.#i;if(!r)throw new Error("no memoMethod provided to constructor");let{context:o,status:s,forceRefresh:a,...c}=n;s&&a&&(s.forceRefresh=!0);let l=this.#V(t,c),u=a||l===void 0;if(s&&(s.memo=u?"miss":"hit",u||(s.value=l)),!u)return l;let d=r(t,l,{options:c,context:o});return s&&(s.value=d),this.#F(t,d,c),d}get(t,n={}){let{status:r=Gv.hasSubscribers?{}:void 0}=n;n.status=r,r&&(r.op="get",r.key=t,r.cache=this);let o=this.#V(t,n);return r&&(o!==void 0&&(r.value=o),Gv.hasSubscribers&&Gv.publish(r)),o}#V(t,n={}){let{allowStale:r=this.allowStale,updateAgeOnGet:o=this.updateAgeOnGet,noDeleteOnStaleGet:s=this.noDeleteOnStaleGet,status:a}=n,c=this.#d.get(t);if(c===void 0){a&&(a.get="miss");return}let l=this.#l[c],u=this.#C(l);return a&&this.#O(a,c),this.#w(c)?u?(a&&(a.get="stale-fetching"),r&&l.__staleWhileFetching!==void 0?(a&&(a.returnedStale=!0),l.__staleWhileFetching):void 0):(s||this.#H(t,"expire"),a&&(a.get="stale"),r?(a&&(a.returnedStale=!0),l):void 0):(a&&(a.get=u?"fetching":"hit"),this.#K(c),o&&this.#R(c),u?l.__staleWhileFetching:l)}#Y(t,n){this.#m[n]=t,this.#f[t]=n}#K(t){t!==this.#A&&(t===this.#y?this.#y=this.#f[t]:this.#Y(this.#m[t],this.#f[t]),this.#Y(this.#A,t),this.#A=t)}delete(t){return this.#H(t,"delete")}#H(t,n){Gv.hasSubscribers&&Gv.publish({op:"delete",delete:n,key:t,cache:this});let r=!1;if(this.#c!==0){let o=this.#d.get(t);if(o!==void 0)if(this.#v?.[o]&&(clearTimeout(this.#v[o]),this.#v[o]=void 0),r=!0,this.#c===1)this.#J(n);else{this.#M(o);let s=this.#l[o];if(this.#C(s)?s.__abortController.abort(new Error("deleted")):(this.#I||this.#h)&&(this.#I&&this.#n?.(s,t,n),this.#h&&this.#g?.push([s,t,n])),this.#d.delete(t),this.#u[o]=void 0,this.#l[o]=void 0,o===this.#A)this.#A=this.#m[o];else if(o===this.#y)this.#y=this.#f[o];else{let a=this.#m[o];this.#f[a]=this.#f[o];let c=this.#f[o];this.#m[c]=this.#m[o]}this.#c--,this.#E.push(o)}}if(this.#h&&this.#g?.length){let o=this.#g,s;for(;s=o?.shift();)this.#o?.(...s)}return r}clear(){return this.#J("delete")}#J(t){for(let n of this.#P({allowStale:!0})){let r=this.#l[n];if(this.#C(r))r.__abortController.abort(new Error("deleted"));else{let o=this.#u[n];this.#I&&this.#n?.(r,o,t),this.#h&&this.#g?.push([r,o,t])}}if(this.#d.clear(),this.#l.fill(void 0),this.#u.fill(void 0),this.#S&&this.#b){this.#S.fill(0),this.#b.fill(0);for(let n of this.#v??[])n!==void 0&&clearTimeout(n);this.#v?.fill(void 0)}if(this.#_&&this.#_.fill(0),this.#y=0,this.#A=0,this.#E.length=0,this.#p=0,this.#c=0,this.#h&&this.#g){let n=this.#g,r;for(;r=n?.shift();)this.#o?.(...r)}}},yMo=typeof process=="object"&&process?process:{stdout:null,stderr:null},C7a=i(e=>!!e&&typeof e=="object"&&(e instanceof wMt||e instanceof JMo||v7a(e)||I7a(e)),"Li"),v7a=i(e=>!!e&&typeof e=="object"&&e instanceof $$n&&typeof e.pipe=="function"&&e.pipe!==JMo.Writable.prototype.pipe,"ji"),I7a=i(e=>!!e&&typeof e=="object"&&e instanceof $$n&&typeof e.write=="function"&&typeof e.end=="function","Wi"),tW=Symbol("EOF"),nW=Symbol("maybeEmitEnd"),Mte=Symbol("emittedEnd"),fMt=Symbol("emittingEnd"),nJe=Symbol("emittedError"),mMt=Symbol("closed"),EMo=Symbol("read"),hMt=Symbol("flush"),SMo=Symbol("flushChunk"),TQ=Symbol("encoding"),iNe=Symbol("decoder"),l0=Symbol("flowing"),rJe=Symbol("paused"),sNe=Symbol("resume"),u0=Symbol("buffer"),DT=Symbol("pipes"),d0=Symbol("bufferLength"),v$n=Symbol("bufferPush"),AMt=Symbol("bufferShift"),Fx=Symbol("objectMode"),oS=Symbol("destroyed"),I$n=Symbol("error"),x$n=Symbol("emitData"),_Mo=Symbol("emitEnd"),w$n=Symbol("emitEnd2"),t4=Symbol("async"),T$n=Symbol("abort"),gMt=Symbol("aborted"),oJe=Symbol("signal"),Qfe=Symbol("dataListeners"),AB=Symbol("discarded"),iJe=i(e=>Promise.resolve().then(e),"Et"),x7a=i(e=>e(),"$i"),w7a=i(e=>e==="end"||e==="finish"||e==="prefinish","Ii"),T7a=i(e=>e instanceof ArrayBuffer||!!e&&typeof e=="object"&&e.constructor&&e.constructor.name==="ArrayBuffer"&&e.byteLength>=0,"Bi"),R7a=i(e=>!Buffer.isBuffer(e)&&ArrayBuffer.isView(e),"Ui"),XMo=class{static{i(this,"Gt")}src;dest;opts;ondrain;constructor(e,t,n){this.src=e,this.dest=t,this.opts=n,this.ondrain=()=>e[sNe](),this.dest.on("drain",this.ondrain)}unpipe(){this.dest.removeListener("drain",this.ondrain)}proxyErrors(e){}end(){this.unpipe(),this.opts.end&&this.dest.end()}},k7a=class extends XMo{static{i(this,"Fe")}unpipe(){this.src.removeListener("error",this.proxyErrors),super.unpipe()}constructor(e,t,n){super(e,t,n),this.proxyErrors=r=>this.dest.emit("error",r),e.on("error",this.proxyErrors)}},O7a=i(e=>!!e.objectMode,"Gi"),N7a=i(e=>!e.objectMode&&!!e.encoding&&e.encoding!=="buffer","Hi"),wMt=class extends $$n{static{i(this,"J")}[l0]=!1;[rJe]=!1;[DT]=[];[u0]=[];[Fx];[TQ];[t4];[iNe];[tW]=!1;[Mte]=!1;[fMt]=!1;[mMt]=!1;[nJe]=null;[d0]=0;[oS]=!1;[oJe];[gMt]=!1;[Qfe]=0;[AB]=!1;writable=!0;readable=!0;constructor(...e){let t=e[0]||{};if(super(),t.objectMode&&typeof t.encoding=="string")throw new TypeError("Encoding and objectMode may not be used together");O7a(t)?(this[Fx]=!0,this[TQ]=null):N7a(t)?(this[TQ]=t.encoding,this[Fx]=!1):(this[Fx]=!1,this[TQ]=null),this[t4]=!!t.async,this[iNe]=this[TQ]?new b7a(this[TQ]):null,t&&t.debugExposeBuffer===!0&&Object.defineProperty(this,"buffer",{get:i(()=>this[u0],"get")}),t&&t.debugExposePipes===!0&&Object.defineProperty(this,"pipes",{get:i(()=>this[DT],"get")});let{signal:n}=t;n&&(this[oJe]=n,n.aborted?this[T$n]():n.addEventListener("abort",()=>this[T$n]()))}get bufferLength(){return this[d0]}get encoding(){return this[TQ]}set encoding(e){throw new Error("Encoding must be set at instantiation time")}setEncoding(e){throw new Error("Encoding must be set at instantiation time")}get objectMode(){return this[Fx]}set objectMode(e){throw new Error("objectMode must be set at instantiation time")}get async(){return this[t4]}set async(e){this[t4]=this[t4]||!!e}[T$n](){this[gMt]=!0,this.emit("abort",this[oJe]?.reason),this.destroy(this[oJe]?.reason)}get aborted(){return this[gMt]}set aborted(e){}write(e,t,n){if(this[gMt])return!1;if(this[tW])throw new Error("write after end");if(this[oS])return this.emit("error",Object.assign(new Error("Cannot call write after a stream was destroyed"),{code:"ERR_STREAM_DESTROYED"})),!0;typeof t=="function"&&(n=t,t="utf8"),t||(t="utf8");let r=this[t4]?iJe:x7a;if(!this[Fx]&&!Buffer.isBuffer(e)){if(R7a(e))e=Buffer.from(e.buffer,e.byteOffset,e.byteLength);else if(T7a(e))e=Buffer.from(e);else if(typeof e!="string")throw new Error("Non-contiguous data written to non-objectMode stream")}return this[Fx]?(this[l0]&&this[d0]!==0&&this[hMt](!0),this[l0]?this.emit("data",e):this[v$n](e),this[d0]!==0&&this.emit("readable"),n&&r(n),this[l0]):e.length?(typeof e=="string"&&!(t===this[TQ]&&!this[iNe]?.lastNeed)&&(e=Buffer.from(e,t)),Buffer.isBuffer(e)&&this[TQ]&&(e=this[iNe].write(e)),this[l0]&&this[d0]!==0&&this[hMt](!0),this[l0]?this.emit("data",e):this[v$n](e),this[d0]!==0&&this.emit("readable"),n&&r(n),this[l0]):(this[d0]!==0&&this.emit("readable"),n&&r(n),this[l0])}read(e){if(this[oS])return null;if(this[AB]=!1,this[d0]===0||e===0||e&&e>this[d0])return this[nW](),null;this[Fx]&&(e=null),this[u0].length>1&&!this[Fx]&&(this[u0]=[this[TQ]?this[u0].join(""):Buffer.concat(this[u0],this[d0])]);let t=this[EMo](e||null,this[u0][0]);return this[nW](),t}[EMo](e,t){if(this[Fx])this[AMt]();else{let n=t;e===n.length||e===null?this[AMt]():typeof n=="string"?(this[u0][0]=n.slice(e),t=n.slice(0,e),this[d0]-=e):(this[u0][0]=n.subarray(e),t=n.subarray(0,e),this[d0]-=e)}return this.emit("data",t),!this[u0].length&&!this[tW]&&this.emit("drain"),t}end(e,t,n){return typeof e=="function"&&(n=e,e=void 0),typeof t=="function"&&(n=t,t="utf8"),e!==void 0&&this.write(e,t),n&&this.once("end",n),this[tW]=!0,this.writable=!1,(this[l0]||!this[rJe])&&this[nW](),this}[sNe](){this[oS]||(!this[Qfe]&&!this[DT].length&&(this[AB]=!0),this[rJe]=!1,this[l0]=!0,this.emit("resume"),this[u0].length?this[hMt]():this[tW]?this[nW]():this.emit("drain"))}resume(){return this[sNe]()}pause(){this[l0]=!1,this[rJe]=!0,this[AB]=!1}get destroyed(){return this[oS]}get flowing(){return this[l0]}get paused(){return this[rJe]}[v$n](e){this[Fx]?this[d0]+=1:this[d0]+=e.length,this[u0].push(e)}[AMt](){return this[Fx]?this[d0]-=1:this[d0]-=this[u0][0].length,this[u0].shift()}[hMt](e=!1){do;while(this[SMo](this[AMt]())&&this[u0].length);!e&&!this[u0].length&&!this[tW]&&this.emit("drain")}[SMo](e){return this.emit("data",e),this[l0]}pipe(e,t){if(this[oS])return e;this[AB]=!1;let n=this[Mte];return t=t||{},e===yMo.stdout||e===yMo.stderr?t.end=!1:t.end=t.end!==!1,t.proxyErrors=!!t.proxyErrors,n?t.end&&e.end():(this[DT].push(t.proxyErrors?new k7a(this,e,t):new XMo(this,e,t)),this[t4]?iJe(()=>this[sNe]()):this[sNe]()),e}unpipe(e){let t=this[DT].find(n=>n.dest===e);t&&(this[DT].length===1?(this[l0]&&this[Qfe]===0&&(this[l0]=!1),this[DT]=[]):this[DT].splice(this[DT].indexOf(t),1),t.unpipe())}addListener(e,t){return this.on(e,t)}on(e,t){let n=super.on(e,t);if(e==="data")this[AB]=!1,this[Qfe]++,!this[DT].length&&!this[l0]&&this[sNe]();else if(e==="readable"&&this[d0]!==0)super.emit("readable");else if(w7a(e)&&this[Mte])super.emit(e),this.removeAllListeners(e);else if(e==="error"&&this[nJe]){let r=t;this[t4]?iJe(()=>r.call(this,this[nJe])):r.call(this,this[nJe])}return n}removeListener(e,t){return this.off(e,t)}off(e,t){let n=super.off(e,t);return e==="data"&&(this[Qfe]=this.listeners("data").length,this[Qfe]===0&&!this[AB]&&!this[DT].length&&(this[l0]=!1)),n}removeAllListeners(e){let t=super.removeAllListeners(e);return(e==="data"||e===void 0)&&(this[Qfe]=0,!this[AB]&&!this[DT].length&&(this[l0]=!1)),t}get emittedEnd(){return this[Mte]}[nW](){!this[fMt]&&!this[Mte]&&!this[oS]&&this[u0].length===0&&this[tW]&&(this[fMt]=!0,this.emit("end"),this.emit("prefinish"),this.emit("finish"),this[mMt]&&this.emit("close"),this[fMt]=!1)}emit(e,...t){let n=t[0];if(e!=="error"&&e!=="close"&&e!==oS&&this[oS])return!1;if(e==="data")return!this[Fx]&&!n?!1:this[t4]?(iJe(()=>this[x$n](n)),!0):this[x$n](n);if(e==="end")return this[_Mo]();if(e==="close"){if(this[mMt]=!0,!this[Mte]&&!this[oS])return!1;let o=super.emit("close");return this.removeAllListeners("close"),o}else if(e==="error"){this[nJe]=n,super.emit(I$n,n);let o=!this[oJe]||this.listeners("error").length?super.emit("error",n):!1;return this[nW](),o}else if(e==="resume"){let o=super.emit("resume");return this[nW](),o}else if(e==="finish"||e==="prefinish"){let o=super.emit(e);return this.removeAllListeners(e),o}let r=super.emit(e,...t);return this[nW](),r}[x$n](e){for(let n of this[DT])n.dest.write(e)===!1&&this.pause();let t=this[AB]?!1:super.emit("data",e);return this[nW](),t}[_Mo](){return this[Mte]?!1:(this[Mte]=!0,this.readable=!1,this[t4]?(iJe(()=>this[w$n]()),!0):this[w$n]())}[w$n](){if(this[iNe]){let t=this[iNe].end();if(t){for(let n of this[DT])n.dest.write(t);this[AB]||super.emit("data",t)}}for(let t of this[DT])t.end();let e=super.emit("end");return this.removeAllListeners("end"),e}async collect(){let e=Object.assign([],{dataLength:0});this[Fx]||(e.dataLength=0);let t=this.promise();return this.on("data",n=>{e.push(n),this[Fx]||(e.dataLength+=n.length)}),await t,e}async concat(){if(this[Fx])throw new Error("cannot concat in objectMode");let e=await this.collect();return this[TQ]?e.join(""):Buffer.concat(e,e.dataLength)}async promise(){return new Promise((e,t)=>{this.on(oS,()=>t(new Error("stream destroyed"))),this.on("error",n=>t(n)),this.on("end",()=>e())})}[Symbol.asyncIterator](){this[AB]=!1;let e=!1,t=i(async()=>(this.pause(),e=!0,{value:void 0,done:!0}),"e");return{next:i(()=>{if(e)return t();let n=this.read();if(n!==null)return Promise.resolve({done:!1,value:n});if(this[tW])return t();let r,o,s=i(u=>{this.off("data",a),this.off("end",c),this.off(oS,l),t(),o(u)},"h"),a=i(u=>{this.off("error",s),this.off("end",c),this.off(oS,l),this.pause(),r({value:u,done:!!this[tW]})},"a"),c=i(()=>{this.off("error",s),this.off("data",a),this.off(oS,l),t(),r({done:!0,value:void 0})},"l"),l=i(()=>s(new Error("stream destroyed")),"c");return new Promise((u,d)=>{o=d,r=u,this.once(oS,l),this.once("error",s),this.once("end",c),this.once("data",a)})},"next"),throw:t,return:t,[Symbol.asyncIterator](){return this},[Symbol.asyncDispose]:async()=>{}}}[Symbol.iterator](){this[AB]=!1;let e=!1,t=i(()=>(this.pause(),this.off(I$n,t),this.off(oS,t),this.off("end",t),e=!0,{done:!0,value:void 0}),"e"),n=i(()=>{if(e)return t();let r=this.read();return r===null?t():{done:!1,value:r}},"s");return this.once("end",t),this.once(I$n,t),this.once(oS,t),{next:n,throw:t,return:t,[Symbol.iterator](){return this},[Symbol.dispose]:()=>{}}}destroy(e){if(this[oS])return e?this.emit("error",e):this.emit(oS),this;this[oS]=!0,this[AB]=!0,this[u0].length=0,this[d0]=0;let t=this;return typeof t.close=="function"&&!this[mMt]&&t.close(),e?this.emit("error",e):this.emit(oS),this}static get isStream(){return C7a}},B7a=A7a.native,lJe={lstatSync:p7a,readdir:f7a,readdirSync:m7a,readlinkSync:h7a,realpathSync:B7a,promises:{lstat:y7a,readdir:E7a,readlink:S7a,realpath:_7a}},ZMo=i(e=>!e||e===lJe||e===g7a?lJe:{...lJe,...e,promises:{...lJe.promises,...e.promises}},"Cs"),D7a=/^\\\\\?\\([a-z]:)\\?$/i,P7a=/^\\\\\?\\UNC\\([^\\]+\\[^\\]+)\\?$/i,M7a=/^\\\\[^\\?]+\\[^\\]+$/,bMo=i(e=>e.replace(/\//g,"\\").replace(D7a,"$1\\").replace(P7a,"\\\\$1\\").replace(M7a,"$&\\"),"Ss"),L7a=/^[\\/]{2}\?[\\/]unc[\\/][^\\/]+[\\/][^\\/]+(?:[\\/]|$)/i,F7a=/^[\\/]{2}\?[\\/](?=[a-z]:)/i,U7a=/^[\\/]{2}\?[\\/]unc(?=[\\/][^\\/]+[\\/][^\\/])/i,Q7a=/[\\/]/,uL=0,eLo=1,tLo=2,n4=4,nLo=6,rLo=8,jfe=10,oLo=12,lL=15,sJe=~lL,R$n=16,CMo=32,uJe=64,RQ=128,yMt=256,vMt=512,vMo=uJe|RQ|vMt,j7a=1023,k$n=i(e=>e.isFile()?rLo:e.isDirectory()?n4:e.isSymbolicLink()?jfe:e.isCharacterDevice()?tLo:e.isBlockDevice()?nLo:e.isSocket()?oLo:e.isFIFO()?eLo:uL,"De"),IMo=new RMt({max:2**12}),dJe=i(e=>{let t=IMo.get(e);if(t)return t;let n=e.normalize("NFKD");return IMo.set(e,n),n},"Mt"),xMo=new RMt({max:2**12}),EMt=i(e=>{let t=xMo.get(e);if(t)return t;let n=dJe(e.toLowerCase());return xMo.set(e,n),n},"qt"),wMo=class extends RMt{static{i(this,"Xt")}constructor(){super({max:256})}},H7a=class extends RMt{static{i(this,"Pe")}constructor(e=16*1024){super({maxSize:e,sizeCalculation:i(t=>t.length+1,"sizeCalculation")})}},iLo=Symbol("PathScurry setAsCwd"),E1=class{static{i(this,"O")}name;root;roots;parent;nocase;isCWD=!1;#e;#t;get dev(){return this.#t}#n;get mode(){return this.#n}#r;get nlink(){return this.#r}#o;get uid(){return this.#o}#s;get gid(){return this.#s}#i;get rdev(){return this.#i}#a;get blksize(){return this.#a}#c;get ino(){return this.#c}#p;get size(){return this.#p}#d;get blocks(){return this.#d}#u;get atimeMs(){return this.#u}#l;get mtimeMs(){return this.#l}#f;get ctimeMs(){return this.#f}#m;get birthtimeMs(){return this.#m}#y;get atime(){return this.#y}#A;get mtime(){return this.#A}#E;get ctime(){return this.#E}#g;get birthtime(){return this.#g}#_;#b;#S;#v;#I;#x;#h;#T;#k;#R;get parentPath(){return(this.parent||this).fullpath()}get path(){return this.parentPath}constructor(e,t=uL,n,r,o,s,a){this.name=e,this.#_=o?EMt(e):dJe(e),this.#h=t&j7a,this.nocase=o,this.roots=r,this.root=n||this,this.#T=s,this.#S=a.fullpath,this.#I=a.relative,this.#x=a.relativePosix,this.parent=a.parent,this.parent?this.#e=this.parent.#e:this.#e=ZMo(a.fs)}get fs(){return this.#e}depth(){return this.#b!==void 0?this.#b:this.parent?this.#b=this.parent.depth()+1:this.#b=0}childrenCache(){return this.#T}resolve(e){if(!e)return this;let t=this.getRootString(e),n=e.substring(t.length).split(this.splitSep);return t?this.getRoot(t).#O(n):this.#O(n)}#O(e){let t=this;for(let n of e)t=t.child(n);return t}children(){let e=this.#T.get(this);if(e)return e;let t=Object.assign([],{provisional:0});return this.#T.set(this,t),this.#h&=~R$n,t}child(e,t){if(e===""||e===".")return this;if(e==="..")return this.parent||this;let n=this.children(),r=this.nocase?EMt(e):dJe(e);for(let c of n)if(c.#_===r)return c;let o=this.parent?this.sep:"",s=this.#S?this.#S+o+e:void 0,a=this.newChild(e,uL,{...t,parent:this,fullpath:s});return this.canReaddir()||(a.#h|=RQ),n.push(a),a}relative(){if(this.isCWD)return"";if(this.#I!==void 0)return this.#I;let e=this.name,t=this.parent;if(!t)return this.#I=this.name;let n=t.relative();return n+(!n||!t.parent?"":this.sep)+e}relativePosix(){if(this.sep==="/")return this.relative();if(this.isCWD)return"";if(this.#x!==void 0)return this.#x;let e=this.name,t=this.parent;if(!t)return this.#x=this.fullpathPosix();let n=t.relativePosix();return n+(!n||!t.parent?"":"/")+e}fullpath(){if(this.#S!==void 0)return this.#S;let e=this.name,t=this.parent;if(!t)return this.#S=this.name;let n=t.fullpath()+(t.parent?this.sep:"")+e;return this.#S=n}fullpathPosix(){if(this.#v!==void 0)return this.#v;if(this.sep==="/")return this.#v=this.fullpath();if(!this.parent){let r=this.fullpath().replace(/\\/g,"/");return/^[a-z]:\//i.test(r)?this.#v=`//?/${r}`:this.#v=r}let e=this.parent,t=e.fullpathPosix(),n=t+(!t||!e.parent?"":"/")+this.name;return this.#v=n}isUnknown(){return(this.#h&lL)===uL}isType(e){return this[`is${e}`]()}getType(){return this.isUnknown()?"Unknown":this.isDirectory()?"Directory":this.isFile()?"File":this.isSymbolicLink()?"SymbolicLink":this.isFIFO()?"FIFO":this.isCharacterDevice()?"CharacterDevice":this.isBlockDevice()?"BlockDevice":this.isSocket()?"Socket":"Unknown"}isFile(){return(this.#h&lL)===rLo}isDirectory(){return(this.#h&lL)===n4}isCharacterDevice(){return(this.#h&lL)===tLo}isBlockDevice(){return(this.#h&lL)===nLo}isFIFO(){return(this.#h&lL)===eLo}isSocket(){return(this.#h&lL)===oLo}isSymbolicLink(){return(this.#h&jfe)===jfe}lstatCached(){return this.#h&CMo?this:void 0}readlinkCached(){return this.#k}realpathCached(){return this.#R}readdirCached(){let e=this.children();return e.slice(0,e.provisional)}canReadlink(){if(this.#k)return!0;if(!this.parent)return!1;let e=this.#h&lL;return!(e!==uL&&e!==jfe||this.#h&yMt||this.#h&RQ)}calledReaddir(){return!!(this.#h&R$n)}isENOENT(){return!!(this.#h&RQ)}isNamed(e){return this.nocase?this.#_===EMt(e):this.#_===dJe(e)}async readlink(){let e=this.#k;if(e)return e;if(this.canReadlink()&&this.parent)try{let t=await this.#e.promises.readlink(this.fullpath()),n=(await this.parent.realpath())?.resolve(t);if(n)return this.#k=n}catch(t){this.#P(t.code);return}}readlinkSync(){let e=this.#k;if(e)return e;if(this.canReadlink()&&this.parent)try{let t=this.#e.readlinkSync(this.fullpath()),n=this.parent.realpathSync()?.resolve(t);if(n)return this.#k=n}catch(t){this.#P(t.code);return}}#N(e){this.#h|=R$n;for(let t=e.provisional;t<e.length;t++){let n=e[t];n&&n.#w()}}#w(){this.#h&RQ||(this.#h=(this.#h|RQ)&sJe,this.#Q())}#Q(){let e=this.children();e.provisional=0;for(let t of e)t.#w()}#M(){this.#h|=vMt,this.#D()}#D(){if(this.#h&uJe)return;let e=this.#h;(e&lL)===n4&&(e&=sJe),this.#h=e|uJe,this.#Q()}#L(e=""){e==="ENOTDIR"||e==="EPERM"?this.#D():e==="ENOENT"?this.#w():this.children().provisional=0}#B(e=""){e==="ENOTDIR"?this.parent.#D():e==="ENOENT"&&this.#w()}#P(e=""){let t=this.#h;t|=yMt,e==="ENOENT"&&(t|=RQ),(e==="EINVAL"||e==="UNKNOWN")&&(t&=sJe),this.#h=t,e==="ENOTDIR"&&this.parent&&this.parent.#D()}#U(e,t){return this.#$(e,t)||this.#F(e,t)}#F(e,t){let n=k$n(e),r=this.newChild(e.name,n,{parent:this}),o=r.#h&lL;return o!==n4&&o!==jfe&&o!==uL&&(r.#h|=uJe),t.unshift(r),t.provisional++,r}#$(e,t){for(let n=t.provisional;n<t.length;n++){let r=t[n];if((this.nocase?EMt(e.name):dJe(e.name))===r.#_)return this.#W(e,r,n,t)}}#W(e,t,n,r){let o=t.name;return t.#h=t.#h&sJe|k$n(e),o!==e.name&&(t.name=e.name),n!==r.provisional&&(n===r.length-1?r.pop():r.splice(n,1),r.unshift(t)),r.provisional++,t}async lstat(){if((this.#h&RQ)===0)try{return this.#G(await this.#e.promises.lstat(this.fullpath())),this}catch(e){this.#B(e.code)}}lstatSync(){if((this.#h&RQ)===0)try{return this.#G(this.#e.lstatSync(this.fullpath())),this}catch(e){this.#B(e.code)}}#G(e){let{atime:t,atimeMs:n,birthtime:r,birthtimeMs:o,blksize:s,blocks:a,ctime:c,ctimeMs:l,dev:u,gid:d,ino:p,mode:f,mtime:h,mtimeMs:g,nlink:y,rdev:S,size:_,uid:b}=e;this.#y=t,this.#u=n,this.#g=r,this.#m=o,this.#a=s,this.#d=a,this.#E=c,this.#f=l,this.#t=u,this.#s=d,this.#c=p,this.#n=f,this.#A=h,this.#l=g,this.#r=y,this.#i=S,this.#p=_,this.#o=b;let v=k$n(e);this.#h=this.#h&sJe|v|CMo,v!==uL&&v!==n4&&v!==jfe&&(this.#h|=uJe)}#j=[];#C=!1;#q(e){this.#C=!1;let t=this.#j.slice();this.#j.length=0,t.forEach(n=>n(null,e))}readdirCB(e,t=!1){if(!this.canReaddir()){t?e(null,[]):queueMicrotask(()=>e(null,[]));return}let n=this.children();if(this.calledReaddir()){let o=n.slice(0,n.provisional);t?e(null,o):queueMicrotask(()=>e(null,o));return}if(this.#j.push(e),this.#C)return;this.#C=!0;let r=this.fullpath();this.#e.readdir(r,{withFileTypes:!0},(o,s)=>{if(o)this.#L(o.code),n.provisional=0;else{for(let a of s)this.#U(a,n);this.#N(n)}this.#q(n.slice(0,n.provisional))})}#z;async readdir(){if(!this.canReaddir())return[];let e=this.children();if(this.calledReaddir())return e.slice(0,e.provisional);let t=this.fullpath();if(this.#z)await this.#z;else{let n=i(()=>{},"s");this.#z=new Promise(r=>n=r);try{for(let r of await this.#e.promises.readdir(t,{withFileTypes:!0}))this.#U(r,e);this.#N(e)}catch(r){this.#L(r.code),e.provisional=0}this.#z=void 0,n()}return e.slice(0,e.provisional)}readdirSync(){if(!this.canReaddir())return[];let e=this.children();if(this.calledReaddir())return e.slice(0,e.provisional);let t=this.fullpath();try{for(let n of this.#e.readdirSync(t,{withFileTypes:!0}))this.#U(n,e);this.#N(e)}catch(n){this.#L(n.code),e.provisional=0}return e.slice(0,e.provisional)}canReaddir(){if(this.#h&vMo)return!1;let e=lL&this.#h;return e===uL||e===n4||e===jfe}shouldWalk(e,t){return(this.#h&n4)===n4&&!(this.#h&vMo)&&!e.has(this)&&(!t||t(this))}async realpath(){if(this.#R)return this.#R;if(!((vMt|yMt|RQ)&this.#h))try{let e=await this.#e.promises.realpath(this.fullpath());return this.#R=this.resolve(e)}catch{this.#M()}}realpathSync(){if(this.#R)return this.#R;if(!((vMt|yMt|RQ)&this.#h))try{let e=this.#e.realpathSync(this.fullpath());return this.#R=this.resolve(e)}catch{this.#M()}}[iLo](e){if(e===this)return;e.isCWD=!1,this.isCWD=!0;let t=new Set([]),n=[],r=this;for(;r&&r.parent;)t.add(r),r.#I=n.join(this.sep),r.#x=n.join("/"),r=r.parent,n.push("..");for(r=e;r&&r.parent&&!t.has(r);)r.#I=void 0,r.#x=void 0,r=r.parent}},sLo=class aLo extends E1{static{i(this,"r")}sep="\\";splitSep=Q7a;constructor(t,n=uL,r,o,s,a,c){super(t,n,r,o,s,a,c)}newChild(t,n=uL,r={}){return new aLo(t,n,this.root,this.roots,this.nocase,this.childrenCache(),r)}getRootString(t){return L7a.exec(t)?.[0]??F$n.parse(t).root}getRoot(t){if(t=bMo(t.toUpperCase()),t===this.root.name||/^[\\/]$/.test(t))return this.root;for(let[n,r]of Object.entries(this.roots))if(this.sameRoot(t,n))return this.roots[t]=r;return this.roots[t]=new G$n(t,{nocase:this.nocase,fs:this.fs}).root}sameRoot(t,n=this.root.name){return bMo(t.toUpperCase())===n}},cLo=class lLo extends E1{static{i(this,"r")}splitSep="/";sep="/";constructor(t,n=uL,r,o,s,a,c){super(t,n,r,o,s,a,c)}getRootString(t){return t.startsWith("/")?"/":""}getRoot(t){return this.root}newChild(t,n=uL,r={}){return new lLo(t,n,this.root,this.roots,this.nocase,this.childrenCache(),r)}},uLo=class{static{i(this,"Jt")}root;rootPath;roots;cwd;#e;#t;#n;nocase;#r;constructor(e=process.cwd(),t,n,{nocase:r,childrenCacheSize:o=16*1024,fs:s=lJe}={}){this.#r=ZMo(s),(e instanceof URL||e.startsWith("file://"))&&(e=d7a(e));let a=t.resolve(e);this.roots=Object.create(null),this.rootPath=this.parseRootPath(a),this.#e=new wMo,this.#t=new wMo,this.#n=new H7a(o);let c=a.substring(this.rootPath.length).split(n);if(c.length===1&&!c[0]&&c.pop(),r===void 0)throw new TypeError("must provide nocase setting to PathScurryBase ctor");this.nocase=r,this.root=this.newRoot(this.#r),this.roots[this.rootPath]=this.root;let l=this.root,u=c.length-1,d=t.sep,p=this.rootPath,f=!1;for(let h of c){let g=u--;l=l.child(h,{relative:new Array(g).fill("..").join(d),relativePosix:new Array(g).fill("..").join("/"),fullpath:p+=(f?"":d)+h}),f=!0}this.cwd=l}depth(e=this.cwd){return typeof e=="string"&&(e=this.cwd.resolve(e)),e.depth()}childrenCache(){return this.#n}resolve(...e){let t="";for(let o=e.length-1;o>=0;o--){let s=e[o];if(!(!s||s===".")&&(t=t?`${s}/${t}`:s,this.isAbsolute(s)))break}let n=this.#e.get(t);if(n!==void 0)return n;let r=this.cwd.resolve(t).fullpath();return this.#e.set(t,r),r}resolvePosix(...e){let t="";for(let o=e.length-1;o>=0;o--){let s=e[o];if(!(!s||s===".")&&(t=t?`${s}/${t}`:s,this.isAbsolute(s)))break}let n=this.#t.get(t);if(n!==void 0)return n;let r=this.cwd.resolve(t).fullpathPosix();return this.#t.set(t,r),r}relative(e=this.cwd){return typeof e=="string"&&(e=this.cwd.resolve(e)),e.relative()}relativePosix(e=this.cwd){return typeof e=="string"&&(e=this.cwd.resolve(e)),e.relativePosix()}basename(e=this.cwd){return typeof e=="string"&&(e=this.cwd.resolve(e)),e.name}dirname(e=this.cwd){return typeof e=="string"&&(e=this.cwd.resolve(e)),(e.parent||e).fullpath()}async readdir(e=this.cwd,t={withFileTypes:!0}){typeof e=="string"?e=this.cwd.resolve(e):e instanceof E1||(t=e,e=this.cwd);let{withFileTypes:n}=t;if(e.canReaddir()){let r=await e.readdir();return n?r:r.map(o=>o.name)}else return[]}readdirSync(e=this.cwd,t={withFileTypes:!0}){typeof e=="string"?e=this.cwd.resolve(e):e instanceof E1||(t=e,e=this.cwd);let{withFileTypes:n=!0}=t;return e.canReaddir()?n?e.readdirSync():e.readdirSync().map(r=>r.name):[]}async lstat(e=this.cwd){return typeof e=="string"&&(e=this.cwd.resolve(e)),e.lstat()}lstatSync(e=this.cwd){return typeof e=="string"&&(e=this.cwd.resolve(e)),e.lstatSync()}async readlink(e=this.cwd,{withFileTypes:t}={withFileTypes:!1}){typeof e=="string"?e=this.cwd.resolve(e):e instanceof E1||(t=e.withFileTypes,e=this.cwd);let n=await e.readlink();return t?n:n?.fullpath()}readlinkSync(e=this.cwd,{withFileTypes:t}={withFileTypes:!1}){typeof e=="string"?e=this.cwd.resolve(e):e instanceof E1||(t=e.withFileTypes,e=this.cwd);let n=e.readlinkSync();return t?n:n?.fullpath()}async realpath(e=this.cwd,{withFileTypes:t}={withFileTypes:!1}){typeof e=="string"?e=this.cwd.resolve(e):e instanceof E1||(t=e.withFileTypes,e=this.cwd);let n=await e.realpath();return t?n:n?.fullpath()}realpathSync(e=this.cwd,{withFileTypes:t}={withFileTypes:!1}){typeof e=="string"?e=this.cwd.resolve(e):e instanceof E1||(t=e.withFileTypes,e=this.cwd);let n=e.realpathSync();return t?n:n?.fullpath()}async walk(e=this.cwd,t={}){typeof e=="string"?e=this.cwd.resolve(e):e instanceof E1||(t=e,e=this.cwd);let{withFileTypes:n=!0,follow:r=!1,filter:o,walkFilter:s}=t,a=[];(!o||o(e))&&a.push(n?e:e.fullpath());let c=new Set,l=i((d,p)=>{c.add(d),d.readdirCB((f,h)=>{if(f)return p(f);let g=h.length;if(!g)return p();let y=i(()=>{--g===0&&p()},"w");for(let S of h)(!o||o(S))&&a.push(n?S:S.fullpath()),r&&S.isSymbolicLink()?S.realpath().then(_=>_?.isUnknown()?_.lstat():_).then(_=>_?.shouldWalk(c,s)?l(_,y):y()):S.shouldWalk(c,s)?l(S,y):y()},!0)},"l"),u=e;return new Promise((d,p)=>{l(u,f=>{if(f)return p(f);d(a)})})}walkSync(e=this.cwd,t={}){typeof e=="string"?e=this.cwd.resolve(e):e instanceof E1||(t=e,e=this.cwd);let{withFileTypes:n=!0,follow:r=!1,filter:o,walkFilter:s}=t,a=[];(!o||o(e))&&a.push(n?e:e.fullpath());let c=new Set([e]);for(let l of c){let u=l.readdirSync();for(let d of u){(!o||o(d))&&a.push(n?d:d.fullpath());let p=d;if(d.isSymbolicLink()){if(!(r&&(p=d.realpathSync())))continue;p.isUnknown()&&p.lstatSync()}p.shouldWalk(c,s)&&c.add(p)}}return a}[Symbol.asyncIterator](){return this.iterate()}iterate(e=this.cwd,t={}){return typeof e=="string"?e=this.cwd.resolve(e):e instanceof E1||(t=e,e=this.cwd),this.stream(e,t)[Symbol.asyncIterator]()}[Symbol.iterator](){return this.iterateSync()}*iterateSync(e=this.cwd,t={}){typeof e=="string"?e=this.cwd.resolve(e):e instanceof E1||(t=e,e=this.cwd);let{withFileTypes:n=!0,follow:r=!1,filter:o,walkFilter:s}=t;(!o||o(e))&&(yield n?e:e.fullpath());let a=new Set([e]);for(let c of a){let l=c.readdirSync();for(let u of l){(!o||o(u))&&(yield n?u:u.fullpath());let d=u;if(u.isSymbolicLink()){if(!(r&&(d=u.realpathSync())))continue;d.isUnknown()&&d.lstatSync()}d.shouldWalk(a,s)&&a.add(d)}}}stream(e=this.cwd,t={}){typeof e=="string"?e=this.cwd.resolve(e):e instanceof E1||(t=e,e=this.cwd);let{withFileTypes:n=!0,follow:r=!1,filter:o,walkFilter:s}=t,a=new wMt({objectMode:!0});(!o||o(e))&&a.write(n?e:e.fullpath());let c=new Set,l=[e],u=0,d=i(()=>{let p=!1;for(;!p;){let f=l.shift();if(!f){u===0&&a.end();return}u++,c.add(f);let h=i((y,S,_=!1)=>{if(y)return a.emit("error",y);if(r&&!_){let b=[];for(let v of S)v.isSymbolicLink()&&b.push(v.realpath().then(x=>x?.isUnknown()?x.lstat():x));if(b.length){Promise.all(b).then(()=>h(null,S,!0));return}}for(let b of S)b&&(!o||o(b))&&(a.write(n?b:b.fullpath())||(p=!0));u--;for(let b of S){let v=b.realpathCached()||b;v.shouldWalk(c,s)&&l.push(v)}p&&!a.flowing?a.once("drain",d):g||d()},"g"),g=!0;f.readdirCB(h,!0),g=!1}},"f");return d(),a}streamSync(e=this.cwd,t={}){typeof e=="string"?e=this.cwd.resolve(e):e instanceof E1||(t=e,e=this.cwd);let{withFileTypes:n=!0,follow:r=!1,filter:o,walkFilter:s}=t,a=new wMt({objectMode:!0}),c=new Set;(!o||o(e))&&a.write(n?e:e.fullpath());let l=[e],u=0,d=i(()=>{let p=!1;for(;!p;){let f=l.shift();if(!f){u===0&&a.end();return}u++,c.add(f);let h=f.readdirSync();for(let g of h)(!o||o(g))&&(a.write(n?g:g.fullpath())||(p=!0));u--;for(let g of h){let y=g;if(g.isSymbolicLink()){if(!(r&&(y=g.realpathSync())))continue;y.isUnknown()&&y.lstatSync()}y.shouldWalk(c,s)&&l.push(y)}}p&&!a.flowing&&a.once("drain",d)},"f");return d(),a}chdir(e=this.cwd){let t=this.cwd;this.cwd=typeof e=="string"?this.cwd.resolve(e):e,this.cwd[iLo](t)}},G$n=class extends uLo{static{i(this,"ot")}sep="\\";constructor(e=process.cwd(),t={}){let{nocase:n=!0}=t;typeof e=="string"&&!e.startsWith("file://")&&(e=e.replace(F7a,"").replace(U7a,"\\")),super(e,F$n,"\\",{...t,nocase:n}),this.nocase=n;for(let r=this.cwd;r;r=r.parent)r.nocase=this.nocase}parseRootPath(e){return F$n.parse(e).root.toUpperCase()}newRoot(e){return new sLo(this.rootPath,n4,void 0,this.roots,this.nocase,this.childrenCache(),{fs:e})}isAbsolute(e){return e.startsWith("/")||e.startsWith("\\")||/^[a-z]:(\/|\\)/i.test(e)}},q$n=class extends uLo{static{i(this,"ht")}sep="/";constructor(e=process.cwd(),t={}){let{nocase:n=!1}=t;super(e,u7a,"/",{...t,nocase:n}),this.nocase=n}parseRootPath(e){return"/"}newRoot(e){return new cLo(this.rootPath,n4,void 0,this.roots,this.nocase,this.childrenCache(),{fs:e})}isAbsolute(e){return e.startsWith("/")}},dLo=class extends q$n{static{i(this,"Rt")}constructor(e=process.cwd(),t={}){let{nocase:n=!0}=t;super(e,{...t,nocase:n})}},Ydp=process.platform==="win32"?sLo:cLo,$7a=process.platform==="win32"?G$n:process.platform==="darwin"?dLo:q$n,G7a=i(e=>e.length>=1,"pn"),q7a=i(e=>e.length>=1,"mn"),z7a=Symbol.for("nodejs.util.inspect.custom"),pLo=class fLo{static{i(this,"r")}#e;#t;#n;length;#r;#o;#s;#i;#a;#c;#p=!0;constructor(t,n,r,o){if(!G7a(t))throw new TypeError("empty pattern list");if(!q7a(n))throw new TypeError("empty glob list");if(n.length!==t.length)throw new TypeError("mismatched pattern list and glob list lengths");if(this.length=t.length,r<0||r>=this.length)throw new TypeError("index out of range");if(this.#e=t,this.#t=n,this.#n=r,this.#r=o,this.#n===0){if(this.isUNC()){let s=this.#d()?6:4,a=this.#e.slice(0,s),c=this.#t.slice(0,s),l=this.#e.slice(s),u=this.#t.slice(s);l[0]===""&&(l.shift(),u.shift());let d=[...a,""].join("/"),p=[...c,""].join("/");this.#e=[d,...l],this.#t=[p,...u],this.length=this.#e.length}else if(this.isDrive()||this.isAbsolute()){let[s,...a]=this.#e,[c,...l]=this.#t;a[0]===""&&(a.shift(),l.shift());let u=`${s}/`,d=`${c}/`;this.#e=[u,...a],this.#t=[d,...l],this.length=this.#e.length}}}[z7a](){return`Pattern <${this.#t.slice(this.#n).join("/")}>`}pattern(){return this.#e[this.#n]}isString(){return typeof this.#e[this.#n]=="string"}isGlobstar(){return this.#e[this.#n]===qy}isMatcher(){return typeof this.#e[this.#n]=="object"}globString(){return this.#s=this.#s||(this.#n===0?this.isAbsolute()?this.#t[0]+this.#t.slice(1).join("/"):this.#t.join("/"):this.#t.slice(this.#n).join("/"))}hasMore(){return this.length>this.#n+1}rest(){return this.#o!==void 0?this.#o:this.hasMore()?(this.#o=new fLo(this.#e,this.#t,this.#n+1,this.#r),this.#o.#c=this.#c,this.#o.#a=this.#a,this.#o.#i=this.#i,this.#o):this.#o=null}#d(){let t=this.#e;return t[2]==="?"&&typeof t[3]=="string"&&/^unc$/i.test(t[3])}isUNC(){let t=this.#e,n=this.#d()?4:2;return this.#a!==void 0?this.#a:this.#a=this.#r==="win32"&&this.#n===0&&t[0]===""&&t[1]===""&&typeof t[n]=="string"&&!!t[n]&&typeof t[n+1]=="string"&&!!t[n+1]}isDrive(){let t=this.#e;return this.#i!==void 0?this.#i:this.#i=this.#r==="win32"&&this.#n===0&&this.length>1&&typeof t[0]=="string"&&/^[a-z]:$/i.test(t[0])}isAbsolute(){let t=this.#e;return this.#c!==void 0?this.#c:this.#c=t[0]===""&&t.length>1||this.isDrive()||this.isUNC()}root(){let t=this.#e[0];return typeof t=="string"&&this.isAbsolute()&&this.#n===0?t:""}checkFollowGlobstar(){return!(this.#n===0||!this.isGlobstar()||!this.#p)}markFollowGlobstar(){return this.#n===0||!this.isGlobstar()||!this.#p?!1:(this.#p=!1,!0)}},W7a=typeof process=="object"&&process&&typeof process.platform=="string"?process.platform:"linux",TMo=class{static{i(this,"lt")}relative;relativeChildren;absolute;absoluteChildren;platform;mmopts;slashRoot;constructor(e,{nobrace:t,nocase:n,noext:r,noglobstar:o,normalize:s,platform:a=W7a,root:c,windowsPathsNoEscape:l,allowWindowsEscape:u,braceExpandMax:d=1e4},p){this.relative=[],this.absolute=[],this.relativeChildren=[],this.absoluteChildren=[],this.platform=a,l=!!l||u===!1,this.mmopts={braceExpandMax:d,dot:!0,nobrace:t,nocase:n,noext:r,noglobstar:o,normalize:s,optimizationLevel:2,platform:a,nocomment:!0,nonegate:!0,windowsPathsNoEscape:l};let f=p?.resolve(c??"/").fullpath()??"/";this.slashRoot=H$n(f.replace(/\\/g,"/").replace(/\/$/,""),{magicalBraces:!0,windowsPathsNoEscape:l});for(let h of e)this.add(h)}add(e){let t=new $fe(e,this.mmopts);for(let n=0;n<t.set.length;n++){let r=t.set[n],o=t.globParts[n];if(!r||!o)throw new Error("invalid pattern object");for(;r[0]==="."&&o[0]===".";)r.shift(),o.shift();let s=new pLo(r,o,0,this.platform),a=s.root()==="/"?`${this.slashRoot}/${s.rest()?.globString()??""}`:s.globString(),c=new $fe(a,this.mmopts),l=o[o.length-1]==="**",u=s.isAbsolute();u?this.absolute.push(c):this.relative.push(c),l&&(u?this.absoluteChildren.push(c):this.relativeChildren.push(c))}}ignored(e){let t=e.fullpath(),n=`${t}/`,r=e.relative()||".",o=`${r}/`;for(let s of this.relative)if(s.match(r)||s.match(o))return!0;for(let s of this.absolute)if(s.match(t)||s.match(n))return!0;return!1}childrenIgnored(e){let t=`${e.fullpath()}/`,n=`${e.relative()||"."}/`;for(let r of this.relativeChildren)if(r.match(n))return!0;for(let r of this.absoluteChildren)if(r.match(t))return!0;return!1}},V7a=class mLo{static{i(this,"r")}parent;store;constructor(t){this.parent=t}copy(){return new mLo(this)}#e(t){let n=this.store?.get(t);return n||!this.parent?n:this.parent.#e(t)}hasWalked(t,n){return!!this.#e(t.fullpath())?.has(n.globString())}storeWalked(t,n){let r=t.fullpath(),o=this.#e(r);o?o.add(n.globString()):(this.store??=new Map).set(r,new Set([n.globString()]))}},hLo=class U$n{static{i(this,"r")}static ABSOLUTE=2;static IF_DIR=1;store=new Map;add(t,n,r){let o=(n?U$n.ABSOLUTE:0)|(r?U$n.IF_DIR:0),s=this.store.get(t);this.store.set(t,s===void 0?o:o&s)}},K7a=class{static{i(this,"Le")}store=new Map;add(e,t){if(!e.canReaddir())return;let n=this.store.get(e);n?n.find(r=>r.globString()===t.globString())||n.push(t):this.store.set(e,[t])}get(e){let t=this.store.get(e);if(!t)throw new Error("attempting to walk unknown path");return t}entries(){return this.keys().map(e=>[e,this.store.get(e)])}keys(){return[...this.store.keys()].filter(e=>e.canReaddir())}},RMo=class ALo{static{i(this,"r")}hasWalkedCache;matches=new hLo;subwalks=new K7a;patterns;follow;dot;opts;constructor(t,n){this.opts=t,this.follow=!!t.follow,this.dot=!!t.dot,this.hasWalkedCache=n?n.copy():new V7a}processPatterns(t,n){this.patterns=n;let r=n.map(o=>[t,o]);for(let[o,s]of r){this.hasWalkedCache.storeWalked(o,s);let a=s.root(),c=s.isAbsolute()&&this.opts.absolute!==!1;if(a){o=o.resolve(a==="/"&&this.opts.root!==void 0?this.opts.root:a);let p=s.rest();if(p)s=p;else{this.matches.add(o,!0,!1);continue}}if(o.isENOENT())continue;let l,u,d=!1;for(;typeof(l=s.pattern())=="string"&&(u=s.rest());)o=o.resolve(l),s=u,d=!0;if(l=s.pattern(),u=s.rest(),d){if(this.hasWalkedCache.hasWalked(o,s))continue;this.hasWalkedCache.storeWalked(o,s)}if(typeof l=="string"){let p=l===".."||l===""||l===".";this.matches.add(o.resolve(l),c,p);continue}else if(l===qy){(!o.isSymbolicLink()||this.follow||s.checkFollowGlobstar())&&this.subwalks.add(o,s);let p=u?.pattern(),f=u?.rest();if(!u||(p===""||p===".")&&!f)this.matches.add(o,c,p===""||p===".");else if(p===".."){let h=o.parent||o;f?this.hasWalkedCache.hasWalked(h,f)||this.subwalks.add(h,f):this.matches.add(h,c,!0)}}else typeof l=="object"&&this.subwalks.add(o,s)}return this}subwalkTargets(){return this.subwalks.keys()}child(){return new ALo(this.opts,this.hasWalkedCache)}filterEntries(t,n){let r=this.subwalks.get(t),o=this.child();for(let s of n)for(let a of r){let c=a.isAbsolute(),l=a.pattern(),u=a.rest();l===qy?o.testGlobstar(s,a,u,c):typeof l=="object"?o.testMatcher(s,l,u,c):o.testString(s,l,u,c)}return o}testGlobstar(t,n,r,o){if((this.dot||!t.name.startsWith("."))&&(n.hasMore()||this.matches.add(t,o,!1),t.canReaddir()&&(this.follow||!t.isSymbolicLink()?this.subwalks.add(t,n):t.isSymbolicLink()&&(r&&n.checkFollowGlobstar()?this.subwalks.add(t,r):n.markFollowGlobstar()&&this.subwalks.add(t,n)))),r){let s=r.pattern();if(typeof s=="string"&&s!==".."&&s!==""&&s!==".")this.testString(t,s,r.rest(),o);else if(s===".."){let a=t.parent||t;this.subwalks.add(a,r)}else typeof s=="object"&&this.testMatcher(t,s,r.rest(),o)}}testMatcher(t,n,r,o){n.testUnchecked(t.name)&&(r?this.subwalks.add(t,r):this.matches.add(t,o,!1))}testString(t,n,r,o){t.isNamed(n)&&(r?this.subwalks.add(t,r):this.matches.add(t,o,!1))}},{ABSOLUTE:SMt,IF_DIR:_Mt}=hLo,Y7a=i((e,t,n)=>typeof e=="string"?new TMo([e],t,n):Array.isArray(e)?new TMo(e,t,n):e,"bn"),gLo=class{static{i(this,"te")}path;patterns;opts;seen=new Set;paused=!1;aborted=!1;#e=[];#t;#n;signal;maxDepth;includeChildMatches;constructor(e,t,n){if(this.patterns=e,this.path=t,this.opts=n,this.#n=!n.posix&&n.platform==="win32"?"\\":"/",this.includeChildMatches=n.includeChildMatches!==!1,(n.ignore||!this.includeChildMatches)&&(this.#t=Y7a(n.ignore??[],n,t),!this.includeChildMatches&&typeof this.#t.add!="function")){let r="cannot ignore child matches, ignore lacks add() method.";throw new Error(r)}this.maxDepth=n.maxDepth||1/0,n.signal&&(this.signal=n.signal,this.signal.addEventListener("abort",()=>{this.#e.length=0}))}#r(e){return this.seen.has(e)||!!this.#t?.ignored?.(e)}#o(e){return!!this.#t?.childrenIgnored?.(e)}pause(){this.paused=!0}resume(){if(this.signal?.aborted)return;this.paused=!1;let e;for(;!this.paused&&(e=this.#e.shift());)e()}onResume(e){this.paused?this.#e.push(e):e()}async matchCheck(e,t){if(t&&this.opts.nodir)return;let n,r;if(this.opts.realpath){if(n=e.realpathCached()||await e.realpath(),!n)return;r=n}else r=e;let o=r.isUnknown()||this.opts.stat?await r.lstat():r;if(this.opts.follow&&this.opts.nodir&&o?.isSymbolicLink()){let s=await o.realpath();s&&(s.isUnknown()||this.opts.stat)&&await s.lstat()}return this.matchCheckTest(o,t)}matchCheckTest(e,t){return e&&(this.maxDepth===1/0||e.depth()<=this.maxDepth)&&(!t||e.canReaddir())&&(!this.opts.nodir||!e.isDirectory())&&(!this.opts.nodir||!this.opts.follow||!e.isSymbolicLink()||!e.realpathCached()?.isDirectory())&&!this.#r(e)?e:void 0}matchCheckSync(e,t){if(t&&this.opts.nodir)return;let n,r;if(this.opts.realpath){if(n=e.realpathCached()||e.realpathSync(),!n)return;r=n}else r=e;let o=r.isUnknown()||this.opts.stat?r.lstatSync():r;if(this.opts.follow&&this.opts.nodir&&o?.isSymbolicLink()){let s=o.realpathSync();s&&(s?.isUnknown()||this.opts.stat)&&s.lstatSync()}return this.matchCheckTest(o,t)}matchFinish(e,t){this.#r(e)||this.#s(e,t)}#s(e,t){if(!this.includeChildMatches&&this.#t?.add){let o=`${e.relativePosix()}/**`;this.#t.add(o)}let n=this.opts.absolute===void 0?t:this.opts.absolute;this.seen.add(e);let r=this.opts.mark&&e.isDirectory()?this.#n:"";if(this.opts.withFileTypes)this.matchEmit(e);else if(n){let o=this.opts.posix?e.fullpathPosix():e.fullpath();this.matchEmit(o+r)}else{let o=this.opts.posix?e.relativePosix():e.relative(),s=this.opts.dotRelative&&!o.startsWith(`..${this.#n}`)?`.${this.#n}`:"";this.matchEmit(o?s+o+r:`.${r}`)}}async match(e,t,n){let r=await this.matchCheck(e,n);r&&this.matchFinish(r,t)}matchSync(e,t,n){let r=this.matchCheckSync(e,n);r&&this.#s(r,t)}walkCB(e,t,n){if(this.signal?.aborted)return n();this.walkCB2(e,t,new RMo(this.opts),n)}walkCB2(e,t,n,r){if(this.#o(e)||this.signal?.aborted)return r();if(this.paused){this.onResume(()=>this.walkCB2(e,t,n,r));return}n.processPatterns(e,t);let o=1,s=i(()=>{--o===0&&r()},"o");for(let[a,c]of n.matches.store)this.#r(a)||(o++,this.match(a,!!(c&SMt),!!(c&_Mt)).then(()=>s()));for(let a of n.subwalkTargets()){if(this.maxDepth!==1/0&&a.depth()>=this.maxDepth)continue;o++;let c=a.readdirCached();a.calledReaddir()?this.walkCB3(a,c,n,s):a.readdirCB((l,u)=>this.walkCB3(a,u,n,s),!0)}s()}walkCB3(e,t,n,r){let o=n.filterEntries(e,t),s=1,a=i(()=>{--s===0&&r()},"h");for(let[c,l]of o.matches.store)this.#r(c)||(s++,this.match(c,!!(l&SMt),!!(l&_Mt)).then(()=>a()));for(let[c,l]of o.subwalks.entries())s++,this.walkCB2(c,l,o.child(),a);a()}walkCBSync(e,t,n){if(this.signal?.aborted)return n();this.walkCB2Sync(e,t,new RMo(this.opts),n)}walkCB2Sync(e,t,n,r){if(this.#o(e)||this.signal?.aborted)return r();if(this.paused){this.onResume(()=>this.walkCB2Sync(e,t,n,r));return}n.processPatterns(e,t);let o=1,s=i(()=>{--o===0&&r()},"o");for(let[a,c]of n.matches.store)this.#r(a)||this.matchSync(a,!!(c&SMt),!!(c&_Mt));for(let a of n.subwalkTargets()){if(this.maxDepth!==1/0&&a.depth()>=this.maxDepth)continue;o++;let c=a.readdirSync();this.walkCB3Sync(a,c,n,s)}s()}walkCB3Sync(e,t,n,r){let o=n.filterEntries(e,t),s=1,a=i(()=>{--s===0&&r()},"h");for(let[c,l]of o.matches.store)this.#r(c)||this.matchSync(c,!!(l&SMt),!!(l&_Mt));for(let[c,l]of o.subwalks.entries())s++,this.walkCB2Sync(c,l,o.child(),a);a()}},kMo=class extends gLo{static{i(this,"Tt")}matches=[];constructor(e,t,n){super(e,t,n)}matchEmit(e){this.matches.push(e)}async walk(){if(this.signal?.aborted)throw this.signal.reason;return this.path.isUnknown()&&await this.path.lstat(),await new Promise((e,t)=>{this.walkCB(this.path,this.patterns,()=>{this.signal?.aborted?t(this.signal.reason):e(this.matches)})}),this.matches}walkSync(){if(this.signal?.aborted)throw this.signal.reason;return this.path.isUnknown()&&this.path.lstatSync(),this.walkCBSync(this.path,this.patterns,()=>{if(this.signal?.aborted)throw this.signal.reason}),this.matches}},OMo=class extends gLo{static{i(this,"_t")}results;constructor(e,t,n){super(e,t,n),this.results=new wMt({signal:this.signal,objectMode:!0}),this.results.on("drain",()=>this.resume()),this.results.on("resume",()=>this.resume())}matchEmit(e){this.results.write(e),this.results.flowing||this.pause()}stream(){let e=this.path;return e.isUnknown()?e.lstat().then(()=>{this.walkCB(e,this.patterns,()=>this.results.end())}):this.walkCB(e,this.patterns,()=>this.results.end()),this.results}streamSync(){return this.path.isUnknown()&&this.path.lstatSync(),this.walkCBSync(this.path,this.patterns,()=>this.results.end()),this.results}},J7a=typeof process=="object"&&process&&typeof process.platform=="string"?process.platform:"linux",rW=class{static{i(this,"j")}absolute;cwd;root;dot;dotRelative;follow;ignore;magicalBraces;mark;matchBase;maxDepth;nobrace;nocase;nodir;noext;noglobstar;pattern;platform;realpath;scurry;stat;signal;windowsPathsNoEscape;withFileTypes;includeChildMatches;opts;patterns;constructor(e,t){if(!t)throw new TypeError("glob options required");if(this.withFileTypes=!!t.withFileTypes,this.signal=t.signal,this.follow=!!t.follow,this.dot=!!t.dot,this.dotRelative=!!t.dotRelative,this.nodir=!!t.nodir,this.mark=!!t.mark,t.cwd?(t.cwd instanceof URL||t.cwd.startsWith("file://"))&&(t.cwd=r7a(t.cwd)):this.cwd="",this.cwd=t.cwd||"",this.root=t.root,this.magicalBraces=!!t.magicalBraces,this.nobrace=!!t.nobrace,this.noext=!!t.noext,this.realpath=!!t.realpath,this.absolute=t.absolute,this.includeChildMatches=t.includeChildMatches!==!1,this.noglobstar=!!t.noglobstar,this.matchBase=!!t.matchBase,this.maxDepth=typeof t.maxDepth=="number"?t.maxDepth:1/0,this.stat=!!t.stat,this.ignore=t.ignore,this.withFileTypes&&this.absolute!==void 0)throw new Error("cannot set absolute and withFileTypes:true");let n=typeof e=="string"?[e]:e;if(this.windowsPathsNoEscape=!!t.windowsPathsNoEscape||t.allowWindowsEscape===!1,this.windowsPathsNoEscape&&(n=n.map(l=>l.replace(/\\/g,"/"))),this.matchBase){if(t.noglobstar)throw new TypeError("base matching requires globstar");n=n.map(l=>l.includes("/")?l:`./**/${l}`)}if(this.pattern=n,this.platform=t.platform||J7a,this.opts={...t,platform:this.platform},t.scurry){if(this.scurry=t.scurry,t.nocase!==void 0&&t.nocase!==t.scurry.nocase)throw new Error("nocase option contradicts provided scurry option")}else{let l=t.platform==="win32"?G$n:t.platform==="darwin"?dLo:t.platform?q$n:$7a;this.scurry=new l(this.cwd,{nocase:t.nocase,fs:t.fs})}this.nocase=this.scurry.nocase;let r=this.platform==="darwin"||this.platform==="win32",o={braceExpandMax:1e4,...t,dot:this.dot,matchBase:this.matchBase,nobrace:this.nobrace,nocase:this.nocase,nocaseMagicOnly:r,nocomment:!0,noext:this.noext,nonegate:!0,optimizationLevel:2,platform:this.platform,windowsPathsNoEscape:this.windowsPathsNoEscape},s=this.pattern.map(l=>new $fe(l,o)),[a,c]=s.reduce((l,u)=>(l[0].push(...u.set),l[1].push(...u.globParts),l),[[],[]]);this.patterns=a.map((l,u)=>{let d=c[u];if(!d)throw new Error("invalid pattern object");return new pLo(l,d,0,this.platform)})}async walk(){return await new kMo(this.patterns,this.scurry.cwd,{...this.opts,maxDepth:this.maxDepth!==1/0?this.maxDepth+this.scurry.cwd.depth():1/0,platform:this.platform,nocase:this.nocase,includeChildMatches:this.includeChildMatches}).walk()}walkSync(){return new kMo(this.patterns,this.scurry.cwd,{...this.opts,maxDepth:this.maxDepth!==1/0?this.maxDepth+this.scurry.cwd.depth():1/0,platform:this.platform,nocase:this.nocase,includeChildMatches:this.includeChildMatches}).walkSync()}stream(){return new OMo(this.patterns,this.scurry.cwd,{...this.opts,maxDepth:this.maxDepth!==1/0?this.maxDepth+this.scurry.cwd.depth():1/0,platform:this.platform,nocase:this.nocase,includeChildMatches:this.includeChildMatches}).stream()}streamSync(){return new OMo(this.patterns,this.scurry.cwd,{...this.opts,maxDepth:this.maxDepth!==1/0?this.maxDepth+this.scurry.cwd.depth():1/0,platform:this.platform,nocase:this.nocase,includeChildMatches:this.includeChildMatches}).streamSync()}iterateSync(){return this.streamSync()[Symbol.iterator]()}[Symbol.iterator](){return this.iterateSync()}iterate(){return this.stream()[Symbol.asyncIterator]()}[Symbol.asyncIterator](){return this.iterate()}},z$n=i((e,t={})=>{for(let n of Array.isArray(e)?e:[e])if(new $fe(n,t).hasMagic())return!0;return!1},"je");i(kMt,"ee");i(yLo,"Ps");i(OMt,"zs");i(NMo,"Ds");i(NMt,"se");i(ELo,"Ls");X7a=kMt,Z7a=Object.assign(yLo,{sync:kMt}),eJa=NMt,tJa=Object.assign(ELo,{sync:NMt}),nJa=Object.assign(OMt,{stream:kMt,iterate:NMt}),TMt=Object.assign(NMo,{glob:NMo,globSync:OMt,sync:nJa,globStream:yLo,stream:Z7a,globStreamSync:kMt,streamSync:X7a,globIterate:ELo,iterate:tJa,globIterateSync:NMt,iterateSync:eJa,Glob:rW,hasMagic:z$n,escape:H$n,unescape:qMo});TMt.glob=TMt});import*as kb from"node:path";function _Lo(e){gv("platformPaths",e)}function W$n(e,t){return kb.isAbsolute(e)?e:(_Lo(`Ignoring ${t}=${e}: it must be an absolute path to be searched for tools.`),null)}function DMt(e){try{return OMt(e).toSorted().toReversed()}catch(t){return _Lo(`Glob failed for ${e}: ${et(t)}`),[]}}function SLo(e){let t=process.env.HOME;t&&e.push(kb.join(t,"bin"),kb.join(t,".local","bin"))}function PMt(){let e=[],t=process.platform;if(t==="darwin")e.push("/opt/homebrew/bin","/usr/local/bin","/Library/TeX/texbin","/usr/texbin"),e.push("/Applications/MiKTeX Console.app/Contents/bin"),SLo(e);else if(t==="win32"){e.push("C:\\Program Files\\MiKTeX\\miktex\\bin\\x64","C:\\Program Files\\MiKTeX\\miktex\\bin","C:\\Program Files\\MiKTeX 2.9\\miktex\\bin\\x64","C:\\Program Files\\MiKTeX 2.9\\miktex\\bin","C:\\Program Files (x86)\\MiKTeX\\miktex\\bin","C:\\Program Files (x86)\\MiKTeX 2.9\\miktex\\bin","C:\\Strawberry\\perl\\bin","C:\\Program Files\\Git\\cmd","C:\\Program Files (x86)\\Git\\cmd");for(let g of["C:/Program Files","C:/Program Files (x86)"])e.push(...DMt(`${g}/gs/*/bin`));let a=process.env.USERPROFILE?kb.join(process.env.USERPROFILE,"AppData","Local"):null,c=process.env.LOCALAPPDATA?W$n(process.env.LOCALAPPDATA,"LOCALAPPDATA"):a;c&&e.push(kb.join(c,"Programs","MiKTeX","miktex","bin","x64"),kb.join(c,"Programs","MiKTeX","miktex","bin"),kb.join(c,"Programs","MiKTeX 2.9","miktex","bin","x64"),kb.join(c,"Programs","MiKTeX 2.9","miktex","bin"),kb.join(c,"MiKTeX","miktex","bin","x64"),kb.join(c,"MiKTeX","miktex","bin"),kb.join(c,"Programs","Git","cmd"),kb.join(c,"Programs","OpenAI","Codex","bin"));let l=process.env.SCOOP||process.env.SCOOP_HOME,u=process.env.USERPROFILE?kb.join(process.env.USERPROFILE,"scoop"):null,d=l?W$n(l,"SCOOP"):u;d&&CJ(d)&&(e.push(kb.join(d,"shims")),e.push(...DMt(`${Ts(d)}/apps/*/current`)));let p=new Set(oJa),f=process.env.MSYS2_HOME?W$n(process.env.MSYS2_HOME,"MSYS2_HOME"):null;f&&p.add(f);for(let g of p)for(let y of iJa){let S=kb.join(g,y);CJ(kb.join(S,"perl.exe"))&&e.push(S)}let h=["C:/texlive/*/tlpkg/tlperl/bin"];process.env.USERPROFILE&&h.push(`${Ts(process.env.USERPROFILE)}/texlive/*/tlpkg/tlperl/bin`);for(let g of h)for(let y of DMt(g))CJ(kb.join(y,"perl.exe"))&&e.push(y)}else e.push("/usr/local/bin","/usr/bin","/opt/miktex/bin","/snap/bin","/home/linuxbrew/.linuxbrew/bin"),SLo(e);let n=t==="win32"?["C:/texlive/*/bin/*"]:["/usr/local/texlive/*/bin/*"],r=t==="win32"?["C:/texlive/*/texmf-dist/scripts"]:["/usr/local/texlive/*/texmf-dist/scripts","/usr/share/texlive/texmf-dist/scripts","/usr/share/texmf/scripts","/usr/share/texmf-dist/scripts"],o=process.env.HOME||process.env.USERPROFILE;if(o){let a=Ts(o);n.push(`${a}/texlive/*/bin/*`,`${a}/TinyTeX/bin/*`),r.push(`${a}/texlive/*/texmf-dist/scripts`,`${a}/TinyTeX/texmf-dist/scripts`)}let s=[...n,...rJa.flatMap(a=>r.map(c=>`${c}/${a}`))];for(let a of s)e.push(...DMt(a));return[...new Set(e)]}var rJa,oJa,iJa,V$n=N(()=>{"use strict";BMt();Co();It();rJa=["latexdiff","latexindent","latexmk"];i(_Lo,"warnSkippedDir");oJa=["C:\\msys64","C:\\msys32"],iJa=["usr\\bin","mingw64\\bin","mingw32\\bin"];i(W$n,"absoluteEnvRoot");i(DMt,"globDescending");i(SLo,"pushHomeBinDirs");i(PMt,"commandDirs")});import*as bLo from"node:os";import*as K$n from"node:path";function CLo(){let e=bLo.homedir();return K$n.join(e,Gfe)}function aNe(e){return K$n.join(e,Gfe,MMt)}var Gfe,MMt,qfe=N(()=>{"use strict";Gfe=".texra",MMt="config.json";i(CLo,"defaultNodeStorageRoot");i(aNe,"workspaceTexraConfigPath")});var fJe,sJa,aJa,vLo,cJa,LMt,ILo,cNe=N(()=>{"use strict";de();YCe();BOt();aKe();o0();QE();nT();qi();vn();fJe=m.fn("startChildRun")(function*(e,t,n,r={}){let{opened:o}=yield*(yield*Ka).start(e,qpe(e,n.parent?.id??null,m.succeed({definition:t,options:{...r,entry:{kind:"fresh",registration:n}}})));return o.activation}),sJa="childLaunch",aJa=m.fn("resumeOwnedChild")(function*(e,t,n){let{opened:r}=yield*(yield*Ka).start(e,qpe(e,t,JPn(e,n,t).pipe(m.catchTag("ResumeNotOpened",({answer:o})=>m.fail(new _t("failed"in o?`Subagent ${e} cannot be resumed here (${o.failed.kind}).`:`Subagent ${e} belongs to an open call of ${o.ownedBy}.`))))));return r.activation}),vLo=m.fn("awaitChildRun")(function*(e,t){return yield*(yield*Rq).run.awaitedCalls.withPermits(1)(cJa(e,t))}),cJa=m.fn("childRunEnd")(function*(e,t){let n=yield*Ka,r=m.suspend(()=>n.get(e)===void 0?m.void:n.stop(e,"released").pipe(m.catchCause(c=>Ir(sJa,`Subagent ${e}: its release was not recorded`)(c).pipe(m.andThen(m.sync(()=>n.interrupt(e))))),m.andThen(n.awaitDrained(e))));yield*t.pipe(m.onInterrupt(()=>r));let o=n.get(e),s=o&&(yield*o.drained.pipe(m.onInterrupt(()=>r))),a=yield*Vd(e).readRunEnd();return a===null?yield*s===void 0?new _t(`Subagent ${e} ended without a recorded end.`):new _t(`Subagent ${e} ended without a recorded end: ${s.message}`,{cause:s}):a.outcome===ls.FAILED?yield*new _t(a.error===void 0?`Subagent ${e} ended with failed outcome.`:NC(a.error)):{runId:e,result:a}}),LMt=i(e=>vLo(e.runId,m.gen(function*(){let t=yield*tG({config:e.config});return yield*fJe(e.runId,t,{identity:{kind:"agent",agent:t.config.label},parent:{id:e.parentId,call:{...e.parentCall,awaited:!0}},grants:e.grants,maxCostUsd:e.maxCostUsd,seed:e.seed},{onProgress:e.notify})})),"executeSubagentInBand"),ILo=i(e=>vLo(e.runId,aJa(e.runId,e.parentId,{onProgress:e.notify})),"resumeSubagentInBand")});import{createHash as lJa}from"node:crypto";function wLo(e,t){return t instanceof FMt?Ws(`'${e}' did not finish within ${t.timeoutMs} ms; its run was stopped.`,{name:"TimedOut",summary:`'${e}' timed out`}):null}function jMt(e,t){let n=e.runs.get(t);if(n===void 0)throw new Error(`Run ${t} is missing from its session's view.`);return n.treeUsage.cost}var xLo,uJa,UMt,zfe,mJe,dJa,FMt,hJe,QMt,TLo,pJa,fJa,mJa,RLo,HMt=N(()=>{"use strict";de();nT();vn();fs();dA();cNe();xLo=1e3,uJa=Ve.Service("@texra-ai/worldline/agent/AgentLaunches"),UMt=i((e,t)=>m.map(e.shared(uJa,m.sync(()=>({count:0}))),n=>n.count>=xLo?Ws(`A script may launch at most ${xLo} agents; '${t}' did not run.`,{name:"CallLimit"}):(n.count+=1,null)),"countLaunch"),zfe=i((e,t=e.attempt)=>npn({parentId:e.run.runId,responseId:e.responseId,callId:e.callId,attempt:t}),"agentChildRunId"),mJe=m.fn("agent.earlierChild")(function*(e){for(let t=e.attempt-1;t>=1;t-=1){let n=zfe(e,t);if(yield*Vd(n).exists())return n}return null}),dJa=m.fn("agent.childStanding")(function*(e){let t=yield*(yield*vr).facts(e),n=yield*Vd(e).readRunEnd();return n===null?{kind:"resume"}:n.outcome===ls.FAILED&&(t?.position===null||t?.position.payload.at==="turn.ready")?{kind:"fresh"}:{kind:"answered",result:n}}),FMt=class extends A.TaggedError()("AgentTimedOut",{timeoutMs:A.Number}){static{i(this,"AgentTimedOut")}},hJe=i((e,t)=>e==null?t:m.timeoutOrElse(t,{duration:e,orElse:i(()=>m.fail(new FMt({timeoutMs:e})),"orElse")}),"withinTime");i(wLo,"limitResult");QMt=m.fn("agent.recoverChild")(function*(e,t){let{runId:n}=e.run,r=yield*mJe(e);if(r===null)return{kind:"launch"};let o=yield*dJa(r);switch(o.kind){case"answered":return{kind:"ended",runId:r,result:o.result};case"fresh":return{kind:"launch"};case"resume":{let{result:s}=yield*hJe(t.timeoutMs,ILo({runId:r,parentId:n,notify:t.notify}));return{kind:"ended",runId:r,result:s}}}}),TLo=m.fn("agent.fingerprint")(function*(e){let t=yield*ot.FileSystem,n=lJa("sha256");return yield*De.fromIterable(e.flatMap((r,o)=>r.map((s,a)=>({group:o,index:a,file:s})))).pipe(De.mapEffect(({group:r,index:o,file:s})=>m.map(t.readFile(s),a=>({group:r,index:o,bytes:a})),{concurrency:8}),De.runForEach(({group:r,index:o,bytes:s})=>m.sync(()=>{n.update(`${r}\0${o}\0${s.length}\0`),n.update(s)}))),n.digest("hex")}),pJa=m.fn("agent.reuseScope")(function*(e){let{runId:t}=e.run,n=yield*(yield*Di).read([]),r=n.runs.get(t),o=r?.identity.kind==="script"?r.launch?.id??t:t,s=[...n.runs.values()].filter(a=>a.identity.kind==="script"&&a.launch?.id===o);return[o,...s.map(a=>a.id)]});i(jMt,"treeCostOf");fJa=i(e=>m.map(Di.use(t=>t.read([])),t=>jMt(t,e.run.runId)),"spentBy"),mJa=Ve.Service("@texra-ai/worldline/agent/AgentKeys"),RLo=m.fn("agent.reusable")(function*(e,t,n){let r=yield*t.shared(mJa,m.sync(()=>new Map)),{callId:o}=e,s=Ws("Another agent call of this script has the same prompt, options and files. Give each a distinct `id` to run both.",{name:"DuplicateCall"}),a=r.get(n);if(a!==void 0&&a!==o)return s;r.set(n,o);let c=yield*vr,u=(yield*m.forEach(yield*pJa(e),g=>c.runRows(g,"results"))).flatMap(g=>g.results).flatMap(g=>g.result.status==="executed"&&g.result.reuseKey===n?[{...g,result:g.result}]:[]),d=`${t.callId}/`;if(u.some(g=>g.responseId===e.responseId&&g.callId.startsWith(d)&&g.callId!==o))return s;let p=u.at(-1);if(p===void 0)return null;let f=p.result.reusedFrom??p.callId,{value:h}=p.result;return{...p.result,output:`Reused the result of call ${f}: nothing ran again.
|
|
1036
1036
|
|
|
1037
1037
|
${p.result.output??""}`,reusedFrom:f,...typeof h=="object"&&h!==null&&!Array.isArray(h)&&{value:{...h,spent:yield*fJa(e)}}}})});var hJa,kLo,OLo=N(()=>{"use strict";de();l0e();LP();nf();vn();fs();mv();nT();hJa=m.fn("checkDeclaredChildOutput")(function*(e,t){let n=Vd(t.runId),[r,o]=yield*m.all([n.readRunEnd(),n.readConfig()]);if((yield*(yield*vr).facts(t.runId))?.start?.parent?.id!==e)return yield*new _t(`Run ${t.runId} is not a direct child of ${e}.`);let a=r?.outcome===ls.COMPLETED?yield*c0e(o,t.runId,yield*rs):void 0;if(a===void 0)return yield*new _t(`Run ${t.runId} is no completed program's run.`);if(!a.changes.some(({absolutePath:l})=>Ts(l)===Ts(t.absolutePath)))return yield*new _t(`${t.relativePath} is not a declared output of run ${t.runId}.`)}),kLo=m.fn("resolveChildRunOutput")(function*(e,t){let r=(yield*rs).storage,o=i0e(r,t);if(!o)return yield*new _t("A declared output is not inside run storage.");o.runId!==e&&(yield*hJa(e,o));let s=yield*s0e(r,o.runId,o.relativePath);switch(s.kind){case"file":return s.location;case"symlink":return;case"missing":return yield*new _t(`Declared output ${o.relativePath} is missing from run ${o.runId}.`);case"invalid":return yield*new _t(`Invalid declared output: ${s.reason}`);default:return yield*new _t(`Declared output ${o.relativePath} is not a regular file.`)}})});import*as lNe from"node:path";function BLo(e,t){let n=e.trim(),r=t?.trim(),o=n?[n]:[];if(r){let s=r===n?"The delegated task above is copied verbatim from the request the agent that launched you is working on.":`The request the agent that launched you is working on (constraint context only):
|
|
@@ -3264,7 +3264,7 @@ Setup:
|
|
|
3264
3264
|
|
|
3265
3265
|
Better BibTeX exposes a JSON-RPC API on localhost:23119
|
|
3266
3266
|
that TeXRA uses to communicate with your library.`,installUrl:"https://retorque.re/zotero-better-bibtex/installation/",configNotes:"Zotero must be running with Better BibTeX installed. Port configurable via texra.bib.zoteroPort."}}})});var Tkl,Khi,Rkl,kkl,Okl,Nkl,Bkl,Dkl,Yhi,Jhi=N(()=>{"use strict";de();p4n();Rn();iXe();wGo();cW();xqo();Tqo();It();Hqo();_8o();Zli();Cui();Rui();Nui();JOe();CJn();api();vfi();gmi();Emi();Nmi();Dmi();chi();uhi();phi();mhi();Shi();vhi();Utt();Q$t();xhi();Vhi();Rn();$g();Tkl=i((e,t,n)=>{if(!Xp(e,".tex"))return m.succeed(t);let r=zte.applyToTexWrite(t,n);return qte(r.diagnostics).pipe(m.as(r.text))},"texWriteFilter"),Khi=i(e=>gt.succeed(R9)({of:i(t=>new Set(e(t)),"of")}),"serves"),Rkl=i(e=>({...pA({id:"latex-diagnostics",tools:[Oui],processLayer:{layer:gt.mergeAll(gt.succeed(Xz)(e),gt.succeed(R9)(e))}}),icons:{diagnostics:"list-check"},dashboard:{name:"LaTeX Diagnostics",description:"Report LaTeX compilation errors and warnings from the VS Code Problems panel."}}),"latexDiagnostics"),kkl='Find the project\'s TeX sources with relative paths (e.g., `find . -name "*.tex"`).',Okl="For math in responses, use $...$ or \\(...\\) for inline and $$...$$ or \\[...\\] for display math. Wrap LaTeX environments like align or gather inside $$...$$ (e.g., $$\\begin{align}...\\end{align}$$) so they render correctly.",Nkl=i((e,t)=>({...pA({id:"core",tools:[Tui,ymi,xGo],scriptModules:shi,programs:ahi,prompt:i(({config:n,offered:r})=>{if(r.length===0)return"";let o=i((...a)=>a.some(c=>r.includes(c)),"offers"),s=Bn.getConfig(n,vHn);return[...o("bash")?[kkl]:[],Okl,...o("open_pdf")?["After compiling a document the user asked to see, show it with `open_pdf`."]:[],...s?[`The default bibliography file is ${s}.${o("grep","read_file","bash")?" You can grep or read this file to search for citations and references.":""}`]:[]].join(`
|
|
3267
|
-
`)},"prompt"),processLayer:{layer:gt.mergeAll(gt.succeed(Xz)(e),...t===void 0?[]:[gt.succeed(_tt)(t)],Khi(n=>[...e.of(n),...t===void 0?[]:["inline-comments"]]))}})}),"core"),Bkl=i((e,t,n)=>pA({id:"setup",prompt:i(({offered:r})=>r.includes("probe_environment")?Bmi:"","prompt"),processLayer:{layer:gt.mergeAll(gt.succeed(jne)(e),gt.succeed(iPe)(t),gt.succeed(oPe)(n),Khi(()=>[...Object.entries(e).flatMap(([r,o])=>o===void 0?[]:[r]),...n?[U$t]:[]]))},tools:[Omi,lhi,dhi,fhi,yhi,Ehi,Chi]}),"setup"),Dkl=Vv({id:"theory",icons:{accept_run_files:"check"},prompt:i(({offered:e})=>e.includes("program")?["`program` starts a document program over files (`inputFiles`, with `contextFiles` it may read and not change).",...e.includes("script")?[]:[`The programs: ${Object.entries(z4n).map(([t,{description:n}])=>`\`${t}\` (${n})`).join("; ")}.`],"Each rewrites whole documents in fixed revisions, with compile checks and diffs, and proposes the result for the user to accept; it reads only the files you pass. What to change, how far and from which point of view is the `prompt`: one program covers a proofread and a restructuring, a referee and a first reader.","Its `args` may switch on `reflect` (a critic reviews each revision but the last), `attachTeXCount` (word counts in the prompt), and `autoExtractFigure`, `autoExtractTikzFigure` or `autoCompileInputPdf` (the inputs' figures, compiled TikZ pictures or PDF as media, for a model that reads images).",'Its delivery lists each proposed file with a `diff` attribute, the diff against the document the program started from, readable among the run\'s files (`/executions/{id}/files/<diff>`), and `large-change="true"` when the file changed extensively; a diff may be truncated.',"The host compiles each .tex the program writes: a file that failed to build leaves its log at `compile/r{n}_<name>.log` among the run's files, which the delivery's `<compile-failures>` names (read it at `/executions/{id}/files/<log>`), and no log means every build passed or no LaTeX toolchain is installed.",...e.includes("script")?["In a script, `program(name, { prompt, inputFiles })` resolves to the program's result, whose `changes` list each revision's files in order: pass the last `absolutePath` of each `path` as the `inputFiles` of the next program to chain them. `describeTool(name)` shows a program's source, and `builtIn:revise` exports what the programs are built from."]:[]].join(" "):"","prompt"),scriptModules:Iqo,programs:z4n,tools:[jqo,tpi,npi,rpi,opi,spi,ipi],factKinds:wqo.theory}),Yhi=i(e=>{let t=e.editors??jPt(()=>({}));return[{...rFt({writeFilter:Tkl}),icons:{bash:"terminal",read_file:"file",write_file:"file-circle-plus",edit_file:"pencil",glob:"magnifying-glass",grep:"magnifying-glass"},dashboard:{name:"File & Shell Operations",description:"Read, write, edit files and run shell commands. Includes glob/grep search."}},Rkl(t),S8o,{...oFt,icons:{web_search:"globe",web_fetch:"globe"},dashboard:{name:"Web Search & Fetch",description:"Search the web with DuckDuckGo Instant Answers and fetch or extract content from URLs."}},{...iFt,icons:{memory:"database",executions:"clock-rotate-left"},dashboard:{name:"Memory & Task History",description:"Persistent memory across tasks and inspection of agents launched during a task."}},{...sFt,dashboard:{name:"Goal Mode",description:"Propose a plan and run it autonomously across rounds until complete or input is needed.",setup:{configNotes:"Turning this off disables the plan tool and stops goal rounds on the next turn."}}},Ihi,Whi,Ami,{...aFt,icons:{agent:"circle-user"},dashboard:{name:"Multi-Agent Workflow",description:"Let the assistant delegate work to helper agents and programs, sequentially or in parallel.",setup:{configNotes:"Turning this off removes delegation and program tools on the next turn."}}},Cfi,bui,Xli,Nkl(t,e.inlineComments),{...cFt,icons:{script:"code"}},Bkl(e.setup??{},e.name,e.editor),Dkl].map(Vv)},"texraPlugins")});import{join as Pkl}from"node:path";var cXn,aXn,Xhi,Zhi,lXn=N(()=>{"use strict";de();Cl();Rn();Co();$7e();lMt();V$n();qfe();$g();Jhi();cXn=Object.freeze({name:"TeXRA",id:"texra"}),aXn=class extends A.TaggedError()("ResourcesNotFound",{message:A.String}){static{i(this,"ResourcesNotFound")}},Xhi=m.fn("checkResourcesPath")(function*(e){let t=yield*ot.FileSystem,n=Pkl(e,"plugins");return(yield*t.stat(n).pipe(m.map(o=>o.type==="Directory"),m.catchIf(br,()=>m.succeed(!1))))?e:yield*new aXn({message:`TeXRA resources not found: ${e} holds no plugins/ directory`})}),Zhi=i(({storageRoot:e,resourcesPath:t,skillSourceOptions:n,usageLog:r,minimumLogLevel:o,workspace:s,...a})=>{let c=iMo(),l=Yhi({...a,editors:c.editors}),u=Vjn({storageRoot:e,settings:bh.catalog,plugins:l,skills:{resourcesPath:t,projectDataDirName:Gfe,skillSourceOptions:n},secrets:Rs.announcing(d=>new Tte(WOe(e),d),cXn),hostResources:gt.succeed(cG)({resourcesRoot:t}),usageLog:zDo(r),minimumLogLevel:o,workspace:s}).pipe(gt.orDie,gt.provideMerge(gt.sync(eT)(()=>{let d=PMt();return()=>d})),gt.provide(U9));return gt.merge(Pte.layer(c),gt.effectDiscard(m.forkScoped(Tte.watch(WOe(e),d=>jE("credentialChanged",{key:d}))))).pipe(gt.provideMerge(u))},"texraProcessLayer")});function tAi(e){return cPe[e].tone}function vhe(e){return cPe[e].label}function lPe(e){return cPe[e].description}var cPe,eAi,Hne=N(()=>{"use strict";de();cPe={yolo:{label:"Auto-approve",description:"Allow shell commands and file edits without asking.",tone:void 0},ask:{label:"Ask",description:"Ask before shell commands and file edits.",tone:void 0},never:{label:"Block",description:"Block shell commands and file edits.",tone:"warning"}},eAi=Object.freeze(Zi.keys(cPe).map(e=>Object.freeze({value:e,label:cPe[e].label,description:cPe[e].description})));i(tAi,"approvalPolicyTone");i(vhe,"approvalPolicyLabel");i(lPe,"formatApprovalPolicy")});import*as uXn from"node:path";function z$t(e,t,n){return t.keys().flatMap(r=>{let o=e.byStoredKey(r);if(o?.slot!=="config")return n?[`Ignoring unknown ${t.filePath} key "${r}".`]:[];let s=t.get(r);return Re.isFailure(A.decodeUnknownResult(o.schema)(s))?[`Ignoring invalid ${t.filePath} value ${JSON.stringify(s)} for "${r}".`]:[]})}var dXn,pXn,nAi,W$t=N(()=>{"use strict";de();Co();It();qfe();i(z$t,"configFileWarnings");dXn=m.fn("nodeStores.openTexraWorkspaceConfigStores")(function*(e,t,n){let r=[],o=Rte.open(uXn.join(Ez(t,n),MMt));if(!n){let l=yield*o;return r.push(...z$t(e,l,!1)),{workspace:l,local:l,warnings:r}}let s=aNe(n),[a,c]=yield*m.all([Rte.open(s).pipe(m.catch(l=>m.sync(()=>r.push(`Cannot read ${s}; project settings are ignored and cannot be saved until it is fixed. Cause: ${et(l)}`)).pipe(m.andThen(Rte.unreadable(s))))),o],{concurrency:"unbounded"});for(let l of a.keys()){let u=e.byStoredKey(l);EPt(u,a.get(l))&&r.push(`Ignoring "${l}" in ${s}: a project file cannot set it. Set it in the settings view or with /config.`)}return r.push(...z$t(e,a,!0),...z$t(e,c,!1)),{workspace:a,local:c,warnings:r}}),pXn=m.fn("nodeStores.openTexraGlobalConfigStore")(function*(e,t){let n=yield*Rte.open(uXn.join(KM(t),MMt));return{store:n,warnings:z$t(e,n,!1)}}),nAi=m.fn("nodeStores.openTexraConfigStores")(function*(e,t,n){let[{workspace:r,local:o,warnings:s},a]=yield*m.all([dXn(e,t,n),pXn(e,t)],{concurrency:"unbounded"});return{stores:{workspace:r,global:a.store,local:o,catalog:e},warnings:[...s,...a.warnings]}})});function rAi(e){return e.trim().toLowerCase().replaceAll(/[^a-z0-9]/g,"")}function oAi(e){let t=Av(e);return[e,t?.id,t?.label].filter(n=>typeof n=="string"&&n.length>0)}function $ne(e){let t=e.trim();if(!t)return;if(Av(t))return t;let n=t.toLowerCase(),r=sce,o=r.find(l=>l.toLowerCase()===n);if(o)return o;let s=r.filter(l=>oAi(l).some(u=>u.toLowerCase()===n));if(s.length===1)return s[0];if(s.length>1)return;let a=rAi(t);if(!a)return;let c=r.filter(l=>oAi(l).some(u=>rAi(u)===a));return c.length===1?c[0]:void 0}function iAi(e,t){let n=Mkl[t];return{model:(Bn.getConfig(e.config,n)??{}).model??Bn.getConfig(e.config,_Hn)}}function Fkl(e){return Lkl.flatMap(([t,n])=>{let r=`${bh.catalog.namespace}.${t.key}`,o=e.get(r);return!Ye.isObject(o)||Re.isFailure(A.decodeUnknownResult(t.schema)(o))?[]:Object.keys(o).filter(s=>!n.has(s)).map(s=>`Ignoring unknown ${e.filePath} key "${r}.${s}".`)})}function sAi(e,t){return m.provide(m.gen(function*(){let{stores:n,warnings:r}=yield*nAi(bh.catalog,t,e),o=yield*NOe(Uce(t));return{config:new wte({workspace:n.workspace,global:n.global,local:n.local,catalog:bh.catalog}),warnings:[...Fkl(n.workspace),...o?.warnings??[]],degradations:r}}),zw)}var Mkl,Lkl,jtt=N(()=>{"use strict";de();gi();Cl();Rn();Co();W$t();$g();Mkl={chat:NPt,run:BPt};i(rAi,"normalizeCliModelLookupKey");i(oAi,"modelLookupKeys");i($ne,"resolveKnownCliModelId");i(iAi,"cliCommandDefaults");Lkl=[NPt,BPt].map(e=>[e,new Set(Object.keys(A.required(e.schema).fields))]);i(Fkl,"commandSectionWarnings");i(sAi,"loadCliStartupConfig")});function oj(e){if(e.mode==="headless"||!e.stdoutIsTty)return"headless";if(e.termIsDumb)return"dumb-terminal"}function Ihe(e,t){if(e==="headless")return t.headlessMessage;let n=t.dumbTerminalOptions?.commandName||"texra",r=t.dumbTerminalOptions?.nonInteractiveFallback,o=r==null?"":` For non-interactive runs, use ${r}.`;return`${n} ${t.dumbTerminalCommand} needs an interactive terminal (TERM=dumb disables cursor controls). Try \`TERM=xterm-256color\`.${o}`}var fXn,xhe=N(()=>{"use strict";fXn="^22.22.2 || >=24.15.0";i(oj,"interactiveTerminalFailure");i(Ihe,"formatInteractiveTerminalFailure")});import K$t from"node:path";import{fileURLToPath as Ukl}from"node:url";function aAi(e){let t=process.env;if(t.NO_COLOR!=null||t.TERM==="dumb")return!1;let n=Qkl(t.FORCE_COLOR);return n??e}function Qkl(e){if(e==null)return;let t=e.trim().toLowerCase();if(t!=="")return!["0","false","no"].includes(t)}function N4(){if(V$t)return V$t;let e=process.stderr.isTTY===!0,t=process.stdin.isTTY===!0,n=process.stdout.isTTY===!0,r=process.env.TERM==="dumb",o=aAi(n),s=aAi(e);return V$t={isCi:!!process.env.CI,stdinIsTty:t,stdoutIsTty:n,stderrIsTty:e,termIsDumb:r,stdoutColorEnabled:o,stderrColorEnabled:s},V$t}function B4(e){return process.env[e]}function Htt(){return process.cwd()}function lAi(){return process.argv.slice(2)}function uPe(){return process.argv[1]??""}function uAi(){return cAi??=Hkl('{"version":"1.0.0-preview.3","bugs":{"url":"https://github.com/LionSR/TeXRA/issues"}}'),cAi}function whe(){return uAi().version}function dAi(e){let t;try{t=uAi().bugs?.url}catch{return}if(!(e instanceof ys||e instanceof m9||!t))return`This looks like a bug \u2014 please report it at ${t} (include the command and the message above).`}function pAi(e,t){return e.print===!0||e.noInput===!0||t.isCi||!t.stdinIsTty?"headless":"interactive"}function fAi(e,t){return oj({mode:pAi(e,t),stdoutIsTty:t.stdoutIsTty,termIsDumb:t.termIsDumb})===void 0}function The(e){return e==="yolo"?"autoApprove":e}function HW(e){return Bn.getConfig(e,NP)}function dPe(e,t){return jan(t,The(e))}function pPe(e,t){if(e===void 0||dPe(e,t)===e)return;let n="Change the project policy with /config in `texra chat` or in Settings.";return e==="yolo"?`Auto-approve cannot override the project's Block policy. ${n}`:`Using project policy (${vhe(t)}) instead of ${vhe(e)} \u2014 per-command flags can only tighten it. ${n}`}var KT,tI,Y$t,ys,Ll,V$t,jkl,Hkl,cAi,$kl,Gkl,mXn,qkl,mAi,bc=N(()=>{"use strict";de();xQ();Rn();gi();Co();It();lXn();qfe();D7e();Hne();jtt();xhe();$g();KT=i(e=>e.minimumLogLevel==="None","isQuiet"),tI=class extends Ve.Service()("@texra-ai/cli/CliInvocation"){static{i(this,"CliInvocation")}},Y$t=i(e=>m.provideService(tI,{context:e,onPromptLane:tu.makeUnsafe(1).withPermit}),"provideCliInvocation"),ys=class extends A.TaggedError()("CliUsageError",{message:A.String}){static{i(this,"CliUsageError")}},Ll=i(e=>m.fail(new ys({message:e})),"failUsage");i(aAi,"resolveStreamColor");i(Qkl,"parseForceColor");i(N4,"readCliAmbientState");i(B4,"cliEnvValue");i(Htt,"readCliCwd");i(lAi,"readCliArgv");i(uPe,"readCliEntrypointPath");jkl=A.Struct({version:A.NonEmptyString,bugs:A.optional(A.Struct({url:A.optional(A.String)}))}),Hkl=A.decodeUnknownSync(A.fromJsonString(jkl));i(uAi,"loadCliPackageManifest");i(whe,"readCliVersion");$kl=m.fn("cliContext.resolveCliResourcesPath")(function*(){let e=K$t.resolve(K$t.dirname(Ukl(import.meta.url)),"../resources");return yield*Xhi(e)});i(dAi,"formatCrashReportLine");i(pAi,"cliMode");i(fAi,"isInteractiveCli");Gkl=i(e=>m.map(vd.String(e).pipe(vd.option,m.orDie),t=>{let n=at.getOrUndefined(t)?.trim();return n===""?void 0:n}),"envTier"),mXn=i((e,t,n)=>m.map(Gkl(e),r=>{if(!r)return;let o=t(r);return o===void 0&&n.push(`Ignoring invalid ${e} "${r}".`),o}),"pickEnv"),qkl=m.fn("cliContext.resolveCliCwd")(function*(e){if(typeof e!="string"||e.trim()==="")return F9(Htt());let t=K$t.resolve(e);return(yield*(yield*ot.FileSystem).stat(t).pipe(m.mapError(o=>br(o)?new ys({message:`--cwd: path does not exist: ${t}`}):new ys({message:`--cwd: cannot access ${t}: ${et(o)}`})))).type!=="Directory"?yield*new ys({message:`--cwd: not a directory: ${t}`}):F9(t)}),mAi=m.fn("cliContext.buildCliContext")(function*(e){let t=e.ambient??N4(),n=yield*qkl(e.globalArgs.cwd),r=e.storageRoot??CLo(),{config:o,warnings:s,degradations:a}=yield*sAi(n,r),c=[...s],l=yield*mXn("TEXRA_MODEL",S=>Av(S)?S:void 0,c),u=e.globalArgs.noColor===!0,d=!u&&t.stdoutColorEnabled,p=!u&&t.stderrColorEnabled,f=e.globalArgs.approvalPolicy??(yield*mXn(QRt(bh.catalog.namespace),Lqe,c)),h=dPe(f,HW(o)),g=e.globalArgs.outputFormat??(yield*mXn("TEXRA_OUTPUT_FORMAT",S=>A.is(CPt)(S)?S:void 0,c))??Bn.getConfig(o,bHn),y="Warn";return e.globalArgs.quiet?y="None":e.globalArgs.verbose&&(y="Debug"),{storageRoot:r,cwd:n,mode:pAi(e.globalArgs,t),outputFormat:g,approvalPolicy:h,...f!==void 0&&{requestedApprovalPolicy:f},minimumLogLevel:y,stdoutIsTty:t.stdoutIsTty,termIsDumb:t.termIsDumb===!0,stderrIsTty:t.stderrIsTty,stdoutColorEnabled:d,stderrColorEnabled:p,commandName:K$t.basename(uPe()).toLowerCase()==="texra-local"?"texra-local":"texra",version:whe(),resourcesPath:yield*$kl(),config:o,configWarnings:c,configDegradations:a,envModel:l,skillSourceOptions:{additionalPaths:e.globalArgs.skillSourcePaths??[]}}});i(The,"launchApproval");i(HW,"projectApprovalPolicy");i(dPe,"effectiveApprovalPolicy");i(pPe,"launchApprovalNotice")});var hAi,zkl,Wkl,q9p,AAi,hXn=N(()=>{"use strict";de();It();m0();hAi=3,zkl=rqe.mapFields(In.pick(["name","source","ref","commit"])),Wkl=dU.mapFields(In.assign({runId:Cr,plugins:A.optional(A.Array(zkl)),workingDirectory:A.optional(A.String)})),q9p=Wkl.mapFields(In.assign({output:dU.fields.output.mapFields(In.omit(["structured"])).mapFields(In.assign({documents:XGo})),runDirectory:A.String,copiedOutput:A.optional(A.String),copiedOutputs:A.optional(A.Array(A.String))})),AAi=Object.freeze({agent:"agent","agent-copy":"copy","workspace-agents":"agents",config:"config",service:"service",task:"task",model:"model","model-catalog":"model","models-enabled":"models","model-enabled":"model","init-config":"init","history-entry":"entry","history-detail":"detail","history-delete":"result",skill:"skill","skill-issue":"issue",plugin:"plugin"})});var ur,fPe,xh=N(()=>{"use strict";ur=Object.freeze({Success:0,AgentError:1,Usage:2,ModelOrNetworkError:3,Cancelled:124,Hangup:129,Interrupted:130,Terminated:143}),fPe=Object.freeze({SIGHUP:ur.Hangup,SIGINT:ur.Interrupted,SIGTERM:ur.Terminated})});import{createInterface as Vkl}from"node:readline/promises";import{Writable as Kkl}from"node:stream";function Ykl(e){if(!Ye.hasProperty(e,"code"))return!1;let t=e.code;return t==="EPIPE"||t==="ERR_STREAM_DESTROYED"}function Jkl(){for(let e of["stdout","stderr"])process[e].on("error",t=>{if(Ykl(t)){Rhe[e]=!0;return}throw t})}function gXn(e){if(Rhe[e])return;let t=process[e];return t.destroyed?void 0:t}function yXn(e,t){try{e()}catch(n){t(n)}}function X$t(e,t){let n=gXn(e);n&&yXn(()=>n.write(t,r=>{r&&(Rhe[e]=!0)}),()=>{Rhe[e]=!0})}function yAi(e,t){return m.callback(n=>{let r=gXn(e);if(!r)return n(m.void);yXn(()=>r.write(t,o=>{o&&(Rhe[e]=!0),n(m.void)}),()=>{Rhe[e]=!0,n(m.void)})})}function pu(e){X$t("stdout",`${e}
|
|
3267
|
+
`)},"prompt"),processLayer:{layer:gt.mergeAll(gt.succeed(Xz)(e),...t===void 0?[]:[gt.succeed(_tt)(t)],Khi(n=>[...e.of(n),...t===void 0?[]:["inline-comments"]]))}})}),"core"),Bkl=i((e,t,n)=>pA({id:"setup",prompt:i(({offered:r})=>r.includes("probe_environment")?Bmi:"","prompt"),processLayer:{layer:gt.mergeAll(gt.succeed(jne)(e),gt.succeed(iPe)(t),gt.succeed(oPe)(n),Khi(()=>[...Object.entries(e).flatMap(([r,o])=>o===void 0?[]:[r]),...n?[U$t]:[]]))},tools:[Omi,lhi,dhi,fhi,yhi,Ehi,Chi]}),"setup"),Dkl=Vv({id:"theory",icons:{accept_run_files:"check"},prompt:i(({offered:e})=>e.includes("program")?["`program` starts a document program over files (`inputFiles`, with `contextFiles` it may read and not change).",...e.includes("script")?[]:[`The programs: ${Object.entries(z4n).map(([t,{description:n}])=>`\`${t}\` (${n})`).join("; ")}.`],"Each rewrites whole documents in fixed revisions, with compile checks and diffs, and proposes the result for the user to accept; it reads only the files you pass. What to change, how far and from which point of view is the `prompt`: one program covers a proofread and a restructuring, a referee and a first reader.","Its `args` may switch on `reflect` (a critic reviews each revision but the last), `attachTeXCount` (word counts in the prompt), and `autoExtractFigure`, `autoExtractTikzFigure` or `autoCompileInputPdf` (the inputs' figures, compiled TikZ pictures or PDF as media, for a model that reads images).",'Its delivery lists each proposed file with a `diff` attribute, the diff against the document the program started from, readable among the run\'s files (`/executions/{id}/files/<diff>`), and `large-change="true"` when the file changed extensively; a diff may be truncated.',"The host compiles each .tex the program writes: a file that failed to build leaves its log at `compile/r{n}_<name>.log` among the run's files, which the delivery's `<compile-failures>` names (read it at `/executions/{id}/files/<log>`), and no log means every build passed or no LaTeX toolchain is installed.",...e.includes("script")?["In a script, `program(name, { prompt, inputFiles })` resolves to the program's result, whose `changes` list each revision's files in order: pass the last `absolutePath` of each `path` as the `inputFiles` of the next program to chain them. `describeTool(name)` shows a program's source, and `builtIn:revise` exports what the programs are built from."]:[]].join(" "):"","prompt"),scriptModules:Iqo,programs:z4n,tools:[jqo,tpi,npi,rpi,opi,spi,ipi],factKinds:wqo.theory}),Yhi=i(e=>{let t=e.editors??jPt(()=>({}));return[{...rFt({writeFilter:Tkl}),icons:{bash:"terminal",read_file:"file",write_file:"file-circle-plus",edit_file:"pencil",glob:"magnifying-glass",grep:"magnifying-glass"},dashboard:{name:"File & Shell Operations",description:"Read, write, edit files and run shell commands. Includes glob/grep search."}},Rkl(t),S8o,{...oFt,icons:{web_search:"globe",web_fetch:"globe"},dashboard:{name:"Web Search & Fetch",description:"Search the web with DuckDuckGo Instant Answers and fetch or extract content from URLs."}},{...iFt,icons:{memory:"database",executions:"clock-rotate-left"},dashboard:{name:"Memory & Task History",description:"Persistent memory across tasks and inspection of agents launched during a task."}},{...sFt,dashboard:{name:"Goal Mode",description:"Propose a plan and run it autonomously across rounds until complete or input is needed.",setup:{configNotes:"Turning this off disables the plan tool and stops goal rounds on the next turn."}}},Ihi,Whi,Ami,{...aFt,icons:{agent:"circle-user"},dashboard:{name:"Multi-Agent Workflow",description:"Let the assistant delegate work to helper agents and programs, sequentially or in parallel.",setup:{configNotes:"Turning this off removes delegation and program tools on the next turn."}}},Cfi,bui,Xli,Nkl(t,e.inlineComments),{...cFt,icons:{script:"code"}},Bkl(e.setup??{},e.name,e.editor),Dkl].map(Vv)},"texraPlugins")});import{join as Pkl}from"node:path";var cXn,aXn,Xhi,Zhi,lXn=N(()=>{"use strict";de();Cl();Rn();Co();$7e();lMt();V$n();qfe();$g();Jhi();cXn=Object.freeze({name:"TeXRA",id:"texra"}),aXn=class extends A.TaggedError()("ResourcesNotFound",{message:A.String}){static{i(this,"ResourcesNotFound")}},Xhi=m.fn("checkResourcesPath")(function*(e){let t=yield*ot.FileSystem,n=Pkl(e,"plugins");return(yield*t.stat(n).pipe(m.map(o=>o.type==="Directory"),m.catchIf(br,()=>m.succeed(!1))))?e:yield*new aXn({message:`TeXRA resources not found: ${e} holds no plugins/ directory`})}),Zhi=i(({storageRoot:e,resourcesPath:t,skillSourceOptions:n,usageLog:r,minimumLogLevel:o,workspace:s,...a})=>{let c=iMo(),l=Yhi({...a,editors:c.editors}),u=Vjn({storageRoot:e,settings:bh.catalog,plugins:l,skills:{resourcesPath:t,projectDataDirName:Gfe,skillSourceOptions:n},secrets:Rs.announcing(d=>new Tte(WOe(e),d),cXn),hostResources:gt.succeed(cG)({resourcesRoot:t}),usageLog:zDo(r),minimumLogLevel:o,workspace:s}).pipe(gt.orDie,gt.provideMerge(gt.sync(eT)(()=>{let d=PMt();return()=>d})),gt.provide(U9));return gt.merge(Pte.layer(c),gt.effectDiscard(m.forkScoped(Tte.watch(WOe(e),d=>jE("credentialChanged",{key:d}))))).pipe(gt.provideMerge(u))},"texraProcessLayer")});function tAi(e){return cPe[e].tone}function vhe(e){return cPe[e].label}function lPe(e){return cPe[e].description}var cPe,eAi,Hne=N(()=>{"use strict";de();cPe={yolo:{label:"Auto-approve",description:"Allow shell commands and file edits without asking.",tone:void 0},ask:{label:"Ask",description:"Ask before shell commands and file edits.",tone:void 0},never:{label:"Block",description:"Block shell commands and file edits.",tone:"warning"}},eAi=Object.freeze(Zi.keys(cPe).map(e=>Object.freeze({value:e,label:cPe[e].label,description:cPe[e].description})));i(tAi,"approvalPolicyTone");i(vhe,"approvalPolicyLabel");i(lPe,"formatApprovalPolicy")});import*as uXn from"node:path";function z$t(e,t,n){return t.keys().flatMap(r=>{let o=e.byStoredKey(r);if(o?.slot!=="config")return n?[`Ignoring unknown ${t.filePath} key "${r}".`]:[];let s=t.get(r);return Re.isFailure(A.decodeUnknownResult(o.schema)(s))?[`Ignoring invalid ${t.filePath} value ${JSON.stringify(s)} for "${r}".`]:[]})}var dXn,pXn,nAi,W$t=N(()=>{"use strict";de();Co();It();qfe();i(z$t,"configFileWarnings");dXn=m.fn("nodeStores.openTexraWorkspaceConfigStores")(function*(e,t,n){let r=[],o=Rte.open(uXn.join(Ez(t,n),MMt));if(!n){let l=yield*o;return r.push(...z$t(e,l,!1)),{workspace:l,local:l,warnings:r}}let s=aNe(n),[a,c]=yield*m.all([Rte.open(s).pipe(m.catch(l=>m.sync(()=>r.push(`Cannot read ${s}; project settings are ignored and cannot be saved until it is fixed. Cause: ${et(l)}`)).pipe(m.andThen(Rte.unreadable(s))))),o],{concurrency:"unbounded"});for(let l of a.keys()){let u=e.byStoredKey(l);EPt(u,a.get(l))&&r.push(`Ignoring "${l}" in ${s}: a project file cannot set it. Set it in the settings view or with /config.`)}return r.push(...z$t(e,a,!0),...z$t(e,c,!1)),{workspace:a,local:c,warnings:r}}),pXn=m.fn("nodeStores.openTexraGlobalConfigStore")(function*(e,t){let n=yield*Rte.open(uXn.join(KM(t),MMt));return{store:n,warnings:z$t(e,n,!1)}}),nAi=m.fn("nodeStores.openTexraConfigStores")(function*(e,t,n){let[{workspace:r,local:o,warnings:s},a]=yield*m.all([dXn(e,t,n),pXn(e,t)],{concurrency:"unbounded"});return{stores:{workspace:r,global:a.store,local:o,catalog:e},warnings:[...s,...a.warnings]}})});function rAi(e){return e.trim().toLowerCase().replaceAll(/[^a-z0-9]/g,"")}function oAi(e){let t=Av(e);return[e,t?.id,t?.label].filter(n=>typeof n=="string"&&n.length>0)}function $ne(e){let t=e.trim();if(!t)return;if(Av(t))return t;let n=t.toLowerCase(),r=sce,o=r.find(l=>l.toLowerCase()===n);if(o)return o;let s=r.filter(l=>oAi(l).some(u=>u.toLowerCase()===n));if(s.length===1)return s[0];if(s.length>1)return;let a=rAi(t);if(!a)return;let c=r.filter(l=>oAi(l).some(u=>rAi(u)===a));return c.length===1?c[0]:void 0}function iAi(e,t){let n=Mkl[t];return{model:(Bn.getConfig(e.config,n)??{}).model??Bn.getConfig(e.config,_Hn)}}function Fkl(e){return Lkl.flatMap(([t,n])=>{let r=`${bh.catalog.namespace}.${t.key}`,o=e.get(r);return!Ye.isObject(o)||Re.isFailure(A.decodeUnknownResult(t.schema)(o))?[]:Object.keys(o).filter(s=>!n.has(s)).map(s=>`Ignoring unknown ${e.filePath} key "${r}.${s}".`)})}function sAi(e,t){return m.provide(m.gen(function*(){let{stores:n,warnings:r}=yield*nAi(bh.catalog,t,e),o=yield*NOe(Uce(t));return{config:new wte({workspace:n.workspace,global:n.global,local:n.local,catalog:bh.catalog}),warnings:[...Fkl(n.workspace),...o?.warnings??[]],degradations:r}}),zw)}var Mkl,Lkl,jtt=N(()=>{"use strict";de();gi();Cl();Rn();Co();W$t();$g();Mkl={chat:NPt,run:BPt};i(rAi,"normalizeCliModelLookupKey");i(oAi,"modelLookupKeys");i($ne,"resolveKnownCliModelId");i(iAi,"cliCommandDefaults");Lkl=[NPt,BPt].map(e=>[e,new Set(Object.keys(A.required(e.schema).fields))]);i(Fkl,"commandSectionWarnings");i(sAi,"loadCliStartupConfig")});function oj(e){if(e.mode==="headless"||!e.stdoutIsTty)return"headless";if(e.termIsDumb)return"dumb-terminal"}function Ihe(e,t){if(e==="headless")return t.headlessMessage;let n=t.dumbTerminalOptions?.commandName||"texra",r=t.dumbTerminalOptions?.nonInteractiveFallback,o=r==null?"":` For non-interactive runs, use ${r}.`;return`${n} ${t.dumbTerminalCommand} needs an interactive terminal (TERM=dumb disables cursor controls). Try \`TERM=xterm-256color\`.${o}`}var fXn,xhe=N(()=>{"use strict";fXn="^22.22.2 || >=24.15.0";i(oj,"interactiveTerminalFailure");i(Ihe,"formatInteractiveTerminalFailure")});import K$t from"node:path";import{fileURLToPath as Ukl}from"node:url";function aAi(e){let t=process.env;if(t.NO_COLOR!=null||t.TERM==="dumb")return!1;let n=Qkl(t.FORCE_COLOR);return n??e}function Qkl(e){if(e==null)return;let t=e.trim().toLowerCase();if(t!=="")return!["0","false","no"].includes(t)}function N4(){if(V$t)return V$t;let e=process.stderr.isTTY===!0,t=process.stdin.isTTY===!0,n=process.stdout.isTTY===!0,r=process.env.TERM==="dumb",o=aAi(n),s=aAi(e);return V$t={isCi:!!process.env.CI,stdinIsTty:t,stdoutIsTty:n,stderrIsTty:e,termIsDumb:r,stdoutColorEnabled:o,stderrColorEnabled:s},V$t}function B4(e){return process.env[e]}function Htt(){return process.cwd()}function lAi(){return process.argv.slice(2)}function uPe(){return process.argv[1]??""}function uAi(){return cAi??=Hkl('{"version":"1.0.0-preview.4","bugs":{"url":"https://github.com/LionSR/TeXRA/issues"}}'),cAi}function whe(){return uAi().version}function dAi(e){let t;try{t=uAi().bugs?.url}catch{return}if(!(e instanceof ys||e instanceof m9||!t))return`This looks like a bug \u2014 please report it at ${t} (include the command and the message above).`}function pAi(e,t){return e.print===!0||e.noInput===!0||t.isCi||!t.stdinIsTty?"headless":"interactive"}function fAi(e,t){return oj({mode:pAi(e,t),stdoutIsTty:t.stdoutIsTty,termIsDumb:t.termIsDumb})===void 0}function The(e){return e==="yolo"?"autoApprove":e}function HW(e){return Bn.getConfig(e,NP)}function dPe(e,t){return jan(t,The(e))}function pPe(e,t){if(e===void 0||dPe(e,t)===e)return;let n="Change the project policy with /config in `texra chat` or in Settings.";return e==="yolo"?`Auto-approve cannot override the project's Block policy. ${n}`:`Using project policy (${vhe(t)}) instead of ${vhe(e)} \u2014 per-command flags can only tighten it. ${n}`}var KT,tI,Y$t,ys,Ll,V$t,jkl,Hkl,cAi,$kl,Gkl,mXn,qkl,mAi,bc=N(()=>{"use strict";de();xQ();Rn();gi();Co();It();lXn();qfe();D7e();Hne();jtt();xhe();$g();KT=i(e=>e.minimumLogLevel==="None","isQuiet"),tI=class extends Ve.Service()("@texra-ai/cli/CliInvocation"){static{i(this,"CliInvocation")}},Y$t=i(e=>m.provideService(tI,{context:e,onPromptLane:tu.makeUnsafe(1).withPermit}),"provideCliInvocation"),ys=class extends A.TaggedError()("CliUsageError",{message:A.String}){static{i(this,"CliUsageError")}},Ll=i(e=>m.fail(new ys({message:e})),"failUsage");i(aAi,"resolveStreamColor");i(Qkl,"parseForceColor");i(N4,"readCliAmbientState");i(B4,"cliEnvValue");i(Htt,"readCliCwd");i(lAi,"readCliArgv");i(uPe,"readCliEntrypointPath");jkl=A.Struct({version:A.NonEmptyString,bugs:A.optional(A.Struct({url:A.optional(A.String)}))}),Hkl=A.decodeUnknownSync(A.fromJsonString(jkl));i(uAi,"loadCliPackageManifest");i(whe,"readCliVersion");$kl=m.fn("cliContext.resolveCliResourcesPath")(function*(){let e=K$t.resolve(K$t.dirname(Ukl(import.meta.url)),"../resources");return yield*Xhi(e)});i(dAi,"formatCrashReportLine");i(pAi,"cliMode");i(fAi,"isInteractiveCli");Gkl=i(e=>m.map(vd.String(e).pipe(vd.option,m.orDie),t=>{let n=at.getOrUndefined(t)?.trim();return n===""?void 0:n}),"envTier"),mXn=i((e,t,n)=>m.map(Gkl(e),r=>{if(!r)return;let o=t(r);return o===void 0&&n.push(`Ignoring invalid ${e} "${r}".`),o}),"pickEnv"),qkl=m.fn("cliContext.resolveCliCwd")(function*(e){if(typeof e!="string"||e.trim()==="")return F9(Htt());let t=K$t.resolve(e);return(yield*(yield*ot.FileSystem).stat(t).pipe(m.mapError(o=>br(o)?new ys({message:`--cwd: path does not exist: ${t}`}):new ys({message:`--cwd: cannot access ${t}: ${et(o)}`})))).type!=="Directory"?yield*new ys({message:`--cwd: not a directory: ${t}`}):F9(t)}),mAi=m.fn("cliContext.buildCliContext")(function*(e){let t=e.ambient??N4(),n=yield*qkl(e.globalArgs.cwd),r=e.storageRoot??CLo(),{config:o,warnings:s,degradations:a}=yield*sAi(n,r),c=[...s],l=yield*mXn("TEXRA_MODEL",S=>Av(S)?S:void 0,c),u=e.globalArgs.noColor===!0,d=!u&&t.stdoutColorEnabled,p=!u&&t.stderrColorEnabled,f=e.globalArgs.approvalPolicy??(yield*mXn(QRt(bh.catalog.namespace),Lqe,c)),h=dPe(f,HW(o)),g=e.globalArgs.outputFormat??(yield*mXn("TEXRA_OUTPUT_FORMAT",S=>A.is(CPt)(S)?S:void 0,c))??Bn.getConfig(o,bHn),y="Warn";return e.globalArgs.quiet?y="None":e.globalArgs.verbose&&(y="Debug"),{storageRoot:r,cwd:n,mode:pAi(e.globalArgs,t),outputFormat:g,approvalPolicy:h,...f!==void 0&&{requestedApprovalPolicy:f},minimumLogLevel:y,stdoutIsTty:t.stdoutIsTty,termIsDumb:t.termIsDumb===!0,stderrIsTty:t.stderrIsTty,stdoutColorEnabled:d,stderrColorEnabled:p,commandName:K$t.basename(uPe()).toLowerCase()==="texra-local"?"texra-local":"texra",version:whe(),resourcesPath:yield*$kl(),config:o,configWarnings:c,configDegradations:a,envModel:l,skillSourceOptions:{additionalPaths:e.globalArgs.skillSourcePaths??[]}}});i(The,"launchApproval");i(HW,"projectApprovalPolicy");i(dPe,"effectiveApprovalPolicy");i(pPe,"launchApprovalNotice")});var hAi,zkl,Wkl,q9p,AAi,hXn=N(()=>{"use strict";de();It();m0();hAi=3,zkl=rqe.mapFields(In.pick(["name","source","ref","commit"])),Wkl=dU.mapFields(In.assign({runId:Cr,plugins:A.optional(A.Array(zkl)),workingDirectory:A.optional(A.String)})),q9p=Wkl.mapFields(In.assign({output:dU.fields.output.mapFields(In.omit(["structured"])).mapFields(In.assign({documents:XGo})),runDirectory:A.String,copiedOutput:A.optional(A.String),copiedOutputs:A.optional(A.Array(A.String))})),AAi=Object.freeze({agent:"agent","agent-copy":"copy","workspace-agents":"agents",config:"config",service:"service",task:"task",model:"model","model-catalog":"model","models-enabled":"models","model-enabled":"model","init-config":"init","history-entry":"entry","history-detail":"detail","history-delete":"result",skill:"skill","skill-issue":"issue",plugin:"plugin"})});var ur,fPe,xh=N(()=>{"use strict";ur=Object.freeze({Success:0,AgentError:1,Usage:2,ModelOrNetworkError:3,Cancelled:124,Hangup:129,Interrupted:130,Terminated:143}),fPe=Object.freeze({SIGHUP:ur.Hangup,SIGINT:ur.Interrupted,SIGTERM:ur.Terminated})});import{createInterface as Vkl}from"node:readline/promises";import{Writable as Kkl}from"node:stream";function Ykl(e){if(!Ye.hasProperty(e,"code"))return!1;let t=e.code;return t==="EPIPE"||t==="ERR_STREAM_DESTROYED"}function Jkl(){for(let e of["stdout","stderr"])process[e].on("error",t=>{if(Ykl(t)){Rhe[e]=!0;return}throw t})}function gXn(e){if(Rhe[e])return;let t=process[e];return t.destroyed?void 0:t}function yXn(e,t){try{e()}catch(n){t(n)}}function X$t(e,t){let n=gXn(e);n&&yXn(()=>n.write(t,r=>{r&&(Rhe[e]=!0)}),()=>{Rhe[e]=!0})}function yAi(e,t){return m.callback(n=>{let r=gXn(e);if(!r)return n(m.void);yXn(()=>r.write(t,o=>{o&&(Rhe[e]=!0),n(m.void)}),()=>{Rhe[e]=!0,n(m.void)})})}function pu(e){X$t("stdout",`${e}
|
|
3268
3268
|
`)}function EXn(e){X$t("stdout",e)}function J$t(e){X$t("stderr",e)}function EAi(){return process.stderr.columns}function SAi(){return process.stdout.columns}function kr(e){X$t("stderr",`${e}
|
|
3269
3269
|
`)}function Gne(e){return yAi("stderr",`${e}
|
|
3270
3270
|
`)}function SXn(e){return yAi(e,"")}function ij(e){return et(e)}function UL(e){kr(ij(e))}function _Ai(e,t,n){return m.tryPromise({try:i(async()=>{rU(_Xn("Warn"),{trusted:!0}),Jkl(),process.exitCode=await t()},"try"),catch:i(r=>new AXn({cause:r}),"catch")}).pipe(m.catch(({cause:r})=>m.sync(()=>{kr(`${e} failed: ${ij(r)}`);let o=n?.(r);o&&kr(o),process.exitCode=ur.AgentError})))}function $tt(e,t={}){return m.acquireUseRelease(m.sync(()=>{let n=process.stdin;return n.ref?.(),t.hidden&&J$t(e),Vkl({input:n,output:t.hidden?new Kkl({write:i((r,o,s)=>s(),"write")}):process.stderr,...t.hidden?{terminal:!0}:{}})}),n=>m.raceFirst(m.tryPromise({try:i(()=>n.question(t.hidden?"":e),"try"),catch:D4.from}),m.callback(r=>{n.once("close",()=>r(m.fail(new D4({message:"The input ended before an answer."}))))})),n=>m.sync(()=>{n.close(),t.hidden&&J$t(`
|