howtocode 0.7.75 → 0.7.76

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,201 +0,0 @@
1
- import{b as df}from"./chunk-XODGJSB3.js";import{t as ff}from"./chunk-ZJL4OEXX.js";import{H as it,K as pf,L as Un,a as Ji}from"./chunk-5FIFNXLT.js";import{a as dr}from"./chunk-UTYFLLSM.js";import{a as Gm,b as Bn,c as Gn,d as Km,e as Hm,f as Do,g as zm,h as Vr,j as jo}from"./chunk-MVVEYKN6.js";import{a as _t}from"./chunk-WOT6VMZA.js";import{spawn as w1}from"node:child_process";import{existsSync as C1,readFileSync as R1}from"node:fs";import{join as P1}from"node:path";var z={};_t(z,{Match:()=>_w});function _w(e,t){return t[e.length]?.(...e)??(()=>{throw Error("Invalid Arguments")})()}var qe={};_t(qe,{Get:()=>ns,Reset:()=>DC,Set:()=>jC});var s={};_t(s,{CodePointCount:()=>tC,Counted:()=>mC,Entries:()=>pC,EntriesRegExp:()=>cC,Every:()=>oC,EveryAll:()=>iC,GraphemeCount:()=>eC,HasPropertyKey:()=>uC,IsArray:()=>qo,IsBigInt:()=>No,IsBoolean:()=>If,IsClassInstance:()=>Zw,IsConstructor:()=>Ww,IsDeepEqual:()=>Jm,IsEqual:()=>ee,IsFunction:()=>bf,IsGreaterEqualThan:()=>Ef,IsGreaterThan:()=>Yw,IsInteger:()=>Wm,IsLessEqualThan:()=>$f,IsLessThan:()=>Qw,IsMaxLength:()=>rC,IsMinLength:()=>nC,IsMultipleOf:()=>Xw,IsNull:()=>Zi,IsNumber:()=>es,IsObject:()=>_o,IsObjectNotArray:()=>Vw,IsString:()=>ts,IsSymbol:()=>Jw,IsUndefined:()=>Vm,IsUnsafePropertyKey:()=>kf,IsValueLike:()=>Sf,Keys:()=>Xi,ShiftLeft:()=>rs,Some:()=>sC,SomeAll:()=>aC,Symbols:()=>fC,Values:()=>dC});function Kn(e,t,r){return e>=t&&e<=r}function Uw(e){return e===8205}function lf(e){return Kn(e,127462,127487)}function Bw(e){return Kn(e,65024,65039)}function Gw(e){return Kn(e,768,879)||Kn(e,6832,6911)||Kn(e,7616,7679)||Kn(e,65056,65071)}function Yi(e){return e>65535?2:1}function gf(e,t){for(;t<e.length;){let r=e.codePointAt(t);if(Gw(r)||Bw(r))t+=Yi(r);else break}return t}function Kw(e,t){let r=e.codePointAt(t),n=t+Yi(r);for(n=gf(e,n);n<e.length-1&&Uw(e.codePointAt(n));){let o=e.codePointAt(n+1);n+=1+Yi(o),n=gf(e,n)}return lf(r)&&n<e.length&&lf(e.codePointAt(n))&&(n+=Yi(e.codePointAt(n))),n}function yf(e){let t=0,r=0;for(;r<e.length;)r=Kw(e,r),t++;return t}function Qi(e){let t=0,r=0,n=0;for(;r<e.length;){let o=e.charCodeAt(r++)>>10;t+=+((n<<8|o)!==13879),n=o}return t}function xf(e,t){return e.length<=t||e.length<=t<<1&&Qi(e)<=t}function hf(e,t){return e.length>=t<<1||e.length>=t&&Qi(e)>=t}function qo(e){return Array.isArray(e)}function No(e){return ee(typeof e,"bigint")}function If(e){return ee(typeof e,"boolean")}function Ww(e){if(Vm(e)||!bf(e))return!1;let t=Function.prototype.toString.call(e);return!!(/^class\s/.test(t)||/\[native code\]/.test(t))}function bf(e){return ee(typeof e,"function")}function Wm(e){return Number.isInteger(e)}function Zi(e){return ee(e,null)}function es(e){return Number.isFinite(e)}function Vw(e){return _o(e)&&!qo(e)}function _o(e){return ee(typeof e,"object")&&!Zi(e)}function ts(e){return ee(typeof e,"string")}function Jw(e){return ee(typeof e,"symbol")}function Vm(e){return ee(e,void 0)}function ee(e,t){return e===t}function Yw(e,t){return e>t}function Qw(e,t){return e<t}function $f(e,t){return e<=t}function Ef(e,t){return e>=t}function Xw(e,t){if(No(e)||No(t))return BigInt(e)%BigInt(t)===0n;let r=1e-10;if(!es(e)||Wm(e)&&1/t%1===0)return!0;let n=e%t;return Math.min(Math.abs(n),Math.abs(n-t),Math.abs(n+t))<r}function Zw(e){if(!_o(e))return!1;let t=globalThis.Object.getPrototypeOf(e);return Zi(t)?!1:ee(typeof t.constructor,"function")&&!(ee(t.constructor,globalThis.Object)||ee(t.constructor.name,"Object"))}function Sf(e){return No(e)||If(e)||Zi(e)||es(e)||ts(e)||Vm(e)}function eC(e){return yf(e)}function tC(e){return Qi(e)}function rC(e,t){return xf(e,t)}function nC(e,t){return hf(e,t)}function oC(e,t,r){return e.every((n,o)=>o<t||r(n,o))}function iC(e,t,r){let n=!0;return e.forEach((o,i)=>{i>=t&&!r(o,i)&&(n=!1)}),n}function sC(e,t){return e.some((r,n)=>t(r,n))}function aC(e,t){let r=!1;return e.forEach((n,o)=>{t(n,o)&&(r=!0)}),r}function mC(e,t){return e.reduce((r,n,o)=>t(n,o)?++r:r,0)}function rs(e,t,r){return ee(e.length,0)?r():t(e[0],e.slice(1))}function kf(e){return ee(e,"__proto__")||ee(e,"constructor")||ee(e,"prototype")}function uC(e,t){return kf(t)?Object.prototype.hasOwnProperty.call(e,t):t in e}function cC(e){return Xi(e).map(t=>[new RegExp(`^${t}$`),e[t]])}function pC(e){return Object.entries(e)}function Xi(e){return Object.getOwnPropertyNames(e)}function fC(e){return Object.getOwnPropertySymbols(e)}function dC(e){return Object.values(e)}function lC(e,t){if(!_o(t))return!1;let r=Xi(e);return ee(r.length,Xi(t).length)&&r.every(n=>Jm(e[n],t[n]))}function gC(e,t){return qo(t)&&ee(e.length,t.length)&&e.every((r,n)=>Jm(e[n],t[n]))}function Jm(e,t){return qo(e)?gC(e,t):_o(e)?lC(e,t):ee(e,t)}var Ke={};_t(Ke,{IsBigInt64Array:()=>PC,IsBigUint64Array:()=>AC,IsBoolean:()=>yC,IsDate:()=>MC,IsFloat32Array:()=>CC,IsFloat64Array:()=>RC,IsInt16Array:()=>SC,IsInt32Array:()=>TC,IsInt8Array:()=>bC,IsMap:()=>FC,IsNumber:()=>xC,IsRegExp:()=>OC,IsSet:()=>vC,IsString:()=>hC,IsTypeArray:()=>IC,IsUint16Array:()=>kC,IsUint32Array:()=>wC,IsUint8Array:()=>$C,IsUint8ClampedArray:()=>EC});function yC(e){return e instanceof Boolean}function xC(e){return e instanceof Number}function hC(e){return e instanceof String}function IC(e){return globalThis.ArrayBuffer.isView(e)}function bC(e){return e instanceof globalThis.Int8Array}function $C(e){return e instanceof globalThis.Uint8Array}function EC(e){return e instanceof globalThis.Uint8ClampedArray}function SC(e){return e instanceof globalThis.Int16Array}function kC(e){return e instanceof globalThis.Uint16Array}function TC(e){return e instanceof globalThis.Int32Array}function wC(e){return e instanceof globalThis.Uint32Array}function CC(e){return e instanceof globalThis.Float32Array}function RC(e){return e instanceof globalThis.Float64Array}function PC(e){return e instanceof globalThis.BigInt64Array}function AC(e){return e instanceof globalThis.BigUint64Array}function OC(e){return e instanceof globalThis.RegExp}function MC(e){return e instanceof globalThis.Date}function vC(e){return e instanceof globalThis.Set}function FC(e){return e instanceof globalThis.Map}var Tf=s;var rr={immutableTypes:!1,maxErrors:8,maxParseErrors:1,maxInstantiationCount:128,useAcceleration:!0,exactOptionalPropertyTypes:!1,enumerableKind:!1,correctiveParse:!1,unionPrioritySort:!0};function DC(){rr.immutableTypes=!1,rr.maxErrors=8,rr.maxParseErrors=1,rr.maxInstantiationCount=128,rr.useAcceleration=!0,rr.exactOptionalPropertyTypes=!1,rr.enumerableKind=!1,rr.correctiveParse=!1,rr.unionPrioritySort=!0}function jC(e){for(let t of s.Keys(e)){let r=e[t];r!==void 0&&Object.defineProperty(rr,t,{value:r})}}function ns(){return rr}function os(e){return s.HasPropertyKey(e,"~refine")&&s.IsArray(e["~refine"])&&s.Every(e["~refine"],0,t=>s.IsObject(t)&&s.HasPropertyKey(t,"check")&&s.HasPropertyKey(t,"error")&&s.IsFunction(t.check)&&s.IsFunction(t.error))}function kt(e){return s.IsObject(e)&&!s.IsArray(e)}function In(e){return s.IsBoolean(e)}function q(e){return kt(e)||In(e)}function is(e){return s.HasPropertyKey(e,"additionalItems")&&q(e.additionalItems)}function Yt(e){return s.HasPropertyKey(e,"additionalProperties")&&q(e.additionalProperties)}function ss(e){return s.HasPropertyKey(e,"allOf")&&s.IsArray(e.allOf)&&e.allOf.every(t=>q(t))}function wf(e){return s.HasPropertyKey(e,"$anchor")&&s.IsString(e.$anchor)}function as(e){return s.HasPropertyKey(e,"anyOf")&&s.IsArray(e.anyOf)&&e.anyOf.every(t=>q(t))}function Ym(e){return s.HasPropertyKey(e,"const")}function Jr(e){return s.HasPropertyKey(e,"contains")&&q(e.contains)}function Pt(e){return s.HasPropertyKey(e,"default")}function Qm(e){return s.HasPropertyKey(e,"dependencies")&&s.IsObject(e.dependencies)&&Object.values(e.dependencies).every(t=>q(t)||s.IsArray(t)&&t.every(r=>s.IsString(r)))}function Xm(e){return s.HasPropertyKey(e,"dependentRequired")&&s.IsObject(e.dependentRequired)&&Object.values(e.dependentRequired).every(t=>s.IsArray(t)&&t.every(r=>s.IsString(r)))}function ms(e){return s.HasPropertyKey(e,"dependentSchemas")&&s.IsObject(e.dependentSchemas)&&Object.values(e.dependentSchemas).every(t=>q(t))}function Yr(e){return s.HasPropertyKey(e,"$dynamicAnchor")&&s.IsString(e.$dynamicAnchor)}function us(e){return s.HasPropertyKey(e,"$dynamicRef")&&s.IsString(e.$dynamicRef)}function cs(e){return s.HasPropertyKey(e,"else")&&q(e.else)}function Zm(e){return s.HasPropertyKey(e,"enum")&&s.IsArray(e.enum)}function eu(e){return s.HasPropertyKey(e,"exclusiveMaximum")&&(s.IsNumber(e.exclusiveMaximum)||s.IsBigInt(e.exclusiveMaximum))}function vr(e){return s.HasPropertyKey(e,"exclusiveMinimum")&&(s.IsNumber(e.exclusiveMinimum)||s.IsBigInt(e.exclusiveMinimum))}function Uo(e){return s.HasPropertyKey(e,"format")&&s.IsString(e.format)}function It(e){return s.HasPropertyKey(e,"$id")&&s.IsString(e.$id)}function ps(e){return s.HasPropertyKey(e,"if")&&q(e.if)}function bn(e){return s.HasPropertyKey(e,"items")&&(q(e.items)||s.IsArray(e.items)&&e.items.every(t=>q(t)))}function fs(e){return bn(e)&&s.IsArray(e.items)}function tu(e){return s.HasPropertyKey(e,"maximum")&&(s.IsNumber(e.maximum)||s.IsBigInt(e.maximum))}function ru(e){return s.HasPropertyKey(e,"maxContains")&&s.IsNumber(e.maxContains)}function Bo(e){return s.HasPropertyKey(e,"maxItems")&&s.IsNumber(e.maxItems)}function nu(e){return s.HasPropertyKey(e,"maxLength")&&s.IsNumber(e.maxLength)}function ou(e){return s.HasPropertyKey(e,"maxProperties")&&s.IsNumber(e.maxProperties)}function Fr(e){return s.HasPropertyKey(e,"minimum")&&(s.IsNumber(e.minimum)||s.IsBigInt(e.minimum))}function $n(e){return s.HasPropertyKey(e,"minContains")&&s.IsNumber(e.minContains)}function En(e){return s.HasPropertyKey(e,"minItems")&&s.IsNumber(e.minItems)}function Go(e){return s.HasPropertyKey(e,"minLength")&&s.IsNumber(e.minLength)}function Ko(e){return s.HasPropertyKey(e,"minProperties")&&s.IsNumber(e.minProperties)}function iu(e){return s.HasPropertyKey(e,"multipleOf")&&(s.IsNumber(e.multipleOf)||s.IsBigInt(e.multipleOf))}function ds(e){return s.HasPropertyKey(e,"not")&&q(e.not)}function ls(e){return s.HasPropertyKey(e,"oneOf")&&s.IsArray(e.oneOf)&&e.oneOf.every(t=>q(t))}function Ho(e){return s.HasPropertyKey(e,"pattern")&&(s.IsString(e.pattern)||e.pattern instanceof RegExp)}function Hn(e){return s.HasPropertyKey(e,"patternProperties")&&s.IsObject(e.patternProperties)&&Object.values(e.patternProperties).every(t=>q(t))}function Sn(e){return s.HasPropertyKey(e,"prefixItems")&&s.IsArray(e.prefixItems)&&e.prefixItems.every(t=>q(t))}function zn(e){return s.HasPropertyKey(e,"properties")&&s.IsObject(e.properties)&&Object.values(e.properties).every(t=>q(t))}function gs(e){return s.HasPropertyKey(e,"propertyNames")&&(s.IsObject(e.propertyNames)||q(e.propertyNames))}function NC(e){return s.HasPropertyKey(e,"$recursiveAnchor")&&s.IsBoolean(e.$recursiveAnchor)}function zo(e){return NC(e)&&s.IsEqual(e.$recursiveAnchor,!0)}function ys(e){return s.HasPropertyKey(e,"$recursiveRef")&&s.IsString(e.$recursiveRef)}function xs(e){return s.HasPropertyKey(e,"$ref")&&s.IsString(e.$ref)}function kn(e){return s.HasPropertyKey(e,"required")&&s.IsArray(e.required)&&e.required.every(t=>s.IsString(t))}function hs(e){return s.HasPropertyKey(e,"then")&&q(e.then)}function su(e){return s.HasPropertyKey(e,"type")&&(s.IsString(e.type)||s.IsArray(e.type)&&e.type.every(t=>s.IsString(t)))}function Qr(e){return s.HasPropertyKey(e,"uniqueItems")&&s.IsBoolean(e.uniqueItems)}function Wo(e){return s.HasPropertyKey(e,"unevaluatedItems")&&q(e.unevaluatedItems)}function Vo(e){return s.HasPropertyKey(e,"unevaluatedProperties")&&q(e.unevaluatedProperties)}var bt=class{constructor(){let t=new Set,r=new Set;this.stack=[{indices:t,keys:r}]}Push(){let t=new Set,r=new Set;return this.stack.push({indices:t,keys:r}),!0}Pop(){return this.stack.pop(),!0}AddIndex(t){return this.GetIndices().add(t),!0}AddKey(t){return this.GetKeys().add(t),!0}GetIndices(){return this.stack[this.stack.length-1].indices}GetKeys(){return this.stack[this.stack.length-1].keys}Merge(t){for(let r of t)r.GetIndices().forEach(n=>this.GetIndices().add(n)),r.GetKeys().forEach(n=>this.GetKeys().add(n));return!0}},ut=class extends bt{constructor(){super(),this.errors=[]}AtCapacity(){return this.errors.length>=qe.Get().maxErrors}AddError(t,r,n,o){return this.AddErrorObject({keyword:t,schemaPath:r,instancePath:n,params:o})}AddErrors(t){return t.forEach(r=>this.AddErrorObject(r)),!1}GetErrors(){return this.errors}AddErrorObject(t){return this.AtCapacity()||this.errors.push(t),!1}};function Cf(e,t,r,n){return s.Every(r["~refine"],0,(o,i)=>o.check(n))}function Rf(e,t,r,n,o,i){return s.EveryAll(o["~refine"],0,(a,m)=>a.check(i)||t.AddError("~refine",r,n,{index:m,message:a.error(i)}))}var Jo="urn:typebox:root";function Lr(e,t){return URL.canParse(e,t)?new URL(e,t):s.IsEqual(t,Jo)?new URL(`${t}:${e}`):new URL(`${t.slice(0,t.lastIndexOf(":"))}:${e}`)}function Vn(e,t){let r=kt(t)&&It(t)?Lr(t.$id,Jo).href:Jo;return{context:e,schema:t,lexicalSchema:t,lexicalBase:r,resourceBase:r,referenceBase:r,ids:[],useResourceBaseForReference:!0,recursiveAnchor:void 0,dynamicAnchors:[],resourceEntries:new Map,pendingResource:!0,enteredResource:!1}}function au(e,t,r=!0){if(In(t))return e;if(Array.isArray(t))return t.reduce((o,i)=>au(o,i,!1),e);if(!kt(t)||!r&&It(t))return e;let n=!r&&Yr(t)?[...e,t]:e;return Object.keys(t).reduce((o,i)=>au(o,t[i],!1),n)}function Yo(e,t){return e.resourceEntries.get(t)}function Pf(e,t){return e.enteredResource||Yo(e,t)!==void 0}function qC(e){return!/^[A-Za-z][A-Za-z0-9+.-]*:/.test(e.$id)}function _C(e,t){return It(t)?[...e.ids,t]:e.ids}function UC(e,t){return e.recursiveAnchor??(zo(t)?t:void 0)}function BC(e,t){let r=It(t)?au(e.dynamicAnchors,t):e.dynamicAnchors;return Yr(t)?[...r,t]:r}function GC(e,t){return It(t)?!1:e.pendingResource}function Af(e,t){let r=Yo(e,t);return r?r.base:It(t)?Lr(t.$id,e.lexicalBase).href:e.lexicalBase}function Of(e,t){let r=Yo(e,t);return r?r.base:It(t)&&e.pendingResource?Lr(t.$id,e.resourceBase).href:e.resourceBase}function Mf(e,t){return It(t)?!qC(t):e.useResourceBaseForReference}function KC(e,t){let r=Pf(e,t),n=Mf(e,t);return r||n?Of(e,t):Af(e,t)}function HC(e,t){let r=Yo(e,t);return r?r.root:It(t)?t:e.lexicalSchema}function zC(e,t){return kt(t)&&(It(t)||Yr(t)||s.IsUndefined(e.recursiveAnchor)&&zo(t)||!s.IsUndefined(Yo(e,t)))}function Jn(e,t){return zC(e,t)?{...e,ids:_C(e,t),dynamicAnchors:BC(e,t),recursiveAnchor:UC(e,t),pendingResource:GC(e,t),lexicalBase:Af(e,t),resourceBase:Of(e,t),useResourceBaseForReference:Mf(e,t),referenceBase:KC(e,t),lexicalSchema:HC(e,t),enteredResource:Pf(e,t)}:e}function vf(e){return bn(e)&&s.IsArray(e.items)}function Ff(e,t,r,n){return vf(r)?s.Every(n,0,(i,a)=>s.IsLessThan(a,r.items.length)||Ut(e,t,r.additionalItems,i)&&t.AddIndex(a)):!0}function Lf(e,t,r,n,o,i){return vf(o)?s.Every(i,0,(m,c)=>{let p=`${r}/additionalItems`,f=`${n}/${c}`;return s.IsLessThan(c,o.items.length)||Bt(e,t,p,f,o.additionalItems,m)&&t.AddIndex(c)}):!0}function At(e){return e.replace(/~/g,"~0").replace(/\//g,"~1")}function Xr(e){return new RegExp(e,"u")}function WC(e){return`^${e.replace(/[.*+?^${}()|[\]\\]/g,"\\$&")}$`}function Df(e){let t=[];return Hn(e)&&t.push(...s.Keys(e.patternProperties)),zn(e)&&t.push(...s.Keys(e.properties).map(WC)),s.IsEqual(t.length,0)?"(?!)":`(${t.join("|")})`}function jf(e,t,r,n){let o=Xr(Df(r));return s.Every(s.Keys(n),0,(a,m)=>o.test(a)||Ut(e,t,r.additionalProperties,n[a])&&t.AddKey(a))}function Nf(e,t,r,n,o,i){let a=Xr(Df(o)),m=[];return s.EveryAll(s.Keys(i),0,(p,f)=>{let d=`${r}/additionalProperties`,g=`${n}/${At(p)}`,y=a.test(p)||Bt(e,t,d,g,o.additionalProperties,i[p])&&t.AddKey(p);return y||m.push(p),y})||t.AddError("additionalProperties",r,n,{additionalProperties:m})}function qf(e,t,r,n){let o=r.allOf.reduce((i,a)=>{let m=new bt;return te(e,m,a,n)?[...i,m]:i},[]);return s.IsEqual(o.length,r.allOf.length)&&t.Merge(o)}function _f(e,t,r,n,o,i){let a=[],m=o.allOf.reduce((p,f,d)=>{let g=`${r}/allOf/${d}`,y=new ut,I=ge(e,y,g,n,f,i);return I||a.push(y),I?[...p,y]:p},[]),c=s.IsEqual(m.length,o.allOf.length)&&t.Merge(m);return c||a.forEach(p=>t.AddErrors(p.GetErrors())),c}function Uf(e,t,r,n){let o=r.anyOf.reduce((i,a)=>{let m=new bt;return te(e,m,a,n)?[...i,m]:i},[]);return s.IsGreaterThan(o.length,0)&&t.Merge(o)}function Bf(e,t,r,n,o,i){let a=[],m=o.anyOf.reduce((p,f,d)=>{let g=new ut,y=`${r}/anyOf/${d}`,I=ge(e,g,y,n,f,i);return I||a.push(g),I?[...p,g]:p},[]),c=s.IsGreaterThan(m.length,0)&&t.Merge(m);return c||a.forEach(p=>t.AddErrors(p.GetErrors())),c||t.AddError("anyOf",r,n,{})}function cu(e,t,r,n){return r}function Gf(e,t,r,n,o,i){return cu(e,t,o,i)||t.AddError("boolean",r,n,{})}function pu(e,t,r,n){return s.IsValueLike(r.const)?s.IsEqual(n,r.const):s.IsDeepEqual(n,r.const)}function Kf(e,t,r,n,o,i){return pu(e,t,o,i)||t.AddError("const",r,n,{allowedValue:o.const})}function VC(e){return!($n(e)&&s.IsEqual(e.minContains,0))}function fu(e,t,r,n){return VC(r)?!s.IsEqual(n.length,0)&&s.SomeAll(n,(o,i)=>te(e,t,r.contains,o)&&t.AddIndex(i)):!0}function Hf(e,t,r,n,o,i){return fu(e,t,o,i)||t.AddError("contains",r,n,{minContains:1})}function zf(e,t,r,n){let o=s.IsEqual(s.Keys(n).length,0),i=s.Every(s.Entries(r.dependencies),0,([a,m])=>!s.HasPropertyKey(n,a)||(s.IsArray(m)?m.every(c=>s.HasPropertyKey(n,c)):te(e,t,m,n)));return o||i}function Wf(e,t,r,n,o,i){let a=s.IsEqual(s.Keys(i).length,0),m=s.EveryAll(s.Entries(o.dependencies),0,([c,p])=>{let f=`${r}/dependencies/${At(c)}`;return!s.HasPropertyKey(i,c)||(s.IsArray(p)?p.every(d=>s.HasPropertyKey(i,d)||t.AddError("dependencies",r,n,{property:c,dependencies:p})):ge(e,t,f,n,p,i))});return a||m}function Vf(e,t,r,n){let o=s.IsEqual(s.Keys(n).length,0),i=s.Every(s.Entries(r.dependentRequired),0,([a,m])=>!s.HasPropertyKey(n,a)||m.every(c=>s.HasPropertyKey(n,c)));return o||i}function Jf(e,t,r,n,o,i){let a=s.IsEqual(s.Keys(i).length,0),m=s.EveryAll(s.Entries(o.dependentRequired),0,([c,p])=>!s.HasPropertyKey(i,c)||s.EveryAll(p,0,f=>s.HasPropertyKey(i,f)||t.AddError("dependentRequired",r,n,{property:c,dependencies:p})));return a||m}function Yf(e,t,r,n){let o=s.IsEqual(s.Keys(n).length,0),i=s.Every(s.Entries(r.dependentSchemas),0,([a,m])=>!s.HasPropertyKey(n,a)||te(e,t,m,n));return o||i}function Qf(e,t,r,n,o,i){let a=s.IsEqual(s.Keys(i).length,0),m=s.EveryAll(s.Entries(o.dependentSchemas),0,([c,p])=>{let f=`${r}/dependentSchemas/${At(c)}`;return!s.HasPropertyKey(i,c)||ge(e,t,f,n,p,i)});return a||m}var Qt={};_t(Qt,{DynamicRef:()=>TR,RecursiveRef:()=>ER,Ref:()=>bR});var gr={};_t(gr,{Delete:()=>XC,Get:()=>YC,Has:()=>JC,Indices:()=>Xo,Set:()=>QC});function Zf(e){throw Error(e)}function Xf(){Zf("Pointer contains unsafe property key")}function du(){Zf("Cannot set value")}function Xo(e){let t=e.split("/").map(r=>r.replace(/~1/g,"/").replace(/~0/g,"~"));return t[0]===""?t.slice(1):t}function JC(e,t){let r=e;for(let n of Xo(t)){if(!s.IsObject(r)||!s.HasPropertyKey(r,n))return!1;r=r[n]}return!0}function YC(e,t){let r=e;for(let n of Xo(t)){if(!s.IsObject(r)||s.IsUnsafePropertyKey(n))return;r=r[n]}return r}function ed(e,t,r){let n=e;for(let o of t)s.IsUnsafePropertyKey(o)&&Xf(),n=s.IsObject(n)?n[o]:void 0;return s.IsUnsafePropertyKey(r)&&Xf(),s.IsObject(n)||du(),n}function QC(e,t,r){let n=Xo(t),o=n.pop();return s.IsUndefined(o)&&du(),ed(e,n,o)[o]=r,e}function XC(e,t){let r=Xo(t),n=r.pop();s.IsUndefined(n)&&du();let o=ed(e,r,n);return s.IsArray(o)&&/^(0|[1-9]\d*)$/.test(n)?o.splice(Number(n),1):delete o[n],e}function yu(e,t){return kt(e)&&It(e)?Lr(e.$id,t.href):t}function xu(e){return Lr(e,Jo)}function lu(e){return e.href.split("#")[0]}function ZC(e,t,r){return gu(e,xu(t),r)}function eR(e,t){return t.$ref.startsWith("#")||e.enteredResource?e.lexicalSchema:e.schema}function tR(e){return e.startsWith("#/")}function td(e,t){if(s.IsObject(e)&&Yr(e)&&s.IsEqual(e.$dynamicAnchor,t))return e;if(s.IsObject(e))for(let r of s.Keys(e)){let n=td(e[r],t);if(n)return n}}function gu(e,t,r){if(s.IsEqual(e,r))return t.href;let n=yu(e,t);if(s.IsArray(e))for(let o of e){let i=gu(o,n,r);if(!s.IsUndefined(i))return i}else if(s.IsObject(e))for(let o of s.Keys(e)){let i=gu(e[o],n,r);if(!s.IsUndefined(i))return i}}function rd(e,t){if(t.href.endsWith("#"))return e;if(!t.hash.startsWith("#"))return;let r=decodeURIComponent(t.hash.slice(1));if(r.startsWith("/"))return gr.Get(e,r)}function rR(e,t,r){if(!It(e))return;if(s.IsEqual(e.$id,r.hash))return e;let n=new URL(r.href,t.href);if(s.IsEqual(t.pathname,n.pathname))return r.hash.startsWith("#")?rd(e,r):e}function nR(e,t,r){if(!wf(e))return;let n=new URL(`#${e.$anchor}`,t.href),o=new URL(r.href,t.href);return s.IsEqual(n.href,o.href)?e:void 0}function oR(e,t,r){if(!Yr(e))return;let n=new URL(`#${e.$dynamicAnchor}`,t.href),o=new URL(r.href,t.href);return s.IsEqual(n.href,o.href)?e:void 0}function iR(e,t,r){if(kt(e))return rR(e,t,r)??nR(e,t,r)??oR(e,t,r)??rd(e,r)}function sR(e,t,r){if(s.IsArray(e))return e.reduce((n,o)=>{let i=Is(o,t,r);return s.IsUndefined(i)?n:i},void 0)}function aR(e,t,r){if(s.IsObject(e))return s.Keys(e).reduce((n,o)=>{if(s.IsEqual(o,"const")||s.IsEqual(o,"enum"))return n;let i=Is(e[o],t,r);return s.IsUndefined(i)?n:i},void 0)}function Is(e,t,r){let n=yu(e,t);return iR(e,n,r)??sR(e,n,r)??aR(e,n,r)}function mR(e,t,r,n){let o=bs(e,t,r,n);return kt(o)&&It(o)?o:void 0}function uR(e,t,r){if(!t.$ref.startsWith("#")||!kt(e.schema)||s.HasPropertyKey(e.schema,"$schema"))return;let n=ZC(e.lexicalSchema,e.referenceBase,r);if(!(s.IsUndefined(n)||s.IsEqual(n,e.referenceBase)))return{target:r,base:n,root:e.lexicalSchema}}function cR(e,t,r){let n=e.context[t];if(kt(n))return{target:r,base:t,root:n}}function pR(e,t,r,n,o){let i=o?cR(e,n,r):void 0;return s.IsUndefined(i)?uR(e,t,r):i}function fR(e,t,r){if(It(r))return;let n=mR(e.context,e.schema,e.referenceBase,t);if(!(!n||e.ids.includes(n)))return{resource:n}}function dR(e,t){return s.HasPropertyKey(e,t)?e[t]:void 0}function lR(e,t,r){return Is(e,t,r)}function gR(e,t,r){let n=lu(r);if(!s.HasPropertyKey(e,n)||s.IsEqual(n,lu(t)))return;let o=e[n],i=yu(o,new URL(n));return s.IsEqual(r.hash,"")?o:Is(o,i,r)}function bs(e,t,r,n){let o=xu(r),i=Lr(n,o.href);return dR(e,n)??lR(t,o,i)??gR(e,o,i)}function yR(e,t){if(!t)return e;let r=new Map(e.resourceEntries);return r.set(t.target,{base:t.base,root:t.root}),{...e,resourceEntries:r}}function xR(e,t){return t?Jn(e,t.resource):e}function nd(e,t,r,n){let o=yR({...e,pendingResource:t},r);return xR(o,n)}function hR(e,t,r){let n=lu(Lr(t.$ref,e.referenceBase)),o=!s.IsEqual(n,e.resourceBase),i=pR(e,t,r,n,o),a=o?fR(e,n,r):void 0;return{schema:r,stack:nd(e,!0,i,a)}}function IR(e,t){return{schema:t,stack:nd(e,!s.IsUndefined(t))}}function bR(e,t){let r=bs(e.context,eR(e,t),e.referenceBase,t.$ref);return kt(r)?hR(e,t,r):IR(e,r)}function $R(e){return kt(e.lexicalSchema)&&zo(e.lexicalSchema)}function ER(e,t){let r=$R(e)?e.recursiveAnchor:e.lexicalSchema;return bs(e.context,r,e.lexicalBase,t.$recursiveRef)}function od(e,t){return Lr(t.$dynamicRef,xu(e.lexicalBase).href).hash}function id(e,t){return e.dynamicAnchors.find(r=>s.IsEqual(r.$dynamicAnchor,t))??td(e.schema,t)}function SR(e,t,r){if(!kt(r)||!Yr(r))return r;let n=od(e,t);return tR(n)?r:id(e,r.$dynamicAnchor)}function kR(e,t){let r=od(e,t);return id(e,decodeURIComponent(r.slice(1)))}function TR(e,t){let r=t.$dynamicRef.startsWith("#")?e.lexicalSchema:e.schema,n=bs(e.context,r,e.lexicalBase,t.$dynamicRef);return s.IsUndefined(n)?kR(e,t):SR(e,t,n)}function sd(e,t,r,n){let o=Qt.DynamicRef(e,r)??!1,i=o?{...e,pendingResource:!0}:e;return q(o)&&te(i,t,o,n)}function ad(e,t,r,n,o,i){let a=Qt.DynamicRef(e,o)??!1,m=a?{...e,pendingResource:!0}:e;return q(a)&&ge(m,t,r,n,a,i)}function bu(e,t,r,n){return s.Some(r.enum,o=>s.IsValueLike(o)?s.IsEqual(n,o):s.IsDeepEqual(n,o))}function md(e,t,r,n,o,i){return bu(e,t,o,i)||t.AddError("enum",r,n,{allowedValues:o.enum})}function $u(e,t,r,n){return s.IsLessThan(n,r.exclusiveMaximum)}function ud(e,t,r,n,o,i){return $u(e,t,o,i)||t.AddError("exclusiveMaximum",r,n,{comparison:"<",limit:o.exclusiveMaximum})}function Eu(e,t,r,n){return s.IsGreaterThan(n,r.exclusiveMinimum)}function cd(e,t,r,n,o,i){return Eu(e,t,o,i)||t.AddError("exclusiveMinimum",r,n,{comparison:">",limit:o.exclusiveMinimum})}var ri={};_t(ri,{Clear:()=>jd,Entries:()=>l0,Get:()=>x0,Has:()=>y0,IsDate:()=>Qn,IsDateTime:()=>$s,IsDuration:()=>Es,IsEmail:()=>Ss,IsHostname:()=>Os,IsIPv4:()=>Fs,IsIPv6:()=>Ls,IsIdnEmail:()=>Ms,IsIdnHostname:()=>vs,IsIri:()=>js,IsIriReference:()=>Ds,IsJsonPointer:()=>qs,IsJsonPointerUriFragment:()=>Ns,IsRegex:()=>_s,IsRelativeJsonPointer:()=>Us,IsTime:()=>Xn,IsUri:()=>Ks,IsUriReference:()=>Bs,IsUriTemplate:()=>Gs,IsUrl:()=>Hs,IsUuid:()=>zs,Reset:()=>Nd,Set:()=>g0,Test:()=>h0});var wR=[0,31,28,31,30,31,30,31,31,30,31,30,31],CR=/^(\d\d\d\d)-(\d\d)-(\d\d)$/;function RR(e){return e%4===0&&(e%100!==0||e%400===0)}function Qn(e){let t=CR.exec(e);if(!t)return!1;let r=+t[1],n=+t[2],o=+t[3];return n>=1&&n<=12&&o>=1&&o<=(n===2&&RR(r)?29:wR[n])}var PR=/^(\d\d):(\d\d):(\d\d)(?:\.\d+)?(?:([Zz])|([+-])(\d\d):(\d\d))?$/;function Xn(e,t=!0){let r=PR.exec(e);if(!r||t&&!r[4]&&!r[5])return!1;let n=+r[1],o=+r[2],i=+r[3];if(n>23||o>59||i>60)return!1;if(r[5]){let f=+r[6],d=+r[7];if(f>23||d>59)return!1}if(i<60)return!0;let a=r[5]==="-"?-1:1,m=+(r[6]||0),c=+(r[7]||0);return((n*60+o-a*(m*60+c))%1440+1440)%1440===1439}var AR=/^(?:\[!?(?:(?!\.{1,2}[/\]])[A-Za-z._][A-Za-z._0-9+-]{0,13}(?:\/(?!\.{1,2}[/\]])[A-Za-z._][A-Za-z._0-9+-]{0,13})*|[+-](?:[01][0-9]|2[0-3]):[0-5][0-9])\](?:\[!?[a-z_][a-z_0-9-]*=[A-Za-z0-9]+(?:-[A-Za-z0-9]+)*\])*|(?:\[!?[a-z_][a-z_0-9-]*=[A-Za-z0-9]+(?:-[A-Za-z0-9]+)*\])*)$/;function $s(e){let t=e.indexOf("["),r=t===-1?e:e.slice(0,t);if(t!==-1&&!AR.test(e.slice(t)))return!1;let n=r.split(/T/i);return n.length===2&&Qn(n[0])&&Xn(n[1])}var OR=/^P((\d+Y(\d+M(\d+D)?)?|\d+M(\d+D)?|\d+D)(T(\d+H(\d+M(\d+S)?)?|\d+M(\d+S)?|\d+S))?|T(\d+H(\d+M(\d+S)?)?|\d+M(\d+S)?|\d+S)|\d+W)$/;function Es(e){return OR.test(e)}var MR=/^(?:[a-z0-9!#$%&'*+/=?^_`{|}~-]+(?:\.[a-z0-9!#$%&'*+/=?^_`{|}~-]+)*|"(?:[^"\\]|\\[\x20-\x7e])*")@(?:[a-z0-9](?:[a-z0-9-]{0,61}[a-z0-9])?(?:\.[a-z0-9](?:[a-z0-9-]{0,61}[a-z0-9])?)*|\[(?:IPv6:[a-f0-9:]+|(?:25[0-5]|2[0-4][0-9]|1[0-9]{2}|[1-9]?[0-9])(?:\.(?:25[0-5]|2[0-4][0-9]|1[0-9]{2}|[1-9]?[0-9])){3})\])$/i;function Ss(e){return MR.test(e)}var pd=/^(?!-).*(?<!-)$/,fd=/^(?!..--)/,dd=/^[a-zA-Z0-9-]*$/,pG=new RegExp("^\\p{ASCII}*$","u"),Zn=/[^\p{ASCII}]/u;var vR=/[0-9]/,ld=/[\u{0660}-\u{0669}]/u,FR=/[\u{06f0}-\u{06f9}]/u,LR=/[\u{002e}\u{002c}\u{003a}\u{002f}]/u,DR=/[\u{002d}\u{002b}]/u,Su=new RegExp("\\p{Mn}","u"),jR=new RegExp("\\p{Mc}","u"),fG=new RegExp("\\p{Me}","u"),gd=/[\p{Mn}\p{Mc}\p{Me}]/u,ku=new RegExp("\\p{L}","u"),NR=new RegExp("\\p{Nd}","u"),yd=new RegExp("\\p{Script=Greek}","u"),ks=new RegExp("\\p{Script=Hebrew}","u"),xd=/[\p{Script=Hiragana}\p{Script=Katakana}\p{Script=Han}]/u,hd=/[\p{Script=Arabic}\p{Script=Syriac}\p{Script=Thaana}\p{Script=Mandaic}]/u,Tu=/[\u{094d}\u{09cd}\u{0a4d}\u{0acd}\u{0b4d}\u{0bcd}\u{0c4d}\u{0ccd}\u{0d3b}\u{0d3c}\u{0d4d}\u{0dca}\u{1b44}\u{1baa}\u{1bab}\u{a9c0}\u{11046}\u{1107f}\u{110b9}\u{11133}\u{11134}\u{111c0}\u{11235}\u{1134d}\u{11442}\u{114c2}\u{115bf}\u{1163f}\u{116b6}\u{11c3f}\u{11d44}\u{11d45}]/u,Id=/[\u{0640}\u{07fa}\u{302e}\u{302f}\u{3031}\u{3032}\u{3033}\u{3034}\u{3035}\u{303b}]/u,qR=/[\u{00b7}\u{0375}\u{05f3}\u{05f4}\u{200c}\u{200d}\u{30fb}]/u,_R=/[\u{00df}\u{03c2}\u{06fd}\u{06fe}\u{0f0b}\u{3007}]/u,bd=new RegExp([vR,FR].map(e=>e.source).join("|"),"u"),$d=new RegExp([ku,DR,LR,NR,Su,jR,qR,_R].map(e=>e.source).join("|"),"u");function Ed(e){return pd.test(e)&&fd.test(e)&&dd.test(e)}var or=36,ei=1,ti=26,BR=38,GR=700,kd=72,Td=128;function wu(){throw null}function Ts(e){return e.toLowerCase().startsWith("xn--")}function wd(e,t,r){e=r?Math.floor(e/GR):e>>1,e+=Math.floor(e/t);let n=0;for(;e>(or-ei)*ti>>1;)e=Math.floor(e/(or-ei)),n+=or;return n+Math.floor((or-ei+1)*e/(e+BR))}function ws(e){let t=[],r=Td,n=0,o=kd,i=e.lastIndexOf("-");if(i>0)for(let m=0;m<i;m++){let c=e.charCodeAt(m);c>=128&&wu(),t.push(c)}let a=i<0?0:i+1;for(;a<e.length;){let m=n,c=1,p=or;for(;;){a>=e.length&&wu();let d=e.charCodeAt(a++),g;d>=97&&d<=122?g=d-97:d>=48&&d<=57?g=d-48+26:wu(),n+=g*c;let y=p<=o?ei:p>=o+ti?ti:p-o;if(g<y)break;c*=or-y,p+=or}let f=t.length+1;o=wd(n-m,f,m===0),r+=Math.floor(n/f),n%=f,t.splice(n,0,r),n++}return String.fromCodePoint(...t)}function Sd(e){return e<26?String.fromCharCode(e+97):String.fromCharCode(e-26+48)}var KR=new RegExp(Zn.source,"gu");function Cd(e){let t=e.replace(KR,""),r=t.length,n=r>0?[t,"-"]:[],o=Array.from(e,p=>p.codePointAt(0)),i=Td,a=0,m=kd,c=r;for(;c<o.length;){let p=1/0;for(let f of o)f>=i&&f<p&&(p=f);a+=(p-i)*(c+1),i=p;for(let f of o)if(f<i&&a++,f===i){let d=a;for(let g=or;;g+=or){let y=g<=m?ei:g>=m+ti?ti:g-m;if(d<y)break;let I=y+(d-y)%(or-y);n.push(Sd(I)),d=Math.floor((d-y)/(or-y))}n.push(Sd(d)),m=wd(a,c+1,c===r),a=0,c++}a++,i++}return n.join("")}var HR=/^(?:R|AL|AN|EN|ES|CS|ET|ON|BN|NSM)$/,Rd=/^(?:L|EN|ES|CS|ET|ON|BN|NSM)$/,zR=/^(?:R|AL|AN)$/;function Pd(e){if(Ts(e))try{return Cs(ws(e.slice(4).toLowerCase()))}catch{return!1}return Cs(e)}function Ad(e){let t=String.fromCodePoint(e);return bd.test(t)?"EN":ld.test(t)?"AN":Su.test(t)?"NSM":ks.test(t)?"R":hd.test(t)?"AL":ku.test(t)?"L":"ON"}function Cs(e){for(let t of e)if(zR.test(Ad(t.codePointAt(0))))return!0;return!1}function Rs(e){let t=!1,r=Rd,n=!1,o=!1,i=!0;for(let a of e){let m=Ad(a.codePointAt(0));if(i){if(m!=="L"&&m!=="R"&&m!=="AL")return!1;t=m==="R"||m==="AL",r=t?HR:Rd,i=!1}if(!r.test(m))return!1;m==="EN"?n=!0:m==="AN"&&(o=!0)}return!(t&&n&&o)}function WR(e){return Zn.test(e)&&Cd(e).length+4>63}function VR(e){return e[0]==="-"||e[e.length-1]==="-"?!0:e.slice(2).join("").startsWith("--")}function Ps(e){if(WR(e)||Cs(e)&&!Rs(e))return!1;let t=[...e],r=t.map(i=>i.codePointAt(0)),n=r.length;if(VR(t)||gd.test(t[0]))return!1;let o=!1;for(let i=0;i<n;i++){let a=r[i],m=t[i];if(Id.test(m)||!$d.test(m))return!1;xd.test(m)&&(o=!0);let c=r[i-1],p=r[i+1];switch(a){case 183:if(c!==108||p!==108)return!1;break;case 885:if(!p||!yd.test(t[i+1]))return!1;break;case 1523:case 1524:if(!c||!ks.test(t[i-1]))return!1;break;case 8204:if(!c||c<128&&!Tu.test(t[i-1]))return!1;break;case 8205:if(!c||!Tu.test(t[i-1]))return!1;break;case 12539:break}}return!(e.includes("\u30FB")&&!o)}function As(e){if(!Ts(e))return!1;try{let t=e.slice(4).toLowerCase();if(t.lastIndexOf("-")===0)return!1;let r=ws(t);return Zn.test(r)?Ps(r):!1}catch{return!1}}function JR(e){return e.length>0&&e.length<=63}function YR(e){return JR(e)&&(As(e)||Ed(e))}function Fd(e){return e.length===0||e.length>253||e.charCodeAt(e.length-1)===46?!1:e.split(".").every(t=>YR(t))}function QR(e){return e.length>0&&e.length<=63}function XR(e){return QR(e)&&(As(e)||Ps(e))}function ZR(e){return e.replace(/[\uff01-\uff5e]/g,t=>String.fromCharCode(t.charCodeAt(0)-65248)).normalize("NFC").replace(/[\u00ad\u034f\u180b-\u180d\u200b\ufe00-\ufe0f\u{e0100}-\u{e01ef}]/gu,"").replace(/[\u002E\u3002\uFF0E\uFF61]/g,".")}function Ld(e){if(e.length===0||e.includes(" "))return!1;let t=ZR(e);if(t.length>253)return!1;let r=t.split("."),n=r.some(o=>Pd(o));return r.every(o=>XR(o)&&(!n||Rs(o)))}function Os(e){return Fd(e)}var e0=/^(?:[A-Za-z0-9!#$%&'*+\/=?^_`{|}~\u{0080}-\u{10FFFF}-]+(?:\.[A-Za-z0-9!#$%&'*+\/=?^_`{|}~\u{0080}-\u{10FFFF}-]+)*|"(?:[^"\\]|\\.)*")@[\p{L}\p{N}](?:[\p{L}\p{N}-]{0,62})(?<!-)(?:\.[\p{L}\p{N}](?:[\p{L}\p{N}-]{0,62})(?<!-))*$/iu;function Ms(e){return e0.test(e.normalize("NFC"))}function vs(e){return Ld(e)}var t0=/^(?:(?:25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)\.){3}(?:25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)$/;function Fs(e){return t0.test(e)}var r0=/^(?:(?:(?:[0-9a-f]{1,4}:){6}|::(?:[0-9a-f]{1,4}:){5}|(?:[0-9a-f]{1,4})?::(?:[0-9a-f]{1,4}:){4}|(?:(?:[0-9a-f]{1,4}:)?[0-9a-f]{1,4})?::(?:[0-9a-f]{1,4}:){3}|(?:(?:[0-9a-f]{1,4}:){0,2}[0-9a-f]{1,4})?::(?:[0-9a-f]{1,4}:){2}|(?:(?:[0-9a-f]{1,4}:){0,3}[0-9a-f]{1,4})?::[0-9a-f]{1,4}:|(?:(?:[0-9a-f]{1,4}:){0,4}[0-9a-f]{1,4})?::)(?:[0-9a-f]{1,4}:[0-9a-f]{1,4}|(?:(?:25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)\.){3}(?:25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d))|(?:(?:[0-9a-f]{1,4}:){0,5}[0-9a-f]{1,4})?::[0-9a-f]{1,4}|(?:(?:[0-9a-f]{1,4}:){0,6}[0-9a-f]{1,4})?::)$/i;function Ls(e){return r0.test(e)}var n0=/[\x00-\x20\x7F\\]|%(?![0-9a-fA-F]{2})/,o0=/^[a-zA-Z][a-zA-Z0-9+\-.]*\/\//;function Ds(e){return!n0.test(e)&&!o0.test(e)&&URL.canParse(e,"http://example.com")}var i0=/[\x00-\x20<>\^`{|}\\]/,s0=/%(?![0-9a-fA-F]{2})/;function js(e){return i0.test(e)||s0.test(e)?!1:URL.canParse(e)}var a0=/^#(?:\/(?:[a-z0-9_\-.!$&'()*+,;:=@]|%[0-9a-f]{2}|~0|~1)*)*$/i;function Ns(e){return a0.test(e)}var m0=/^(?:\/(?:[^~/]|~0|~1)*)*$/;function qs(e){return m0.test(e)}function _s(e){try{return new RegExp(e,"u"),!0}catch{return!1}}var u0=/^(?:0|[1-9][0-9]*)(?:#|(?:\/(?:[^~/]|~0|~1)*)*)$/;function Us(e){return u0.test(e)}var c0=/^(?:[a-z][a-z0-9+\-.]*:(?:\/\/(?:(?:[-a-z0-9._~!$&'()*+,;=:]|%[0-9a-f]{2})*@)?(?:\[(?:(?:(?:[\da-f]{1,4}:){6}(?:[\da-f]{1,4}:[\da-f]{1,4}|(?:(?:25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)\.){3}(?:25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d))|::(?:[\da-f]{1,4}:){5}(?:[\da-f]{1,4}:[\da-f]{1,4}|(?:(?:25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)\.){3}(?:25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d))|(?:[\da-f]{1,4})?::(?:[\da-f]{1,4}:){4}(?:[\da-f]{1,4}:[\da-f]{1,4}|(?:(?:25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)\.){3}(?:25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d))|(?:(?:[\da-f]{1,4}:){0,1}[\da-f]{1,4})?::(?:[\da-f]{1,4}:){3}(?:[\da-f]{1,4}:[\da-f]{1,4}|(?:(?:25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)\.){3}(?:25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d))|(?:(?:[\da-f]{1,4}:){0,2}[\da-f]{1,4})?::(?:[\da-f]{1,4}:){2}(?:[\da-f]{1,4}:[\da-f]{1,4}|(?:(?:25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)\.){3}(?:25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d))|(?:(?:[\da-f]{1,4}:){0,3}[\da-f]{1,4})?::[\da-f]{1,4}:(?:[\da-f]{1,4}:[\da-f]{1,4}|(?:(?:25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)\.){3}(?:25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d))|(?:(?:[\da-f]{1,4}:){0,4}[\da-f]{1,4})?::(?:[\da-f]{1,4}:[\da-f]{1,4}|(?:(?:25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)\.){3}(?:25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d))|(?:(?:[\da-f]{1,4}:){0,5}[\da-f]{1,4})?::[\da-f]{1,4}|(?:(?:[\da-f]{1,4}:){0,6}[\da-f]{1,4})?::)|v[0-9a-f]+\.[-a-z0-9._~!$&'()*+,;=:]+)\]|(?:(?:25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)\.){3}(?:25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)|(?:[-a-z0-9._~!$&'()*+,;=]|%[0-9a-f]{2})*)(?::\d*)?(?:\/(?:[-a-z0-9._~!$&'()*+,;=:@]|%[0-9a-f]{2})*)*|\/(?:(?:[-a-z0-9._~!$&'()*+,;=:@]|%[0-9a-f]{2})+(?:\/(?:[-a-z0-9._~!$&'()*+,;=:@]|%[0-9a-f]{2})*)*)?|(?:[-a-z0-9._~!$&'()*+,;=:@]|%[0-9a-f]{2})+(?:\/(?:[-a-z0-9._~!$&'()*+,;=:@]|%[0-9a-f]{2})*)*)?|(?:\/\/(?:(?:[-a-z0-9._~!$&'()*+,;=:]|%[0-9a-f]{2})*@)?(?:\[(?:(?:(?:[\da-f]{1,4}:){6}(?:[\da-f]{1,4}:[\da-f]{1,4}|(?:(?:25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)\.){3}(?:25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d))|::(?:[\da-f]{1,4}:){5}(?:[\da-f]{1,4}:[\da-f]{1,4}|(?:(?:25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)\.){3}(?:25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d))|(?:[\da-f]{1,4})?::(?:[\da-f]{1,4}:){4}(?:[\da-f]{1,4}:[\da-f]{1,4}|(?:(?:25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)\.){3}(?:25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d))|(?:(?:[\da-f]{1,4}:){0,1}[\da-f]{1,4})?::(?:[\da-f]{1,4}:){3}(?:[\da-f]{1,4}:[\da-f]{1,4}|(?:(?:25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)\.){3}(?:25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d))|(?:(?:[\da-f]{1,4}:){0,2}[\da-f]{1,4})?::(?:[\da-f]{1,4}:){2}(?:[\da-f]{1,4}:[\da-f]{1,4}|(?:(?:25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)\.){3}(?:25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d))|(?:(?:[\da-f]{1,4}:){0,3}[\da-f]{1,4})?::[\da-f]{1,4}:(?:[\da-f]{1,4}:[\da-f]{1,4}|(?:(?:25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)\.){3}(?:25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d))|(?:(?:[\da-f]{1,4}:){0,4}[\da-f]{1,4})?::(?:[\da-f]{1,4}:[\da-f]{1,4}|(?:(?:25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)\.){3}(?:25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d))|(?:(?:[\da-f]{1,4}:){0,5}[\da-f]{1,4})?::[\da-f]{1,4}|(?:(?:[\da-f]{1,4}:){0,6}[\da-f]{1,4})?::)|v[0-9a-f]+\.[-a-z0-9._~!$&'()*+,;=:]+)\]|(?:(?:25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)\.){3}(?:25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)|(?:[-a-z0-9._~!$&'()*+,;=]|%[0-9a-f]{2})*)(?::\d*)?(?:\/(?:[-a-z0-9._~!$&'()*+,;=:@]|%[0-9a-f]{2})*)*|\/(?:(?:[-a-z0-9._~!$&'()*+,;=:@]|%[0-9a-f]{2})+(?:\/(?:[-a-z0-9._~!$&'()*+,;=:@]|%[0-9a-f]{2})*)*)?|(?:[-a-z0-9._~!$&'()*+,;=@]|%[0-9a-f]{2})+(?:\/(?:[-a-z0-9._~!$&'()*+,;=:@]|%[0-9a-f]{2})*)*)?)(?:\?(?:[-a-z0-9._~!$&'()*+,;=:@/?]|%[0-9a-f]{2})*)?(?:#(?:[-a-z0-9._~!$&'()*+,;=:@/?]|%[0-9a-f]{2})*)?$/i;function Bs(e){return c0.test(e)}var p0=/^(?:(?:[^\x00-\x20"<>%\\^`{|}\x7f]|%[0-9a-f]{2})|\{[+#./;?&=,!@|]?(?:[a-z0-9_]|%[0-9a-f]{2})+(?:\.(?:[a-z0-9_]|%[0-9a-f]{2})+)*(?::[1-9]\d{0,3}|\*)?(?:,(?:[a-z0-9_]|%[0-9a-f]{2})+(?:\.(?:[a-z0-9_]|%[0-9a-f]{2})+)*(?::[1-9]\d{0,3}|\*)?)*\})*$/i;function Gs(e){return p0.test(e)}var f0=/^[a-z][a-z0-9+\-.]*:(?:\/\/(?:(?:[-a-z0-9._~!$&'()*+,;=:]|%[0-9a-f]{2})*@)?(?:\[(?:(?:(?:[\da-f]{1,4}:){6}(?:[\da-f]{1,4}:[\da-f]{1,4}|(?:(?:25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)\.){3}(?:25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d))|::(?:[\da-f]{1,4}:){5}(?:[\da-f]{1,4}:[\da-f]{1,4}|(?:(?:25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)\.){3}(?:25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d))|(?:[\da-f]{1,4})?::(?:[\da-f]{1,4}:){4}(?:[\da-f]{1,4}:[\da-f]{1,4}|(?:(?:25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)\.){3}(?:25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d))|(?:(?:[\da-f]{1,4}:){0,1}[\da-f]{1,4})?::(?:[\da-f]{1,4}:){3}(?:[\da-f]{1,4}:[\da-f]{1,4}|(?:(?:25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)\.){3}(?:25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d))|(?:(?:[\da-f]{1,4}:){0,2}[\da-f]{1,4})?::(?:[\da-f]{1,4}:){2}(?:[\da-f]{1,4}:[\da-f]{1,4}|(?:(?:25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)\.){3}(?:25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d))|(?:(?:[\da-f]{1,4}:){0,3}[\da-f]{1,4})?::[\da-f]{1,4}:(?:[\da-f]{1,4}:[\da-f]{1,4}|(?:(?:25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)\.){3}(?:25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d))|(?:(?:[\da-f]{1,4}:){0,4}[\da-f]{1,4})?::(?:[\da-f]{1,4}:[\da-f]{1,4}|(?:(?:25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)\.){3}(?:25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d))|(?:(?:[\da-f]{1,4}:){0,5}[\da-f]{1,4})?::[\da-f]{1,4}|(?:(?:[\da-f]{1,4}:){0,6}[\da-f]{1,4})?::)|v[0-9a-f]+\.[-a-z0-9._~!$&'()*+,;=:]+)\]|(?:(?:25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)\.){3}(?:25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)|(?:[-a-z0-9._~!$&'()*+,;=]|%[0-9a-f]{2})*)(?::\d*)?(?:\/(?:[-a-z0-9._~!$&'()*+,;=:@]|%[0-9a-f]{2})*)*|\/(?:(?:[-a-z0-9._~!$&'()*+,;=:@]|%[0-9a-f]{2})+(?:\/(?:[-a-z0-9._~!$&'()*+,;=:@]|%[0-9a-f]{2})*)*)?|(?:[-a-z0-9._~!$&'()*+,;=:@]|%[0-9a-f]{2})+(?:\/(?:[-a-z0-9._~!$&'()*+,;=:@]|%[0-9a-f]{2})*)*)?(?:\?(?:[-a-z0-9._~!$&'()*+,;=:@/?]|%[0-9a-f]{2})*)?(?:#(?:[-a-z0-9._~!$&'()*+,;=:@/?]|%[0-9a-f]{2})*)?$/i;function Ks(e){return f0.test(e)}function Hs(e){return URL.canParse(e)}var d0=/^[0-9a-f]{8}-(?:[0-9a-f]{4}-){3}[0-9a-f]{12}$/i;function zs(e){return d0.test(e)}var be=new Map;function jd(){be.clear()}function l0(){return[...be.entries()]}function g0(e,t){be.set(e,t)}function y0(e){return be.has(e)}function x0(e){return be.get(e)}function h0(e,t){return be.get(e)?.(t)??!0}function Nd(){jd(),be.set("date-time",$s),be.set("date",Qn),be.set("duration",Es),be.set("email",Ss),be.set("hostname",Os),be.set("idn-email",Ms),be.set("idn-hostname",vs),be.set("ipv4",Fs),be.set("ipv6",Ls),be.set("iri-reference",Ds),be.set("iri",js),be.set("json-pointer-uri-fragment",Ns),be.set("json-pointer",qs),be.set("regex",_s),be.set("relative-json-pointer",Us),be.set("time",Xn),be.set("uri-reference",Bs),be.set("uri-template",Gs),be.set("uri",Ks),be.set("url",Hs),be.set("uuid",zs)}Nd();function Ru(e,t,r,n){return ri.Test(r.format,n)}function qd(e,t,r,n,o,i){return Ru(e,t,o,i)||t.AddError("format",r,n,{format:o.format})}function _d(e,t,r,n){let o=hs(r)?r.then:!0,i=cs(r)?r.else:!0;return te(e,t,r.if,n)?te(e,t,o,n):te(e,t,i,n)}function Ud(e,t,r,n,o,i){let a=hs(o)?o.then:!0,m=cs(o)?o.else:!0,c=new ut,p=ge(e,c,`${r}/if`,n,o.if,i)?ge(e,c,`${r}/then`,n,a,i)||t.AddError("if",r,n,{failingKeyword:"then"}):ge(e,t,`${r}/else`,n,m,i)||t.AddError("if",r,n,{failingKeyword:"else"});return p&&t.Merge([c]),p}function I0(e,t,r,n){return s.Every(r.items,0,(o,i)=>s.IsLessEqualThan(n.length,i)||Ut(e,t,o,n[i])&&t.AddIndex(i))}function b0(e,t,r,n,o,i){return s.EveryAll(o.items,0,(a,m)=>{let c=`${r}/items/${m}`,p=`${n}/${m}`;return s.IsLessEqualThan(i.length,m)||Bt(e,t,c,p,a,i[m])&&t.AddIndex(m)})}function $0(e,t,r,n){let o=Sn(r)?r.prefixItems.length:0;return s.Every(n,o,(i,a)=>Ut(e,t,r.items,i)&&t.AddIndex(a))}function E0(e,t,r,n,o,i){let a=Sn(o)?o.prefixItems.length:0;return s.EveryAll(i,a,(m,c)=>{let p=`${r}/items`,f=`${n}/${c}`;return Bt(e,t,p,f,o.items,m)&&t.AddIndex(c)})}function Bd(e,t,r,n){return fs(r)?I0(e,t,r,n):$0(e,t,r,n)}function Gd(e,t,r,n,o,i){return fs(o)?b0(e,t,r,n,o,i):E0(e,t,r,n,o,i)}function S0(e){return Jr(e)}function Pu(e,t,r,n){if(!S0(r))return!0;let o=s.Counted(n,i=>te(e,t,r.contains,i));return s.IsLessEqualThan(o,r.maxContains)}function Kd(e,t,r,n,o,i){let a=$n(o)?o.minContains:1;return Pu(e,t,o,i)||t.AddError("contains",r,n,{minContains:a,maxContains:o.maxContains})}function Au(e,t,r,n){return s.IsLessEqualThan(n,r.maximum)}function Hd(e,t,r,n,o,i){return Au(e,t,o,i)||t.AddError("maximum",r,n,{comparison:"<=",limit:o.maximum})}function Ou(e,t,r,n){return s.IsLessEqualThan(n.length,r.maxItems)}function zd(e,t,r,n,o,i){return Ou(e,t,o,i)||t.AddError("maxItems",r,n,{limit:o.maxItems})}function Mu(e,t,r,n){return s.IsMaxLength(n,r.maxLength)}function Wd(e,t,r,n,o,i){return Mu(e,t,o,i)||t.AddError("maxLength",r,n,{limit:o.maxLength})}function vu(e,t,r,n){return s.IsLessEqualThan(s.Keys(n).length,r.maxProperties)}function Vd(e,t,r,n,o,i){return vu(e,t,o,i)||t.AddError("maxProperties",r,n,{limit:o.maxProperties})}function k0(e){return Jr(e)}function Fu(e,t,r,n){if(!k0(r))return!0;let o=s.Counted(n,(i,a)=>te(e,t,r.contains,i)&&t.AddIndex(a));return s.IsGreaterEqualThan(o,r.minContains)}function Jd(e,t,r,n,o,i){return Fu(e,t,o,i)||t.AddError("contains",r,n,{minContains:o.minContains})}function Lu(e,t,r,n){return s.IsGreaterEqualThan(n,r.minimum)}function Yd(e,t,r,n,o,i){return Lu(e,t,o,i)||t.AddError("minimum",r,n,{comparison:">=",limit:o.minimum})}function Du(e,t,r,n){return s.IsGreaterEqualThan(n.length,r.minItems)}function Qd(e,t,r,n,o,i){return Du(e,t,o,i)||t.AddError("minItems",r,n,{limit:o.minItems})}function ju(e,t,r,n){return s.IsMinLength(n,r.minLength)}function Xd(e,t,r,n,o,i){return ju(e,t,o,i)||t.AddError("minLength",r,n,{limit:o.minLength})}function Nu(e,t,r,n){return s.IsGreaterEqualThan(s.Keys(n).length,r.minProperties)}function Zd(e,t,r,n,o,i){return Nu(e,t,o,i)||t.AddError("minProperties",r,n,{limit:o.minProperties})}function qu(e,t,r,n){return s.IsMultipleOf(n,r.multipleOf)}function el(e,t,r,n,o,i){return qu(e,t,o,i)||t.AddError("multipleOf",r,n,{multipleOf:o.multipleOf})}function _u(e,t,r,n){let o=new bt;return!te(e,o,r.not,n)&&t.Merge([o])}function tl(e,t,r,n,o,i){return _u(e,t,o,i)||t.AddError("not",r,n,{})}function rl(e,t,r,n){let o=r.oneOf.reduce((i,a)=>{let m=new bt;return te(e,m,a,n)?[...i,m]:i},[]);return s.IsEqual(o.length,1)&&t.Merge(o)}function nl(e,t,r,n,o,i){let a=[],m=[],c=o.oneOf.reduce((f,d,g)=>{let y=new ut,I=`${r}/oneOf/${g}`,h=ge(e,y,I,n,d,i);return h&&m.push(g),h||a.push(y),h?[...f,y]:f},[]),p=s.IsEqual(c.length,1)&&t.Merge(c);return!p&&s.IsEqual(m.length,0)&&a.forEach(f=>t.AddErrors(f.GetErrors())),p||t.AddError("oneOf",r,n,{passingSchemas:m})}function Uu(e,t,r,n){return(s.IsString(r.pattern)?Xr(r.pattern):r.pattern).test(n)}function ol(e,t,r,n,o,i){return Uu(e,t,o,i)||t.AddError("pattern",r,n,{pattern:o.pattern})}function il(e,t,r,n){return s.Every(s.Entries(r.patternProperties),0,([o,i])=>{let a=Xr(o);return s.Every(s.Entries(n),0,([m,c])=>!a.test(m)||Ut(e,t,i,c)&&t.AddKey(m))})}function sl(e,t,r,n,o,i){return s.EveryAll(s.Entries(o.patternProperties),0,([a,m])=>{let c=`${r}/patternProperties/${At(a)}`,p=Xr(a);return s.EveryAll(s.Entries(i),0,([f,d])=>{let g=`${n}/${At(f)}`;return!p.test(f)||Bt(e,t,c,g,m,d)&&t.AddKey(f)})})}function al(e,t,r,n){return s.IsEqual(n.length,0)||s.Every(r.prefixItems,0,(o,i)=>s.IsLessEqualThan(n.length,i)||Ut(e,t,o,n[i])&&t.AddIndex(i))}function ml(e,t,r,n,o,i){return s.IsEqual(i.length,0)||s.EveryAll(o.prefixItems,0,(a,m)=>{let c=`${r}/prefixItems/${m}`,p=`${n}/${m}`;return s.IsLessEqualThan(i.length,m)||Bt(e,t,c,p,a,i[m])&&t.AddIndex(m)})}function Bu(e,t){return e.includes(t)||qe.Get().exactOptionalPropertyTypes}function Gu(e,t){return s.IsUndefined(e[t])}function ul(e,t,r,n){let o=kn(r)?r.required:[];return s.Every(s.Entries(r.properties),0,([a,m])=>{let c=!s.HasPropertyKey(n,a)||Ut(e,t,m,n[a])&&t.AddKey(a);return Bu(o,a)?c:Gu(n,a)||c})}function cl(e,t,r,n,o,i){let a=kn(o)?o.required:[];return s.EveryAll(s.Entries(o.properties),0,([c,p])=>{let f=`${r}/properties/${At(c)}`,d=`${n}/${At(c)}`,g=()=>!s.HasPropertyKey(i,c)||Bt(e,t,f,d,p,i[c])&&t.AddKey(c);return Bu(a,c)?g():Gu(i,c)||g()})}function pl(e,t,r,n){return s.Every(s.Keys(n),0,(o,i)=>te(e,t,r.propertyNames,o))}function fl(e,t,r,n,o,i){let a=[];return s.EveryAll(s.Keys(i),0,(c,p)=>{let f=`${n}/${At(c)}`,d=`${r}/propertyNames`,g=ge(e,t,d,f,o.propertyNames,c);return g||a.push(c),g})||t.AddError("propertyNames",r,n,{propertyNames:a})}function dl(e,t,r,n){let o=Qt.RecursiveRef(e,r)??!1,i=o?{...e,pendingResource:!0}:e;return q(o)&&te(i,t,o,n)}function ll(e,t,r,n,o,i){let a=Qt.RecursiveRef(e,o)??!1,m=a?{...e,pendingResource:!0}:e;return q(a)&&ge(m,t,r,n,a,i)}function gl(e,t,r,n){let o=Qt.Ref(e,r),i=o.schema??!1,a=new bt,m=q(i)&&te(o.stack,a,i,n);return m&&t.Merge([a]),m}function yl(e,t,r,n,o,i){let a=Qt.Ref(e,o),m=a.schema??!1,c=new ut,p=q(m)&&ge(a.stack,c,r,n,m,i);return p&&t.Merge([c]),p||t.AddErrors(c.GetErrors()),p}function xl(e,t,r,n){return s.Every(r.required,0,o=>s.HasPropertyKey(n,o))}function hl(e,t,r,n,o,i){let a=[];return s.EveryAll(o.required,0,c=>{let p=s.HasPropertyKey(i,c);return p||a.push(c),p})||t.AddError("required",r,n,{requiredProperties:a})}function Ku(e,t,r,n,o){return s.IsEqual(r,"object")?s.IsObjectNotArray(o):s.IsEqual(r,"array")?s.IsArray(o):s.IsEqual(r,"boolean")?s.IsBoolean(o):s.IsEqual(r,"integer")?s.IsInteger(o):s.IsEqual(r,"number")?s.IsNumber(o):s.IsEqual(r,"null")?s.IsNull(o):s.IsEqual(r,"string")?s.IsString(o):s.IsEqual(r,"bigint")?s.IsBigInt(o):s.IsEqual(r,"constructor")?s.IsConstructor(o):s.IsEqual(r,"function")?s.IsFunction(o):s.IsEqual(r,"symbol")?s.IsSymbol(o):s.IsEqual(r,"undefined")?s.IsUndefined(o):s.IsEqual(r,"void")?s.IsUndefined(o):!0}function Il(e,t,r,n,o){return s.Some(r,i=>Ku(e,t,i,n,o))}function bl(e,t,r,n){return s.IsArray(r.type)?Il(e,t,r.type,r,n):Ku(e,t,r.type,r,n)}function $l(e,t,r,n,o,i){return(s.IsArray(o.type)?Il(e,t,o.type,o,i):Ku(e,t,o.type,o,i))||t.AddError("type",r,n,{type:o.type})}function El(e,t,r,n){let o=t.GetIndices();return s.Every(n,0,(i,a)=>(o.has(a)||te(e,t,r.unevaluatedItems,i))&&t.AddIndex(a))}function Sl(e,t,r,n,o,i){let a=t.GetIndices(),m=[];return s.EveryAll(i,0,(p,f)=>{let d=new ut,g=(a.has(f)||ge(e,d,r,n,o.unevaluatedItems,p))&&t.AddIndex(f);return g||m.push(f),g})||t.AddError("unevaluatedItems",r,n,{unevaluatedItems:m})}function kl(e,t,r,n){let o=t.GetKeys();return s.Every(s.Entries(n),0,([i,a])=>o.has(i)||te(e,t,r.unevaluatedProperties,a)&&t.AddKey(i))}function Tl(e,t,r,n,o,i){let a=t.GetKeys(),m=[];return s.EveryAll(s.Entries(i),0,([p,f])=>{let d=new ut,g=a.has(p)||ge(e,d,r,n,o.unevaluatedProperties,f)&&t.AddKey(p);return g||m.push(p),g})||t.AddError("unevaluatedProperties",r,n,{unevaluatedProperties:m})}var Dr={};_t(Dr,{Hash:()=>Ol,HashCode:()=>q0});function Re(){throw new Error("Unreachable")}function T0(e){let t=new Set,r=e;for(;r&&r!==Object.prototype;){for(let n of Reflect.ownKeys(r))n!=="constructor"&&typeof n!="symbol"&&t.add(n);r=Object.getPrototypeOf(r)}return[...t]}function w0(e){return typeof e=="number"}var Mt={Array:0,BigInt:1,Boolean:2,Date:3,Constructor:4,Function:5,Null:6,Number:7,Object:8,RegExp:9,String:10,Symbol:11,TypeArray:12,Undefined:13},Vs=8997,ni=33826,Js=40164,Ys=52210,Rl=new Float64Array(1),Pl=new DataView(Rl.buffer),Al=new Uint8Array(Rl.buffer);function Qe(e){let t=Vs^e,r=t*435,n=ni*435+(r>>>16),o=Js*435+(n>>>16)+(t<<8),i=Ys*435+(o>>>16)+(ni<<8);Vs=r&65535,ni=n&65535,Js=o&65535,Ys=i&65535}function C0(e){Qe(Mt.Array);for(let t of e)Zr(t)}function R0(e){Qe(Mt.BigInt),Pl.setBigInt64(0,e);for(let t of Al)Qe(t)}function wl(e){Qe(Mt.Boolean),Qe(e?1:0)}function P0(e){Qe(Mt.Constructor),Zr(e.toString())}function A0(e){Qe(Mt.Date),Zr(e.getTime())}function O0(e){Qe(Mt.Function),Zr(e.toString())}function M0(e){Qe(Mt.Null)}function Cl(e){Qe(Mt.Number),Pl.setFloat64(0,e,!0);for(let t of Al)Qe(t)}function v0(e){Qe(Mt.Object);for(let t of T0(e).sort())Zr(t),Zr(e[t])}function F0(e){Qe(Mt.RegExp),Hu(e.toString())}var L0=new TextEncoder;function Hu(e){Qe(Mt.String);for(let t=0;t<e.length;t++){let r=e.charCodeAt(t);if(r>127){for(let n of L0.encode(e.slice(t)))Qe(n);return}Qe(r)}}function D0(e){Qe(Mt.Symbol),Zr(e.toString())}function j0(e){Qe(Mt.TypeArray);let t=new Uint8Array(e.buffer);for(let r=0;r<t.length;r++)Qe(t[r])}function N0(e){return Qe(Mt.Undefined)}function Zr(e){return Ke.IsTypeArray(e)?j0(e):Ke.IsDate(e)?A0(e):Ke.IsRegExp(e)?F0(e):Ke.IsBoolean(e)?wl(e.valueOf()):Ke.IsString(e)?Hu(e.valueOf()):Ke.IsNumber(e)?Cl(e.valueOf()):w0(e)?Cl(e):s.IsArray(e)?C0(e):s.IsBoolean(e)?wl(e):s.IsBigInt(e)?R0(e):s.IsConstructor(e)?P0(e):s.IsNull(e)?M0(e):s.IsObject(e)?v0(e):s.IsString(e)?Hu(e):s.IsSymbol(e)?D0(e):s.IsUndefined(e)?N0(e):s.IsFunction(e)?O0(e):Re()}function Ws(e){return e.toString(16).padStart(4,"0")}function q0(e){return BigInt(`0x${Ol(e)}`)}function Ol(e){return Vs=8997,ni=33826,Js=40164,Ys=52210,Zr(e),`${Ws(Ys)}${Ws(Js)}${Ws(ni)}${Ws(Vs)}`}function Ml(e){return!s.IsEqual(e.uniqueItems,!1)}function vl(e,t,r,n){if(!Ml(r))return!0;let o=new Set(n.map(Dr.Hash)).size,i=n.length;return s.IsEqual(o,i)}function Fl(e,t,r,n,o,i){if(!Ml(o))return!0;let a=new Set,m=i.reduce((p,f,d)=>{let g=Dr.Hash(f);return a.has(g)?[...p,d]:(a.add(g),p)},[]);return s.IsEqual(m.length,0)||t.AddError("uniqueItems",r,n,{duplicateItems:m})}function Ut(e,t,r,n){return t.Push()&&te(e,t,r,n)&&t.Pop()}function te(e,t,r,n){let o=Jn(e,r);return In(r)?cu(o,t,r,n):(!su(r)||bl(o,t,r,n))&&(!(s.IsObject(n)&&!s.IsArray(n))||(!kn(r)||xl(o,t,r,n))&&(!Yt(r)||jf(o,t,r,n))&&(!Qm(r)||zf(o,t,r,n))&&(!Xm(r)||Vf(o,t,r,n))&&(!ms(r)||Yf(o,t,r,n))&&(!Hn(r)||il(o,t,r,n))&&(!zn(r)||ul(o,t,r,n))&&(!gs(r)||pl(o,t,r,n))&&(!Ko(r)||Nu(o,t,r,n))&&(!ou(r)||vu(o,t,r,n)))&&(!s.IsArray(n)||(!is(r)||Ff(o,t,r,n))&&(!Jr(r)||fu(o,t,r,n))&&(!bn(r)||Bd(o,t,r,n))&&(!$n(r)||Fu(o,t,r,n))&&(!ru(r)||Pu(o,t,r,n))&&(!En(r)||Du(o,t,r,n))&&(!Bo(r)||Ou(o,t,r,n))&&(!Sn(r)||al(o,t,r,n))&&(!Qr(r)||vl(o,t,r,n)))&&(!s.IsString(n)||(!Go(r)||ju(o,t,r,n))&&(!nu(r)||Mu(o,t,r,n))&&(!Uo(r)||Ru(o,t,r,n))&&(!Ho(r)||Uu(o,t,r,n)))&&(!(s.IsNumber(n)||s.IsBigInt(n))||(!vr(r)||Eu(o,t,r,n))&&(!eu(r)||$u(o,t,r,n))&&(!Fr(r)||Lu(o,t,r,n))&&(!tu(r)||Au(o,t,r,n))&&(!iu(r)||qu(o,t,r,n)))&&(!xs(r)||gl(o,t,r,n))&&(!ys(r)||dl(o,t,r,n))&&(!us(r)||sd(o,t,r,n))&&(!Ym(r)||pu(o,t,r,n))&&(!Zm(r)||bu(o,t,r,n))&&(!ps(r)||_d(o,t,r,n))&&(!ds(r)||_u(o,t,r,n))&&(!ss(r)||qf(o,t,r,n))&&(!as(r)||Uf(o,t,r,n))&&(!ls(r)||rl(o,t,r,n))&&(!Wo(r)||!s.IsArray(n)||El(o,t,r,n))&&(!Vo(r)||!s.IsObject(n)||kl(o,t,r,n))&&(!os(r)||Cf(o,t,r,n))}function Bt(e,t,r,n,o,i){return t.Push()&&ge(e,t,r,n,o,i)&&t.Pop()}function ge(e,t,r,n,o,i){if(t.AtCapacity())return!1;let a=Jn(e,o);return In(o)?Gf(a,t,r,n,o,i):!!(+(!su(o)||$l(a,t,r,n,o,i))&+(!(s.IsObject(i)&&!s.IsArray(i))||!!(+(!kn(o)||hl(a,t,r,n,o,i))&+(!Yt(o)||Nf(a,t,r,n,o,i))&+(!Qm(o)||Wf(a,t,r,n,o,i))&+(!Xm(o)||Jf(a,t,r,n,o,i))&+(!ms(o)||Qf(a,t,r,n,o,i))&+(!Hn(o)||sl(a,t,r,n,o,i))&+(!zn(o)||cl(a,t,r,n,o,i))&+(!gs(o)||fl(a,t,r,n,o,i))&+(!Ko(o)||Zd(a,t,r,n,o,i))&+(!ou(o)||Vd(a,t,r,n,o,i))))&+(!s.IsArray(i)||!!(+(!is(o)||Lf(a,t,r,n,o,i))&+(!Jr(o)||Hf(a,t,r,n,o,i))&+(!bn(o)||Gd(a,t,r,n,o,i))&+(!$n(o)||Jd(a,t,r,n,o,i))&+(!ru(o)||Kd(a,t,r,n,o,i))&+(!En(o)||Qd(a,t,r,n,o,i))&+(!Bo(o)||zd(a,t,r,n,o,i))&+(!Sn(o)||ml(a,t,r,n,o,i))&+(!Qr(o)||Fl(a,t,r,n,o,i))))&+(!s.IsString(i)||!!(+(!Go(o)||Xd(a,t,r,n,o,i))&+(!nu(o)||Wd(a,t,r,n,o,i))&+(!Uo(o)||qd(a,t,r,n,o,i))&+(!Ho(o)||ol(a,t,r,n,o,i))))&+(!(s.IsNumber(i)||s.IsBigInt(i))||!!(+(!vr(o)||cd(a,t,r,n,o,i))&+(!eu(o)||ud(a,t,r,n,o,i))&+(!Fr(o)||Yd(a,t,r,n,o,i))&+(!tu(o)||Hd(a,t,r,n,o,i))&+(!iu(o)||el(a,t,r,n,o,i))))&+(!xs(o)||yl(a,t,r,n,o,i))&+(!ys(o)||ll(a,t,r,n,o,i))&+(!us(o)||ad(a,t,r,n,o,i))&+(!Ym(o)||Kf(a,t,r,n,o,i))&+(!Zm(o)||md(a,t,r,n,o,i))&+(!ps(o)||Ud(a,t,r,n,o,i))&+(!ds(o)||tl(a,t,r,n,o,i))&+(!ss(o)||_f(a,t,r,n,o,i))&+(!as(o)||Bf(a,t,r,n,o,i))&+(!ls(o)||nl(a,t,r,n,o,i))&+(!Wo(o)||!s.IsArray(i)||Sl(a,t,r,n,o,i))&+(!Vo(o)||!s.IsObject(i)||Tl(a,t,r,n,o,i)))&&(!os(o)||Rf(a,t,r,n,o,i))}function Dl(e){switch(e.keyword){case"additionalProperties":return"must not have additional properties";case"anyOf":return"must match a schema in anyOf";case"boolean":return"schema is false";case"const":return"must be equal to constant";case"contains":return"must contain at least 1 valid item";case"dependencies":return`must have properties ${e.params.dependencies.join(", ")} when property ${e.params.property} is present`;case"dependentRequired":return`must have properties ${e.params.dependencies.join(", ")} when property ${e.params.property} is present`;case"enum":return"must be equal to one of the allowed values";case"exclusiveMaximum":return`must be ${e.params.comparison} ${e.params.limit}`;case"exclusiveMinimum":return`must be ${e.params.comparison} ${e.params.limit}`;case"format":return`must match format "${e.params.format}"`;case"if":return`must match "${e.params.failingKeyword}" schema`;case"maxItems":return`must not have more than ${e.params.limit} items`;case"maxLength":return`must not have more than ${e.params.limit} characters`;case"maxProperties":return`must not have more than ${e.params.limit} properties`;case"maximum":return`must be ${e.params.comparison} ${e.params.limit}`;case"minItems":return`must not have fewer than ${e.params.limit} items`;case"minLength":return`must not have fewer than ${e.params.limit} characters`;case"minProperties":return`must not have fewer than ${e.params.limit} properties`;case"minimum":return`must be ${e.params.comparison} ${e.params.limit}`;case"multipleOf":return`must be multiple of ${e.params.multipleOf}`;case"not":return"must not be valid";case"oneOf":return"must match exactly one schema in oneOf";case"pattern":return`must match pattern "${e.params.pattern}"`;case"propertyNames":return`property names ${e.params.propertyNames.join(", ")} are invalid`;case"required":return`must have required properties ${e.params.requiredProperties.join(", ")}`;case"type":return typeof e.params.type=="string"?`must be ${e.params.type}`:`must be either ${e.params.type.join(" or ")}`;case"unevaluatedItems":return"must not have unevaluated items";case"unevaluatedProperties":return"must not have unevaluated properties";case"uniqueItems":return"must not have duplicate items";case"~refine":return e.params.message;default:return"an unknown validation error occurred"}}var _0=Dl;function jl(){return _0}var l={};_t(l,{Assign:()=>B0,Clone:()=>G0,Create:()=>H0,Discard:()=>z0,Metrics:()=>ir,Update:()=>Y0});var ir={assign:0,create:0,clone:0,discard:0,update:0};function Gt(e){return[...s.Keys(e),...s.Symbols(e)]}function Nl(e,t){if(!t.has(e)){t.add(e);for(let r of Gt(e)){let n=Object.getOwnPropertyDescriptor(e,r);!n||!("value"in n)||s.IsObject(n.value)&&Nl(n.value,t)}Object.freeze(e)}}function en(e){return qe.Get().immutableTypes&&Nl(e,new WeakSet),e}function B0(e,t){ir.assign+=1;let r={},n=Gt(t),o=Gt(e);for(let i of o)n.includes(i)||Object.defineProperty(r,i,Object.getOwnPropertyDescriptor(e,i));for(let i of n)Object.defineProperty(r,i,Object.getOwnPropertyDescriptor(t,i));return en(r)}function G0(e){ir.clone+=1;let t={};for(let r of Gt(e)){if(s.IsUnsafePropertyKey(r))continue;let n=Object.getOwnPropertyDescriptor(e,r);s.IsEqual(n.enumerable,!0)?t[r]=n.value:Object.defineProperty(t,r,n)}return t}function ql(e,t){return{...e,...t}}function K0(e,t){for(let r of Object.keys(t))Object.defineProperty(e,r,{configurable:!0,writable:!0,enumerable:!1,value:t[r]});return e}function H0(e,t,r={}){ir.create+=1;let n=ql(t,r),o=qe.Get().enumerableKind?ql(n,e):K0(n,e);return en(o)}function z0(e,t){ir.discard+=1;let r={};for(let n of Gt(e)){if(t.includes(n))continue;let o=Object.getOwnPropertyDescriptor(e,n);Object.defineProperty(r,n,o)}return en(r)}function W0(e,t,r,n){for(let o of Gt(e)){if(s.IsUnsafePropertyKey(o)||t.includes(o)||r.includes(o))continue;let i=Object.getOwnPropertyDescriptor(e,o);Object.defineProperty(n,o,i)}}function V0(e,t,r){let n=qe.Get().enumerableKind;for(let o of t)s.IsUnsafePropertyKey(o)||Object.defineProperty(r,o,{configurable:!0,writable:!0,enumerable:n,value:e[o]})}function J0(e,t,r){for(let n of t)s.IsUnsafePropertyKey(n)||Object.defineProperty(r,n,{configurable:!0,enumerable:!0,writable:!0,value:e[n]})}function Y0(e,t,r){ir.update+=1;let n={},o=Gt(t),i=Gt(r);return W0(e,o,i,n),V0(t,o,n),J0(r,i,n),en(n)}function Qs(...e){let[t,r,n]=z.Match(e,{3:(f,d,g)=>[f,d,g],2:(f,d)=>[{},f,d]}),o=Vn(t,r),i=new ut,a=ge(o,i,"#","",r,n),m=i.GetErrors(),c=jl(),p=m.map(f=>({...f,message:c(f)}));return[a,p]}var Ul=0;function Xs(){let e=ns();Ul=e.maxErrors,e.maxErrors=e.maxParseErrors}function Zs(){let e=ns();e.maxErrors=Ul}function Wu(...e){let[t,r,n]=z.Match(e,{3:(a,m,c)=>[a,m,c],2:(a,m)=>[{},a,m]}),o=Vn(t,r),i=new bt;return te(o,i,r,n)}function V(...e){let[t,r,n]=z.Match(e,{3:(o,i,a)=>[o,i,a],2:(o,i)=>[{},o,i]});return Wu(t,r,n)}function sr(...e){let[t,r,n]=z.Match(e,{3:(a,m,c)=>[a,m,c],2:(a,m)=>[{},a,m]}),[o,i]=Qs(t,r,n);return i}var jr=class extends Error{constructor(t,r,n){super(t),Object.defineProperty(this,"cause",{value:{source:t,errors:n,value:r},writable:!1,configurable:!1,enumerable:!1})}};function ea(...e){let[t,r,n]=z.Match(e,{3:(i,a,m)=>[i,a,m],2:(i,a)=>[{},i,a]});if(!V(t,r,n))throw new jr("Assert",n,sr(t,r,n))}function w(e,t){return s.IsObject(e)&&s.HasPropertyKey(e,"~kind")&&s.IsEqual(e["~kind"],t)}function Ee(e){return s.IsObject(e)}function C(e,t,r){return l.Create({"~kind":"Deferred"},{type:"deferred",action:e,parameters:t,options:r},{})}function tn(e){return w(e,"Deferred")}function yr(e,t){return l.Update(e,{"~readonly":!0},t)}function Bl(e,t,r,n){let o=$(e,t,r);return yr(o,n)}function xr(e,t){return l.Update(e,{"~optional":!0},t)}function Gl(e,t,r,n){let o=$(e,t,r);return xr(o,n)}function Tt(e,t){return l.Create({"~kind":"Array"},{type:"array",items:e},t)}function Y(e){return w(e,"Array")}function eo(e){return l.Discard(e,["~kind","type","items"])}function hr(e,t,r={}){return l.Create({"~kind":"Constructor"},{type:"constructor",parameters:e,instanceType:t},r)}function Pe(e){return w(e,"Constructor")}function Kl(e){return l.Discard(e,["~kind","type","parameters","instanceType"])}function Ir(e,t,r={}){return l.Create({"~kind":"Function"},{type:"function",parameters:e,returnType:t},r)}function Ae(e){return w(e,"Function")}function Hl(e){return l.Discard(e,["~kind","type","parameters","returnType"])}function Ye(e,t){return l.Create({"~kind":"Ref"},{$ref:e},t)}function oe(e){return w(e,"Ref")}function rn(e,t){return l.Create({"~kind":"Generic"},{type:"generic",parameters:e,expression:t})}function to(e){return w(e,"Generic")}function ro(e){return l.Create({"~kind":"Any"},{},e)}function Te(e){return w(e,"Any")}var zl="(?!)";function me(e){return l.Create({"~kind":"Never"},{not:{}},e)}function wt(e){return w(e,"Never")}function br(e,t={}){return C("AddOptional",[e],t)}function ta(e,t={}){return xr(e,t)}function Wl(e){return ta(e)}function _e(e){return Ee(e)&&s.HasPropertyKey(e,"~optional")}function Vl(e){return s.Keys(e).filter(t=>!_e(e[t]))}function ra(e){return s.Keys(e)}function na(e){return s.Values(e)}function L(e,t={}){let r=Vl(e),n=r.length>0?{required:r}:{};return l.Create({"~kind":"Object"},{type:"object",...n,properties:e},t)}function M(e){return w(e,"Object")}function Jl(e){return l.Discard(e,["~kind","type","properties","required"])}function He(e){return l.Create({"~kind":"Unknown"},{},e)}function Ue(e){return w(e,"Unknown")}function $r(e,t,r){let n=s.Keys(e).reduce((o,i)=>({...o,[i]:l.Update(e[i],{},{$id:i})}),{});return l.Create({"~kind":"Cyclic"},{$defs:n,$ref:t},r)}function fe(e){return w(e,"Cyclic")}function Yl(e){return l.Update(e,{"~unsafe":null},{})}function oa(e){return s.IsObjectNotArray(e)&&s.HasPropertyKey(e,"~unsafe")&&s.IsNull(e["~unsafe"])}function oi(...e){let[t,r]=z.Match(e,{2:(n,o)=>[n,o,o],1:n=>[n,He(),He()]});return l.Create({"~kind":"Infer"},{type:"infer",name:t,extends:r},{})}function Be(e){return w(e,"Infer")}function wn(e,t,r,n={}){return l.Create({"~kind":"Dependent"},{if:e,then:t,else:r},n)}function Oe(e){return w(e,"Dependent")}function Ql(e){return l.Discard(e,["~kind","if","then","else"])}function Xl(e){return s.IsObjectNotArray(e)}function Zl(e){return s.Keys(e).filter(r=>isNaN(r)).reduce((r,n)=>[...r,e[n]],[])}function eg(e){return s.IsString(e)||s.IsNumber(e)}function tg(e,t){let r=Xl(e)?Zl(e):e;return l.Create({"~kind":"Enum"},{enum:r},t)}function Me(e){return w(e,"Enum")}function lt(e,t={}){return l.Create({"~kind":"Intersect"},{allOf:e},t)}function v(e){return w(e,"Intersect")}function rg(e){return l.Discard(e,["~kind","allOf"])}var ii=class{constructor(t,r){this.type=t,this.decode=r}Encode(t){let r=this.type,n=$t(r)?a=>this.decode(r["~codec"].decode(a)):this.decode,o=$t(r)?a=>r["~codec"].encode(t(a)):t,i={decode:n,encode:o};return l.Update(this.type,{"~codec":i},{})}},si=class{constructor(t){this.type=t}Decode(t){return new ii(this.type,t)}};function ia(e){return new si(e)}function ng(e,t){return ia(e).Decode(t).Encode(()=>{throw Error("Encode not implemented")})}function og(e,t){return ia(e).Decode(()=>{throw Error("Decode not implemented")}).Encode(t)}function $t(e){return Ee(e)&&s.HasPropertyKey(e,"~codec")&&s.IsObject(e["~codec"])&&s.HasPropertyKey(e["~codec"],"encode")&&s.HasPropertyKey(e["~codec"],"decode")}function ig(e){return no(e)}function Cn(e){return Ee(e)&&s.HasPropertyKey(e,"~immutable")}function Er(e,t={}){return C("AddReadonly",[e],t)}function sa(e,t={}){return yr(e,t)}function sg(e){return sa(e)}function Nr(e){return Ee(e)&&s.HasPropertyKey(e,"~readonly")}function Z0(e,t){let r=ai(e)?[...e["~refine"],t]:[t];return l.Update(e,{"~refine":r},{})}function ag(...e){let[t,r,n]=z.Match(e,{3:(o,i,a)=>[o,i,a],2:(o,i)=>[o,i,()=>"Refine Error"]});return Z0(t,{check:r,error:n})}function eP(e){return s.IsObjectNotArray(e)&&s.HasPropertyKey(e,"check")&&s.HasPropertyKey(e,"error")&&s.IsFunction(e.check)&&s.IsFunction(e.error)}function ai(e){return Ee(e)&&s.HasPropertyKey(e,"~refine")&&s.IsArray(e["~refine"])&&s.Every(e["~refine"],0,t=>eP(t))}var mg="-?(?:0|[1-9][0-9]*)n";function mi(e){return l.Create({"~kind":"BigInt"},{type:"bigint"},e)}function vt(e){return w(e,"BigInt")}function aa(e){return l.Create({"~kind":"Boolean"},{type:"boolean"},e)}function Et(e){return w(e,"Boolean")}function ui(e){return l.Create({"~kind":"Identifier"},{name:e})}function ug(e){return w(e,"Identifier")}var ma="-?(?:0|[1-9][0-9]*)";function Rn(e){return l.Create({"~kind":"Integer"},{type:"integer"},e)}function Xe(e){return w(e,"Integer")}var Vu=class extends Error{constructor(t){super("Invalid Literal value"),Object.defineProperty(this,"cause",{value:{value:t},writable:!1,configurable:!1,enumerable:!1})}};function tP(e){return s.IsBigInt(e)?"bigint":s.IsBoolean(e)?"boolean":s.IsNumber(e)?"number":s.IsString(e)?"string":(()=>{throw new Vu(e)})()}function W(e,t){return l.Create({"~kind":"Literal"},{type:tP(e),const:e},t)}function ua(e){return s.IsBigInt(e)||s.IsBoolean(e)||s.IsNumber(e)||s.IsString(e)}function cg(e){return J(e)&&s.IsBigInt(e.const)}function pg(e){return J(e)&&s.IsBoolean(e.const)}function ca(e){return J(e)&&s.IsNumber(e.const)}function pa(e){return J(e)&&s.IsString(e.const)}function J(e){return w(e,"Literal")}function oo(e){return l.Create({"~kind":"Null"},{type:"null"},e)}function Sr(e){return w(e,"Null")}var fa="-?(?:0|[1-9][0-9]*)(?:\\.[0-9]+)?";function Ft(e){return l.Create({"~kind":"Number"},{type:"number"},e)}function Se(e){return w(e,"Number")}function io(e){return l.Create({"~kind":"Symbol"},{type:"symbol"},e)}function kr(e){return w(e,"Symbol")}function Pn(...e){let[t,r,n]=z.Match(e,{3:(o,i,a)=>[o,i,a],2:(o,i)=>[o,i,i],1:o=>[o,He(),He()]});return l.Create({"~kind":"Parameter"},{name:t,extends:r,equals:n},{})}function fg(e){return w(e,"Parameter")}var da=".*";function ct(e){return l.Create({"~kind":"String"},{type:"string"},e)}function ze(e){return w(e,"String")}function _(e,t={}){return l.Create({"~kind":"Union"},{anyOf:e},t)}function S(e){return w(e,"Union")}function dg(e){return l.Discard(e,["~kind","anyOf"])}function ci(e){let t=lg(e);return s.IsEqual(t.length,2)?t[0]:[]}function rP(e){return!0}function gg(e){return s.ShiftLeft(e,(t,r)=>nP(t)?gg(r):!1,()=>!0)}function yg(e){return s.IsEqual(e.length,0)?!1:gg(e)}function nP(e){return S(e)?yg(e.anyOf):J(e)?rP(e.const):!1}function la(e){return yg(e)}function ga(e){return l.Create({"~kind":"TemplateLiteral"},{type:"string",pattern:e},{})}function xg(e,t,r=[]){return s.ShiftLeft(e,(n,o)=>xg(o,t,[...r,`${n}${t}`]),()=>r)}function oP(e,t){return s.IsEqual(e.length,0)?[`${t}`]:xg(e,t)}function hg(e,t,r=[]){return s.ShiftLeft(t,(n,o)=>hg(e,o,[...r,...Ig(e,n)]),()=>r)}function Ig(e,t){return S(t)?hg(e,t.anyOf):J(t)?oP(e,t.const):Re()}function bg(e,t){return s.ShiftLeft(t,(r,n)=>bg(Ig(e,r),n),()=>e)}function iP(e){return e.map(t=>W(t))}function sP(e){let t=bg([],e),r=iP(t);return _(r)}function aP(e){return s.IsEqual(e.length,0)?Re():s.IsEqual(e.length,1)&&J(e[0])?e[0]:sP(e)}function Ju(e){let t=ci(e);return s.IsEqual(t.length,0)?ct():la(t)?aP(t):ga(e)}function so(e){let t=Ju(e);return de(t)?ct():t}function Ct(e,t){let r="object",n={[e]:t};return l.Create({"~kind":"Record"},{type:r,patternProperties:n})}function $g(e){return Ct(ar,e)}function Eg(e){return L({true:e,false:e})}function ve(e,t={}){let[r,n,o]=[e,e.length,!1];return l.Create({"~kind":"Tuple"},{type:"array",additionalItems:o,items:r,minItems:n},t)}function G(e){return w(e,"Tuple")}function Sg(e){return l.Discard(e,["~kind","type","items","minItems","additionalItems"])}function Yu(e){return e.reduceRight((r,n,o)=>({[o]:n,...r}),{})}function kg(e){let t=Yu(e.items);return L(t)}function mP(e){return l.Discard(e,["~optional"])}function An(e,t){return l.Update(mP(e),{},t)}function Tg(e,t,r,n){let o=$(e,t,r);return An(o,n)}function uP(e){return l.Discard(e,["~readonly"])}function ao(e,t){return l.Update(uP(e),{},t)}function wg(e,t,r,n){let o=$(e,t,r);return ao(o,n)}function ya(e,t){let r=Nr(e)&&Nr(t),n=_e(e)&&_e(t),o=Fe([e,t]),i=ao(An(o,{}),{});return r&&n?yr(xr(i,{}),{}):r?yr(i,{}):n?xr(i,{}):i}function Cg(e,t){let r=Nr(e)||Nr(t),n=_e(e)||_e(t),o=ao(An(e,{}),{}),i=ao(An(t,{}),{}),a=Rt([o,i]);return r&&n?yr(xr(a,{}),{}):r?yr(a,{}):n?xr(a,{}):a}function cP(e,t,r){return r in e?r in t?ya(e[r],t[r]):e[r]:r in t?t[r]:me()}function pP(e,t){return[...new Set([...s.Keys(e),...s.Keys(t)])].reduce((o,i)=>({...o,[i]:cP(e,t,i)}),{})}function Rg(e){return M(e)?e.properties:G(e)?Yu(e.items):{}}function Pg(e,t){let r=Rg(e),n=Rg(t),o=pP(r,n);return L(o)}function fP(e,t){let r=mo(e,t);return s.IsEqual(r,fi)?e:s.IsEqual(r,di)||s.IsEqual(r,pi)?t:me()}function Ag(e){return M(e)||G(e)}function dP(e,t){let r=Ag(e),n=Ag(t);return r&&n?Pg(e,t):r&&!n?e:!r&&n?t:fP(e,t)}function Og(e,t){return wt(e)||Te(e)?e:Ue(e)||wt(t)||Te(t)?t:Ue(t)?e:dP(e,t)}function lP(e,t){return S(e)||S(t)}function gP(e,t){let r=Xt(e),n=Xt(t);return lP(r,n)?Fe([r,n]):Og(r,n)}function Mg(e,t,r=[]){return s.ShiftLeft(t,(n,o)=>Mg(e,o,[...r,gP(n,e)]),()=>s.IsEqual(r.length,0)?[e]:r)}function vg(e,t,r=[]){return s.ShiftLeft(e,(n,o)=>vg(o,t,[...r,...li([n],t)]),()=>r)}function li(e,t=[]){return s.ShiftLeft(e,(r,n)=>S(r)?li(n,vg(r.anyOf,t)):li(n,Mg(r,t)),()=>t)}function yP(e,t){let r=pt({},e,t);return N.IsExtendsTrueLike(r)?[]:[e]}function Fg(e,t,r=[]){return s.ShiftLeft(e,(n,o)=>Fg(o,t,[...r,...yP(n,t)]),()=>r)}function xa(e,t){let r=Xt(e),n=S(r)?r.anyOf:[r],o=Fg(n,t);return Rt(o)}function mr(e,t,r){let n=Fe([e,t]),o=xa(r,e);return Rt([n,o])}function St(e,t=[]){return s.ShiftLeft(e,(r,n)=>St(n,[...t,W(r)]),()=>Rt(t))}function Fe(e){let t=li(e),r=Qu(t);return Rt(r)}function gt(e){let t=so(e);return Xt(t)}function Rt(e){let t=Qu(e);return nn(t)}function Xt(e){return Oe(e)?mr(e.if,e.then,e.else):Me(e)?St(e.enum):v(e)?Fe(e.allOf):de(e)?gt(e.pattern):S(e)?Rt(e.anyOf):e}function nn(e){return s.IsEqual(e.length,1)?e[0]:s.IsEqual(e.length,0)?me():_(e)}function Lg(e,t){let r=St(e);return on(r,t)}function Dg(e,t){return Ct(sn,t)}function jg(e,t){let r=Fe(e);return on(r,t)}function Ng(e,t){return s.IsString(e)||s.IsNumber(e)?L({[e]:t}):s.IsEqual(e,!1)?L({false:t}):s.IsEqual(e,!0)?L({true:t}):L({})}function qg(e,t){return Ct(uo,t)}function _g(e,t){return s.HasPropertyKey(e,"pattern")&&(s.IsString(e.pattern)||e.pattern instanceof RegExp)?Ct(e.pattern.toString(),t):Ct(ar,t)}function Ug(e,t){let r=ci(e);return la(r)?on(gt(e),t):Ct(e,t)}function xP(e){return S(e)?an(e.anyOf):[e]}function an(e,t=[]){return s.ShiftLeft(e,(r,n)=>an(n,[...t,...xP(r)]),()=>t)}function hP(e){return e.some(t=>ze(t)||Se(t)||Xe(t))}function IP(e,t){return s.IsEqual(hP(e),!0)?Ct(ar,t):void 0}function bP(e,t){return e.reduce((r,n)=>J(n)&&(s.IsString(n.const)||s.IsNumber(n.const))?{...r,[n.const]:t}:r,{})}function $P(e,t){let r=bP(e,t);return L(r)}function Bg(e,t){let r=an(e),n=IP(r,t);return Ee(n)?n:$P(r,t)}function on(e,t){return Te(e)?$g(t):Et(e)?Eg(t):Me(e)?Lg(e.enum,t):Xe(e)?Dg(e,t):v(e)?jg(e.allOf,t):J(e)?Ng(e.const,t):Se(e)?qg(e,t):S(e)?Bg(e.anyOf,t):ze(e)?_g(e,t):de(e)?Ug(e.pattern,t):L({})}function Xu(e,t,r){return K([e])?l.Update(on(e,t),{},r):ha(e,t,r)}function Gg(e,t,r,n,o){let i=$(e,t,r),a=$(e,t,n);return Xu(i,a,o)}var sn=`^${ma}$`,uo=`^${fa}$`,ar=`^${da}$`;function ha(e,t,r={}){return C("Record",[e,t],r)}function co(e,t,r={}){return Xu(e,t,r)}function Kg(e,t){return Ct(e,t)}function Ia(e){return s.IsEqual(e,ar)?ct():s.IsEqual(e,sn)?Rn():s.IsEqual(e,uo)?Ft():Ju(e)}function Ge(e){return s.Keys(e.patternProperties)[0]}function po(e){let t=Ge(e);return Ia(t)}function ye(e){return e.patternProperties[Ge(e)]}function se(e){return w(e,"Record")}function On(e){return l.Create({"~kind":"Rest"},{type:"rest",items:e},{})}function mn(e){return w(e,"Rest")}function ba(e){return l.Create({"~kind":"This"},{$ref:"#"},e)}function $a(e){return w(e,"This")}function fo(e){return l.Create({"~kind":"Undefined"},{type:"undefined"},e)}function Zt(e){return w(e,"Undefined")}function Ea(e){return l.Create({"~kind":"Void"},{type:"void"},e)}function Lt(e){return w(e,"Void")}function SP(e,t){return s.IsEqual(e,"Array")?Tt(t[0]):s.IsEqual(e,"Capitalize")?ka(t[0]):s.IsEqual(e,"ConstructorParameters")?Pa(t[0]):s.IsEqual(e,"Evaluate")?Wx(t[0]):s.IsEqual(e,"Exclude")?Aa(t[0],t[1]):s.IsEqual(e,"Extract")?Oa(t[0],t[1]):s.IsEqual(e,"Index")?hi(t[0],t[1]):s.IsEqual(e,"InstanceType")?Ma(t[0]):s.IsEqual(e,"Lowercase")?Ta(t[0]):s.IsEqual(e,"NonNullable")?va(t[0]):s.IsEqual(e,"Omit")?Fa(t[0],t[1]):s.IsEqual(e,"Parameters")?La(t[0]):s.IsEqual(e,"Partial")?Da(t[0]):s.IsEqual(e,"Pick")?ja(t[0],t[1]):s.IsEqual(e,"Readonly")?Na(t[0]):s.IsEqual(e,"KeyOf")?Ii(t[0]):s.IsEqual(e,"Record")?ha(t[0],t[1]):s.IsEqual(e,"Required")?qa(t[0]):s.IsEqual(e,"ReturnType")?_a(t[0]):s.IsEqual(e,"Uncapitalize")?wa(t[0]):s.IsEqual(e,"Uppercase")?Ca(t[0]):xi(Ye(e),t)}function Mn(){throw Error("Unreachable")}function Jg(e,t=[]){return s.ShiftLeft(e,(r,n)=>Jg(n,[...t,r[1]]),()=>t)}function qr(e){return s.IsEqual(e.length,3)?[e[0],...Jg(e[1])]:[]}function Yg(e){return Pn(e[0],e[2],e[4])}function Qg(e){return Pn(e[0],e[2],e[2])}function Xg(e){return Pn(e[0],He(),e[2])}function Zg(e){return Pn(e,He(),He())}function ey(e){return qr(e)}function ty(e){return e[1]}function ry(e){return qr(e)}function ny(e){return e[1]}function oy(e){return SP(e[0],e[1])}function iy(e){return null}function sy(e){return ct()}function ay(e){return Ft()}function my(e){return aa()}function uy(e){return fo()}function cy(e){return oo()}function py(e){return Rn()}function fy(e){return mi()}function dy(e){return He()}function ly(e){return ro()}function gy(e){return L({})}function yy(e){return me()}function xy(e){return io()}function hy(e){return Ea()}function Iy(e){return ba()}function by(e){return W(BigInt(e))}function $y(e){return W(s.IsEqual(e,"true"))}function Ey(e){return W(parseFloat(e))}function Sy(e){return W(e)}function ky(e){return e[1]}function Ty(e){return W(e)}function wy(e){return s.IsEqual(e.length,3)?[e[0],e[1],...e[2]]:[e[0]]}function Cy(e){return e[1]}function Ry(e){return Sa(e)}function Py(e){return s.IsEqual(e.length,6)?wn(e[1],e[3],e[5]):wn(e[1],e[3],He())}function Ay(e){return e.length>0}function Oy(e){return e.reduce((t,r)=>s.IsEqual(r.length,3)?[...t,[r[1]]]:[...t,[]],[])}function My(e){return s.IsEqual(e.length,6)?[e[1],e[3],e[5]]:[]}function vy(e){return s.IsArray(e)&&s.IsEqual(e.length,3)?e[1]:e}function Fy(e){return s.IsEqual(e.length,2)?e[1]:[]}function Hg(e,t){return t.reduce((r,n)=>{let o=n;return s.IsEqual(o.length,1)?hi(r,o[0]):s.IsEqual(o.length,0)?Tt(r):Mn()},e)}function zg(e,t){return s.IsEqual(t.length,3)?Ra(e,t[0],t[1],t[2]):e}function kP(e,t){return s.IsArray(t)&&s.IsEqual(t.length,0)?e:Ua(e,t)}function Ly(e){let[t,r,n,o,i]=e;return kP(zg(t?Ii(Hg(r,n)):Hg(r,n),o),i)}function Zu(e,t){return s.IsEqual(t.length,3)?(()=>{let[r,n,o]=t,i=Zu(n,o);if(s.IsEqual(r,"&"))return v(i)?lt([e,...i.allOf]):lt([e,i]);if(s.IsEqual(r,"|"))return S(i)?_([e,...i.anyOf]):_([e,i]);Mn()})():e}function Dy(e){let[t,r]=e;return Zu(t,r)}function jy(e){let[t,r]=e;return Zu(t,r)}function Ny(e){return Hx(e[1])}function qy(e){return e[1]}function _y(e){return rn(e[0],e[2])}function Uy(e){return s.IsEqual(e.length,4)?oi(e[1],e[3]):s.IsEqual(e.length,2)?oi(e[1],He()):Mn()}function By(e){return`${e}`}function Gy(e){return Xe(e[3])?sn:Se(e[3])?uo:kr(e[3])?ar:ze(e[3])?ar:Mn()}function Ky(e){return e.length>0}function Hy(e){return e.length>0}function zy(e){let[t,r,n,o,i]=e;return{[r]:t&&n?Er(br(i)):t&&!n?Er(i):!t&&n?br(i):i}}function Wy(e){return qr(e)}function Vy(e){return e.reduce((t,r)=>s.HasPropertyKey(r,sn)||s.HasPropertyKey(r,uo)||s.HasPropertyKey(r,ar)?[t[0],l.Assign(t[1],r)]:[l.Assign(t[0],r),t[1]],[{},{}])}function Jy(e){return Vy(e[1])}function Yy(e){let[t,r]=e,n=s.IsEqual(s.Keys(r).length,0)?{}:{patternProperties:r};return L(t,n)}function Qy(e){return s.IsEqual(e.length,5)?Er(br(e[4])):s.IsEqual(e.length,3)?e[2]:s.IsEqual(e.length,4)?s.IsEqual(e[2],"readonly")?Er(e[3]):br(e[3]):Mn()}function Xy(e){if(!s.IsArray(e)||!s.IsEqual(e.length,3))return e;let[t,r,n]=e;return t&&n?Er(br(r)):t&&!n?Er(r):!t&&n?br(r):r}function Zy(e){return s.IsEqual(e.length,2)?On(e[1]):s.IsEqual(e.length,1)?e[0]:Mn()}function ex(e){return qr(e)}function tx(e){return ve(e[1])}function rx(e){return Er(br(e[4]))}function nx(e){return Er(e[3])}function ox(e){return br(e[3])}function ix(e){return e[2]}function sx(e){return s.IsEqual(e.length,2)?On(e[1]):s.IsEqual(e.length,1)?e[0]:Mn()}function ax(e){return qr(e)}function mx(e){return Ir(e[1],e[4])}function ux(e){return hr(e[2],e[5])}function Wg(e,t){return s.IsEqual(e,"remove")?zx(t):s.IsEqual(e,"add")?Er(t):t}function cx(e){return s.IsEqual(e.length,2)&&s.IsEqual(e[0],"-")?"remove":s.IsEqual(e.length,2)&&s.IsEqual(e[0],"+")||s.IsEqual(e.length,1)?"add":"none"}function Vg(e,t){return s.IsEqual(e,"remove")?Kx(t):s.IsEqual(e,"add")?br(t):t}function px(e){return s.IsEqual(e.length,2)&&s.IsEqual(e[0],"-")?"remove":s.IsEqual(e.length,2)&&s.IsEqual(e[0],"+")||s.IsEqual(e.length,1)?"add":"none"}function fx(e){return s.IsEqual(e.length,2)?[e[1]]:[]}function dx(e){return s.IsArray(e[6])&&s.IsEqual(e[6].length,1)?gi(ui(e[3]),e[5],e[6][0],Wg(e[1],Vg(e[8],e[10]))):gi(ui(e[3]),e[5],Ye(e[3]),Wg(e[1],Vg(e[8],e[10])))}function lx(e){return Ye(e)}function gx(e){return BigInt(e)}function yx(e){return parseFloat(e)}function xx(e){return s.IsEqual(e,"true")}function hx(e){return null}function Ix(e){return{[e[0]]:e[2]}}function bx(e){return qr(e)}function TP(e){return e.reduce((t,r)=>l.Assign(t,r),{})}function $x(e){return TP(e[1])}function Ex(e){return qr(e)}function Sx(e){return e[1]}function kx(e){return mi()}function Tx(e){return ct()}function wx(e){return Ft()}function Cx(e){return Rn()}function Rx(e){return me()}function Px(e){return W(e)}function Ax(e){return _(e[1])}function Ox(e){return e.length===3?[...e[0],...e[2]]:e.length===1?[...e[0]]:[]}function Mx(e){return[e[0],...e[1]]}function vx(e){return e[1]}function Fx(e){return qr(e)}function Lx(e){return s.IsEqual(e.length,2)?e[1]:[]}function Dx(e){let t=e[2],r=e[3],[n,o]=e[4],i=s.IsEqual(s.Keys(o).length,0)?{}:{patternProperties:o};return{[e[1]]:rn(t,yi(r,n,i))}}function jx(e){let t=e[2],[r,n]=e[3],o=s.IsEqual(s.Keys(n).length,0)?{}:{patternProperties:n};return{[e[1]]:yi(t,r,o)}}function Nx(e){return{[e[1]]:rn(e[2],e[4])}}function qx(e){return{[e[1]]:e[3]}}function _x(e){return null}function Ux(e){return qr(e)}function Bx(e){return e[1]}function Gx(e){let[t,r]=[e[0],e[1]];return Vx(l.Assign(t,Vy(r)[0]))}function bi(e){return ee(e.length,2)}function X(e,t,r){return bi(e)?t(e[0],e[1]):r()}function RP(e,t){return ee(t.indexOf(e),0)?[e,t.slice(e.length)]:[]}function we(e,t){for(let r=0;r<e.length;r++){let n=RP(e[r],t);if(bi(n))return n}return[]}function ec(e,t){return Array.from({length:t-e+1},(r,n)=>String.fromCharCode(e+n))}var Jx=[...ec(97,122),...ec(65,90)],tc="0",rc=ec(49,57),lo=[tc,...rc],Yx=" ",go=`
2
- `;var un="_",Ba=".",Qx="$",Ga="-";var Xx="//",Zx="/*",AP="*/";function eh(e){let t=e.indexOf(AP);return ee(t,-1)?"":e.slice(t+2)}function th(e){let t=e.indexOf(go);return ee(t,-1)?"":e.slice(t)}function OP(e){return e.replace(/^[ \t\r\f\v]+/,"")}function Ka(e){let t=OP(e);return t.startsWith(Zx)?Ka(eh(t.slice(2))):t.startsWith(Xx)?Ka(th(t.slice(2))):t}function st(e){let t=e.trimStart();return t.startsWith(Zx)?st(eh(t.slice(2))):t.startsWith(Xx)?st(th(t.slice(2))):t}function Ha(e,t){return X(we([e],t),(r,n)=>[r,n],()=>["",t])}function MP(e,t){return e.includes(t)}function yo(e,t,r,n=""){return X(we(e,r),(o,i)=>MP(t,o)?yo(e,t,i,n):yo(e,t,i,`${n}${o}`),()=>[n,r])}function vP(e){return we(rc,e)}var FP=[...lo,un];function LP(e){return yo(FP,[un],e)}function DP(e){return X(we([tc],e),(t,r)=>[t,r],()=>X(vP(e),(t,r)=>X(LP(r),(n,o)=>[`${t}${n}`,o],()=>[]),()=>[]))}function za(e){return DP(st(e))}function jP(e){return Ha(Ga,e)}function NP(e){return X(jP(e),(t,r)=>X(za(r),(n,o)=>[`${t}${n}`,o],()=>[]),()=>[])}function rh(e){return NP(st(e))}function qP(e){return X(rh(e),(t,r)=>X(we(["n"],r),(n,o)=>[`${t}`,o],()=>[]),()=>[])}function nc(e){return qP(e)}function oc(e,t){return we([e],t)}function x(e,t){return ee(e,"")?["",t]:e.startsWith(go)?oc(e,Ka(t)):e.startsWith(Yx)?oc(e,t):oc(e,st(t))}var nh=[...Jx,un,Qx];function _P(e){return we(nh,e)}var UP=[...nh,...lo];function oh(e,t=""){return X(we(UP,e),(r,n)=>oh(n,`${t}${r}`),()=>[t,e])}function BP(e){return X(_P(e),(t,r)=>X(oh(r),(n,o)=>[`${t}${n}`,o],()=>[]),()=>[])}function Le(e){return BP(st(e))}var GP=[...lo,un];function KP(e){return bi(we([Ba],e))}function ih(e){return X(yo(GP,[un],e),(t,r)=>ee(t,"")?[]:[t,r],()=>[])}function HP(e){return X(we([Ba],e),(t,r)=>X(ih(r),(n,o)=>[`0${t}${n}`,o],()=>[]),()=>[])}function zP(e){return X(za(e),(t,r)=>X(we([Ba],r),(n,o)=>X(ih(o),(i,a)=>[`${t}${n}${i}`,a],()=>[`${t}`,o]),()=>[`${t}`,r]),()=>[])}function WP(e){return KP(e)?HP(e):zP(e)}function sh(e){return WP(st(e))}function VP(e){return Ha(Ga,e)}function JP(e){return X(VP(e),(t,r)=>X(sh(r),(n,o)=>[`${t}${n}`,o],()=>[]),()=>[])}function Wa(e){return JP(st(e))}function YP(e){return ee(e,"")?[]:[e.slice(0,1),e.slice(1)]}function ah(e,t){return rs(e,(r,n)=>t.startsWith(r)?!0:ah(n,t),()=>!1)}function cn(e,t,r=""){return X(YP(t),(n,o)=>ah(e,t)?[r,t]:cn(e,o,`${r}${n}`),()=>[])}function QP(e,t,r){return X(we([e],r),(n,o)=>X(cn([t],o),(i,a)=>X(we([t],a),(m,c)=>[`${i}`,c],()=>[]),()=>[]),()=>[])}function XP(e,t,r){return X(we([e],r),(n,o)=>X(cn([go,t],o),(i,a)=>X(we([t],a),(m,c)=>[`${i}`,c],()=>[]),()=>[]),()=>[])}function mh(e,t,r,n){return r?QP(e,t,st(n)):XP(e,t,st(n))}function ZP(e,t){return we(e,t)}function eA(e,t){return mh(e,e,!1,t)}function tA(e,t){return X(ZP(e,t),(r,n)=>eA(r,`${r}${n}`),()=>[])}function Va(e,t){return tA(e,st(t))}function uh(e,t){return X(cn(e,t),(r,n)=>ee(r,"")?[]:[r,n],()=>[])}var u=(e,t,r=()=>[])=>e.length===2?t(e):r(),nA=e=>u(u(Le(e),([t,r])=>u(x("extends",r),([n,o])=>u(re(o),([i,a])=>u(x("=",a),([m,c])=>u(re(c),([p,f])=>[[t,n,i,m,p],f]))))),([t,r])=>[Yg(t),r]),oA=e=>u(u(Le(e),([t,r])=>u(x("extends",r),([n,o])=>u(re(o),([i,a])=>[[t,n,i],a]))),([t,r])=>[Qg(t),r]),iA=e=>u(u(Le(e),([t,r])=>u(x("=",r),([n,o])=>u(re(o),([i,a])=>[[t,n,i],a]))),([t,r])=>[Xg(t),r]),sA=e=>u(Le(e),([t,r])=>[Zg(t),r]),fh=e=>u(u(nA(e),([t,r])=>[t,r],()=>u(oA(e),([t,r])=>[t,r],()=>u(iA(e),([t,r])=>[t,r],()=>u(sA(e),([t,r])=>[t,r],()=>[])))),([t,r])=>[t,r]),dh=(e,t=[])=>u(u(x(",",e),([r,n])=>u(fh(n),([o,i])=>[[r,o],i])),([r,n])=>dh(n,[...t,r]),()=>[t,e]),aA=e=>u(u(u(fh(e),([t,r])=>u(dh(r),([n,o])=>u(u(x(",",o),([i,a])=>[[i],a],()=>[[],o]),([i,a])=>[[t,n,i],a]))),([t,r])=>[t,r],()=>u([[],e],([t,r])=>[t,r],()=>[])),([t,r])=>[ey(t),r]),ac=e=>u(u(x("<",e),([t,r])=>u(aA(r),([n,o])=>u(x(">",o),([i,a])=>[[t,n,i],a]))),([t,r])=>[ty(t),r]),lh=(e,t=[])=>u(u(x(",",e),([r,n])=>u(re(n),([o,i])=>[[r,o],i])),([r,n])=>lh(n,[...t,r]),()=>[t,e]),mA=e=>u(u(u(re(e),([t,r])=>u(lh(r),([n,o])=>u(u(x(",",o),([i,a])=>[[i],a],()=>[[],o]),([i,a])=>[[t,n,i],a]))),([t,r])=>[t,r],()=>u([[],e],([t,r])=>[t,r],()=>[])),([t,r])=>[ry(t),r]),uA=e=>u(u(x("<",e),([t,r])=>u(mA(r),([n,o])=>u(x(">",o),([i,a])=>[[t,n,i],a]))),([t,r])=>[ny(t),r]),cA=e=>u(u(Le(e),([t,r])=>u(uA(r),([n,o])=>[[t,n],o])),([t,r])=>[oy(t),r]),gh=e=>u(u(u(x(";",e),([t,r])=>[[t],r]),([t,r])=>[t,r],()=>u([[],e],([t,r])=>[t,r],()=>[])),([t,r])=>[iy(t),r]),yh=e=>u(x("string",e),([t,r])=>[sy(t),r]),xh=e=>u(x("number",e),([t,r])=>[ay(t),r]),pA=e=>u(x("boolean",e),([t,r])=>[my(t),r]),fA=e=>u(x("undefined",e),([t,r])=>[uy(t),r]),dA=e=>u(x("null",e),([t,r])=>[cy(t),r]),hh=e=>u(x("integer",e),([t,r])=>[py(t),r]),lA=e=>u(x("bigint",e),([t,r])=>[fy(t),r]),gA=e=>u(x("unknown",e),([t,r])=>[dy(t),r]),yA=e=>u(x("any",e),([t,r])=>[ly(t),r]),xA=e=>u(x("object",e),([t,r])=>[gy(t),r]),hA=e=>u(x("never",e),([t,r])=>[yy(t),r]),Ih=e=>u(x("symbol",e),([t,r])=>[xy(t),r]),IA=e=>u(x("void",e),([t,r])=>[hy(t),r]),bA=e=>u(x("this",e),([t,r])=>[Iy(t),r]),$A=e=>u(u(x("${",e),([t,r])=>u(re(r),([n,o])=>u(x("}",o),([i,a])=>[[t,n,i],a]))),([t,r])=>[ky(t),r]),ic=e=>u(cn(["${","`"],e),([t,r])=>[Ty(t),r]),bh=e=>u(u(u(ic(e),([t,r])=>u($A(r),([n,o])=>u(bh(o),([i,a])=>[[t,n,i],a]))),([t,r])=>[t,r],()=>u(u(ic(e),([t,r])=>[[t],r]),([t,r])=>[t,r],()=>u(u(ic(e),([t,r])=>[[t],r]),([t,r])=>[t,r],()=>[]))),([t,r])=>[wy(t),r]),mc=e=>u(u(x("`",e),([t,r])=>u(bh(r),([n,o])=>u(x("`",o),([i,a])=>[[t,n,i],a]))),([t,r])=>[Cy(t),r]),EA=e=>u(mc(e),([t,r])=>[Ry(t),r]),SA=e=>u(u(u(x("if",e),([t,r])=>u(re(r),([n,o])=>u(x("then",o),([i,a])=>u(re(a),([m,c])=>u(x("else",c),([p,f])=>u(re(f),([d,g])=>[[t,n,i,m,p,d],g])))))),([t,r])=>[t,r],()=>u(u(x("if",e),([t,r])=>u(re(r),([n,o])=>u(x("then",o),([i,a])=>u(re(a),([m,c])=>[[t,n,i,m],c])))),([t,r])=>[t,r],()=>[])),([t,r])=>[Py(t),r]),kA=e=>u(nc(e),([t,r])=>[by(t),r]),TA=e=>u(u(x("true",e),([t,r])=>[t,r],()=>u(x("false",e),([t,r])=>[t,r],()=>[])),([t,r])=>[$y(t),r]),wA=e=>u(Wa(e),([t,r])=>[Ey(t),r]),CA=e=>u(Va(["'",'"'],e),([t,r])=>[Sy(t),r]),RA=e=>u(u(u(x("keyof",e),([t,r])=>[[t],r]),([t,r])=>[t,r],()=>u([[],e],([t,r])=>[t,r],()=>[])),([t,r])=>[Ay(t),r]),$h=(e,t=[])=>u(u(u(x("[",e),([r,n])=>u(re(n),([o,i])=>u(x("]",i),([a,m])=>[[r,o,a],m]))),([r,n])=>[r,n],()=>u(u(x("[",e),([r,n])=>u(x("]",n),([o,i])=>[[r,o],i])),([r,n])=>[r,n],()=>[])),([r,n])=>$h(n,[...t,r]),()=>[t,e]),PA=e=>u($h(e),([t,r])=>[Oy(t),r]),AA=e=>u(u(u(x("extends",e),([t,r])=>u(re(r),([n,o])=>u(x("?",o),([i,a])=>u(re(a),([m,c])=>u(x(":",c),([p,f])=>u(re(f),([d,g])=>[[t,n,i,m,p,d],g])))))),([t,r])=>[t,r],()=>u([[],e],([t,r])=>[t,r],()=>[])),([t,r])=>[My(t),r]),OA=e=>u(u(u(x("(",e),([t,r])=>u(re(r),([n,o])=>u(x(")",o),([i,a])=>[[t,n,i],a]))),([t,r])=>[t,r],()=>u(yh(e),([t,r])=>[t,r],()=>u(xh(e),([t,r])=>[t,r],()=>u(pA(e),([t,r])=>[t,r],()=>u(fA(e),([t,r])=>[t,r],()=>u(dA(e),([t,r])=>[t,r],()=>u(hh(e),([t,r])=>[t,r],()=>u(lA(e),([t,r])=>[t,r],()=>u(gA(e),([t,r])=>[t,r],()=>u(yA(e),([t,r])=>[t,r],()=>u(xA(e),([t,r])=>[t,r],()=>u(hA(e),([t,r])=>[t,r],()=>u(Ih(e),([t,r])=>[t,r],()=>u(IA(e),([t,r])=>[t,r],()=>u(bA(e),([t,r])=>[t,r],()=>u(kA(e),([t,r])=>[t,r],()=>u(TA(e),([t,r])=>[t,r],()=>u(wA(e),([t,r])=>[t,r],()=>u(CA(e),([t,r])=>[t,r],()=>u(EA(e),([t,r])=>[t,r],()=>u(SA(e),([t,r])=>[t,r],()=>u(BA(e),([t,r])=>[t,r],()=>u(HA(e),([t,r])=>[t,r],()=>u(QA(e),([t,r])=>[t,r],()=>u(YA(e),([t,r])=>[t,r],()=>u(tO(e),([t,r])=>[t,r],()=>u(cA(e),([t,r])=>[t,r],()=>u(rO(e),([t,r])=>[t,r],()=>[])))))))))))))))))))))))))))),([t,r])=>[vy(t),r]),MA=e=>u(u(u(x("with",e),([t,r])=>u(Nh(r),([n,o])=>[[t,n],o])),([t,r])=>[t,r],()=>u([[],e],([t,r])=>[t,r],()=>[])),([t,r])=>[Fy(t),r]),Eh=e=>u(u(RA(e),([t,r])=>u(OA(r),([n,o])=>u(PA(o),([i,a])=>u(AA(a),([m,c])=>u(MA(c),([p,f])=>[[t,n,i,m,p],f]))))),([t,r])=>[Ly(t),r]),Sh=e=>u(u(u(x("&",e),([t,r])=>u(Eh(r),([n,o])=>u(Sh(o),([i,a])=>[[t,n,i],a]))),([t,r])=>[t,r],()=>u([[],e],([t,r])=>[t,r],()=>[])),([t,r])=>[t,r]),kh=e=>u(u(Eh(e),([t,r])=>u(Sh(r),([n,o])=>[[t,n],o])),([t,r])=>[Dy(t),r]),Th=e=>u(u(u(x("|",e),([t,r])=>u(kh(r),([n,o])=>u(Th(o),([i,a])=>[[t,n,i],a]))),([t,r])=>[t,r],()=>u([[],e],([t,r])=>[t,r],()=>[])),([t,r])=>[t,r]),Ja=e=>u(u(kh(e),([t,r])=>u(Th(r),([n,o])=>[[t,n],o])),([t,r])=>[jy(t),r]),vA=e=>u(u(x("readonly",e),([t,r])=>u(Ja(r),([n,o])=>[[t,n],o])),([t,r])=>[Ny(t),r]),FA=e=>u(u(x("|",e),([t,r])=>u(Ja(r),([n,o])=>[[t,n],o])),([t,r])=>[qy(t),r]),LA=e=>u(u(ac(e),([t,r])=>u(x("=",r),([n,o])=>u(re(o),([i,a])=>[[t,n,i],a]))),([t,r])=>[_y(t),r]),DA=e=>u(u(u(x("infer",e),([t,r])=>u(Le(r),([n,o])=>u(x("extends",o),([i,a])=>u(Ja(a),([m,c])=>[[t,n,i,m],c])))),([t,r])=>[t,r],()=>u(u(x("infer",e),([t,r])=>u(Le(r),([n,o])=>[[t,n],o])),([t,r])=>[t,r],()=>[])),([t,r])=>[Uy(t),r]),re=e=>u(u(DA(e),([t,r])=>[t,r],()=>u(FA(e),([t,r])=>[t,r],()=>u(vA(e),([t,r])=>[t,r],()=>u(Ja(e),([t,r])=>[t,r],()=>[])))),([t,r])=>[t,r]),jA=e=>u(Wa(e),([t,r])=>[By(t),r]),NA=e=>u(Le(e),([t,r])=>[t,r]),qA=e=>u(Va(["'",'"'],e),([t,r])=>[t,r]),_A=e=>u(u(x("[",e),([t,r])=>u(Le(r),([n,o])=>u(x(":",o),([i,a])=>u(u(hh(a),([m,c])=>[m,c],()=>u(xh(a),([m,c])=>[m,c],()=>u(yh(a),([m,c])=>[m,c],()=>u(Ih(a),([m,c])=>[m,c],()=>[])))),([m,c])=>u(x("]",c),([p,f])=>[[t,n,i,m,p],f]))))),([t,r])=>[Gy(t),r]),wh=e=>u(u(jA(e),([t,r])=>[t,r],()=>u(NA(e),([t,r])=>[t,r],()=>u(qA(e),([t,r])=>[t,r],()=>u(_A(e),([t,r])=>[t,r],()=>[])))),([t,r])=>[t,r]),Ch=e=>u(u(u(x("readonly",e),([t,r])=>[[t],r]),([t,r])=>[t,r],()=>u([[],e],([t,r])=>[t,r],()=>[])),([t,r])=>[Ky(t),r]),Rh=e=>u(u(u(x("?",e),([t,r])=>[[t],r]),([t,r])=>[t,r],()=>u([[],e],([t,r])=>[t,r],()=>[])),([t,r])=>[Hy(t),r]),Ph=e=>u(u(Ch(e),([t,r])=>u(wh(r),([n,o])=>u(Rh(o),([i,a])=>u(x(":",a),([m,c])=>u(re(c),([p,f])=>[[t,n,i,m,p],f]))))),([t,r])=>[zy(t),r]),Ya=e=>u(u(u(x(",",e),([t,r])=>u(x(`
3
- `,r),([n,o])=>[[t,n],o])),([t,r])=>[t,r],()=>u(u(x(";",e),([t,r])=>u(x(`
4
- `,r),([n,o])=>[[t,n],o])),([t,r])=>[t,r],()=>u(u(x(",",e),([t,r])=>[[t],r]),([t,r])=>[t,r],()=>u(u(x(";",e),([t,r])=>[[t],r]),([t,r])=>[t,r],()=>u(u(x(`
5
- `,e),([t,r])=>[[t],r]),([t,r])=>[t,r],()=>[]))))),([t,r])=>[t,r]),Ah=(e,t=[])=>u(u(Ya(e),([r,n])=>u(Ph(n),([o,i])=>[[r,o],i])),([r,n])=>Ah(n,[...t,r]),()=>[t,e]),UA=e=>u(u(u(Ph(e),([t,r])=>u(Ah(r),([n,o])=>u(u(Ya(o),([i,a])=>[[i],a],()=>[[],o]),([i,a])=>[[t,n,i],a]))),([t,r])=>[t,r],()=>u([[],e],([t,r])=>[t,r],()=>[])),([t,r])=>[Wy(t),r]),uc=e=>u(u(x("{",e),([t,r])=>u(UA(r),([n,o])=>u(x("}",o),([i,a])=>[[t,n,i],a]))),([t,r])=>[Jy(t),r]),BA=e=>u(uc(e),([t,r])=>[Yy(t),r]),GA=e=>u(u(u(Le(e),([t,r])=>u(x("?",r),([n,o])=>u(x(":",o),([i,a])=>u(x("readonly",a),([m,c])=>u(re(c),([p,f])=>[[t,n,i,m,p],f]))))),([t,r])=>[t,r],()=>u(u(Le(e),([t,r])=>u(x(":",r),([n,o])=>u(x("readonly",o),([i,a])=>u(re(a),([m,c])=>[[t,n,i,m],c])))),([t,r])=>[t,r],()=>u(u(Le(e),([t,r])=>u(x("?",r),([n,o])=>u(x(":",o),([i,a])=>u(re(a),([m,c])=>[[t,n,i,m],c])))),([t,r])=>[t,r],()=>u(u(Le(e),([t,r])=>u(x(":",r),([n,o])=>u(re(o),([i,a])=>[[t,n,i],a]))),([t,r])=>[t,r],()=>[])))),([t,r])=>[Qy(t),r]),ch=e=>u(u(GA(e),([t,r])=>[t,r],()=>u(u(Ch(e),([t,r])=>u(re(r),([n,o])=>u(Rh(o),([i,a])=>[[t,n,i],a]))),([t,r])=>[t,r],()=>[])),([t,r])=>[Xy(t),r]),Oh=e=>u(u(u(x("...",e),([t,r])=>u(ch(r),([n,o])=>[[t,n],o])),([t,r])=>[t,r],()=>u(u(ch(e),([t,r])=>[[t],r]),([t,r])=>[t,r],()=>[])),([t,r])=>[Zy(t),r]),Mh=(e,t=[])=>u(u(x(",",e),([r,n])=>u(Oh(n),([o,i])=>[[r,o],i])),([r,n])=>Mh(n,[...t,r]),()=>[t,e]),KA=e=>u(u(u(Oh(e),([t,r])=>u(Mh(r),([n,o])=>u(u(x(",",o),([i,a])=>[[i],a],()=>[[],o]),([i,a])=>[[t,n,i],a]))),([t,r])=>[t,r],()=>u([[],e],([t,r])=>[t,r],()=>[])),([t,r])=>[ex(t),r]),HA=e=>u(u(x("[",e),([t,r])=>u(KA(r),([n,o])=>u(x("]",o),([i,a])=>[[t,n,i],a]))),([t,r])=>[tx(t),r]),zA=e=>u(u(Le(e),([t,r])=>u(x("?",r),([n,o])=>u(x(":",o),([i,a])=>u(x("readonly",a),([m,c])=>u(re(c),([p,f])=>[[t,n,i,m,p],f]))))),([t,r])=>[rx(t),r]),WA=e=>u(u(Le(e),([t,r])=>u(x(":",r),([n,o])=>u(x("readonly",o),([i,a])=>u(re(a),([m,c])=>[[t,n,i,m],c])))),([t,r])=>[nx(t),r]),VA=e=>u(u(Le(e),([t,r])=>u(x("?",r),([n,o])=>u(x(":",o),([i,a])=>u(re(a),([m,c])=>[[t,n,i,m],c])))),([t,r])=>[ox(t),r]),JA=e=>u(u(Le(e),([t,r])=>u(x(":",r),([n,o])=>u(re(o),([i,a])=>[[t,n,i],a]))),([t,r])=>[ix(t),r]),ph=e=>u(u(zA(e),([t,r])=>[t,r],()=>u(WA(e),([t,r])=>[t,r],()=>u(VA(e),([t,r])=>[t,r],()=>u(JA(e),([t,r])=>[t,r],()=>[])))),([t,r])=>[t,r]),vh=e=>u(u(u(x("...",e),([t,r])=>u(ph(r),([n,o])=>[[t,n],o])),([t,r])=>[t,r],()=>u(u(ph(e),([t,r])=>[[t],r]),([t,r])=>[t,r],()=>[])),([t,r])=>[sx(t),r]),Fh=(e,t=[])=>u(u(x(",",e),([r,n])=>u(vh(n),([o,i])=>[[r,o],i])),([r,n])=>Fh(n,[...t,r]),()=>[t,e]),Lh=e=>u(u(u(vh(e),([t,r])=>u(Fh(r),([n,o])=>u(u(x(",",o),([i,a])=>[[i],a],()=>[[],o]),([i,a])=>[[t,n,i],a]))),([t,r])=>[t,r],()=>u([[],e],([t,r])=>[t,r],()=>[])),([t,r])=>[ax(t),r]),YA=e=>u(u(x("(",e),([t,r])=>u(Lh(r),([n,o])=>u(x(")",o),([i,a])=>u(x("=>",a),([m,c])=>u(re(c),([p,f])=>[[t,n,i,m,p],f]))))),([t,r])=>[mx(t),r]),QA=e=>u(u(x("new",e),([t,r])=>u(x("(",r),([n,o])=>u(Lh(o),([i,a])=>u(x(")",a),([m,c])=>u(x("=>",c),([p,f])=>u(re(f),([d,g])=>[[t,n,i,m,p,d],g])))))),([t,r])=>[ux(t),r]),XA=e=>u(u(u(x("+",e),([t,r])=>u(x("readonly",r),([n,o])=>[[t,n],o])),([t,r])=>[t,r],()=>u(u(x("-",e),([t,r])=>u(x("readonly",r),([n,o])=>[[t,n],o])),([t,r])=>[t,r],()=>u(u(x("readonly",e),([t,r])=>[[t],r]),([t,r])=>[t,r],()=>u([[],e],([t,r])=>[t,r],()=>[])))),([t,r])=>[cx(t),r]),ZA=e=>u(u(u(x("+",e),([t,r])=>u(x("?",r),([n,o])=>[[t,n],o])),([t,r])=>[t,r],()=>u(u(x("-",e),([t,r])=>u(x("?",r),([n,o])=>[[t,n],o])),([t,r])=>[t,r],()=>u(u(x("?",e),([t,r])=>[[t],r]),([t,r])=>[t,r],()=>u([[],e],([t,r])=>[t,r],()=>[])))),([t,r])=>[px(t),r]),eO=e=>u(u(u(x("as",e),([t,r])=>u(re(r),([n,o])=>[[t,n],o])),([t,r])=>[t,r],()=>u([[],e],([t,r])=>[t,r],()=>[])),([t,r])=>[fx(t),r]),tO=e=>u(u(x("{",e),([t,r])=>u(XA(r),([n,o])=>u(x("[",o),([i,a])=>u(Le(a),([m,c])=>u(x("in",c),([p,f])=>u(re(f),([d,g])=>u(eO(g),([y,I])=>u(x("]",I),([h,b])=>u(ZA(b),([k,j])=>u(x(":",j),([P,Je])=>u(re(Je),([Ce,ae])=>u(gh(ae),([Q,E])=>u(x("}",E),([F,R])=>[[t,n,i,m,p,d,y,h,k,P,Ce,Q,F],R]))))))))))))),([t,r])=>[dx(t),r]),rO=e=>u(Le(e),([t,r])=>[lx(t),r]),nO=e=>u(nc(e),([t,r])=>[gx(t),r]),oO=e=>u(Wa(e),([t,r])=>[yx(t),r]),iO=e=>u(u(x("true",e),([t,r])=>[t,r],()=>u(x("false",e),([t,r])=>[t,r],()=>[])),([t,r])=>[xx(t),r]),sO=e=>u(Va(['"',"'"],e),([t,r])=>[t,r]),aO=e=>u(x("null",e),([t,r])=>[hx(t),r]),mO=e=>u(x("undefined",e),([t,r])=>[void 0,r]),Dh=e=>u(u(wh(e),([t,r])=>u(x(":",r),([n,o])=>u(cc(o),([i,a])=>[[t,n,i],a]))),([t,r])=>[Ix(t),r]),jh=(e,t=[])=>u(u(Ya(e),([r,n])=>u(Dh(n),([o,i])=>[[r,o],i])),([r,n])=>jh(n,[...t,r]),()=>[t,e]),uO=e=>u(u(u(Dh(e),([t,r])=>u(jh(r),([n,o])=>u(u(Ya(o),([i,a])=>[[i],a],()=>[[],o]),([i,a])=>[[t,n,i],a]))),([t,r])=>[t,r],()=>u([[],e],([t,r])=>[t,r],()=>[])),([t,r])=>[bx(t),r]),Nh=e=>u(u(x("{",e),([t,r])=>u(uO(r),([n,o])=>u(x("}",o),([i,a])=>[[t,n,i],a]))),([t,r])=>[$x(t),r]),qh=(e,t=[])=>u(u(x(",",e),([r,n])=>u(cc(n),([o,i])=>[[r,o],i])),([r,n])=>qh(n,[...t,r]),()=>[t,e]),cO=e=>u(u(u(cc(e),([t,r])=>u(qh(r),([n,o])=>u(u(x(",",o),([i,a])=>[[i],a],()=>[[],o]),([i,a])=>[[t,n,i],a]))),([t,r])=>[t,r],()=>u([[],e],([t,r])=>[t,r],()=>[])),([t,r])=>[Ex(t),r]),pO=e=>u(u(x("[",e),([t,r])=>u(cO(r),([n,o])=>u(x("]",o),([i,a])=>[[t,n,i],a]))),([t,r])=>[Sx(t),r]),cc=e=>u(u(nO(e),([t,r])=>[t,r],()=>u(oO(e),([t,r])=>[t,r],()=>u(iO(e),([t,r])=>[t,r],()=>u(sO(e),([t,r])=>[t,r],()=>u(aO(e),([t,r])=>[t,r],()=>u(mO(e),([t,r])=>[t,r],()=>u(Nh(e),([t,r])=>[t,r],()=>u(pO(e),([t,r])=>[t,r],()=>[])))))))),([t,r])=>[t,r]),fO=e=>u(x("-?(?:0|[1-9][0-9]*)n",e),([t,r])=>[kx(t),r]),dO=e=>u(x(".*",e),([t,r])=>[Tx(t),r]),lO=e=>u(x("-?(?:0|[1-9][0-9]*)(?:\\.[0-9]+)?",e),([t,r])=>[wx(t),r]),gO=e=>u(x("-?(?:0|[1-9][0-9]*)",e),([t,r])=>[Cx(t),r]),yO=e=>u(x("(?!)",e),([t,r])=>[Rx(t),r]),xO=e=>u(uh(["-?(?:0|[1-9][0-9]*)n",".*","-?(?:0|[1-9][0-9]*)(?:\\.[0-9]+)?","-?(?:0|[1-9][0-9]*)","(?!)","(",")","$","|"],e),([t,r])=>[Px(t),r]),hO=e=>u(u(fO(e),([t,r])=>[t,r],()=>u(dO(e),([t,r])=>[t,r],()=>u(lO(e),([t,r])=>[t,r],()=>u(gO(e),([t,r])=>[t,r],()=>u(yO(e),([t,r])=>[t,r],()=>u(IO(e),([t,r])=>[t,r],()=>u(xO(e),([t,r])=>[t,r],()=>[]))))))),([t,r])=>[t,r]),IO=e=>u(u(x("(",e),([t,r])=>u(pc(r),([n,o])=>u(x(")",o),([i,a])=>[[t,n,i],a]))),([t,r])=>[Ax(t),r]),_h=e=>u(u(u(sc(e),([t,r])=>u(x("|",r),([n,o])=>u(_h(o),([i,a])=>[[t,n,i],a]))),([t,r])=>[t,r],()=>u(u(sc(e),([t,r])=>[[t],r]),([t,r])=>[t,r],()=>u([[],e],([t,r])=>[t,r],()=>[]))),([t,r])=>[Ox(t),r]),sc=e=>u(u(hO(e),([t,r])=>u(pc(r),([n,o])=>[[t,n],o])),([t,r])=>[Mx(t),r]),pc=e=>u(u(_h(e),([t,r])=>[t,r],()=>u(sc(e),([t,r])=>[t,r],()=>[])),([t,r])=>[t,r]),lg=e=>u(u(x("^",e),([t,r])=>u(pc(r),([n,o])=>u(x("$",o),([i,a])=>[[t,n,i],a]))),([t,r])=>[vx(t),r]),Uh=(e,t=[])=>u(u(x(",",e),([r,n])=>u(re(n),([o,i])=>[[r,o],i])),([r,n])=>Uh(n,[...t,r]),()=>[t,e]),bO=e=>u(u(u(re(e),([t,r])=>u(Uh(r),([n,o])=>u(u(x(",",o),([i,a])=>[[i],a],()=>[[],o]),([i,a])=>[[t,n,i],a]))),([t,r])=>[t,r],()=>u([[],e],([t,r])=>[t,r],()=>[])),([t,r])=>[Fx(t),r]),Bh=e=>u(u(u(x("extends",e),([t,r])=>u(bO(r),([n,o])=>[[t,n],o])),([t,r])=>[t,r],()=>u([[],e],([t,r])=>[t,r],()=>[])),([t,r])=>[Lx(t),r]),$O=e=>u(u(x("interface",e),([t,r])=>u(Le(r),([n,o])=>u(ac(o),([i,a])=>u(Bh(a),([m,c])=>u(uc(c),([p,f])=>[[t,n,i,m,p],f]))))),([t,r])=>[Dx(t),r]),EO=e=>u(u(x("interface",e),([t,r])=>u(Le(r),([n,o])=>u(Bh(o),([i,a])=>u(uc(a),([m,c])=>[[t,n,i,m],c])))),([t,r])=>[jx(t),r]),SO=e=>u(u(x("type",e),([t,r])=>u(Le(r),([n,o])=>u(ac(o),([i,a])=>u(x("=",a),([m,c])=>u(re(c),([p,f])=>[[t,n,i,m,p],f]))))),([t,r])=>[Nx(t),r]),kO=e=>u(u(x("type",e),([t,r])=>u(Le(r),([n,o])=>u(x("=",o),([i,a])=>u(re(a),([m,c])=>[[t,n,i,m],c])))),([t,r])=>[qx(t),r]),TO=e=>u(u(u(x("export",e),([t,r])=>[[t],r]),([t,r])=>[t,r],()=>u([[],e],([t,r])=>[t,r],()=>[])),([t,r])=>[_x(t),r]),Gh=e=>u(u(u(x(";",e),([t,r])=>u(x(`
6
- `,r),([n,o])=>[[t,n],o])),([t,r])=>[t,r],()=>u(u(x(";",e),([t,r])=>[[t],r]),([t,r])=>[t,r],()=>u(u(x(`
7
- `,e),([t,r])=>[[t],r]),([t,r])=>[t,r],()=>[]))),([t,r])=>[t,r]),Kh=(e,t=[])=>u(u(Gh(e),([r,n])=>u(fc(n),([o,i])=>[[r,o],i])),([r,n])=>Kh(n,[...t,r]),()=>[t,e]),wO=e=>u(u(u(fc(e),([t,r])=>u(Kh(r),([n,o])=>u(u(Gh(o),([i,a])=>[[i],a],()=>[[],o]),([i,a])=>[[t,n,i],a]))),([t,r])=>[t,r],()=>u([[],e],([t,r])=>[t,r],()=>[])),([t,r])=>[Ux(t),r]),fc=e=>u(u(TO(e),([t,r])=>u(u($O(r),([n,o])=>[n,o],()=>u(EO(r),([n,o])=>[n,o],()=>u(SO(r),([n,o])=>[n,o],()=>u(kO(r),([n,o])=>[n,o],()=>[])))),([n,o])=>u(gh(o),([i,a])=>[[t,n,i],a]))),([t,r])=>[Bx(t),r]),CO=e=>u(u(fc(e),([t,r])=>u(wO(r),([n,o])=>[[t,n],o])),([t,r])=>[Gx(t),r]),Hh=e=>u(u(CO(e),([t,r])=>[t,r],()=>u(LA(e),([t,r])=>[t,r],()=>u(re(e),([t,r])=>[t,r],()=>[]))),([t,r])=>[t,r]);function zh(e){let t=mc(`\`${e}\``);return s.IsEqual(t.length,2)?t[0]:Re()}function PO(e){return e.join("|")}function AO(e){return e.slice(1,e.length-1)}function OO(e,t,r){return pn(t,`${r}${e}`)}function MO(e,t){return pn(e,`${t}${mg}`)}function vO(e,t){return pn(e,`${t}${ma}`)}function FO(e,t){return pn(e,`${t}${fa}`)}function LO(e,t){return $i(_([W("false"),W("true")]),e,t)}function DO(e,t){return pn(e,`${t}${da}`)}function jO(e,t,r){return pn(t,`${r}${AO(e)}`)}function NO(e,t,r){let n=Ei(e,{});return $i(n,t,r)}function qO(e,t,r){let n=St(e);return $i(n,t,r)}function Wh(e,t,r,n=[]){return s.ShiftLeft(e,(o,i)=>Wh(i,t,r,[...n,$i(o,[],"")]),()=>pn(t,`${r}(${PO(n)})`))}function $i(e,t,r){return Me(e)?qO(e.enum,t,r):Xe(e)?vO(t,r):J(e)?OO(e.const,t,r):vt(e)?MO(t,r):Et(e)?LO(t,r):Se(e)?FO(t,r):ze(e)?DO(t,r):de(e)?jO(e.pattern,t,r):Jh(e)?NO(e.parameters[0],t,r):S(e)?Wh(e.anyOf,t,r):zl}function pn(e,t){return s.ShiftLeft(e,(r,n)=>$i(r,n,t),()=>t)}function _O(e){return`^${pn(e,"")}$`}function Vh(e){let t=_O(e);return ga(t)}function Ei(e,t){return K(e)?l.Update(Vh(e),{},t):Sa(e,t)}function Yh(e,t,r,n){let o=Kt(e,t,r);return Ei(o,n)}function Sa(e,t={}){return C("TemplateLiteral",[e],t)}function Jh(e){return Ee(e)&&s.HasPropertyKey(e,"action")&&s.IsEqual(e.action,"TemplateLiteral")}function Qh(e){return Ei(e,{})}function UO(e){let t=zh(e);return Qh(t)}function Xh(e,t={}){let r=s.IsString(e)?UO(e):Qh(e);return l.Update(r,{},t)}function de(e){return w(e,"TemplateLiteral")}var N={};_t(N,{ExtendsFalse:()=>B,ExtendsTrue:()=>T,ExtendsUnion:()=>dc,IsExtendsFalse:()=>BO,IsExtendsTrue:()=>eI,IsExtendsTrueLike:()=>Tr,IsExtendsUnion:()=>Zh,Match:()=>De});function dc(e){return l.Create({"~kind":"ExtendsUnion"},{inferred:e})}function Zh(e){return s.IsObject(e)&&s.HasPropertyKey(e,"~kind")&&s.HasPropertyKey(e,"inferred")&&s.IsEqual(e["~kind"],"ExtendsUnion")&&s.IsObject(e.inferred)}function T(e){return l.Create({"~kind":"ExtendsTrue"},{inferred:e})}function eI(e){return s.IsObject(e)&&s.HasPropertyKey(e,"~kind")&&s.HasPropertyKey(e,"inferred")&&s.IsEqual(e["~kind"],"ExtendsTrue")&&s.IsObject(e.inferred)}function B(){return l.Create({"~kind":"ExtendsFalse"},{})}function BO(e){return s.IsObject(e)&&s.HasPropertyKey(e,"~kind")&&s.IsEqual(e["~kind"],"ExtendsFalse")}function Tr(e){return Zh(e)||eI(e)}function De(e,t,r){return Tr(e)?t(e.inferred):r()}function GO(e,t,r,n){return De(Z(e,r,n),o=>T(l.Assign(l.Assign(e,o),{[t]:r})),()=>B())}function KO(e,t){return T(e)}function HO(e,t,r,n,o){return De(Z(e,t,r),i=>De(Z(i,t,n),a=>T(a),()=>B()),()=>De(Z(e,t,o),i=>T(i),()=>B()))}function zO(e,t,r){let n=St(r);return Z(e,t,n)}function tI(e,t,r){return s.ShiftLeft(r,(n,o)=>De(Z(e,t,n),i=>tI(i,t,o),()=>B()),()=>T(e))}function WO(e,t,r){let n=gt(r);return Z(e,t,n)}function rI(e,t,r){return s.ShiftLeft(r,(n,o)=>De(Z(e,t,n),i=>T(i),()=>rI(e,t,o)),()=>B())}function ie(e,t,r){return Te(r)?KO(e,t):Oe(r)?HO(e,t,r.if,r.then,r.else):Me(r)?zO(e,t,r.enum):Be(r)?GO(e,r.name,t,r.extends):v(r)?tI(e,t,r.allOf):de(r)?WO(e,t,r.pattern):S(r)?rI(e,t,r.anyOf):Ue(r)?T(e):B()}function nI(e,t,r){return Be(r)?ie(e,t,r):Te(r)?T(e):Ue(r)?T(e):dc(e)}function VO(e,t){let r=Cn(e),n=Cn(t);return r&&n||!r&&n?!0:!(r&&!n)}function oI(e,t,r,n){return Y(n)?VO(t,n)?Z(e,r,n.items):B():ie(e,t,n)}function iI(e,t,r){return vt(r)?T(e):ie(e,t,r)}function sI(e,t,r){return Et(r)?T(e):ie(e,t,r)}function JO(e,t,r,n,o){let i=Be(n)?t:n,a=Be(n)?n:t,m=_e(t),c=_e(n);return!m&&c?B():De(Z(e,i,a),p=>Si(p,r,o),()=>B())}function YO(e,t,r,n){return s.ShiftLeft(n,(o,i)=>JO(e,t,r,o,i),()=>_e(t)?T(e):B())}function QO(e,t,r){return s.ShiftLeft(t,(n,o)=>YO(e,n,o,r),()=>T(e))}function Si(e,t,r){return QO(e,t,r)}function Qa(e,t,r){return Lt(r)?T(e):Z(e,t,r)}function aI(e,t,r,n){return Te(n)?T(e):Ue(n)?T(e):Pe(n)?De(Si(e,t,n.parameters),o=>Qa(o,r,n.instanceType),()=>B()):B()}function mI(e,t,r,n,o){return De(Z(e,t,o),()=>Z(e,r,o),()=>Z(e,n,o))}function uI(e,t,r){let n=St(t);return Z(e,n,r)}function cI(e,t,r,n){return Te(n)?T(e):Ue(n)?T(e):Ae(n)?De(Si(e,t,n.parameters),o=>Qa(o,r,n.returnType),()=>B()):B()}function pI(e,t,r){return Xe(r)?T(e):Se(r)?T(e):ie(e,t,r)}function fI(e,t,r){let n=Fe(t);return Z(e,n,r)}function Xa(e,t,r){return t===r?T(e):B()}function XO(e,t,r){return J(r)?Xa(e,t,r.const):vt(r)?T(e):ie(e,W(t),r)}function ZO(e,t,r){return J(r)?Xa(e,t,r.const):Et(r)?T(e):ie(e,W(t),r)}function eM(e,t,r){return J(r)?Xa(e,t,r.const):Se(r)?T(e):ie(e,W(t),r)}function tM(e,t,r){return J(r)?Xa(e,t,r.const):ze(r)?T(e):ie(e,W(t),r)}function dI(e,t,r){return s.IsBigInt(t.const)?XO(e,t.const,r):s.IsBoolean(t.const)?ZO(e,t.const,r):s.IsNumber(t.const)?eM(e,t.const,r):s.IsString(t.const)?tM(e,t.const,r):Re()}function lI(e,t,r){return Be(r)?ie(e,t,r):T(e)}function gI(e,t,r){return Sr(r)?T(e):ie(e,t,r)}function yI(e,t,r){return Se(r)?T(e):ie(e,t,r)}function rM(e,t,r){return _e(t)?_e(r)?T(e):B():T(e)}function nM(e,t,r){return Be(r)&&wt(r.extends)?B():De(Z(e,t,r),n=>rM(n,t,r),()=>B())}function oM(e,t){return e.reduce((r,n)=>n in t?Tr(t[n])?{...r,...t[n].inferred}:Re():Re(),{})}function iM(e,t,r){let n={};for(let a of s.Keys(r))n[a]=a in t?nM({},t[a],r[a]):_e(r[a])?Be(r[a])?T(l.Assign(e,{[r[a].name]:r[a].extends})):T(e):B();let o=s.Values(n).every(a=>Tr(a)),i=o?oM(s.Keys(n),n):{};return o?T(i):B()}function sM(e,t,r){let n=iM(e,t,r);return Tr(n)?T(l.Assign(e,n.inferred)):B()}function aM(e,t,r){return sM(e,t,r)}function mM(e,t){return s.Keys(t).reduce((r,n)=>({...r,[n]:s.HasPropertyKey(e,n)?S(r[n])?_([...r[n].anyOf,t[n]]):_([e[n],t[n]]):t[n]}),e)}function xI(e,t,r,n){return s.ShiftLeft(t,(o,i)=>De(Z({},e[o],r),a=>xI(e,i,r,mM(n,a)),()=>B()),()=>T(n))}function uM(e,t,r,n){let o=s.Keys(t);return xI(t,o,n,e)}function hI(e,t,r){return se(r)?uM(e,t,Ge(r),ye(r)):M(r)?aM(e,t,r.properties):ie(e,L(t),r)}function cM(e,t){return s.IsEqual(s.Keys(t).length,0)?T(e):B()}function pM(e,t,r,n,o){return Z(e,r,o)}function II(e,t,r,n){return se(n)?pM(e,Ia(t),r,Ia(Ge(n)),ye(n)):M(n)?cM(e,n.properties):Te(n)?T(e):Ue(n)?T(e):B()}function bI(e,t,r){return ze(r)?T(e):ie(e,t,r)}function $I(e,t,r){return kr(r)?T(e):ie(e,t,r)}function EI(e,t,r){let n=gt(t);return Z(e,n,r)}function lc(e,t){return l.Create({"~kind":"Inferrable"},{name:e,type:t},{})}function ki(e){return s.IsObject(e)&&s.HasPropertyKey(e,"~kind")&&s.HasPropertyKey(e,"name")&&s.HasPropertyKey(e,"type")&&s.IsEqual(e["~kind"],"Inferrable")&&s.IsString(e.name)&&s.IsObject(e.type)}function gc(e){return mn(e)?Be(e.items)?Y(e.items.extends)?lc(e.items.name,e.items.extends.items):Ue(e.items.extends)?lc(e.items.name,e.items.extends):void 0:Re():void 0}function Za(e){return Be(e)?lc(e.name,e.extends):void 0}function SI(e,t){let r=[];for(let n of e){if(!Tr(Z({},n,t)))return;r.push(n)}return r}function kI(e,t,r,n){let o=SI(r,n);return s.IsArray(o)?T(l.Assign(e,{[t]:ve(o)})):B()}function em(e,t,r,n){let o=SI(r,n);return s.IsArray(o)?T(l.Assign(e,{[t]:_(o)})):B()}function fM(e){return[...e].reverse()}function yc(e,t){return t?fM(e):e}function dM(e){let t=e.length>0?e[0]:void 0,r=Ee(t)?gc(t):void 0;return Ee(r)}function lM(e,t,r,n,o,i){return De(Z(e,r,o),a=>TI(a,t,n,i),()=>B())}function gM(e,t,r,n,o){let i=gc(n);return ki(i)?kI(e,i.name,yc(r,t),i.type):s.ShiftLeft(r,(a,m)=>lM(e,t,a,m,n,o),()=>B())}function yM(e,t,r,n){return s.ShiftLeft(n,(o,i)=>gM(e,t,r,o,i),()=>s.IsEqual(r.length,0)?T(e):B())}function TI(e,t,r,n){return yM(e,t,r,n)}function xM(e,t,r){let n=fn(e,Ie([],[]),r),o=dM(n);return TI(e,o,yc(t,o),yc(n,o))}function hM(e,t,r){for(let n of t){let o=Z(e,n,r);if(!Tr(o))return o;e=o.inferred}return T(e)}function IM(e,t,r){let n=Za(r);return ki(n)?em(e,n.name,t,n.type):hM(e,t,r)}function wI(e,t,r){let n=fn(e,Ie([],[]),t);return G(r)?xM(e,n,r.items):Y(r)?IM(e,n,r.items):ie(e,ve(n),r)}function CI(e,t,r){return Lt(r)?T(e):Zt(r)?T(e):ie(e,t,r)}function RI(e,t,r){return s.ShiftLeft(r,(n,o)=>De(Z(e,t,n),i=>T(i),()=>RI(e,t,o)),()=>B())}function xc(e,t,r){return s.ShiftLeft(t,(n,o)=>De(RI(e,n,r),i=>xc(i,o,r),()=>B()),()=>T(e))}function PI(e,t,r){let n=Za(r);return ki(n)?em(e,n.name,t,n.type):S(r)?xc(e,t,r.anyOf):xc(e,t,[r])}function AI(e,t,r){return Be(r)?ie(e,t,r):Te(r)?T(e):Ue(r)?T(e):B()}function OI(e,t,r){return Lt(r)?T(e):ie(e,t,r)}function Z(e,t,r){return Te(t)?nI(e,t,r):Y(t)?oI(e,t,t.items,r):vt(t)?iI(e,t,r):Et(t)?sI(e,t,r):Pe(t)?aI(e,t.parameters,t.instanceType,r):Oe(t)?mI(e,t.if,t.then,t.else,r):Me(t)?uI(e,t.enum,r):Ae(t)?cI(e,t.parameters,t.returnType,r):Xe(t)?pI(e,t,r):v(t)?fI(e,t.allOf,r):J(t)?dI(e,t,r):wt(t)?lI(e,t,r):Sr(t)?gI(e,t,r):Se(t)?yI(e,t,r):M(t)?hI(e,t.properties,r):se(t)?II(e,Ge(t),ye(t),r):ze(t)?bI(e,t,r):kr(t)?$I(e,t,r):de(t)?EI(e,t.pattern,r):G(t)?wI(e,t.items,r):Zt(t)?CI(e,t,r):S(t)?PI(e,t.anyOf,r):Ue(t)?AI(e,t,r):Lt(t)?OI(e,t,r):B()}function bM(e,t){return Fe([...e,L(t)])}function hc(e,t,r){return K(e)?l.Update(bM(e,t),{},r):yi(e,t,r)}function MI(e,t,r,n,o){let i=Kt(e,t,r),a=Ti(e,t,n);return hc(i,a,o)}function yi(e,t,r={}){return C("Interface",[e,t],r)}function xo(e){return Ee(e)&&s.HasPropertyKey(e,"action")&&s.IsEqual(e.action,"Interface")}function vI(e,t,r={}){return hc(e,t,r)}function $M(e,t,r){return e.includes(r)?!0:wi([...e,r],t,t[r])}function FI(e,t,r){let n=na(r);return vn(e,t,n)}function vn(e,t,r){return s.ShiftLeft(r,(n,o)=>wi(e,t,n)?!0:vn(e,t,o),()=>!1)}function wi(e,t,r){return oe(r)?$M(e,t,r.$ref):Y(r)?wi(e,t,r.items):Pe(r)?vn(e,t,[...r.parameters,r.instanceType]):Ae(r)?vn(e,t,[...r.parameters,r.returnType]):xo(r)?FI(e,t,r.parameters[1]):v(r)?vn(e,t,r.allOf):M(r)?FI(e,t,r.properties):S(r)?vn(e,t,r.anyOf):G(r)?vn(e,t,r.items):se(r)?wi(e,t,ye(r)):!1}function LI(e,t,r){return wi(e,t,r)}function EM(e,t){return t.reduce((r,n)=>LI([n],e,e[n])?[...r,n]:r,[])}function DI(e){let t=ra(e);return EM(e,t)}function SM(e,t,r){return r.includes(t)?r:t in e?Ci(e,e[t],[...r,t]):Re()}function jI(e,t,r){let n=na(t);return ho(e,n,r)}function ho(e,t,r){return t.reduce((n,o)=>Ci(e,o,n),r)}function Ci(e,t,r){return oe(t)?SM(e,t.$ref,r):Y(t)?Ci(e,t.items,r):Pe(t)?ho(e,[...t.parameters,t.instanceType],r):Ae(t)?ho(e,[...t.parameters,t.returnType],r):xo(t)?jI(e,t.parameters[1],r):v(t)?ho(e,t.allOf,r):M(t)?jI(e,t.properties,r):S(t)?ho(e,t.anyOf,r):G(t)?ho(e,t.items,r):se(t)?Ci(e,ye(t),r):r}function NI(e,t,r){return Ci(e,r,[t])}function kM(e){return ro()}function TM(e){return s.Keys(e).reduce((t,r)=>({...t,[r]:Fn(e[r])}),{})}function Ri(e){return e.reduce((t,r)=>[...t,Fn(r)],[])}function Fn(e){return oe(e)?kM(e.$ref):Y(e)?Tt(Fn(e.items),eo(e)):Pe(e)?hr(Ri(e.parameters),Fn(e.instanceType)):Ae(e)?Ir(Ri(e.parameters),Fn(e.returnType)):v(e)?lt(Ri(e.allOf)):M(e)?L(TM(e.properties)):se(e)?co(po(e),Fn(ye(e))):S(e)?_(Ri(e.anyOf)):G(e)?ve(Ri(e.items)):e}function wM(e,t){return t in e?Fn(e[t]):He()}function qI(e){return wM(e.$defs,e.$ref)}function CM(e,t,r){let n=Kt(e,Ie([],[]),t),o=Ti({},Ie([],[]),r);return Fe([...n,L(o)])}function RM(e,t){return s.Keys(e).filter(n=>t.includes(n)).reduce((n,o)=>{let i=e[o],a=xo(i)?CM(e,i.parameters[0],i.parameters[1]):i;return{...n,[o]:a}},{})}function _I(e,t,r){let n=NI(e,t,r),o=RM(e,n);return $r(o,t)}function UI(e,t){return t in e?oe(e[t])?UI(e,e[t].$ref):e[t]:me()}function wr(e,t){return UI(e,t)}function BI(e){return fe(e)?qI(e):oa(e)?He():e}function pt(e,t,r){let n=BI(t),o=BI(r);return Z(e,n,o)}var pi=0,Pi=1,fi=2,di=3;function mo(e,t){let r=[pt({},e,t),pt({},t,e)];return N.IsExtendsTrueLike(r[0])&&N.IsExtendsTrueLike(r[1])?pi:N.IsExtendsTrueLike(r[0])&&N.IsExtendsFalse(r[1])?fi:N.IsExtendsFalse(r[0])&&N.IsExtendsTrueLike(r[1])?di:Pi}function Ic(e,t,r=[],n=t){return s.ShiftLeft(t,(o,i)=>{let a=mo(e,o);return s.IsEqual(a,fi)||s.IsEqual(a,pi)?n:s.IsEqual(a,Pi)?Ic(e,i,[...r,o],n):Ic(e,i,r,n)},()=>[...r,e])}function PM(e,t,r){let n=Xt(e);return Te(n)?[n]:Ue(n)?[n]:wt(n)?tm(t,r):M(n)?tm(t,[...r,n]):tm(t,Ic(n,r))}function tm(e,t=[]){return s.ShiftLeft(e,(r,n)=>PM(r,n,t),()=>t)}function Qu(e){let t=tm(e);return an(t)}function bc(e,t){return l.Update(Xt(e),{},t)}function GI(e,t,r,n){let o=$(e,t,r);return bc(o,n)}function Ai(e,t=[]){return tn(e)&&s.IsEqual(e.action,"Conditional")?oe(e.parameters[0])?Ai(e.parameters[2],Ai(e.parameters[3],[...t,e.parameters[0].$ref])):Ai(e.parameters[2],Ai(e.parameters[3],t)):tn(e)&&s.IsEqual(e.action,"Mapped")&&tn(e.parameters[1])&&s.IsEqual(e.parameters[1].action,"KeyOf")&&oe(e.parameters[1].parameters[0])?[...t,e.parameters[1].parameters[0].$ref]:t}function AM(e,t){return e.reduce((r,n)=>[...r,t.includes(n.name)],[])}function zI(e,t,r=[]){return s.ShiftLeft(e,(n,o)=>s.ShiftLeft(t,(i,a)=>zI(o,a,[...r,[i,n]]),()=>r),()=>r)}function OM(e){return de(e)?gt(e.pattern):Me(e)?St(e.enum):e}function MM(e){let t=OM(e);return S(t)?[...t.anyOf]:[t]}function vM(e,t){return e.reduce((r,n)=>[...r,[...n,t]],[])}function KI(e,t){return t.reduce((r,n)=>[...r,...vM(e,n)],[])}function HI(e){return e.reduce((t,r)=>s.IsEqual(r[0],!0)?KI(t,MM(r[1])):KI(t,[r[1]]),[[]])}function WI(e,t,r){let n=Ai(r),o=AM(e,n),i=zI(t,o);return tn(r)&&s.IsEqual(r.action,"Conditional")||tn(r)&&s.IsEqual(r.action,"Mapped")?HI(i):[t]}function FM(){return["(not-resolvable)",me()]}function LM(){return["(not-generic)",me()]}function DM(e,t,r){return[e,rn(t,r)]}function jM(e,t,r){return t in e?VI(e,t,e[t],r):FM()}function VI(e,t,r,n){return to(r)?DM(t,r.parameters,r.expression):oe(r)?jM(e,r.$ref,n):LM()}function JI(e,t,r){return VI(e,"(anonymous)",t,r)}function NM(e,t,r){if(Be(t)||Io(t)||N.IsExtendsTrueLike(pt({},t,r)))return;let n={parameter:e,expect:r,actual:t};throw new Error(`Argument for parameter ${e} does not satisfy constraint`,{cause:n})}function YI(e,t,r,n,o){let i=$(e,t,o);return NM(r,i,n),l.Assign(e,{[r]:i})}function qM(e,t,r,n,o){let i=$(e,t,r.extends),a=$(e,t,r.equals);return s.ShiftLeft(o,(m,c)=>$c(YI(e,t,r.name,i,m),t,n,c),()=>$c(YI(e,t,r.name,i,a),t,n,[]))}function $c(e,t,r,n){return s.ShiftLeft(r,(o,i)=>qM(e,t,o,i,n),()=>e)}function QI(e,t,r,n){return $c(e,t,r,n)}var Ec=0,Sc=0;function _M(){if(!s.IsLessThan(Sc,qe.Get().maxInstantiationCount))throw Error("Type instantiation is excessively deep and possibly infinite")}function UM(){_M(),Sc++,Ec++}function BM(){Ec--,s.IsEqual(Ec,0)&&(Sc=0)}function GM(e){return s.IsGreaterThan(e.callstack.length,0)?e.callstack[e.callstack.length-1]:""}function KM(e,t){return s.IsEqual(GM(e),t)}function HM(e,t,r,n,o,i){UM();try{let a=QI(e,t,n,i),m=$(a,Ie([...t.callstack,r.$ref],t.visited),o);return $(a,Ie([],[]),m)}finally{BM()}}function zM(e,t,r,n,o,i){return i.reduce((a,m)=>{let c=HM(e,t,r,n,o,m);return[...a,c]},[])}function WM(e,t,r,n,o,i){let a=WI(n,i,o),m=zM(e,t,r,n,o,a);return s.IsEqual(m.length,1)?m[0]:Rt(m)}function rm(e,t,r,n){let o=Kt(e,t,n),i=JI(e,r,n),a=i[0],m=i[1];return to(m)?KM(t,a)?xi(Ye(a),o):WM(e,t,Ye(a),m.parameters,m.expression,o):xi(r,o)}function xi(e,t){return l.Create({"~kind":"Call"},{type:"call",target:e,arguments:t},{})}function XI(e,t){return rm({},Ie([],[]),e,t)}function Io(e){return w(e,"Call")}function VM(e){return l.Discard(e,["~immutable"])}function ZI(e,t){return l.Update(VM(e),{},t)}function eb(e,t,r,n){let o=$(e,t,r);return ZI(o,n)}function tb(e,t){return e(t)}function rb(e,t){return s.IsString(t)?W(tb(e,t)):W(t)}function nb(e,t){let r=gt(t);return _r(e,r)}function ob(e,t){let r=t.map(n=>_r(e,n));return _(r)}function _r(e,t){return J(t)?rb(e,t.const):de(t)?nb(e,t.pattern):S(t)?ob(e,t.anyOf):t}function ka(e,t={}){return C("Capitalize",[e],t)}function ib(e,t={}){return kc(e,t)}function Ta(e,t={}){return C("Lowercase",[e],t)}function sb(e,t={}){return Tc(e,t)}function wa(e,t={}){return C("Uncapitalize",[e],t)}function ab(e,t={}){return wc(e,t)}function Ca(e,t={}){return C("Uppercase",[e],t)}function mb(e,t={}){return Cc(e,t)}var JM=e=>e[0].toUpperCase()+e.slice(1),YM=e=>e.toLowerCase(),QM=e=>e[0].toLowerCase()+e.slice(1),XM=e=>e.toUpperCase();function kc(e,t){return K([e])?l.Update(_r(JM,e),{},t):ka(e,t)}function Tc(e,t){return K([e])?l.Update(_r(YM,e),{},t):Ta(e,t)}function wc(e,t){return K([e])?l.Update(_r(QM,e),{},t):wa(e,t)}function Cc(e,t){return K([e])?l.Update(_r(XM,e),{},t):Ca(e,t)}function ub(e,t,r,n){let o=$(e,t,r);return kc(o,n)}function cb(e,t,r,n){let o=$(e,t,r);return Tc(o,n)}function pb(e,t,r,n){let o=$(e,t,r);return wc(o,n)}function fb(e,t,r,n){let o=$(e,t,r);return Cc(o,n)}function Ra(e,t,r,n,o={}){return C("Conditional",[e,t,r,n],o)}function db(e,t,r,n,o={}){return Rc({},Ie([],[]),e,t,r,n,o)}function ZM(e,t,r,n,o,i){let a=pt(e,r,n);return N.IsExtendsUnion(a)?_([$(a.inferred,t,o),$(e,t,i)]):N.IsExtendsTrue(a)?$(a.inferred,t,o):$(e,t,i)}function Rc(e,t,r,n,o,i,a){return K([r,n])?l.Update(ZM(e,t,r,n,o,i),{},a):Ra(r,n,o,i,a)}function lb(e,t,r,n,o,i,a){let m=$(e,t,r),c=$(e,t,n);return Rc(e,t,m,c,o,i,a)}function Pa(e,t={}){return C("ConstructorParameters",[e],t)}function gb(e,t={}){return Pc(e,t)}function ev(e){let t=Pe(e)?e.parameters:[],r=fn({},Ie([],[]),t);return ve(r)}function Pc(e,t){return K([e])?l.Update(ev(e),{},t):Pa(e,t)}function yb(e,t,r,n){let o=$(e,t,r);return Pc(o,n)}function Aa(e,t,r={}){return C("Exclude",[e,t],r)}function xb(e,t,r={}){return Oi(e,t,r)}function Oi(e,t,r){return K([e,t])?l.Update(xa(e,t),{},r):Aa(e,t,r)}function hb(e,t,r,n,o){let i=$(e,t,r),a=$(e,t,n);return Oi(i,a,o)}function Oa(e,t,r={}){return C("Extract",[e,t],r)}function Ib(e,t,r={}){return Ac(e,t,r)}function tv(e,t){let r=pt({},e,t);return N.IsExtendsTrueLike(r)?[e]:[]}function bb(e,t,r=[]){return s.ShiftLeft(e,(n,o)=>bb(o,t,[...r,...tv(n,t)]),()=>r)}function $b(e,t){let r=Xt(e),n=S(r)?r.anyOf:[r],o=bb(n,t);return Rt(o)}function Ac(e,t,r){return K([e,t])?l.Update($b(e,t),{},r):Oa(e,t,r)}function Eb(e,t,r,n,o){let i=$(e,t,r),a=$(e,t,n);return Ac(i,a,o)}function rv(e){return e.reduce((t,r)=>ua(r)?[...t,W(r)]:t,[])}function bo(e){let t=rv(e);return _(t)}function hi(e,t,r={}){return C("Index",[e,t],r)}function Sb(e,t,r={}){let n=s.IsArray(t)?bo(t):t;return Oc(e,n,r)}function kb(e,t){let r=wr(e,t);return Ht(r)}function Tb(e,t,r){let n=mr(e,t,r);return Ht(n)}function nv(e,t){let r=s.Keys(e).filter(f=>!s.HasPropertyKey(t,f)),n=s.Keys(t).filter(f=>!s.HasPropertyKey(e,f)),o=s.Keys(e).filter(f=>s.HasPropertyKey(t,f)),i=r.reduce((f,d)=>({...f,[d]:e[d]}),{}),a=n.reduce((f,d)=>({...f,[d]:t[d]}),{}),m=o.reduce((f,d)=>({...f,[d]:ya(e[d],t[d])}),{}),c=l.Assign(i,a);return l.Assign(c,m)}function wb(e){return e.reduce((t,r)=>nv(t,Ht(r)),{})}function Cb(e){let t=kg(ve(e));return Ht(t)}function ov(e,t){return s.Keys(e).filter(o=>o in t).reduce((o,i)=>({...o,[i]:Cg(e[i],t[i])}),{})}function Rb(e,t){return s.ShiftLeft(e,(r,n)=>Rb(n,ov(t,Ht(r))),()=>t)}function Pb(e){return s.ShiftLeft(e,(t,r)=>Rb(r,Ht(t)),()=>Re())}function Ht(e){return fe(e)?kb(e.$defs,e.$ref):Oe(e)?Tb(e.if,e.then,e.else):v(e)?wb(e.allOf):S(e)?Pb(e.anyOf):G(e)?Cb(e.items):M(e)?e.properties:{}}function $o(e){let t=Ht(e);return L(t)}var iv=new RegExp("^(?:0|[1-9][0-9]*)$");function Eo(e){let t=`${e}`;return iv.test(t)?parseInt(t):e}function sv(e){return W(Eo(e))}function Ab(e){return e.map(t=>Ob(t))}function Ob(e){return v(e)?lt(Ab(e.allOf)):S(e)?_(Ab(e.anyOf)):J(e)?sv(e.const):e}function Mb(e,t){let r=Ob(t),n=pt({},r,Ft());return N.IsExtendsTrueLike(n)?e:J(t)&&s.IsEqual(t.const,"length")?Ft():me()}function vb(e,t){let r=wr(e,t);return Dt(r)}function Fb(e,t,r){let n=mr(e,t,r);return Dt(n)}function Lb(e){let t=St(e);return Dt(t)}function Db(e){let t=Fe(e);return Dt(t)}function jb(e){return[`${e}`]}function Nb(e){let t=gt(e);return Dt(t)}function qb(e){return e.reduce((t,r)=>[...t,...Dt(r)],[])}function Dt(e){return fe(e)?vb(e.$defs,e.$ref):Oe(e)?Fb(e.if,e.then,e.else):Me(e)?Lb(e.enum):v(e)?Db(e.allOf):J(e)?jb(e.const):de(e)?Nb(e.pattern):S(e)?qb(e.anyOf):[]}function So(e){return Dt(e)}function Mi(e,t){return t.map(r=>vi(e,r))}function vi(e,t){return Y(t)?Tt(vi(e,t.items)):Pe(t)?hr(Mi(e,t.parameters),vi(e,t.instanceType)):Ae(t)?Ir(Mi(e,t.parameters),vi(e,t.returnType)):G(t)?ve(Mi(e,t.items)):S(t)?_(Mi(e,t.anyOf)):v(t)?lt(Mi(e,t.allOf)):$a(t)?L(e):t}function _b(e,t){return vi(e,t)}function av(e,t){let r=t in e?e[t]:me();return _b(e,r)}function Ub(e,t){return t.reduce((r,n)=>[...r,av(e,n)],[])}function mv(e,t){let r=So(t),n=Ub(e,r);return Rt(n)}var uv=new RegExp(sn);function cv(e){return e.filter(r=>uv.test(r))}function pv(e){let t=ra(e),r=cv(t),n=Ub(e,r);return Rt(n)}function Bb(e,t){return Se(t)?pv(e):mv(e,t)}function fv(e){return W(Eo(e))}function Gb(e){return e.map(t=>Mc(t))}function Mc(e){return v(e)?lt(Gb(e.allOf)):S(e)?_(Gb(e.anyOf)):J(e)?fv(e.const):e}function dv(e,t){return e.reduceRight((r,n,o)=>{let i=pt({},W(o),t);return N.IsExtendsTrueLike(i)?[n,...r]:r},[])}function lv(e,t){let r=Mc(t),n=dv(e,r);return nn(n)}function gv(e){return nn(e)}function Kb(e,t){return J(t)&&s.IsEqual(t.const,"length")?W(e.length):Se(t)||Xe(t)?gv(e):lv(e,t)}function Hb(e,t){return Y(e)?Mb(e.items,t):M(e)?Bb(e.properties,t):G(e)?Kb(e.items,t):me()}function yv(e){return fe(e)||Oe(e)||v(e)||S(e)?$o(e):e}function Oc(e,t,r){return K([e,t])?l.Update(Hb(yv(e),t),{},r):hi(e,t,r)}function zb(e,t,r,n,o){let i=$(e,t,r),a=$(e,t,n);return Oc(i,a,o)}function Ma(e,t={}){return C("InstanceType",[e],t)}function Wb(e,t={}){return vc(e,t)}function xv(e){return Pe(e)?e.instanceType:me()}function vc(e,t){return K([e])?l.Update(xv(e),{},t):Ma(e,t)}function Vb(e,t,r,n={}){let o=$(e,t,r);return vc(o,n)}function Ii(e,t={}){return C("KeyOf",[e],t)}function Jb(e,t={}){return Fc(e,t)}function Yb(){return _([Ft(),ct(),io()])}function Qb(e){return Ft()}function hv(e){return e.reduce((r,n)=>ua(n)?[...r,W(Eo(n))]:Re(),[])}function Xb(e){let t=s.Keys(e),r=hv(t);return nn(r)}function Zb(e){return po(e)}function e$(e){let t=e.map((r,n)=>W(n));return nn(t)}function t$(e){return Te(e)?Yb():Y(e)?Qb(e.items):M(e)?Xb(e.properties):se(e)?Zb(e):G(e)?e$(e.items):me()}function Iv(e){return fe(e)||Oe(e)||v(e)||S(e)?$o(e):e}function Fc(e,t){return K([e])?l.Update(t$(Iv(e)),{},t):Ii(e,t)}function r$(e,t,r,n){let o=$(e,t,r);return Fc(o,n)}function gi(e,t,r,n,o={}){return C("Mapped",[e,t,r,n],o)}function n$(e,t,r,n,o={}){return Lc({},Ie([],[]),e,t,r,n,o)}function bv(e){let t=gt(e);return nm(t)}function $v(e){return e.reduce((t,r)=>[...t,...nm(r)],[])}function Ev(e){let t=St(e);return nm(t)}function Sv(e){return s.IsNumber(e)?[W(`${e}`)]:[W(e)]}function nm(e){return Me(e)?Ev(e.enum):J(e)?Sv(e.const):de(e)?bv(e.pattern):S(e)?$v(e.anyOf):[e]}function o$(e){return nm(e)}function kv(e){return de(e)?gt(e.pattern):e}function Tv(e,t,r,n,o,i){let a=l.Assign(e,{[r.name]:n}),m=$(a,t,o),c=kv(m),p=$(a,t,i);return ca(c)||pa(c)?{[c.const]:p}:{}}function wv(e,t,r,n,o,i){return n.reduce((a,m)=>[...a,Tv(e,t,r,m,o,i)],[])}function Cv(e){return e.reduce((t,r)=>[...t,L(r)],[])}function i$(e,t,r,n,o,i){let a=o$(n),m=wv(e,t,r,a,o,i),c=Cv(m);return Fe(c)}function Lc(e,t,r,n,o,i,a){return K([n])?l.Update(i$(e,t,r,n,o,i),{},a):gi(r,n,o,i,a)}function s$(e,t,r,n,o,i,a){let m=$(e,t,n);return Lc(e,t,r,m,o,i,a)}function Rv(e,t,r){let n=l.Assign(e,t);return s.Keys(t).filter(i=>r.includes(i)).reduce((i,a)=>({...i,[a]:_I(n,a,t[a])}),{})}function Pv(e,t,r){let n=l.Assign(e,t);return s.Keys(t).filter(i=>!r.includes(i)).reduce((i,a)=>({...i,[a]:$(n,Ie([],[]),t[a])}),{})}function Av(e,t,r){let n=DI(t),o=Rv(e,t,n),i=Pv(e,t,n),a={...o,...i};return l.Update(a,{},r)}function om(e,t,r,n){return Av(e,r,n)}function va(e,t={}){return C("NonNullable",[e],t)}function a$(e,t={}){return Dc(e,t)}function Ov(e){let t=_([oo(),fo()]);return Oi(e,t,{})}function Dc(e,t){return K([e])?l.Update(Ov(e),{},t):va(e,t)}function m$(e,t,r,n){let o=$(e,t,r);return Dc(o,n)}function Fa(e,t,r={}){return C("Omit",[e,t],r)}function u$(e,t,r={}){let n=s.IsArray(t)?bo(t):t;return jc(e,n,r)}function im(e){let t=$o(e);return M(t)?t.properties:Re()}function Mv(e,t){return s.Keys(e).reduce((n,o)=>t.includes(o)?n:{...n,[o]:e[o]},{})}function c$(e,t){let r=im(e),n=So(t),o=Mv(r,n);return L(o)}function jc(e,t,r){return K([e,t])?l.Update(c$(e,t),{},r):Fa(e,t,r)}function p$(e,t,r,n,o){let i=$(e,t,r),a=$(e,t,n);return jc(i,a,o)}function La(e,t={}){return C("Parameters",[e],t)}function f$(e,t={}){return Nc(e,t)}function vv(e){let t=Ae(e)?e.parameters:[],r=fn({},Ie([],[]),t);return ve(r)}function Nc(e,t){return K([e])?l.Update(vv(e),{},t):La(e,t)}function d$(e,t,r,n){let o=$(e,t,r);return Nc(o,n)}function Da(e,t={}){return C("Partial",[e],t)}function l$(e,t={}){return qc(e,t)}function g$(e,t){let r=wr(e,t),n=Cr(r);return $r(l.Assign(e,{[t]:n}),t)}function y$(e,t,r){let n=mr(e,t,r);return Cr(n)}function x$(e){let t=Fe(e);return Cr(t)}function h$(e){let t=e.map(r=>Cr(r));return _(t)}function I$(e){let t=s.Keys(e).reduce((n,o)=>({...n,[o]:ta(e[o])}),{});return L(t)}function Cr(e){return fe(e)?g$(e.$defs,e.$ref):Oe(e)?y$(e.if,e.then,e.else):v(e)?x$(e.allOf):S(e)?h$(e.anyOf):M(e)?I$(e.properties):L({})}function qc(e,t){return K([e])?l.Update(Cr(e),{},t):Da(e,t)}function b$(e,t,r,n){let o=$(e,t,r);return qc(o,n)}function ja(e,t,r={}){return C("Pick",[e,t],r)}function $$(e,t,r={}){let n=s.IsArray(t)?bo(t):t;return _c(e,n,r)}function Fv(e,t){return s.Keys(e).reduce((n,o)=>t.includes(o)?l.Assign(n,{[o]:e[o]}):n,{})}function E$(e,t){let r=im(e),n=So(t),o=Fv(r,n);return L(o)}function _c(e,t,r){return K([e,t])?l.Update(E$(e,t),{},r):ja(e,t,r)}function S$(e,t,r,n,o){let i=$(e,t,r),a=$(e,t,n);return _c(i,a,o)}function Na(e,t={}){return C("ReadonlyObject",[e],t)}function Uc(e,t={}){return Bc(e,t)}var k$=Uc;function T$(e){return no(Tt(e))}function w$(e,t){let r=wr(e,t),n=Rr(r);return $r(l.Assign(e,{[t]:n}),t)}function C$(e,t,r){let n=mr(e,t,r);return Rr(n)}function R$(e){let t=Fe(e);return Rr(t)}function P$(e){let t=s.Keys(e).reduce((n,o)=>({...n,[o]:sa(e[o])}),{});return L(t)}function A$(e){return no(ve(e))}function O$(e){let t=e.map(r=>Rr(r));return _(t)}function Rr(e){return Y(e)?T$(e.items):fe(e)?w$(e.$defs,e.$ref):Oe(e)?C$(e.if,e.then,e.else):v(e)?R$(e.allOf):M(e)?P$(e.properties):G(e)?A$(e.items):S(e)?O$(e.anyOf):e}function Bc(e,t){return K([e])?l.Update(Rr(e),{},t):Na(e)}function M$(e,t,r,n){let o=$(e,t,r);return Bc(o,n)}function v$(e,t,r,n){return t.visited.includes(n)?r:n in e?$(e,Ie(t.callstack,[...t.visited,n]),e[n]):r}function F$(e,t){let r=wr(e,t),n=Pr(r);return $r(l.Assign(e,{[t]:n}),t)}function L$(e,t,r){let n=mr(e,t,r);return Pr(n)}function D$(e){let t=Fe(e);return Pr(t)}function j$(e){let t=e.map(r=>Pr(r));return _(t)}function Kx(e,t={}){return C("RemoveOptional",[e],t)}function N$(e,t={}){return An(e,t)}function q$(e){let t=s.Keys(e).reduce((n,o)=>({...n,[o]:N$(e[o])}),{});return L(t)}function Pr(e){return fe(e)?F$(e.$defs,e.$ref):Oe(e)?L$(e.if,e.then,e.else):v(e)?D$(e.allOf):S(e)?j$(e.anyOf):M(e)?q$(e.properties):L({})}function qa(e,t={}){return C("Required",[e],t)}function _$(e,t={}){return Gc(e,t)}function Gc(e,t){return K([e])?l.Update(Pr(e),{},t):qa(e,t)}function U$(e,t,r,n){let o=$(e,t,r);return Gc(o,n)}function _a(e,t={}){return C("ReturnType",[e],t)}function B$(e,t={}){return Kc(e,t)}function Lv(e){return Ae(e)?e.returnType:me()}function Kc(e,t){return K([e])?l.Update(Lv(e),{},t):_a(e,t)}function G$(e,t,r,n={}){let o=$(e,t,r);return Kc(o,n)}function Ua(e,t){return C("With",[e,t],{})}function sm(e,t){return Hc(e,t)}function Hc(e,t){return K([e])?l.Update(e,{},t):Ua(e,t)}function K$(e,t,r,n){let o=$(e,t,r);return Hc(o,n)}function Dv(e){return mn(e)?G(e.items)?zc(e.items.items):Be(e.items)?[e]:oe(e.items)?[e]:[me()]:[e]}function zc(e){return e.reduce((r,n)=>[...r,...Dv(n)],[])}function Ie(e,t){return{callstack:e,visited:t}}function K(e){return s.ShiftLeft(e,(t,r)=>oe(t)?!1:K(r),()=>!0)}function Ti(e,t,r){return s.Keys(r).reduce((n,o)=>({...n,[o]:$(e,t,r[o])}),{})}function fn(e,t,r){let n=Kt(e,t,r);return zc(n)}function Kt(e,t,r){return r.map(n=>$(e,t,n))}function jv(e,t){let r=_e(e)?xr(t,{}):t,n=Nr(e)?yr(r,{}):r;return Cn(e)?Fi(n,{}):n}function Nv(e,t,r,n,o){return s.IsEqual(r,"AddImmutable")?H$(e,t,n[0],o):s.IsEqual(r,"RemoveImmutable")?eb(e,t,n[0],o):s.IsEqual(r,"AddReadonly")?Bl(e,t,n[0],o):s.IsEqual(r,"RemoveReadonly")?wg(e,t,n[0],o):s.IsEqual(r,"AddOptional")?Gl(e,t,n[0],o):s.IsEqual(r,"RemoveOptional")?Tg(e,t,n[0],o):s.IsEqual(r,"Capitalize")?ub(e,t,n[0],o):s.IsEqual(r,"Conditional")?lb(e,t,n[0],n[1],n[2],n[3],o):s.IsEqual(r,"ConstructorParameters")?yb(e,t,n[0],o):s.IsEqual(r,"Evaluate")?GI(e,t,n[0],o):s.IsEqual(r,"Exclude")?hb(e,t,n[0],n[1],o):s.IsEqual(r,"Extract")?Eb(e,t,n[0],n[1],o):s.IsEqual(r,"Index")?zb(e,t,n[0],n[1],o):s.IsEqual(r,"InstanceType")?Vb(e,t,n[0],o):s.IsEqual(r,"Interface")?MI(e,t,n[0],n[1],o):s.IsEqual(r,"KeyOf")?r$(e,t,n[0],o):s.IsEqual(r,"Lowercase")?cb(e,t,n[0],o):s.IsEqual(r,"Mapped")?s$(e,t,n[0],n[1],n[2],n[3],o):s.IsEqual(r,"Module")?om(e,t,n[0],o):s.IsEqual(r,"NonNullable")?m$(e,t,n[0],o):s.IsEqual(r,"Pick")?S$(e,t,n[0],n[1],o):s.IsEqual(r,"Parameters")?d$(e,t,n[0],o):s.IsEqual(r,"Partial")?b$(e,t,n[0],o):s.IsEqual(r,"Omit")?p$(e,t,n[0],n[1],o):s.IsEqual(r,"ReadonlyObject")?M$(e,t,n[0],o):s.IsEqual(r,"Record")?Gg(e,t,n[0],n[1],o):s.IsEqual(r,"Required")?U$(e,t,n[0],o):s.IsEqual(r,"ReturnType")?G$(e,t,n[0],o):s.IsEqual(r,"TemplateLiteral")?Yh(e,t,n[0],o):s.IsEqual(r,"Uncapitalize")?pb(e,t,n[0],o):s.IsEqual(r,"Uppercase")?fb(e,t,n[0],o):s.IsEqual(r,"With")?K$(e,t,n[0],n[1]):C(r,n,o)}function qv(e,t,r){let n=oe(r)?v$(e,t,r,r.$ref):Y(r)?Tt($(e,t,r.items),eo(r)):Io(r)?rm(e,t,r.target,r.arguments):Pe(r)?hr(Kt(e,t,r.parameters),$(e,t,r.instanceType),Kl(r)):Ae(r)?Ir(Kt(e,t,r.parameters),$(e,t,r.returnType),Hl(r)):Oe(r)?wn($(e,t,r.if),$(e,t,r.then),$(e,t,r.else),Ql(r)):v(r)?lt(Kt(e,t,r.allOf),rg(r)):M(r)?L(Ti(e,t,r.properties),Jl(r)):se(r)?Kg(Ge(r),$(e,t,ye(r))):mn(r)?On($(e,t,r.items)):G(r)?ve(fn(e,t,r.items),Sg(r)):S(r)?_(Kt(e,t,r.anyOf),dg(r)):r;return jv(r,n)}function $(e,t,r){return tn(r)?Nv(e,t,r.action,r.parameters,r.options):qv(e,t,r)}function zt(e,t){return $(e,Ie([],[]),t)}function Fi(e,t){return l.Update(e,{"~immutable":!0},t)}function H$(e,t,r,n){let o=$(e,t,r);return Fi(o,n)}function Hx(e,t={}){return C("AddImmutable",[e],t)}function no(e,t={}){return Fi(e,t)}function zx(e,t={}){return C("RemoveReadonly",[e],t)}function Wx(e,t={}){return C("Evaluate",[e],t)}function Ze(e,t={}){return bc(e,t)}function Vx(e,t={}){return C("Module",[e],t)}function z$(e,t={}){return om({},Ie([],[]),e,t)}function _v(e,t){let r=mo(e,t);return s.IsEqual(r,di)||s.IsEqual(r,Pi)?1:0}function W$(e,t,r=[]){return s.ShiftLeft(t,(n,o)=>s.IsEqual(_v(e,n),1)?W$(e,o,[...r,n]):[...r,e,...t],()=>[...r,e])}function V$(e,t=[]){return s.ShiftLeft(e,(r,n)=>V$(n,W$(r,t)),()=>t)}function J$(e){return V$(e)}function Y$(...e){let[t,r,n]=z.Match(e,{2:(a,m)=>s.IsString(a)?[{},a,m]:[a,m,{}],3:(a,m,c)=>[a,m,c],1:a=>[{},a,{}]}),o=Hh(r),i=s.IsArray(o)&&s.IsEqual(o.length,2)?$(t,Ie([],[]),o[0]):me();return l.Update(i,{},n)}function Q$(e,t,r){return s.IsArray(r)?r.map(n=>et(e,t.items,n)):r}function X$(e,t,r){return et({...e,...t.$defs},Ye(t.$ref),r)}function Uv(e,t){let r=s.HasPropertyKey(t,"unevaluatedProperties")?{additionalProperties:t.unevaluatedProperties}:{},n=zt(e,t),o=Ze(n);return M(o)?sm(o,r):o}function Z$(e,t,r){let n=Uv(e,t);return et(e,n,r)}function am(e){return s.HasPropertyKey(e,"additionalProperties")?e.additionalProperties:void 0}function eE(e,t,r){if(!s.IsObject(r)||s.IsArray(r))return r;let n=am(t);for(let o of s.Keys(r)){if(s.HasPropertyKey(t.properties,o)&&Ee(t.properties[o])){r[o]=et(e,t.properties[o],r[o]);continue}if(s.IsBoolean(n)&&s.IsEqual(n,!0)||Ee(n)&&V(e,n,r[o])){r[o]=et(e,n,r[o]);continue}delete r[o]}return r}function tE(e,t,r){if(!s.IsObject(r))return r;let n=am(t),[o,i]=[new RegExp(Ge(t)),ye(t)];for(let a of s.Keys(r)){if(o.test(a)){r[a]=et(e,i,r[a]);continue}if(s.IsBoolean(n)&&s.IsEqual(n,!0)||Ee(n)&&V(e,n,r[a])){r[a]=et(e,n,r[a]);continue}delete r[a]}return r}function rE(e,t,r){return s.HasPropertyKey(e,t.$ref)?et(e,e[t.$ref],r):r}function nE(e,t,r){if(!s.IsArray(r))return r;let n=Math.min(r.length,t.items.length);for(let o=0;o<n;o++)r[o]=et(e,t.items[o],r[o]);return s.IsGreaterThan(r.length,n)?r.slice(0,n):r}function Bv(e){return s.HasPropertyKey(e,"~kind")||s.HasPropertyKey(e,"~unsafe")}function Gv(e){let t={};for(let r of s.Keys(e)){if(s.IsUnsafePropertyKey(r))continue;let n=Object.getOwnPropertyDescriptor(e,r);n.value=Dn(n.value),s.IsEqual(n.enumerable,!0)?t[r]=n.value:Object.defineProperty(t,r,n)}return t}function Kv(e){let t={};for(let r of s.Keys(e))s.IsUnsafePropertyKey(r)||(t[r]=Dn(e[r]));for(let r of s.Symbols(e))t[r]=Dn(e[r]);return t}function Hv(e){return s.IsClassInstance(e)?e:Bv(e)?Gv(e):Kv(e)}function zv(e){return e.map(t=>Dn(t))}function Wv(e){return e.slice()}function Vv(e){return new RegExp(e.source,e.flags)}function Jv(e){return new Map(Dn([...e.entries()]))}function Yv(e){return new Set(Dn([...e.values()]))}function Dn(e){return Ke.IsTypeArray(e)?Wv(e):Ke.IsRegExp(e)?Vv(e):Ke.IsMap(e)?Jv(e):Ke.IsSet(e)?Yv(e):s.IsArray(e)?zv(e):s.IsObject(e)?Hv(e):e}function oE(e){return Dn(e)}function xe(e){return oE(e)}function iE(e,t,r){for(let n of t.anyOf){let o=et(e,n,xe(r));if(V(e,n,o))return o}return r}function et(e,t,r){return Y(t)?Q$(e,t,r):fe(t)?X$(e,t,r):v(t)?Z$(e,t,r):M(t)?eE(e,t,r):se(t)?tE(e,t,r):oe(t)?rE(e,t,r):G(t)?nE(e,t,r):S(t)?iE(e,t,r):r}function Qv(e,t){return l.Assign(e,t)}function Xv(e){let t={};for(let r of Tf.Keys(e))t[r]=Li(e[r]);return t}function Zv(e){return ct({pattern:Ge(e)})}function eF(e){return Wc(J$(e))}function Wc(e){return e.map(t=>Li(t))}function Li(e){let t=Y(e)?Tt(Li(e.items),eo(e)):v(e)?lt(Wc(e.allOf)):S(e)?_(eF(e.anyOf)):M(e)?L(Xv(e.properties)):se(e)?co(Zv(e),Li(ye(e))):G(e)?ve(Wc(e.items)):e;return Qv(e,t)}function ko(e){return Li(e)}function ur(...e){let[t,r,n]=z.Match(e,{3:(i,a,m)=>[i,a,m],2:(i,a)=>[{},i,a]}),o=qe.Get().unionPrioritySort?ko(r):r;return et(t,o,n)}var ne={};_t(ne,{Fail:()=>jn,IsOk:()=>Vc,Ok:()=>O,TryArray:()=>tF,TryBigInt:()=>Jc,TryBoolean:()=>dF,TryNull:()=>hF,TryNumber:()=>EF,TryString:()=>SF,TryUndefined:()=>RF});function Vc(e){return s.IsObject(e)&&s.HasPropertyKey(e,"value")}function O(e){return{value:e}}function jn(){}function tF(e){return s.IsArray(e)?O(e):O([e])}function rF(e){return s.IsEqual(e,!0)?O(BigInt(1)):O(BigInt(0))}var nF=/^-?(0|[1-9]\d*)n$/,oF=/^-?(0|[1-9]\d*)\.\d+$/,iF=/^-?(0|[1-9]\d*)$/;function sF(e){return nF.test(e)}function aF(e){return oF.test(e)}function mF(e){return iF.test(e)}function uF(e){let t=e.toLowerCase();return sF(e)?O(BigInt(e.slice(0,e.length-1))):aF(e)?O(BigInt(e.split(".")[0])):mF(e)?O(BigInt(e)):s.IsEqual(t,"false")?O(BigInt(0)):s.IsEqual(t,"true")?O(BigInt(1)):void 0}function Jc(e){return s.IsBigInt(e)?O(e):s.IsBoolean(e)?rF(e):s.IsNumber(e)?O(BigInt(Math.trunc(e))):s.IsNull(e)?O(BigInt(0)):s.IsString(e)?uF(e):s.IsUndefined(e)?O(BigInt(0)):void 0}function cF(e){return s.IsEqual(e,BigInt(0))?O(!1):s.IsEqual(e,BigInt(1))?O(!0):void 0}function pF(e){return s.IsEqual(e,0)?O(!1):s.IsEqual(e,1)?O(!0):void 0}function fF(e){return s.IsEqual(e.toLowerCase(),"false")?O(!1):s.IsEqual(e.toLowerCase(),"true")?O(!0):s.IsEqual(e,"0")?O(!1):s.IsEqual(e,"1")?O(!0):void 0}function dF(e){return s.IsBigInt(e)?cF(e):s.IsBoolean(e)?O(e):s.IsNumber(e)?pF(e):s.IsNull(e)?O(!1):s.IsString(e)?fF(e):s.IsUndefined(e)?O(!1):void 0}function lF(e){return s.IsEqual(e,BigInt(0))?O(null):void 0}function gF(e){return s.IsEqual(e,!1)?O(null):void 0}function yF(e){return s.IsEqual(e,0)?O(null):void 0}function xF(e){let t=e.toLowerCase();return s.IsEqual(t,"undefined")||s.IsEqual(t,"null")||s.IsEqual(e,"")||s.IsEqual(e,"0")?O(null):void 0}function hF(e){return s.IsBigInt(e)?lF(e):s.IsBoolean(e)?gF(e):s.IsNumber(e)?yF(e):s.IsNull(e)?O(null):s.IsString(e)?xF(e):s.IsUndefined(e)?O(null):void 0}var sE=BigInt(Number.MAX_SAFE_INTEGER),aE=BigInt(Number.MIN_SAFE_INTEGER);function IF(e){return e<=sE&&e>=aE?O(Number(e)):void 0}function bF(e){return O(e?1:0)}function $F(e){let t=+e;if(s.IsNumber(t))return O(t);let r=e.toLowerCase();if(s.IsEqual(r,"false"))return O(0);if(s.IsEqual(r,"true"))return O(1);let n=Jc(e);return Vc(n)?n.value<=sE&&n.value>=aE?O(Number(n.value)):void 0:void 0}function EF(e){return s.IsBigInt(e)?IF(e):s.IsBoolean(e)?bF(e):s.IsNumber(e)?O(e):s.IsNull(e)?O(0):s.IsString(e)?$F(e):s.IsUndefined(e)?O(0):void 0}function SF(e){return s.IsBigInt(e)?O(e.toString()):s.IsBoolean(e)?O(e.toString()):s.IsNumber(e)?O(e.toString()):s.IsNull(e)?O("null"):s.IsString(e)?O(e):s.IsUndefined(e)?O(""):void 0}function kF(e){return s.IsEqual(e,BigInt(0))?O(void 0):void 0}function TF(e){return s.IsEqual(e,!1)?O(void 0):void 0}function wF(e){return s.IsEqual(e,0)?O(void 0):void 0}function CF(e){let t=e.toLowerCase();return s.IsEqual(t,"undefined")||s.IsEqual(t,"null")||s.IsEqual(e,"")||s.IsEqual(e,"0")?O(void 0):void 0}function RF(e){return s.IsBigInt(e)?kF(e):s.IsBoolean(e)?TF(e):s.IsNumber(e)?wF(e):s.IsNull(e)?O(void 0):s.IsString(e)?CF(e):s.IsUndefined(e)?O(e):void 0}function mE(e,t,r){return ne.TryArray(r).value.map(o=>je(e,t.items,o))}function uE(e,t,r){let n=ne.TryBigInt(r);return ne.IsOk(n)?n.value:r}function cE(e,t,r){let n=ne.TryBoolean(r);return ne.IsOk(n)?n.value:r}function pE(e,t,r){return je({...e,...t.$defs},Ye(t.$ref),r)}function fE(e,t,r){return je(e,Ze(t),r)}function dE(e,t,r){let n=ne.TryNumber(r);return ne.IsOk(n)?Math.trunc(n.value):r}function lE(e,t,r){let n=zt(e,t),o=Ze(n);return je(e,o,r)}function PF(e,t,r){let n=ne.TryBigInt(r);return ne.IsOk(n)&&s.IsEqual(t.const,n.value)?n.value:r}function AF(e,t,r){let n=ne.TryBoolean(r);return ne.IsOk(n)&&s.IsEqual(t.const,n.value)?n.value:r}function OF(e,t,r){let n=ne.TryNumber(r);return ne.IsOk(n)&&s.IsEqual(t.const,n.value)?n.value:r}function MF(e,t,r){let n=ne.TryString(r);return ne.IsOk(n)&&s.IsEqual(t.const,n.value)?n.value:r}function gE(e,t,r){return s.IsEqual(t.const,r)?r:cg(t)?PF(e,t,r):pg(t)?AF(e,t,r):ca(t)?OF(e,t,r):pa(t)?MF(e,t,r):Re()}function yE(e,t,r){let n=ne.TryNull(r);return ne.IsOk(n)?n.value:r}function xE(e,t,r){let n=ne.TryNumber(r);return ne.IsOk(n)?n.value:r}function mm(e,t,r,n){let o=s.Keys(n);for(let[i,a]of t)for(let m of o)i.test(m)||(n[m]=je(e,r,n[m]));return n}function Di(e,t,r){return _e(e)&&s.IsUndefined(r[t])}function vF(e,t,r){let n=s.EntriesRegExp(t.properties),o=s.Keys(r);for(let[i,a]of n)for(let m of o)!i.test(m)||Di(a,m,r)||(r[m]=je(e,a,r[m]));return s.HasPropertyKey(t,"additionalProperties")&&s.IsObject(t.additionalProperties)?mm(e,n,t.additionalProperties,r):r}function hE(e,t,r){return s.IsObjectNotArray(r)?vF(e,t,r):r}function FF(e,t,r){let n=s.EntriesRegExp(t.patternProperties),o=s.Keys(r);for(let[i,a]of n)for(let m of o)i.test(m)&&(r[m]=je(e,a,r[m]));return s.HasPropertyKey(t,"additionalProperties")&&s.IsObject(t.additionalProperties)?mm(e,n,t.additionalProperties,r):r}function IE(e,t,r){return s.IsObjectNotArray(r)?FF(e,t,r):r}function bE(e,t,r){return s.HasPropertyKey(e,t.$ref)?je(e,e[t.$ref],r):r}function $E(e,t,r){let n=ne.TryString(r);return ne.IsOk(n)?n.value:r}function EE(e,t,r){return je(e,Ze(t),r)}function SE(e,t,r){if(!s.IsArray(r))return r;for(let n=0;n<Math.min(t.items.length,r.length);n++)r[n]=je(e,t.items[n],r[n]);return r}function kE(e,t,r){let n=ne.TryUndefined(r);return ne.IsOk(n)?n.value:r}function TE(e,t,r){if(t.anyOf.some(a=>V(e,a,r)))return r;let i=t.anyOf.map(a=>je(e,a,xe(r))).find(a=>V(e,t,a));return s.IsUndefined(i)?r:i}function wE(e,t,r){let n=ne.TryUndefined(r);return ne.IsOk(n)?void 0:r}function je(e,t,r){return Y(t)?mE(e,t,r):vt(t)?uE(e,t,r):Et(t)?cE(e,t,r):fe(t)?pE(e,t,r):Me(t)?fE(e,t,r):Xe(t)?dE(e,t,r):v(t)?lE(e,t,r):J(t)?gE(e,t,r):Sr(t)?yE(e,t,r):Se(t)?xE(e,t,r):M(t)?hE(e,t,r):se(t)?IE(e,t,r):oe(t)?bE(e,t,r):ze(t)?$E(e,t,r):de(t)?EE(e,t,r):G(t)?SE(e,t,r):Zt(t)?kE(e,t,r):S(t)?TE(e,t,r):Lt(t)?wE(e,t,r):r}function Ar(...e){let[t,r,n]=z.Match(e,{3:(o,i,a)=>[o,i,a],2:(o,i)=>[{},o,i]});return je(t,r,n)}function CE(e,t,r){if(!s.IsArray(r))return r;for(let n=0;n<r.length;n++)r[n]=tt(e,t.items,r[n]);return r}function RE(e,t,r){return tt({...e,...t.$defs},Ye(t.$ref),r)}function PE(e,t){return s.IsUndefined(t)?s.IsFunction(e.default)?e.default():xe(e.default):t}function AE(e,t,r){let n=zt(e,t),o=Ze(n);return tt(e,o,r)}function OE(e,t,r){if(!s.IsObject(r))return r;let n=s.Keys(t.properties);for(let o of n){let i=tt(e,t.properties[o],r[o]);s.IsUndefined(i)&&(_e(t.properties[o])||!s.HasPropertyKey(t.properties[o],"default"))||(r[o]=i)}if(!Yt(t)||s.IsBoolean(t.additionalProperties))return r;for(let o of s.Keys(r))n.includes(o)||(r[o]=tt(e,t.additionalProperties,r[o]));return r}function ME(e,t,r){if(!s.IsObject(r))return r;let[n,o]=[new RegExp(Ge(t)),ye(t)];for(let i of s.Keys(r))n.test(i)&&Pt(o)&&(r[i]=tt(e,o,r[i]));if(!Yt(t))return r;for(let i of s.Keys(r))n.test(i)||(r[i]=tt(e,t.additionalProperties,r[i]));return r}function vE(e,t,r){return s.HasPropertyKey(e,t.$ref)?tt(e,e[t.$ref],r):r}function FE(e,t,r){if(!s.IsArray(r))return r;let[n,o]=[t.items,Math.max(t.items.length,r.length)];for(let i=0;i<o;i++)i<n.length&&(r[i]=tt(e,n[i],r[i]));return r}function LE(e,t,r){for(let n of t.anyOf){let o=tt(e,n,xe(r));if(V(e,n,o))return o}return r}function tt(e,t,r){let n=Pt(t)?PE(t,r):r;return Y(t)?CE(e,t,n):fe(t)?RE(e,t,n):v(t)?AE(e,t,n):M(t)?OE(e,t,n):se(t)?ME(e,t,n):oe(t)?vE(e,t,n):G(t)?FE(e,t,n):S(t)?LE(e,t,n):n}function dn(...e){let[t,r,n]=z.Match(e,{3:(o,i,a)=>[o,i,a],2:(o,i)=>[{},o,i]});return tt(t,r,n)}function To(e){return(...t)=>{let[r,n,o]=z.Match(t,{3:(i,a,m)=>[i,a,m],2:(i,a)=>[{},i,a]});return e.reduce((i,a)=>a(r,n,i),o)}}function LF(e,t,r){return t["~codec"].decode(r)}function DF(e,t,r){return t["~codec"].encode(r)}function $e(e,t,r,n){return $t(r)?s.IsEqual(e,"Decode")?LF(t,r,n):DF(t,r,n):n}function jF(e,t,r,n){if(!s.IsArray(n))return n;for(let o=0;o<n.length;o++)n[o]=ke(e,t,r.items,n[o]);return $e(e,t,r,n)}function NF(e,t,r,n){let o=$e(e,t,r,n);if(!s.IsArray(o))return o;for(let i=0;i<o.length;i++)o[i]=ke(e,t,r.items,o[i]);return o}function DE(e,t,r,n){return s.IsEqual(e,"Decode")?jF(e,t,r,n):NF(e,t,r,n)}function jE(e,t,r,n){return n=ke(e,{...t,...r.$defs},Ye(r.$ref),n),$e(e,t,r,n)}function NE(e){return e.reduce((t,r)=>({...t,...r}),{})}function qE(e,t){for(let r of t)if(!s.IsDeepEqual(e,r))return r;return e}function qF(e,t,r,n){if(s.IsEqual(r.allOf.length,0))return $e(e,t,r,n);let o=r.allOf.map(m=>ke(e,t,m,ur(m,xe(n)))),a=o.every(m=>s.IsObject(m))?NE(o):qE(n,o);return $e(e,t,r,a)}function _F(e,t,r,n){if(s.IsEqual(r.allOf.length,0))return $e(e,t,r,n);let o=$e(e,t,r,n),i=r.allOf.map(m=>ke(e,t,m,ur(m,xe(o))));return i.every(m=>s.IsObject(m))?NE(i):qE(o,i)}function _E(e,t,r,n){return s.IsEqual(e,"Decode")?qF(e,t,r,n):_F(e,t,r,n)}function UF(e,t,r,n){if(!s.IsObjectNotArray(n))return n;for(let o of s.Keys(r.properties))!s.HasPropertyKey(n,o)||Di(r.properties[o],o,n)||(n[o]=ke(e,t,r.properties[o],n[o]));return $e(e,t,r,n)}function BF(e,t,r,n){let o=$e(e,t,r,n);if(!s.IsObjectNotArray(o))return o;for(let i of s.Keys(r.properties))!s.HasPropertyKey(o,i)||Di(r.properties[i],i,o)||(o[i]=ke(e,t,r.properties[i],o[i]));return o}function UE(e,t,r,n){return s.IsEqual(e,"Decode")?UF(e,t,r,n):BF(e,t,r,n)}function GF(e,t,r,n){if(!s.IsObjectNotArray(n))return n;let o=new RegExp(Ge(r));for(let i of s.Keys(n))o.test(i)&&(n[i]=ke(e,t,ye(r),n[i]));return $e(e,t,r,n)}function KF(e,t,r,n){let o=$e(e,t,r,n);if(!s.IsObjectNotArray(o))return o;let i=new RegExp(Ge(r));for(let a of s.Keys(o))i.test(a)&&(o[a]=ke(e,t,ye(r),o[a]));return o}function BE(e,t,r,n){return s.IsEqual(e,"Decode")?GF(e,t,r,n):KF(e,t,r,n)}function GE(e,t,r,n){return s.HasPropertyKey(t,r.$ref)?ke(e,t,t[r.$ref],n):n}function KE(e,t,r,n){return s.IsEqual(e,"Decode")?$e(e,t,r,GE(e,t,r,n)):GE(e,t,r,$e(e,t,r,n))}function HF(e,t,r,n){if(!s.IsArray(n))return n;for(let o=0;o<Math.min(r.items.length,n.length);o++)n[o]=ke(e,t,r.items[o],n[o]);return $e(e,t,r,n)}function zF(e,t,r,n){let o=$e(e,t,r,n);if(!s.IsArray(o))return n;for(let i=0;i<Math.min(r.items.length,o.length);i++)o[i]=ke(e,t,r.items[i],o[i]);return o}function HE(e,t,r,n){return s.IsEqual(e,"Decode")?HF(e,t,r,n):zF(e,t,r,n)}function WF(e,t,r,n){for(let o of r.anyOf){if(!V(t,o,n))continue;let i=ke(e,t,o,n);return $e(e,t,r,i)}return n}function VF(e,t,r,n){let o=$e(e,t,r,n);for(let i of r.anyOf){let a=ke(e,t,i,xe(o));if(V(t,i,a))return a}return o}function zE(e,t,r,n){return s.IsEqual(e,"Decode")?WF(e,t,r,n):VF(e,t,r,n)}function ke(e,t,r,n){return Y(r)?DE(e,t,r,n):fe(r)?jE(e,t,r,n):v(r)?_E(e,t,r,n):M(r)?UE(e,t,r,n):se(r)?BE(e,t,r,n):oe(r)?KE(e,t,r,n):G(r)?HE(e,t,r,n):S(r)?zE(e,t,r,n):$e(e,t,r,n)}var Yc=class extends jr{constructor(t,r){super("Decode",t,r)}};function JF(e,t,r){if(!V(e,t,r))throw new Yc(r,sr(e,t,r));return r}function YF(e,t,r){let n=qe.Get().unionPrioritySort?ko(t):t;return ke("Decode",e,n,r)}var QF=To([(e,t,r)=>xe(r),(e,t,r)=>dn(e,t,r),(e,t,r)=>Ar(e,t,r),(e,t,r)=>ur(e,t,r),(e,t,r)=>JF(e,t,r),(e,t,r)=>YF(e,t,r)]);function WE(...e){let[t,r,n]=z.Match(e,{3:(o,i,a)=>[o,i,a],2:(o,i)=>[{},o,i]});return QF(t,r,n)}var Qc=class extends jr{constructor(t,r){super("Encode",t,r)}};function XF(e,t,r){if(!V(e,t,r))throw new Qc(r,sr(e,t,r));return r}function ZF(e,t,r){let n=qe.Get().unionPrioritySort?ko(t):t;return ke("Encode",e,n,r)}var e1=To([(e,t,r)=>xe(r),(e,t,r)=>ZF(e,t,r),(e,t,r)=>dn(e,t,r),(e,t,r)=>Ar(e,t,r),(e,t,r)=>ur(e,t,r),(e,t,r)=>XF(e,t,r)]);function VE(...e){let[t,r,n]=z.Match(e,{3:(o,i,a)=>[o,i,a],2:(o,i)=>[{},o,i]});return e1(t,r,n)}function t1(e,t){return $t(t)||ln(e,t.items)}function r1(e,t){return $t(t)||JE({...e,...t.$defs},Ye(t.$ref))}function n1(e,t){return $t(t)||t.allOf.some(r=>ln(e,r))}function o1(e,t){return $t(t)||s.Keys(t.properties).some(r=>ln(e,t.properties[r]))}function i1(e,t){return $t(t)||ln(e,ye(t))}function JE(e,t){return Xc.has(t.$ref)?!1:(Xc.add(t.$ref),$t(t)||s.HasPropertyKey(e,t.$ref)&&ln(e,e[t.$ref]))}function s1(e,t){return $t(t)||t.items.some(r=>ln(e,r))}function a1(e,t){return $t(t)||t.anyOf.some(r=>ln(e,r))}function ln(e,t){return Y(t)?t1(e,t):fe(t)?r1(e,t):v(t)?n1(e,t):M(t)?o1(e,t):se(t)?i1(e,t):oe(t)?JE(e,t):G(t)?s1(e,t):S(t)?a1(e,t):$t(t)}var Xc=new Set;function YE(...e){let[t,r]=z.Match(e,{2:(n,o)=>[n,o],1:n=>[{},n]});return Xc.clear(),ln(t,r)}var er=class extends Error{constructor(t,r){super(r),this.type=t}};function QE(e,t){return s.IsFunction(t.default)?t.default(t):s.IsObject(t.default)?xe(t.default):t.default}function XE(e,t){if(Qr(t)&&!Pt(t))throw new er(t,"Arrays with uniqueItems constraints must specify a default annotation");let r=En(t)?t.minItems:0;return Array.from({length:r},()=>Ne(e,t.items))}function ZE(e,t){return vr(t)?BigInt(t.exclusiveMinimum)+BigInt(1):Fr(t)?BigInt(t.minimum):BigInt(0)}function eS(e,t){return!1}function tS(e,t){let r=Ne(e,t.instanceType);return class{constructor(){Object.assign(this,r)}}}function rS(e,t){return Ne({...e,...t.$defs},Ye(t.$ref))}function nS(e,t){return Ne(e,Ze(t))}function oS(e,t){let r=Ne(e,t.returnType);return()=>r}function iS(e,t){return vr(t)&&s.IsNumber(t.exclusiveMinimum)?t.exclusiveMinimum+1:Fr(t)?t.minimum:0}function sS(e,t){let r=zt(e,t),n=Ze(r);return Ne(e,n)}function aS(e,t){return t.const}function mS(e,t){throw new er(t,"Cannot create TNever types")}function uS(e,t){return null}function cS(e,t){return vr(t)&&s.IsNumber(t.exclusiveMinimum)?t.exclusiveMinimum+1:Fr(t)?t.minimum:0}function pS(e,t){return(s.IsUndefined(t.required)?[]:t.required).reduce((n,o)=>({...n,[o]:Ne(e,t.properties[o])}),{})}function fS(e,t){if(Ko(t)&&!Pt(t))throw new er(t,"Record with the minProperties constraint must have a default annotation");return{}}function dS(e,t){return s.HasPropertyKey(e,t.$ref)?Ne(e,e[t.$ref]):(()=>{throw new er(t,"Unable to deref Ref")})()}function lS(e,t){if((Ho(t)||Uo(t))&&!Pt(t))throw Error("Strings with format or pattern constraints must specify default");let n=Go(t)?t.minLength:0;return"".padEnd(n)}function gS(e,t){return Symbol()}function yS(e,t){let r=so(t.pattern);if(ze(r))throw new er(t,"Unable to create TemplateLiteral due to infinite type expansion");return Ne(e,r)}function xS(e,t){return Array.from({length:t.minItems},(r,n)=>Ne(e,t.items[n]))}function hS(e,t){if(s.IsEqual(t.anyOf.length,0))throw Error("Unable to create Union with no variants");return Ne(e,t.anyOf[0])}function Ne(e,t){return Pt(t)?QE(e,t):Y(t)?XE(e,t):vt(t)?ZE(e,t):Et(t)?eS(e,t):Pe(t)?tS(e,t):fe(t)?rS(e,t):Me(t)?nS(e,t):Ae(t)?oS(e,t):Xe(t)?iS(e,t):v(t)?sS(e,t):J(t)?aS(e,t):wt(t)?mS(e,t):Sr(t)?uS(e,t):Se(t)?cS(e,t):M(t)?pS(e,t):se(t)?fS(e,t):oe(t)?dS(e,t):ze(t)?lS(e,t):kr(t)?gS(e,t):de(t)?yS(e,t):G(t)?xS(e,t):Zt(t)?void 0:S(t)?hS(e,t):Lt(t)?void 0:void 0}function at(...e){let[t,r]=z.Match(e,{2:(n,o)=>[n,o],1:n=>[{},n]});return Ne(t,r)}function um(e,t){return s.IsDeepEqual(e,t)}function cm(e){return Dr.Hash(e)}var pm=class extends jr{constructor(t,r){super("Parse",t,r)}};function m1(e,t,r){Xs();let n=sr(e,t,r);if(Zs(),!V(e,t,r))throw new pm(r,n);return r}var u1=To([(e,t,r)=>xe(r),(e,t,r)=>dn(e,t,r),(e,t,r)=>Ar(e,t,r),(e,t,r)=>ur(e,t,r),(e,t,r)=>m1(e,t,r)]);function IS(...e){let[t,r,n]=z.Match(e,{3:(a,m,c)=>[a,m,c],2:(a,m)=>[{},a,m]});if(V(t,r,n))return n;if(qe.Get().correctiveParse)return u1(t,r,n);Xs();let i=sr(t,r,n);throw Zs(),new pm(n,i)}function fm(e,t){return{type:"update",path:e,value:t}}function $S(e,t){return{type:"insert",path:e,value:t}}function ES(e){return{type:"delete",path:e}}function bS(e){if(!(s.IsObject(e)&&s.IsEqual(s.Symbols(e).length,0)))throw new Error("Cannot create diffs for objects with symbols keys")}function*c1(e,t,r){if(!s.IsObject(r)||s.IsArray(r))return yield fm(e,r);bS(t),bS(r);let n=s.Keys(t),o=s.Keys(r);for(let i of o)s.HasPropertyKey(t,i)||s.IsUnsafePropertyKey(i)||(yield $S(`${e}/${i}`,r[i]));for(let i of n)s.HasPropertyKey(r,i)&&(s.IsUnsafePropertyKey(i)||um(t,r)||(yield*dm(`${e}/${i}`,t[i],r[i])));for(let i of n)s.HasPropertyKey(r,i)||s.IsUnsafePropertyKey(i)||(yield ES(`${e}/${i}`))}function*p1(e,t,r){if(!s.IsArray(r))return yield fm(e,r);for(let n=0;n<Math.min(t.length,r.length);n++)yield*dm(`${e}/${n}`,t[n],r[n]);for(let n=0;n<r.length;n++)n<t.length||(yield $S(`${e}/${n}`,r[n]));for(let n=t.length-1;n>=0;n--)n<r.length||(yield ES(`${e}/${n}`))}function*f1(e,t,r){let n=globalThis.Object.getPrototypeOf(t).constructor.name,o=globalThis.Object.getPrototypeOf(r).constructor.name;if(Ke.IsTypeArray(r)&&s.IsEqual(t.length,r.length)&&s.IsEqual(n,o))for(let a=0;a<Math.min(t.length,r.length);a++)yield*dm(`${e}/${a}`,t[a],r[a]);else return yield fm(e,r)}function*d1(e,t,r){t!==r&&(yield fm(e,r))}function*dm(e,t,r){return Ke.IsTypeArray(t)?yield*f1(e,t,r):s.IsArray(t)?yield*p1(e,t,r):s.IsObject(t)?yield*c1(e,t,r):yield*d1(e,t,r)}function SS(e,t){return[...dm("",e,t)]}var l1=L({type:W("insert"),path:ct(),value:He()}),g1=Object({type:W("update"),path:ct(),value:He()}),y1=L({type:W("delete"),path:ct()}),gRe=_([l1,g1,y1]);function x1(e){return e.length>0&&e[0].path===""&&e[0].type==="update"}function h1(e){return e.length===0}function kS(e,t){if(x1(t))return xe(t[0].value);if(h1(t))return xe(e);let r=xe(e);for(let n of t)switch(n.type){case"insert":{gr.Set(r,n.path,n.value);break}case"update":{gr.Set(r,n.path,n.value);break}case"delete":{gr.Delete(r,n.path);break}}return r}var Ur=class extends Error{constructor(t,r,n,o){super(o),this.context=t,this.type=r,this.value=n}};function I1(e){let[t,r]=[new Set,[]];for(let n of e){let o=cm(n);t.has(o)||(t.add(o),r.push(n))}return r}function TS(e,t,r){if(V(e,t,r))return r;let n=s.IsArray(r)?r:at(e,t),o=En(t)&&n.length<t.minItems?[...n,...Array.from({length:t.minItems-n.length},()=>at(e,t))]:n,a=(Bo(t)&&o.length>t.maxItems?o.slice(0,t.maxItems):o).map(c=>We(e,t.items,c));if(!Qr(t)||Qr(t)&&!s.IsEqual(t.uniqueItems,!0))return a;let m=I1(a);if(!V(e,t,m))throw new Ur(e,t,r,"Failed to repair Array due to uniqueItems constraint");return m}function wS(e,t,r){return We(e,Ze(t),r)}function CS(e,t,r){let n=zt(e,t),o=Ze(n);return We(e,o,r)}function RS(e,t,r){if(V(e,t,r))return r;if(!s.IsObjectNotArray(r))return at(e,t);let n=new Set(s.IsUndefined(t.required)?[]:t.required),o={};for(let[a,m]of s.Entries(t.properties))!n.has(a)&&s.IsUndefined(r[a])||(o[a]=a in r?We(e,m,r[a]):at(e,m));let i=s.Keys(t.properties);if(Yt(t)&&s.IsObject(t.additionalProperties))for(let a of s.Keys(r))i.includes(a)||(o[a]=We(e,t.additionalProperties,r[a]));return o}function PS(e,t,r){if(V(e,t,r))return r;if(s.IsNull(r)||!s.IsObject(r)||s.IsArray(r))return at(e,t);let n=new RegExp(Ge(t)),o=ye(t),i=new Set,a={};for(let[m,c]of s.Entries(r))n.test(m)&&(a[m]=We(e,o,c),i.add(m));if(Yt(t))for(let m of s.Keys(r))i.has(m)||(a[m]=We(e,t.additionalProperties,r[m]));return a}function AS(e,t,r){return s.HasPropertyKey(e,t.$ref)?We(e,e[t.$ref],r):(()=>{throw new Ur(e,t,r,"Unable to de-reference target type")})()}function OS(e,t,r){let n=so(t.pattern);return We(e,n,r)}function MS(e,t,r){return V(e,t,r)?r:s.IsArray(r)?t.items.map((n,o)=>We(e,n,r[o])):at(e,t)}function vS(e,t,r){return oe(t)?s.HasPropertyKey(e,t.$ref)?vS(e,e[t.$ref],r):(()=>{throw new Error("Unable to Deref target")})():t}function b1(e,t,r){if(!(M(t)&&s.IsObject(r)))return 0;let n=s.Keys(r);return s.Entries(t.properties).reduce((i,[a,m])=>{let c=J(m)&&s.IsEqual(m.const,r[a])?100:0,p=V(e,m,r[a])?10:0,f=n.includes(a)?1:0;return i+(c+p+f)},0)}function FS(e,t,r){let n=t.anyOf.map(a=>vS(e,a,r)),[o,i]=[n[0],0];for(let a of n){let m=b1(e,a,r);m>i&&(o=a,i=m)}return o}function $1(e,t,r){let n=_(an(t.anyOf)),o=FS(e,n,r);return We(e,o,r)}function LS(e,t,r){return V(e,t,r)?xe(r):Pt(t)?at(e,t):$1(e,t,r)}function DS(e,t,r){if(V(e,t,r))return r;let n=Ar(e,t,r);return V(e,t,n)?n:at(e,t)}function E1(e,t,r){if(Ke.IsDate(r)||Ke.IsMap(r)||Ke.IsSet(r)||Ke.IsTypeArray(r)||s.IsConstructor(r)||s.IsFunction(r))throw new Ur(e,t,r,"Value is not repairable")}function S1(e,t,r){if(Pe(t)||Ae(t)||wt(t))throw new Ur(e,t,r,"Type is not repairable")}function k1(e,t,r){return s.IsUndefined(r)&&!Zt(t)?at(e,t):r}function T1(e,t,r){return ai(t)?V(e,t,r)?r:at(e,t):r}function We(e,t,r){E1(e,t,r),S1(e,t,r);let n=k1(e,t,r),o=Y(t)?TS(e,t,n):Me(t)?wS(e,t,n):v(t)?CS(e,t,n):M(t)?RS(e,t,n):se(t)?PS(e,t,n):oe(t)?AS(e,t,n):de(t)?OS(e,t,n):G(t)?MS(e,t,n):S(t)?LS(e,t,n):DS(e,t,n);return T1(e,t,o)}function jS(...e){let[t,r,n]=z.Match(e,{3:(i,a,m)=>[i,a,m],2:(i,a)=>[{},i,a]}),o=We(t,r,n);return ea(t,r,o),o}var wo={};_t(wo,{Assert:()=>ea,Check:()=>V,Clean:()=>ur,Clone:()=>xe,Convert:()=>Ar,Create:()=>at,Decode:()=>WE,Default:()=>dn,Diff:()=>SS,Encode:()=>VE,Equal:()=>um,Errors:()=>sr,HasCodec:()=>YE,Hash:()=>cm,Parse:()=>IS,Patch:()=>kS,Pointer:()=>gr,Repair:()=>jS});var A1=P1(it,"hooks.json"),NS=64*1024,US=30,qS=["PreToolUse","PostToolUse","UserPromptSubmit","SessionStart","Stop","PreCompact","SessionEnd"];function NPe(e,t){if(t===null||typeof t!="object"||Array.isArray(t))return"the rewrite is not a JSON object";if(!(e===null||typeof e!="object"))try{if(wo.Check(e,t))return;let r=[...wo.Errors(e,t)][0];if(!r)return"the rewrite does not match the tool's schema";let n="instancePath"in r?String(r.instancePath):"";return`the rewrite does not match the tool's schema${n&&n!=="/"?` at \`${n}\``:""}: ${r.message}`}catch(r){return`the tool's schema could not be checked: ${r instanceof Error?r.message:String(r)}`}}function qPe(e=A1){let t=[],r={hooks:{}};try{if(!C1(e))return{config:r,diagnostics:t};let n=R1(e,"utf8");if(Buffer.byteLength(n,"utf8")>NS)return t.push({source:e,message:`skipped: larger than ${NS} bytes`}),{config:r,diagnostics:t};let o=JSON.parse(n),i=O1(o);for(let a of i.diagnostics)t.push({source:e,message:a});return{config:i.config,diagnostics:t}}catch(n){return t.push({source:e,message:`unreadable: ${n instanceof Error?n.message:String(n)}`}),{config:r,diagnostics:t}}}function O1(e){let t=[],r={hooks:{}};if(e===null||typeof e!="object"||Array.isArray(e))return{config:r,diagnostics:["expected a JSON object with a `hooks` key"]};let n=e.hooks;if(n===void 0)return{config:r,diagnostics:["no `hooks` key"]};if(n===null||typeof n!="object"||Array.isArray(n))return{config:r,diagnostics:["`hooks` must be an object keyed by event name"]};for(let[o,i]of Object.entries(n)){if(!qS.includes(o)){t.push(`unknown event \`${o}\` \u2014 supported: ${qS.join(", ")}`);continue}if(!Array.isArray(i)){t.push(`\`${o}\` must be an array of matchers`);continue}let a=[];for(let m of i){let c=M1(m,o,t);c&&a.push(c)}a.length&&(r.hooks[o]=a)}return{config:r,diagnostics:t}}function M1(e,t,r){if(e===null||typeof e!="object"||Array.isArray(e)){r.push(`\`${t}\`: a matcher must be an object`);return}let n=e,o=Array.isArray(n.hooks)?n.hooks:void 0;if(!o){r.push(`\`${t}\`: a matcher needs a \`hooks\` array`);return}let i=[];for(let m of o){if(m===null||typeof m!="object")continue;let c=m,p=typeof c.type=="string"?c.type:"command";if(p!=="command"){r.push(`\`${t}\`: only \`type: "command"\` is supported, got \`${p}\``);continue}if(typeof c.command!="string"||!c.command.trim()){r.push(`\`${t}\`: a hook needs a non-empty \`command\``);continue}let f=typeof c.timeout=="number"&&Number.isFinite(c.timeout)&&c.timeout>0?c.timeout:void 0;i.push({type:"command",command:c.command,timeout:f,...c.async===!0?{async:!0}:{},...c.once===!0?{once:!0}:{}})}return i.length?{matcher:typeof n.matcher=="string"?n.matcher:void 0,hooks:i}:void 0}function v1(e,t,r){let n=e.hooks[t];return n?n.filter(o=>{let i=o.matcher?.trim();if(!i||i==="*")return!0;if(r===void 0)return!1;let a=r.toLowerCase();return i.split("|").map(m=>m.trim().toLowerCase()).filter(Boolean).includes(a)}):[]}function _S(e,t,r={cwd:process.cwd()}){let n=r.timeoutS??US;return new Promise(o=>{let i="",a="",m=!1,c=!1,p=w1(e,{cwd:r.cwd,shell:!0,stdio:["pipe","pipe","pipe"]});p.stdin?.on("error",()=>{}),p.stdout?.on("error",()=>{}),p.stderr?.on("error",()=>{});let f=setTimeout(()=>{m=!0,p.kill("SIGKILL")},n*1e3);p.stdout?.on("data",g=>{i+=g.toString("utf8")}),p.stderr?.on("data",g=>{a+=g.toString("utf8")});let d=g=>{c||(c=!0,clearTimeout(f),o({code:g,stdout:i,stderr:a,timedOut:m}))};p.on("error",g=>{a+=g.message,d(null)}),p.on("close",g=>d(g));try{p.stdin?.end(JSON.stringify(t))}catch{}})}function F1(e){let{code:t,stdout:r,stderr:n,timedOut:o}=e,i=n.trim();if(o)return{block:!1,error:`timed out after ${US}s and was killed`};let a=L1(r),m=a?.hookSpecificOutput,c=typeof m?.additionalContext=="string"?m.additionalContext:typeof a?.additionalContext=="string"?a.additionalContext:void 0,p=typeof m?.permissionDecision=="string"?m.permissionDecision:void 0,f=typeof m?.permissionDecisionReason=="string"?m.permissionDecisionReason:void 0,d=m?.updatedInput,g=d!==null&&typeof d=="object"&&!Array.isArray(d)?d:void 0;return p==="deny"||p==="block"?{block:!0,reason:f||i||"denied by a hook",context:c}:p==="allow"?{block:!1,context:c,updatedInput:g}:t===2?{block:!0,reason:i||"blocked by a hook",context:c}:t!==0?{block:!1,context:c,updatedInput:g,error:`exited ${t===null?"without a status":t}${i?`: ${i}`:""}`}:!a&&r.trim()?{block:!1,context:r.trim()}:{block:!1,context:c,updatedInput:g}}function L1(e){let t=e.trim();if(t.startsWith("{"))try{let r=JSON.parse(t);return r&&typeof r=="object"&&!Array.isArray(r)?r:void 0}catch{return}}var Zc=new Set;function _Pe(){Zc.clear()}async function UPe(e,t,r,n){let o=v1(e,t,r.tool_name);if(!o.length)return{outcome:{block:!1},ran:0};let i=[],a=0,m,c,p;for(let f of o)for(let d of f.hooks){if(d.once){let I=`${t}\0${d.command}`;if(Zc.has(I))continue;Zc.add(I)}if(a+=1,d.async){_S(d.command,r,{cwd:n.cwd,timeoutS:d.timeout}).catch(()=>{});continue}let g=await _S(d.command,r,{cwd:n.cwd,timeoutS:d.timeout}),y=F1(g);y.context&&i.push(y.context),y.error&&(c=y.error),y.updatedInput&&(p=y.updatedInput),y.block&&!m&&(m=y)}return m?{outcome:{block:!0,reason:m.reason,context:i.join(`
8
-
9
- `)||void 0},ran:a}:{outcome:{block:!1,context:i.join(`
10
-
11
- `)||void 0,error:c,updatedInput:p},ran:a}}import{existsSync as BS,readFileSync as D1}from"node:fs";function j1(e){return`${e}/.howtocode/mcp.json`}function ep(e,t){if(!BS(e))return{};try{let n=JSON.parse(D1(e,"utf8"))?.mcpServers;return!n||typeof n!="object"||Array.isArray(n)?{}:n}catch(r){return t.push(`${e}: ${r instanceof Error?r.message:String(r)}`),{}}}function zPe(e){let t=[];return ep(Ji(e??it),t)}function WPe(e){let t=[],r=ep(Ji(e.agentDir??it),t),n=j1(e.cwd),o=e.projectTrusted&&BS(n)?n:void 0,i=o?ep(o,t):{},a=Ji(e.agentDir??it),m=new Map;for(let[c,p]of Object.entries(r))m.set(c,{name:c,config:p,source:a,scope:"global"});for(let[c,p]of Object.entries(i))m.set(c,{name:c,config:p,source:o,scope:"project"});return{servers:[...m.values()],errors:t,projectConfig:o}}import{mkdirSync as N1,readdirSync as q1,readFileSync as _1,renameSync as U1,unlinkSync as GS,writeFileSync as B1}from"node:fs";import{join as KS}from"node:path";var G1=180*1e3,QPe="presence";function HS(e,t){return KS(e.dir,`${t.replace(/[^A-Za-z0-9._-]/g,"_")}.json`)}function K1(e,t=Date.now()){let r;try{r=q1(e.dir)}catch{return[]}let n=[];for(let o of r){if(!o.endsWith(".json"))continue;let i=KS(e.dir,o),a;try{a=_1(i,"utf8")}catch{continue}let m;try{m=JSON.parse(a)}catch{tp(i);continue}if(typeof m?.id!="string"||typeof m?.cwd!="string"||typeof m?.at!="number"){tp(i);continue}if(t-m.at>=G1){tp(i);continue}n.push({id:m.id,cwd:m.cwd,host:typeof m.host=="string"?m.host:"",pid:typeof m.pid=="number"?m.pid:0,at:m.at,...typeof m.activity=="string"&&m.activity?{activity:m.activity}:{}})}return n.sort((o,i)=>i.at-o.at)}function XPe(e,t){N1(e.dir,{recursive:!0});let r=HS(e,t.id),n=`${r}.${process.pid}.tmp`;B1(n,JSON.stringify(t,null,2)),U1(n,r)}function ZPe(e,t){try{GS(HS(e,t))}catch{}}function zS(e,t,r,n=Date.now()){return K1(e,n).filter(o=>o.cwd===t&&o.id!==r)}function tp(e){try{GS(e)}catch{}}import{Type as mt}from"@netrodev/hxf-ai";import{defineTool as lm}from"@netrodev/hxf-coding-agent";import{relative as eL,join as tL}from"node:path";import{mkdirSync as rL,writeFileSync as nL}from"node:fs";import{existsSync as rAe,mkdirSync as H1,readFileSync as z1,renameSync as W1,writeFileSync as V1}from"node:fs";import{dirname as J1,isAbsolute as Y1,join as JS,relative as Q1,resolve as WS,sep as VS}from"node:path";var X1=1800*1e3,Z1=JS(".howtocode","claims.json");function YS(e){return JS(e,Z1)}function np(e,t){try{let r=z1(YS(e),"utf8"),n=JSON.parse(r);return(Array.isArray(n.claims)?[...n.claims]:[]).filter(i=>typeof i?.path=="string"&&typeof i?.holder=="string"&&typeof i?.at=="number"&&t-i.at<X1)}catch{return[]}}function QS(e,t){let r=YS(e);H1(J1(r),{recursive:!0});let n=`${r}.${process.pid}.tmp`;V1(n,JSON.stringify({version:1,claims:[...t]},null,2)),W1(n,r)}function XS(e,t){return Y1(t)?WS(t):WS(e,t)}function ZS(e,t){if(e===t)return!0;let r=n=>n.endsWith(VS)?n:n+VS;return e.startsWith(r(t))||t.startsWith(r(e))}function ek(e){let t=e.now??Date.now(),r=np(e.root,t),n=[],o=[],i=[];for(let a of e.paths){if(!a.trim())continue;let m=XS(e.root,a.trim()),c=r.find(p=>p.holder!==e.holder&&ZS(p.path,m));if(c){o.push({path:rp(e.root,m),by:c.holder,reason:c.reason||"no reason given"});continue}n.push(rp(e.root,m)),i.push({path:m,holder:e.holder,reason:e.reason,at:t})}if(i.length>0){let a=r.filter(m=>m.holder!==e.holder||!i.some(c=>c.path===m.path));QS(e.root,[...a,...i])}return{granted:n,conflicts:o}}function tk(e,t,r){let n=Date.now(),o=np(e,n),i=r?.length?r.map(c=>XS(e,c.trim())).filter(Boolean):void 0,a=[],m=[];for(let c of o){let p=c.holder===t,f=i===void 0||i.some(d=>ZS(c.path,d));p&&f?m.push(rp(e,c.path)):a.push(c)}return QS(e,a),m}function op(e,t=Date.now()){return np(e,t)}function rp(e,t){let r=Q1(e,t);return r&&!r.startsWith("..")?r:t}var ip;function pAe(e){ip=e}var fAe=lm({name:"think",label:"think",description:"Private scratchpad. The text is not shown to the user. Use it before a non-obvious step.",promptSnippet:"think: private notes, not shown to the user",parameters:mt.Object({thoughts:mt.String({description:"Private notes"})}),async execute(){return{content:[{type:"text",text:"noted"}],details:{recorded:!0}}}}),dAe=lm({name:"ask",label:"ask",description:"Ask the user one question and wait for a selected answer. Use this instead of guessing when a choice blocks the task.",promptSnippet:"ask: ask the user to pick one option",parameters:mt.Object({question:mt.String(),options:mt.Array(mt.String(),{minItems:2})}),async execute(e,t){if(!ip)return{content:[{type:"text",text:"cancelled"}],details:{answer:"cancelled"}};let r=await ip(t.question,t.options);return{content:[{type:"text",text:r}],details:{answer:r}}}}),ji;function lAe(e){ji=e}var gAe=lm({name:"sessions",label:"sessions",description:"See the other HowToCode sessions working in this workspace, what they hold, and what they are doing. Use it to find who is blocking a claim, or to tell another session to release a file. Send a message with message + to.",promptSnippet:"sessions: other CLI sessions, and who holds what",parameters:mt.Object({message:mt.Optional(mt.String({description:"Message text to leave for another session."})),to:mt.Optional(mt.String({description:"Session id to send the message to. Use `all` for every other session."}))}),async execute(e,t){let r=ji,n=r?.presenceDir?.();if(!r||!n)return{content:[{type:"text",text:"the session registry is unavailable here"}],details:{}};let o=r.selfId?.()??"",i=r.root(),a=zS({dir:n},i);if(t.message&&t.message.trim()){let c=t.to?.trim()||"all",p=a.filter(f=>f.id!==o&&(c==="all"||f.id===c));if(p.length===0)return{content:[{type:"text",text:"no other session in this workspace to message"}],details:{sent:0}};for(let f of p){let d=tL(n,`${f.id.replace(/[^A-Za-z0-9._-]/g,"_")}.inbox`);try{rL(n,{recursive:!0}),nL(d,`${JSON.stringify({from:o,at:Date.now(),text:t.message.trim()})}
12
- `,{flag:"a"})}catch{}}return{content:[{type:"text",text:`left a message for ${p.map(f=>f.id).join(", ")}`}],details:{sent:p.length}}}if(a.length===0)return{content:[{type:"text",text:"no other session in this workspace"}],details:{sessions:[]}};let m=a.map(c=>{let p=c.id===o?"this session":c.id,f=op(i).filter(y=>y.holder===`session:${c.id}`),d=c.activity?` \u2014 ${c.activity}`:"",g=f.length>0?`
13
- holds:
14
- ${f.map(y=>` ${nk(i,y.path)} \u2014 ${y.reason}`).join(`
15
- `)}`:"";return` ${p} (pid ${c.pid}${c.id===o?"":`, seen ${Math.round((Date.now()-c.at)/1e3)}s ago`})${d}${g}`});return{content:[{type:"text",text:`sessions in ${i}:
16
- ${m.join(`
17
- `)}`}],details:{sessions:a}}}});function oL(e){let t=[];if(e.granted.length>0&&t.push(`claimed: ${e.granted.join(", ")}`),e.conflicts.length>0){t.push(""),t.push("refused \u2014 another agent is working on these:");for(let r of e.conflicts)t.push(` ${r.path} \u2014 held by ${r.by}: ${r.reason}`);t.push(""),t.push("Wait for the holder to release it, or work on something else. Do not edit a refused path.")}return t.length===0&&t.push("nothing to claim"),{text:t.join(`
18
- `),isError:e.conflicts.length>0}}var rk=lm({name:"claim",label:"claim",description:"Claim files or directories before editing them, so a parallel agent cannot overwrite your work. Refused paths are held by someone else \u2014 do not edit them. Pass no paths to list every claim in this workspace.",promptSnippet:"claim: reserve files before editing",parameters:mt.Object({paths:mt.Optional(mt.Array(mt.String(),{description:"Files or directories to claim. Omit to list the current claims."})),reason:mt.Optional(mt.String({description:"Why you are taking them, shown to a refused agent."})),release:mt.Optional(mt.Boolean({description:"Release these paths instead of claiming them. Omit paths to release everything you hold."}))}),async execute(e,t){if(!ji)return{content:[{type:"text",text:"claims are unavailable in this session"}],details:{},isError:!0};let r=ji.root(),n=ji.holder();if(t.release){let m=tk(r,n,t.paths);return{content:[{type:"text",text:m.length>0?`released: ${m.join(", ")}`:"you held nothing matching that"}],details:{released:m}}}if(!t.paths||t.paths.length===0){let m=op(r);return m.length===0?{content:[{type:"text",text:"no active claims in this workspace"}],details:{claims:[]}}:{content:[{type:"text",text:m.map(p=>`${p.holder===n?"(you) ":""}${nk(r,p.path)} \u2014 ${p.reason}`).join(`
19
- `)}],details:{claims:m}}}let o=ek({root:r,holder:n,reason:t.reason??"no reason given",paths:t.paths}),{text:i,isError:a}=oL(o);return{content:[{type:"text",text:i}],isError:a,details:o}}});function nk(e,t){let r=eL(e,t);return r&&!r.startsWith("..")?r:t}import{StringEnum as iL}from"@netrodev/hxf-ai";import{defineTool as sL}from"@netrodev/hxf-coding-agent";var D={};_t(D,{Any:()=>ro,Array:()=>Tt,BigInt:()=>mi,Boolean:()=>aa,Call:()=>XI,Capitalize:()=>ib,Codec:()=>ia,Conditional:()=>db,Constructor:()=>hr,ConstructorParameters:()=>gb,Cyclic:()=>$r,Decode:()=>ng,DecodeBuilder:()=>si,Dependent:()=>wn,Encode:()=>og,EncodeBuilder:()=>ii,Enum:()=>tg,Evaluate:()=>Ze,Exclude:()=>xb,Extends:()=>pt,ExtendsResult:()=>N,Extract:()=>Ib,Function:()=>Ir,Generic:()=>rn,Identifier:()=>ui,Immutable:()=>ig,Index:()=>Sb,Infer:()=>oi,InstanceType:()=>Wb,Instantiate:()=>zt,Integer:()=>Rn,Interface:()=>vI,Intersect:()=>lt,IsAny:()=>Te,IsArray:()=>Y,IsBigInt:()=>vt,IsBoolean:()=>Et,IsCall:()=>Io,IsCodec:()=>$t,IsConstructor:()=>Pe,IsCyclic:()=>fe,IsDependent:()=>Oe,IsEnum:()=>Me,IsEnumValue:()=>eg,IsFunction:()=>Ae,IsGeneric:()=>to,IsIdentifier:()=>ug,IsImmutable:()=>Cn,IsInfer:()=>Be,IsInteger:()=>Xe,IsIntersect:()=>v,IsKind:()=>w,IsLiteral:()=>J,IsNever:()=>wt,IsNull:()=>Sr,IsNumber:()=>Se,IsObject:()=>M,IsOptional:()=>_e,IsParameter:()=>fg,IsReadonly:()=>Nr,IsRecord:()=>se,IsRef:()=>oe,IsRefine:()=>ai,IsRest:()=>mn,IsSchema:()=>Ee,IsString:()=>ze,IsSymbol:()=>kr,IsTemplateLiteral:()=>de,IsThis:()=>$a,IsTuple:()=>G,IsUndefined:()=>Zt,IsUnion:()=>S,IsUnknown:()=>Ue,IsUnsafe:()=>oa,IsVoid:()=>Lt,KeyOf:()=>Jb,Literal:()=>W,Lowercase:()=>sb,Mapped:()=>n$,Module:()=>z$,Never:()=>me,NonNullable:()=>a$,Null:()=>oo,Number:()=>Ft,Object:()=>L,Omit:()=>u$,Optional:()=>Wl,Parameter:()=>Pn,Parameters:()=>f$,Partial:()=>l$,Pick:()=>$$,Readonly:()=>sg,ReadonlyObject:()=>Uc,ReadonlyType:()=>k$,Record:()=>co,RecordKey:()=>po,RecordPattern:()=>Ge,RecordValue:()=>ye,Ref:()=>Ye,Refine:()=>ag,Required:()=>_$,Rest:()=>On,ReturnType:()=>B$,Script:()=>Y$,String:()=>ct,Symbol:()=>io,TemplateLiteral:()=>Xh,This:()=>ba,Tuple:()=>ve,Uncapitalize:()=>ab,Undefined:()=>fo,Union:()=>_,Unknown:()=>He,Unsafe:()=>Yl,Uppercase:()=>mb,Void:()=>Ea,With:()=>sm});var aL={pending:"[ ]",in_progress:"[>]",completed:"[x]",dropped:"[-]"},mL=D.Object({op:iL(["init","start","done","drop","view"],{description:"init replaces the list; start/done/drop move one task; view reads it"}),items:D.Optional(D.Array(D.String(),{description:"Task labels for init. 5-10 words each, specific enough to execute without re-planning"})),task:D.Optional(D.String({description:"Exact label of the task to start, complete or drop"}))});function ok(e){if(e.length===0)return"Todo list is empty.";let t=e.filter(o=>o.status==="completed").length,r=e.map(o=>`${aL[o.status]} ${o.content}`),n=e.filter(o=>o.status==="pending"||o.status==="in_progress").length;return[`${t}/${e.length} done, ${n} open`,...r].join(`
20
- `)}function uL(e,t,r,n){let o=e.map(i=>({...i}));switch(t){case"init":return!r||r.length===0?{todos:o,error:"init needs a non-empty items array"}:{todos:r.map(i=>({content:i,status:"pending"}))};case"view":return{todos:o};case"start":case"done":case"drop":{if(!n)return{todos:o,error:`${t} needs task`};let i=o.find(a=>a.content===n);if(!i)return{todos:o,error:`no task matches ${JSON.stringify(n)}`};if(t==="start"){for(let a of o)a.status==="in_progress"&&(a.status="pending");i.status="in_progress"}else i.status=t==="done"?"completed":"dropped";return{todos:o}}default:return{todos:o,error:`unknown op ${JSON.stringify(t)}`}}}function cL(e){let t=[];for(let r of e.sessionManager.getBranch()){if(r.type!=="message")continue;let n=r.message;if(n.role!=="toolResult"||n.toolName!=="todo")continue;let o=n.details;o?.todos&&(t=o.todos)}return t}var ik=sL({name:"todo",label:"todo",description:"Track the plan for this task. Use `init` once with the whole plan (investigation through verification), then `start`/`done` as you go. Keep the list current so progress stays visible; do not re-init unless the plan materially changes.",promptSnippet:"todo: record and advance the plan for the current task",parameters:mL,async execute(e,t,r,n,o){let i=cL(o),{todos:a,error:m}=uL(i,t.op,t.items,t.task),c={op:t.op,todos:a,...m?{error:m}:{}};return{content:[{type:"text",text:m?`Error: ${m}
21
- ${ok(a)}`:ok(a)}],details:c,...m?{isError:!0}:{}}}});import{StringEnum as pL}from"@netrodev/hxf-ai";import{defineTool as fL}from"@netrodev/hxf-coding-agent";var Or=new Map,sk=2e3,ak=80;function GOe(){Or.clear()}function mk(){return Or.size===0?"":["<shared-notes>","Working notes recorded with the `context` tool. They survive compaction and are visible to every agent on this task.",...[...Or].map(([t,r])=>`- ${t}: ${r}`),"</shared-notes>"].join(`
22
- `)}function dL(e,t,r){if(e==="list")return Or.size===0?{text:"No notes."}:{text:[...Or].map(([n,o])=>`${n} = ${o}`).join(`
23
- `)};if(!t)return{text:"Error: key is required",error:"key required"};if(t.length>ak)return{text:`Error: key longer than ${ak} characters`,error:"key too long"};if(e==="forget")return{text:Or.delete(t)?`Removed ${t}`:`No note named ${t}`};if(e==="set"){if(!r)return{text:"Error: value is required for set",error:"value required"};let n=r.length>sk?`${r.slice(0,sk)}\u2026`:r;return Or.set(t,n),{text:`Recorded ${t} (${Or.size} note${Or.size===1?"":"s"} held)`}}return{text:`Error: unknown op ${JSON.stringify(e)}`,error:"unknown op"}}var uk=fL({name:"context",label:"context",description:"Record a durable working note (a decision, a file's role, a fact you would otherwise re-derive). Notes survive context compaction and are visible to every agent on this task, including subagents. Use `set` to write, `list` to read, `forget` to remove.",promptSnippet:"context: durable notes shared with every agent on this task",parameters:D.Object({op:pL(["set","list","forget"],{description:"set writes a note, list reads all, forget removes one"}),key:D.Optional(D.String({description:"Short lookup key, e.g. 'auth-entrypoint'"})),value:D.Optional(D.String({description:"The fact to keep (for set)"}))}),async execute(e,t){let{text:r,error:n}=dL(t.op,t.key,t.value);return{content:[{type:"text",text:r}],details:{op:t.op,notes:Object.fromEntries(Or)},...n?{isError:!0}:{}}}});import{StringEnum as lL}from"@netrodev/hxf-ai";import{defineTool as gL}from"@netrodev/hxf-coding-agent";var ck="howtocode.goal",VOe="howtocode.goal.continue",pk=400,gm=25,fk={active:"\u25CF",paused:"\u2016",done:"\u2713",cleared:"\u25CB"};function yL(e){if(!e||e.status==="cleared")return"No goal set.";let t=e.budget??gm,r=[`${fk[e.status]} ${e.status}`,`${e.used}/${t} continuations`];return e.note&&r.push(e.note),`${r.join(" \xB7 ")}
24
- ${e.text}`}function JOe(e){if(!e||e.status==="cleared"||e.status==="done")return"";let t=e.budget??gm,r=e.text.length>48?`${e.text.slice(0,47)}\u2026`:e.text;return`goal ${fk[e.status]} ${e.used}/${t} \xB7 ${r}`}function YOe(e){let t=["<goal>",e.text,`Status: ${e.status}.`];return e.status==="active"&&t.push("Work toward this goal until it is genuinely met. When it is, call the `goal` tool with",'op="complete" and a note naming the evidence; a command you ran or a file you checked.',"If you are blocked and cannot proceed, say so plainly instead of repeating an attempt."),t.push("</goal>"),t.join(`
25
- `)}function QOe(e){return["[goal] The goal is still open and you stopped without closing it:",` ${e.text}`,"","Continue from where you left off. Do not repeat work you already did. If the goal is met,",'call the `goal` tool with op="complete" and a note naming the evidence. Do not call it',"complete to escape a hard problem: if you cannot make progress, state what is blocking you.",`Continuations used: ${e.used}/${e.budget??gm}.`].join(`
26
- `)}var dk;function XOe(){return dk}function xL(e){dk=e}function ZOe(e){if(!e)return{action:"stop",reason:"no goal",close:!1};if(e.status==="done")return{action:"stop",reason:"goal complete",close:!1};if(e.status==="cleared")return{action:"stop",reason:"goal cleared",close:!1};if(e.status==="paused")return{action:"stop",reason:"goal paused",close:!1};let t=e.budget??gm;return e.used>=t?{action:"stop",reason:`budget exhausted (${t} continuations)`,close:!0}:{action:"continue"}}function hL(e,t,r,n,o){switch(t){case"view":return{goal:e};case"set":return r?.trim()?r.length>pk?{goal:e,error:`text longer than ${pk} characters`}:n!==void 0&&(!Number.isInteger(n)||n<1)?{goal:e,error:"budget must be a positive integer"}:{goal:{text:r.trim(),status:"active",used:0,...n===void 0?{}:{budget:n}}}:{goal:e,error:"set needs text"};case"pause":case"resume":case"complete":case"clear":return!e||e.status==="cleared"?{goal:e,error:"no goal to change"}:t==="resume"?e.status==="done"?{goal:e,error:"goal is complete; set a new one instead"}:{goal:{...e,status:"active",note:void 0}}:t==="pause"?{goal:{...e,status:"paused"}}:t==="clear"?{goal:{...e,status:"cleared"}}:o?.trim()?{goal:{...e,status:"done",note:o.trim()}}:{goal:e,error:"complete needs a note naming the evidence (a command you ran or a file you checked)"};default:return{goal:e,error:`unknown op ${JSON.stringify(t)}`}}}function IL(e){let t;for(let r of e.sessionManager.getBranch()){if(r.type==="custom"&&r.customType===ck){t=r.data;continue}if(r.type==="custom_message"&&r.customType===ck){t=r.details??t;continue}if(r.type!=="message")continue;let n=r.message;if(n.role!=="toolResult"||n.toolName!=="goal")continue;let o=n.details;o?.goal&&(t=o.goal)}return t}var bL=D.Object({op:lL(["set","view","pause","resume","complete","clear"],{description:"set starts a goal; complete closes it with evidence; pause/resume/clear manage it; view reads it"}),text:D.Optional(D.String({description:"The goal, in one sentence, as the user would state it (for set)"})),budget:D.Optional(D.Number({description:"Optional cap on automatic continuations before the run stops"})),note:D.Optional(D.String({description:"Evidence that the goal is met (required for complete)"}))}),eMe=gL({name:"goal",label:"goal",description:"Track the goal for this session. The goal is already shown in your context every request, so you rarely need `view`. Call `complete` only when the goal is genuinely met, and pass a note naming the evidence. When a goal is active the harness continues the run if you stop without closing it, so closing it is how you stop.",promptSnippet:"goal: the session's objective, and how to close it",parameters:bL,async execute(e,t,r,n,o){let i=IL(o),{goal:a,error:m}=hL(i,t.op,t.text,t.budget,t.note);xL(a);let c=yL(a);return{content:[{type:"text",text:m?`Error: ${m}
27
- ${c}`:c}],details:{op:t.op,goal:a},...m?{isError:!0}:{}}}});import{existsSync as mp,mkdirSync as lk,readFileSync as gk}from"node:fs";import{dirname as yk,join as xk}from"node:path";import{defineTool as hk}from"@netrodev/hxf-coding-agent";function ym(){return{state:"inactive",wasActive:!1}}function $L(e){return e?e.state==="pending"?{...e,state:"inactive"}:{...e}:ym()}function aMe(e){return e.state!=="inactive"?e:{...e,state:"pending"}}function EL(e){return e.state!=="pending"?e:{state:"active",wasActive:!0}}function SL(e){return e.state!=="inactive"?e:{state:"active",wasActive:!0}}function kL(e){return e.state!=="active"?e:{...e,state:"inactive"}}function mMe(e){return e.state==="inactive"?e:{...e,state:"inactive"}}function xm(e){return e.state==="active"}function TL(e,t){return e===t}function wL(e,t){return["<plan-mode>","Plan mode is active. Do not make any edits or writes to the system.",t?`A plan file exists at ${e}. Read it and refine it with the \`edit\` tool.`:`No plan is written yet. Write yours to ${e} with the \`write\` tool.`,"That file is the only path you may edit.","Explore first: read, search, and run read-only commands until the approach is clear.","End your turn with either `ask` to clarify a requirement, or `exit_plan_mode` to present","the plan for approval. Do not start implementing before the plan is approved.","</plan-mode>"].join(`
28
- `)}function CL(e){return`Rejected: file edits are not allowed in plan mode. The only editable file is the plan file (${e}). Present the plan with exit_plan_mode first.`}var yt,xt=ym(),ap;function uMe(){return xt}function cMe(){return yt}function pMe(){return xm(xt)}function Ik(){if(!(!yt||!mp(yt)))try{let e=gk(yt,"utf8");return e.trim()?e:void 0}catch{return}}function bk(){return Ik()!==void 0}function fMe(){return xt.state==="inactive"?"":xt.state==="pending"?"plan pending":bk()?"plan \u25CF ready":"plan \u25CF planning"}function $k(){return ap?xk(ap,"plan_mode.json"):void 0}function RL(){let e=$k();if(e)try{lk(yk(e),{recursive:!0}),dr(e,JSON.stringify(xt))}catch{}}function PL(){let e=$k();if(!e||!mp(e))return ym();try{return $L(JSON.parse(gk(e,"utf8")))}catch{return ym()}}function AL(e){ap=e,yt=xk(e,"plan.md"),xt=PL()}function up(e){return xt=e,RL(),xt}function dMe(){return e=>{e.on("tool_call",async t=>{if(!xm(xt)||t.toolName!=="edit"&&t.toolName!=="write")return;let r=t.input?.path;if(typeof r=="string"&&!(!yt||TL(r,yt)))return{block:!0,reason:CL(yt)}})}}function lMe(){return e=>{e.on("session_start",async(t,r)=>{AL(r.sessionManager.getSessionDir())}),e.on("before_agent_start",async()=>{xt.state==="pending"&&up(EL(xt))}),e.on("context_with_system",async t=>{if(!xm(xt)||!yt)return;let r=t.messages[0];if(!r||r.role!=="system")return;let n=wL(yt,bk()),o=`${typeof r.content=="string"?r.content:""}
29
-
30
- ${n}`;return{messages:t.messages.map(a=>a===r?{...r,content:o}:a)}})}}var sp=2e4;function OL(){if(yt){try{lk(yk(yt),{recursive:!0}),mp(yt)||dr(yt,"")}catch{return}return yt}}var gMe=hk({name:"enter_plan_mode",label:"enter_plan_mode",description:"Enter plan mode to design an approach before writing code. Use it when a task has genuine ambiguity; several reasonable designs, or a restructuring where the wrong approach wastes significant effort. Do not use it for a clear fix, a rename, or a task that follows existing conventions. The user must approve entering.",promptSnippet:"enter_plan_mode: design first when the approach is genuinely ambiguous",parameters:D.Object({}),async execute(e,t,r,n,o){if(xt.state!=="inactive")return{content:[{type:"text",text:`Plan mode is already ${xt.state}.`}],details:{}};if(!o.hasUI)return{content:[{type:"text",text:"Plan mode needs an interactive session: there is no one to approve the plan. Proceed normally."}],details:{},isError:!0};if(!await o.ui.confirm("Enter plan mode?","The agent will explore and design an approach before editing anything."))return{content:[{type:"text",text:"The user declined plan mode. Proceed normally."}],details:{}};up(SL(xt));let a=OL();return{content:[{type:"text",text:["Plan mode is active. Edits are blocked except for the plan file.",a?`Write your plan to ${a}.`:"Write your plan to the session plan file."].join(`
31
- `)}],details:{planFile:a}}}}),yMe=hk({name:"exit_plan_mode",label:"exit_plan_mode",description:"Present your plan for approval when you have finished planning. The plan is read from the plan file on disk, so write the file first. If the user asks for changes, stay in plan mode and revise it.",promptSnippet:"exit_plan_mode: present the written plan for approval",parameters:D.Object({}),executionMode:"sequential",async execute(e,t,r,n,o){if(!xm(xt))return{content:[{type:"text",text:"Plan mode is not active."}],details:{},isError:!0};let i=Ik();if(!i)return{content:[{type:"text",text:`No plan has been written yet. Write it to ${yt??"the plan file"} before exiting plan mode.`}],details:{},isError:!0};if(!o.hasUI)return{content:[{type:"text",text:"Plan approval needs an interactive session."}],details:{},isError:!0};let a=i.length>sp?`${i.slice(0,sp)}
32
- \u2026 (${i.length-sp} more characters)`:i;return await o.ui.confirm("Approve this plan?",a)?(up(kL(xt)),{content:[{type:"text",text:"Plan approved. You may now implement it."}],details:{approved:!0,planFile:yt}}):{content:[{type:"text",text:"The user did not approve the plan. Stay in plan mode, revise the plan file with the feedback, and present it again."}],details:{approved:!1}}}});function Co(e){return typeof e=="string"?e:Array.isArray(e)?e.map(t=>{let r=t;return r.type==="text"&&typeof r.text=="string"?r.text:""}).join(`
33
- `):e==null?"":String(e)}function hm(e,t){if(Array.isArray(e)){let r=e.map(o=>({...o})),n=r.filter(o=>o.type==="text");if(n.length>0){n[0].text=t;for(let o of n.slice(1))o.text="";return r}return[...r,{type:"text",text:t}]}return t}function Ek(){return e=>{e.on("context_with_system",async t=>{let r=mk();if(!r)return;let n=t.messages[0];if(!n||n.role!=="system")return;let o=`${Co(n.content)}
34
-
35
- ${r}`;return{messages:t.messages.map(a=>a===n?{...n,content:hm(n.content,o)}:a)}})}}import{Type as Nn}from"@netrodev/hxf-ai";import{defineTool as ML}from"@netrodev/hxf-coding-agent";var Ro="[Compressed conversation section]";function Ni(e){return Math.round(e.length/4)}function cp(e){let t=e.prune.messages.nextBlockId;return!Number.isInteger(t)||t<1?(e.prune.messages.nextBlockId=2,1):(e.prune.messages.nextBlockId=t+1,t)}function pp(e){let t=e.prune.messages.nextRunId;return!Number.isInteger(t)||t<1?(e.prune.messages.nextRunId=2,1):(e.prune.messages.nextRunId=t+1,t)}function fp(e,t,r="xml"){let n=Do(Gn(e,r),void 0,r),o=t.trim();return o.length===0?`${Ro}
36
- ${n}`:`${Ro}
37
- ${o}
38
-
39
- ${n}`}function Br(e){return e.prune.messages.blocks.filter(t=>t.active).map(t=>({blockId:t.blockId,anchorIndex:t.anchorIndex,coveredIndices:t.coveredIndices,summary:t.summary}))}function dp(e,t,r,n,o,i,a){let m=e.prune.messages,c=[...new Set(a.filter(b=>Number.isInteger(b)&&b>0))],p=new Set;for(let b of m.blocks)if(b.active)for(let k of b.coveredIndices)p.add(k);let f=new Set(r.indices);for(let b of c){let k=m.blocks.find(j=>j.blockId===b);if(k)for(let j of k.coveredIndices)f.add(j)}let d=[...f].sort((b,k)=>b-k),g=d.filter(b=>!p.has(b)),y=0;for(let b of g)y+=r.tokenByIndex.get(b)??0;let I={blockId:o,runId:t.runId,active:!0,deactivatedByUser:!1,mode:t.mode,topic:t.topic,startId:t.startId,endId:t.endId,anchorIndex:n,compressedTokens:y,summaryTokens:Ni(i),coveredIndices:d,consumedBlockIds:c,parentBlockIds:[],createdAt:Date.now(),summary:i};m.blocks.push(I);let h=Date.now();for(let b of c){let k=m.blocks.find(j=>j.blockId===b);!k||!k.active||(k.active=!1,k.deactivatedAt=h,k.deactivatedByBlockId=o,k.parentBlockIds.includes(o)||k.parentBlockIds.push(o))}return e.stats.totalCompressTokens+=y,{compressedTokens:y,coveredIndices:d,newlyCoveredIndices:g}}function kk(e,t="xml"){let r=[],n=t==="compact"?/@b([1-9]\d*)@/gi:/\(b(\d+)\)/gi,o;for(;(o=n.exec(e))!==null;){let i=Number.parseInt(o[1],10);Number.isInteger(i)&&r.push({raw:o[0],blockId:i,startIndex:o.index,endIndex:o.index+o[0].length})}return r}function Tk(e){if(typeof e.topic!="string"||e.topic.trim().length===0)throw new Error("topic is required and must be a non-empty string");if(!Array.isArray(e.content)||e.content.length===0)throw new Error("content is required and must be a non-empty array");for(let t=0;t<e.content.length;t++){let r=e.content[t],n=`content[${t}]`;if(typeof r?.startId!="string"||r.startId.trim().length===0)throw new Error(`${n}.startId is required and must be a non-empty string`);if(typeof r?.endId!="string"||r.endId.trim().length===0)throw new Error(`${n}.endId is required and must be a non-empty string`);if(typeof r?.summary!="string"||r.summary.trim().length===0)throw new Error(`${n}.summary is required and must be a non-empty string`)}}function lp(e,t,r,n){let o=new Set,i=new Map;for(let d of r)o.add(d.index),i.set(d.index,d.tokenCount??0);let a=Sk(e,o,t.startId,"startId",n),m=Sk(e,o,t.endId,"endId",n);if(a.index>m.index)throw new Error(`startId ${a.ref} appears after endId ${m.ref} in the conversation. Start must come before end.`);let c=[];for(let d of r)d.index>=a.index&&d.index<=m.index&&c.push(d.index);let p=new Set(c),f=e.prune.messages.blocks.filter(d=>d.active&&p.has(d.anchorIndex)).map(d=>d.blockId);return{startIdx:a.index,endIdx:m.index,indices:c,requiredBlockIds:f,tokenByIndex:i}}function Sk(e,t,r,n,o){let i=Km(r,o);if(i===null){let m=o==="compact"?"@4@":"mNNNN",c=o==="compact"?"@b1@":"bN";throw new Error(`${n} is invalid. Use an injected message ID (${m}) or block ID (${c}).`)}let a;if(i.kind==="message")a=i.index;else{let m=e.prune.messages.blocks.find(c=>c.blockId===i.blockId&&c.active);a=m?m.anchorIndex:-1}if(a<0||!t.has(a))throw new Error(`${n} ${i.ref} is not available in the current conversation context. Choose an injected ID visible in context.`);return{ref:i.ref,index:a}}function wk(e,t,r,n="xml"){let i=[...e.map((m,c)=>{let p={startId:m.startId.trim(),endId:m.endId.trim(),summary:m.summary};return{index:c,entry:p,selection:lp(t,p,r,n)}})].sort((m,c)=>m.selection.startIdx-c.selection.startIdx||m.selection.endIdx-c.selection.endIdx||m.index-c.index),a=[];for(let m=1;m<i.length;m++){let c=i[m-1],p=i[m];!c||!p||p.selection.startIdx>c.selection.endIdx||a.push(`content[${c.index}] (${c.entry.startId}..${c.entry.endId}) overlaps content[${p.index}] (${p.entry.startId}..${p.entry.endId}). Overlapping ranges cannot be compressed in the same batch.`)}if(a.length>0)throw new Error(a.length===1?a[0]:a.map(m=>`- ${m}`).join(`
40
- `))}function Ck(e,t,r,n="xml"){let o=new Set(t.prune.messages.blocks.filter(i=>i.active).map(i=>i.blockId));return e.map((i,a)=>{let m={startId:i.startId.trim(),endId:i.endId.trim(),summary:i.summary},c=lp(t,m,r,n),p=new Set(c.requiredBlockIds),f=kk(m.summary,n),d=new Set,g=`content[${a}]`;for(let y of f){if(d.has(y.blockId))throw new Error(`${g}.summary duplicates placeholder ${y.raw}`);if(d.add(y.blockId),!p.has(y.blockId))throw new Error(o.has(y.blockId)?`${g}.summary references ${y.raw}, which is outside the selected range`:`${g}.summary references ${y.raw}, which is not an active compressed block`)}for(let y of c.requiredBlockIds)if(!d.has(y)){let I=n==="compact"?`@b${y}@`:`(b${y})`;throw new Error(`${g}.summary is missing the required placeholder ${I}`)}return f})}function Rk(e,t,r,n="xml"){return e.map((o,i)=>{let a={startId:o.startId.trim(),endId:o.endId.trim(),summary:o.summary},m=lp(t,a,r,n);return{index:i,entry:a,selection:m,anchorIndex:m.startIdx}})}function vL(e){let t=e.match(/^\s*\[Compressed conversation(?: section)?(?: b\d+)?\]/i);return t?e.slice(t[0].length).replace(/^(?:\r?\n)+/,"").replace(/(?:\r?\n)*<dcp-message-id>b\d+<\/dcp-message-id>\s*$/i,"").replace(/(?:\r?\n)*@b[1-9]\d*@\s*$/i,"").replace(/(?:\r?\n)+$/,""):e}function FL(e,t,r){if(t.length===0)return{expanded:e,consumedBlockIds:[]};let n="",o=0,i=[];for(let a of t){let m=r.prune.messages.blocks.find(c=>c.blockId===a.blockId&&c.active);if(!m)throw new Error(`Compressed block not found: ${a.raw}`);n+=e.slice(o,a.startIndex),n+=vL(m.summary),o=a.endIndex,i.push(a.blockId)}return n+=e.slice(o),{expanded:n,consumedBlockIds:i}}function Pk(e,t,r,n="xml"){Tk(e),wk(e.content,t,r,n);let o=Ck(e.content,t,r,n),i=Rk(e.content,t,r,n),a=pp(t),m=[];for(let[c,p]of i.entries()){let f=o[c]??[],{expanded:d,consumedBlockIds:g}=FL(p.entry.summary,f,t),y=cp(t),I=fp(y,d,n),h=dp(t,{topic:e.topic,startId:p.entry.startId,endId:p.entry.endId,mode:"range",runId:a},p.selection,p.anchorIndex,y,I,g);m.push({blockId:y,runId:a,coveredCount:h.coveredIndices.length,compressedTokens:h.compressedTokens,summaryTokens:Ni(I),expandedSummary:d})}return m}function LL(e){let t=e.format??"xml",r=Bn(1,t),n=Gn(2,t);return ML({name:"compress",label:"compress",description:`Collapse conversation ranges into stored compressed summaries, each marked with "${Ro}". Copy startId and endId from the injected IDs in context (message IDs like ${r}, block IDs like ${n}); startId must come before endId. Ranges in one call must not overlap, and each summary must reference every required block placeholder exactly once.`,promptSnippet:"compress: replace a conversation range with a stored summary",parameters:Nn.Object({topic:Nn.String({description:"Short label (3-5 words) for display - e.g., 'Auth System Exploration'"}),content:Nn.Array(Nn.Object({startId:Nn.String({description:`Message or block ID marking the beginning of range (e.g. ${r}, ${n})`}),endId:Nn.String({description:`Message or block ID marking the end of range (e.g. ${Bn(12,t)}, ${Gn(5,t)})`}),summary:Nn.String({description:"Complete technical summary replacing all content in range"})}),{description:"One or more ranges to compress, each with start/end boundaries and a summary"})}),async execute(o,i){try{let a=Pk(i,e.state(),e.messages(),t),m=a.map(g=>g.blockId),c=a.reduce((g,y)=>g+y.coveredCount,0),p=a.reduce((g,y)=>g+y.compressedTokens,0),f=a.reduce((g,y)=>g+y.summaryTokens,0),d=Math.max(0,p-f);return{content:[{type:"text",text:`Compressed ${c} messages into ${Ro}`+(p>0?` - ${p} tokens replaced by ${f}, saving ${d}.`:".")}],details:{blockIds:m,runId:a[0]?.runId,messages:c,compressedTokens:p,summaryTokens:f}}}catch(a){let m=a instanceof Error?a.message:String(a);return{content:[{type:"text",text:m}],details:{error:m},isError:!0}}}})}import{existsSync as Ak,mkdirSync as DL,readFileSync as Ok,unlinkSync as jL}from"node:fs";import{dirname as NL,join as Mk}from"node:path";function gp(e){try{let t=Mk(e,".howtocode","dcp.json");if(!Ak(t))return;let r=JSON.parse(Ok(t,"utf8"));if(typeof r!="object"||r===null)return;let n=r.enabled;return typeof n=="boolean"?n:void 0}catch{return}}function yp(e){if(e.env!==void 0){let t=e.env.trim().toLowerCase();return{enabled:t!=="0"&&t!=="false",source:"env"}}return e.config!==void 0?{enabled:e.config,source:"config"}:e.runtime!==void 0?{enabled:e.runtime,source:"session"}:{enabled:!0,source:"default"}}function vk(){return{messageIds:Gm(),prune:{tools:{},messages:{blocks:[],nextBlockId:1,nextRunId:1}},stats:{totalPruneTokens:0,totalCompressTokens:0}}}function bm(e){let t=e.replace(/[^A-Za-z0-9._-]/g,"_")||"session";return Mk(it,"dcp",`${t}.json`)}function qL(e){if(typeof e!="object"||e===null)return!1;let t=e,r=t.prune?.messages,n=t.messageIds;return typeof t.prune=="object"&&t.prune!==null&&typeof t.prune.tools=="object"&&t.prune.tools!==null&&typeof r=="object"&&r!==null&&Array.isArray(r.blocks)&&Number.isInteger(r.nextBlockId)&&Number.isInteger(r.nextRunId)&&typeof n=="object"&&n!==null&&Number.isInteger(n.nextRef)&&typeof n.keyToRef=="object"&&n.keyToRef!==null&&typeof n.refToKey=="object"&&n.refToKey!==null&&typeof t.stats=="object"&&t.stats!==null&&Number.isFinite(t.stats.totalPruneTokens)&&Number.isFinite(t.stats.totalCompressTokens)}var Im=new Map;function qi(e){let t=Im.get(e);if(t)return t;let r;try{let o=bm(e);if(Ak(o)){let i=JSON.parse(Ok(o,"utf8"));qL(i)&&(r=i)}}catch{r=void 0}let n=r??vk();return Im.set(e,n),n}function gn(e){let t=Im.get(e);if(!t)return;let r=bm(e);DL(NL(r),{recursive:!0}),dr(r,JSON.stringify(t))}function _L(e){Im.delete(e);try{jL(bm(e))}catch{}}function cr(e){return e.replaceAll("\\","/")}function UL(e){return/[\\.^$+{}()|\[\]]/.test(e)?`\\${e}`:e}function xp(e,t){if(!t)return!1;let r=cr(e),n=cr(t),o="^";for(let i=0;i<n.length;i++){let a=n[i];if(a==="*"){if(n[i+1]==="*"){if(n[i+2]==="/"){o+="(?:.*/)?",i+=2;continue}o+=".*",i++;continue}o+="[^/]*";continue}if(a==="?"){o+="[^/]";continue}if(a==="/"){o+="/";continue}o+=UL(a)}return o+="$",new RegExp(o).test(r)}function $m(e,t){if(typeof t!="object"||t===null)return[];let r=[],n=t;if((e==="apply_patch"||e==="patch")&&typeof n.patchText=="string"){let o=/\*\*\* (?:Add|Delete|Update) File: ([^\n\r]+)/g,i;for(;(i=o.exec(n.patchText))!==null;)r.push(i[1].trim())}if(e==="multiedit"&&(typeof n.filePath=="string"&&r.push(n.filePath),Array.isArray(n.edits)))for(let o of n.edits)o&&typeof o=="object"&&typeof o.filePath=="string"&&r.push(o.filePath);return typeof n.filePath=="string"&&r.push(n.filePath),["read","write","edit"].includes(e)&&typeof n.path=="string"&&r.push(n.path),[...new Set(r)].filter(o=>o.length>0)}function Fk(e,t){return e.length===0||t.length===0?!1:e.some(r=>t.some(n=>xp(r,n)))}var BL=/[*?]/,qn=["todo","goal","context","task"];function Lk(e,t){if(!e||t.length===0)return!1;let r=new Set,n=[];for(let o of t)BL.test(o)?n.push(o):r.add(o);return r.has(e)?!0:n.some(o=>xp(e,o))}function Em(e,t,r,n,o){let i=[{tool:e,input:t}];if(e==="execute"&&Array.isArray(o?.toolCalls))for(let a of o.toolCalls)a&&typeof a=="object"&&typeof a.tool=="string"&&i.push({tool:a.tool,input:a.input});return i.some(a=>Lk(a.tool,r)||Fk($m(a.tool,a.input),n))}function Ip(e,t){return t==null?e:`${e}::${JSON.stringify(hp(GL(t)))}`}function GL(e){if(typeof e!="object"||e===null||Array.isArray(e))return e;let t={};for(let[r,n]of Object.entries(e))n!=null&&(t[r]=n);return t}function hp(e){if(typeof e!="object"||e===null)return e;if(Array.isArray(e))return e.map(hp);let t={};for(let r of Object.keys(e).sort())t[r]=hp(e[r]);return t}var Po="[Output removed to save context - information superseded or no longer needed]",bp="[input removed due to failed tool call]",jk="[questions removed - see output for user's answers]",Nk=2e3,Sm=["ask","question"],Dk=["read","grep","ls"],KL=["edit","write","multiedit","apply_patch","patch"];function HL(e){return e.filter(t=>t.type==="text").map(t=>t.text).join("")}function zL(e){if(!e)return{total:0,count:0};let t=0,r=0;for(let n of Object.values(e))typeof n=="string"&&(t+=n.length,r++);return{total:t,count:r}}function WL(e){return e.replace(/[.*+?^${}()|[\]\\]/g,"\\$&")}function $p(e,t,r){let n=r?.bigOutputChars??Nk,o=new Map,i=[];for(let h=0;h<e.length;h++){let b=e[h];if(b.role==="assistant")for(let k of b.content)k.type==="toolCall"&&o.set(k.id,{name:k.name,args:k.arguments,callIndex:h});else if(b.role==="toolResult"){let k=o.get(b.toolCallId),j=b.toolName;i.push({index:h,callId:b.toolCallId,tool:j,isError:b.isError,text:HL(b.content),paths:k?$m(j,k.args):[],signature:Ip(j,k?.args),callIndex:k?.callIndex??-1})}}let a=t.planFile?cr(t.planFile):void 0,m=h=>h.index===0||qn.includes(h.tool)||a!==void 0&&h.paths.some(b=>cr(b)===a),c=h=>h.callIndex<0||h.callIndex===0||qn.includes(h.tool)||a!==void 0&&h.paths.some(b=>cr(b)===a),p=[],f=new Set,d=h=>{let b=`${h.kind}:${h.callId}`;f.has(b)||(f.add(b),p.push(h))},g=new Map;for(let h of i)if(!(h.isError||!Dk.includes(h.tool)&&!KL.includes(h.tool)))for(let b of h.paths){let k=cr(b),j=g.get(k);(j===void 0||h.index>j)&&g.set(k,h.index)}for(let h of i){if(h.isError||!Dk.includes(h.tool)||m(h)||h.text===Po)continue;h.paths.some(k=>(g.get(cr(k))??-1)>h.index)&&d({kind:"output",reason:"superseded-read",callId:h.callId,messageIndex:h.index,savedChars:Math.max(0,h.text.length-Po.length)})}let y=new Map;for(let h of i){if(h.isError)continue;let b=y.get(h.signature);(b===void 0||h.index>b)&&y.set(h.signature,h.index)}for(let h of i){if(!h.isError||m(h))continue;let b=y.get(h.signature);if(!(b===void 0||b<=h.index)&&(d({kind:"output",reason:"error-then-success",callId:h.callId,messageIndex:h.index,savedChars:Math.max(0,h.text.length-Po.length)}),!c(h))){let k=o.get(h.callId)?.args,{total:j,count:P}=zL(k);P>0&&d({kind:"failed-input",reason:"error-then-success",callId:h.callId,messageIndex:h.callIndex,savedChars:Math.max(0,j-P*bp.length)})}}if(t.files.length>0||t.identifiers.length>0){let h=[...t.files.map(cr),...a?[a]:[]],b=h.map(P=>P.split("/").pop()??"").filter(P=>P.length>0),k=t.identifiers.map(P=>new RegExp(`(?<![\\w.-])${WL(P)}(?![\\w.-])`)),j=P=>{let Je=cr(P);return h.some(Ce=>Je.includes(Ce))||b.some(Ce=>P.includes(Ce))?!0:k.some(Ce=>Ce.test(P))};for(let P of i)m(P)||Sm.includes(P.tool)||P.text.length<=n||j(P.text)||d({kind:"output",reason:"unrelated-big-output",callId:P.callId,messageIndex:P.index,savedChars:Math.max(0,P.text.length-Po.length)})}let I=0;for(let h of p)I+=h.savedChars;return{ops:p,savedChars:I}}function Ep(e,t){let r=new Set,n=new Set,o=new Set;for(let i of t)i.kind==="output"?r.add(i.callId):i.kind==="question-input"?n.add(i.callId):o.add(i.callId);return Uk(_k(qk(e,r),n),o)}function qk(e,t){return t.size===0?[...e]:e.map((r,n)=>n===0||r.role!=="toolResult"||!t.has(r.toolCallId)||Sm.includes(r.toolName)?r:{...r,content:[{type:"text",text:Po}]})}function _k(e,t){if(t.size===0)return[...e];let r=new Set;for(let n of e)n.role==="toolResult"&&!n.isError&&t.has(n.toolCallId)&&r.add(n.toolCallId);return r.size===0?[...e]:e.map((n,o)=>{if(o===0||n.role!=="assistant")return n;let i=!1,a=n.content.map(m=>{if(m.type!=="toolCall"||!r.has(m.id)||!Sm.includes(m.name))return m;let c={...m.arguments},p=!1;for(let f of["question","questions","options"])f in c&&(c[f]=jk,p=!0);return p?(i=!0,{...m,arguments:c}):m});return i?{...n,content:a}:n})}function Uk(e,t){if(t.size===0)return[...e];let r=new Set;for(let n of e)n.role==="toolResult"&&n.isError&&t.has(n.toolCallId)&&r.add(n.toolCallId);return r.size===0?[...e]:e.map((n,o)=>{if(o===0||n.role!=="assistant")return n;let i=!1,a=n.content.map(m=>{if(m.type!=="toolCall"||!r.has(m.id))return m;let c={},p=!1;for(let[f,d]of Object.entries(m.arguments))typeof d=="string"?(c[f]=bp,p=!0):c[f]=d;return p?(i=!0,{...m,arguments:c}):m});return i?{...n,content:a}:n})}function Sp(e,t,r){if(t.length===0)return[...e];let n=Vr(r,e),o=new Map;for(let d=0;d<n.length;d++){let g=n[d];g!==null&&o.set(g,d)}let i=new Set,a=new Map;for(let d of t){let g=[];for(let I of d.coveredIndices){let h=o.get(I);h!==void 0&&(i.add(h),g.push(h))}let y=o.get(d.anchorIndex)??(g.length>0?Math.min(...g):void 0);if(d.summary&&y!==void 0){let I=a.get(y);I?I.push(d.summary):a.set(y,[d.summary])}}let m=new Map,c=new Map;for(let d=0;d<e.length;d++){let g=e[d];if(g)if(g.role==="assistant"&&Array.isArray(g.content))for(let y of g.content)y.type==="toolCall"&&m.set(d,y.id);else g.role==="toolResult"&&c.set(g.toolCallId,d)}let p=[...i];for(;p.length>0;){let d=p.pop(),g=m.get(d);if(g!==void 0){let I=c.get(g);I!==void 0&&!i.has(I)&&(i.add(I),p.push(I))}let y=e[d];if(y?.role==="toolResult")for(let[I,h]of m)h===y.toolCallId&&!i.has(I)&&(i.add(I),p.push(I))}let f=[];for(let d=0;d<e.length;d++){let g=a.get(d);if(g){let y=e[d];for(let I of g){let h={role:"user",content:I,timestamp:y.timestamp};f.push(h)}}i.has(d)||f.push(e[d])}return f}var kp={thresholdChars:8192,headChars:4096,tailChars:1024};function VL(e,t={}){let r=t.thresholdChars??kp.thresholdChars,n=t.headChars??kp.headChars,o=t.tailChars??kp.tailChars;if(e.length<=r||n+o>=e.length)return{text:e,prunedChars:0};let i=n,a=e.charCodeAt(i-1);a>=55296&&a<=56319&&(i-=1);let m=e.length-o,c=e.charCodeAt(m);c>=56320&&c<=57343&&(m+=1);let p=e.slice(0,i),f=e.slice(m),d=m-i,g=`
41
-
42
- [... ${d} characters pruned from the middle ...]
43
-
44
- `;return{text:p+g+f,prunedChars:d-g.length}}function Bk(e,t={}){let r=0,n=0,o=!1,i=e.map(a=>{let m=a;if(m.role!=="toolResult"||!Array.isArray(m.content))return a;let c=m.content,p=!1,f=c.map(d=>{if(!d||typeof d!="object")return d;let g=d;if(g.type!=="text"||typeof g.text!="string")return d;let y=VL(g.text,t);return y.prunedChars<=0?d:(p=!0,r+=y.prunedChars,{...d,text:y.text})});return p?(o=!0,n+=1,{...a,content:f}):a});return{messages:o?i:e,savedChars:r,prunedResults:n}}function Tp(e="xml"){let t=e==="compact",r=t?"@4@":"mNNNN",n=t?"@b1@":"bN",o=t?"@b1@":"(bN)";return`COMPRESSING A RANGE OF THIS CONVERSATION
45
-
46
- This is what the \`compress\` tool is for, and how a range must be summarised when it is used. Reach for it when the conversation has grown long enough that its older turns cost more than they are worth - never as a way to answer the user, and never on a range they did not ask about. Nothing here is a standing instruction to summarise: it is the contract the tool's output is held to.
47
-
48
- THE SUMMARY
49
- Your summary must be EXHAUSTIVE. Capture file paths, function signatures, decisions made, constraints discovered, key findings... EVERYTHING that maintains context integrity. This is not a brief note - it is an authoritative record so faithful that the original conversation adds no value.
50
-
51
- USER INTENT FIDELITY
52
- When the compressed range includes user messages, preserve the user's intent with extra care. Do not change scope, constraints, priorities, acceptance criteria, or requested outcomes.
53
- Directly quote user messages when they are short enough to include safely. Direct quotes are preferred when they best preserve exact meaning.
54
-
55
- Yet be LEAN. Strip away the noise: failed attempts that led nowhere, verbose tool outputs, back-and-forth exploration. What remains should be pure signal - golden nuggets of detail that preserve full understanding with zero ambiguity.
56
-
57
- COMPRESSED BLOCK PLACEHOLDERS
58
- When the selected range includes previously compressed blocks, use this exact placeholder format when referencing one:
59
-
60
- - \`${o}\`
61
-
62
- Compressed block sections in context are clearly marked with a header:
63
-
64
- - \`[Compressed conversation section]\`
65
-
66
- ${t?"Compressed block IDs look like `@b1@`, distinct from raw message IDs like `@4@`.":"Compressed block IDs always use the `bN` form (never `mNNNN`) and are represented in the same XML metadata tag format."}
67
-
68
- Rules:
69
-
70
- - Include every required block placeholder exactly once.
71
- - Do not invent placeholders for blocks outside the selected range.
72
- - Treat \`${o}\` placeholders as RESERVED TOKENS. Do not emit \`${o}\` text anywhere except intentional placeholders.
73
- - If you need to mention a block in prose, use plain text like \`compressed ${t?"block 1":"bN"}\` (not as a placeholder).
74
- - Preflight check before finalizing: the set of \`${o}\` placeholders in your summary must exactly match the required set, with no duplicates.
75
-
76
- These placeholders are semantic references. They will be replaced with the full stored compressed block content when the tool processes your output.
77
-
78
- FLOW PRESERVATION WITH PLACEHOLDERS
79
- When you use compressed block placeholders, write the surrounding summary text so it still reads correctly AFTER placeholder expansion.
80
-
81
- - Treat each placeholder as a stand-in for a full conversation segment, not a short label.
82
- - Ensure transitions before and after each placeholder preserve chronology and causality.
83
- - Do not write text that depends on the placeholder staying literal (for example, "as noted in \`${t?"@b2@":"(b2)"}\`").
84
- - Your final meaning must be coherent once each placeholder is replaced with its full compressed block content.
85
-
86
- BOUNDARY IDS
87
- You specify boundaries by ID using the injected IDs visible in the conversation:
88
-
89
- - \`${r}\` IDs identify raw messages
90
- - \`${n}\` IDs identify previously compressed blocks
91
-
92
- ${t?"Each message has an ID like `@4@`. Copy the whole marker, including both `@` characters, into `startId` and `endId`.":"Each message has an ID inside XML metadata tags like `<dcp-message-id>...</dcp-message-id>`."}
93
- The same ID tag appears in every tool output of the message it belongs to \u2014 each unique ID identifies one complete message.
94
- Treat these tags as boundary metadata only, not as tool result content.
95
-
96
- Rules:
97
-
98
- - Pick \`startId\` and \`endId\` directly from injected IDs in context.
99
- - IDs must exist in the current visible context.
100
- - \`startId\` must appear before \`endId\`.
101
- - Do not invent IDs. Use only IDs that are present in context.
102
-
103
- BATCHING
104
- When multiple independent ranges are ready and their boundaries do not overlap, include all of them as separate entries in the \`content\` array of a single tool call. Each entry should have its own \`startId\`, \`endId\`, and \`summary\`.
105
- `}function wp(e,t,r,n){let o=new Map;if(t.idState){let m=Vr(t.idState,t.messages);for(let c=0;c<m.length;c++){let p=m[c];p!==null&&o.set(p,c)}}let i=new Set;for(let m of Br(r))if(!(n!==void 0&&m.blockId===n))for(let c of m.coveredIndices)i.add(c);let a=[];if(t.idState)for(let m of e.indices){if(i.has(m))continue;let c=o.get(m);c!==void 0&&a.push(c)}return a}function Gk(e){if(typeof e.content=="string")return e.content.trim()?[e.content]:[];let t=[];for(let r of e.content)r.type==="text"&&r.text.trim()&&t.push(r.text);return t}function Kk(e,t,r,n,o,i){if(!o)return e;let a=[];for(let p of wp(t,r,n,i)){let f=r.messages[p];if(!f||f.role!=="user")continue;let d=Gk(f)[0];d!==void 0&&a.push(d)}if(a.length===0)return e;let m=`
106
-
107
- The following user messages were sent in this conversation verbatim:`,c=a.map(p=>`
108
- ${p}`).join("");return e+m+c}function Hk(e,t,r,n,o,i){if(!o)return e;let a=[];for(let p of wp(t,r,n,i)){let f=r.messages[p];if(!(!f||f.role!=="user"))for(let d of Gk(f))a.push(...zk(d))}if(a.length===0)return e;let m=`
109
-
110
- The following protected prompt information was included in this conversation verbatim:`,c=a.map(p=>`
111
- ${p}`).join("");return e+m+c}function zk(e){let t=[],r=/<protect>([\s\S]*?)<\/protect>/gi;for(let n of e.matchAll(r)){let o=n[1]?.trim();o&&t.push(o)}return t}function Wk(e,t,r,n,o=[],i=[],a){let m=new Map,c=[];for(let y of wp(t,r,n,a)){let I=r.messages[y];if(I){if(I.role==="assistant"){for(let h of I.content)h.type==="toolCall"&&m.set(h.id,h.arguments);continue}if(I.role==="toolResult"){if(I.isError)continue;let h=I.content.filter(b=>b.type==="text").map(b=>b.text).join("");h.trim()&&c.push({toolCallId:I.toolCallId,toolName:I.toolName,text:h})}}}if(c.length===0)return e;let p=[...new Set([...qn,...o])],f=[...i],d=[];for(let y of c){let I=m.get(y.toolCallId);Em(y.toolName,I,p,f)&&d.push(`
112
- ### Tool: ${y.toolName}
113
- ${y.text}`)}return d.length===0?e:e+`
114
-
115
- The following protected tools were used in this conversation as well:`+d.join("")}function Vk(e,t,r){if(t.protectedEnriched)return;let n=t.coveredIndices;if(n.length>0){let o={startIdx:Math.min(...n),endIdx:Math.max(...n),indices:[...n],requiredBlockIds:[],tokenByIndex:new Map},i={messages:r,idState:e.messageIds},a=Wk(Hk(Kk(t.summary,o,i,e,!0,t.blockId),o,i,e,!0,t.blockId),o,i,e,[],[],t.blockId);t.summary=a,t.summaryTokens=Ni(a)}t.protectedEnriched=!0}function Jk(e,t){let r=[];for(let n=0;n<e.length;n+=1){let o=e[n];if(o===null)continue;let i=t[n],a=i&&"content"in i?Co(i.content):"";r.push({index:o,tokenCount:Math.round(a.length/4)})}return r}var JL="COMPRESSED BLOCK PLACEHOLDERS",Cp=new Map;function YL(e){return Cp.get(e)??[]}function QL(e){Cp.delete(e)}var Yk;function XL(){return Yk}function ZL(e={}){return t=>{t.on("context_with_system",async(r,n)=>{let o=n?.sessionManager?.getSessionId()??"dcp-sessionless",i=qi(o);if(i.enabled===!1)return;let a=r.messages,m=a[0];if(!m||m.role!=="system")return;zm(i.messageIds,a);let c=Vr(i.messageIds,a);Cp.set(o,Jk(c,a)),Yk=o;let p=eD(a),f=Sp(p,Br(i),i.messageIds),d=Bk(f);d.prunedResults>0&&(f=[...d.messages]);let g=e.keepSet?.()??{files:[],identifiers:[]},y=$p(f,g);if(y.ops.length>0){f=Ep(f,y.ops);for(let h of y.ops)i.prune.tools[h.callId]=(i.prune.tools[h.callId]??0)+h.savedChars;i.stats.totalPruneTokens=Object.values(i.prune.tools).reduce((h,b)=>h+b,0)}for(let h of i.prune.messages.blocks)h.active&&!h.protectedEnriched&&Vk(i,h,a);gn(o);let I=f.map((h,b)=>{if(b!==0||!("content"in h))return h;let k=Co(h.content);return k.includes(JL)?h:{...h,content:hm(h.content,`${k}
116
-
117
- ${Tp()}`)}});return{messages:rD(I,i.messageIds)}})}}function eD(e){return e.map(t=>{if(t.role!=="assistant"||!("content"in t))return t;let r=tD(t.content);return r===t.content?t:{...t,content:r}})}function tD(e){if(typeof e=="string")return Hm(e);if(!Array.isArray(e))return e;let t=!1,r=e.map(n=>{if(!n||typeof n!="object"||!("type"in n)||n.type!=="text")return n;let o="text"in n&&typeof n.text=="string"?n.text:"",i=Hm(o);return i===o?n:(t=!0,{...n,text:i})});return t?r:e}function rD(e,t){let r=Vr(t,e);return e.map((n,o)=>{let i=r[o];if(i==null||!("content"in n))return n;let a=Do(Bn(i));return Co(n.content).includes(a)?n:{...n,content:nD(n.content,a)}})}function nD(e,t){if(typeof e=="string")return e+t;if(!Array.isArray(e))return e;let r=!1,n=e.map(o=>{if(!o||typeof o!="object"||!("type"in o)||o.type!=="text")return o;r=!0;let i="text"in o&&typeof o.text=="string"?o.text:"";return{...o,text:i+t}});return r?n:[...n,{type:"text",text:t.trimStart()}]}var Qk={on:"turn the transform on for this session",off:"turn it off; the full transcript is sent unchanged",status:"the switch, the block count, and the tokens saved",blocks:"list the active compressed blocks",stats:"prune and compress totals for this session",context:"what the next request will carry, and what was saved",decompress:"reopen one block by id, e.g. /dcp decompress b2",sweep:"drop blocks no longer referenced by the ref state"};function Rp(e){return e<1e3?`${e}`:`${(e/1e3).toFixed(1)}k`}function oD(e,t,r){let[n]=e.trim().split(/\s+/),o=n===void 0||n===""?"status":n,i=qi(r);switch(o){case"on":return i.enabled=!0,gn(r),"dcp: on";case"off":return i.enabled=!1,gn(r),"dcp: off; the full transcript is sent unchanged";case"blocks":{let a=Br(i);return a.length===0?"dcp: no active blocks":a.map(m=>{let c=String(m.anchorIndex).padStart(4,"0");return`b${m.blockId} covers ${m.coveredIndices.length} message(s), anchored at m${c}`}).join(`
118
- `)}case"status":{let a=yp({runtime:i.enabled,config:gp(t)}),m=Br(i),c=Object.values(i.prune.tools).reduce((p,f)=>p+f,0);return[`dcp: ${a.enabled?"on":"off"} (source: ${a.source})`,`messages tracked: ${Object.keys(i.messageIds.keyToRef).length}`,`active blocks: ${m.length}`,`pruned tool calls: ${Object.keys(i.prune.tools).length} (${Rp(c)} chars)`,`compressed tokens total: ${i.stats.totalCompressTokens}`].join(`
119
- `)}case"stats":{let a=i.prune.messages.blocks,m=a.filter(p=>p.active).length,c=Object.values(i.prune.tools).reduce((p,f)=>p+f,0);return[`blocks: ${m} active of ${a.length} total`,`compressed tokens: ${i.stats.totalCompressTokens}`,`pruned tool calls: ${Object.keys(i.prune.tools).length} (${Rp(c)} chars)`,`messages tracked: ${Object.keys(i.messageIds.keyToRef).length}`,`refs allocated: ${i.messageIds.nextRef-1}`].join(`
120
- `)}case"context":{let a=Br(i),m=new Set;for(let f of a)for(let d of f.coveredIndices)m.add(d);let c=Object.keys(i.messageIds.keyToRef).length,p=Object.values(i.prune.tools).reduce((f,d)=>f+d,0);return[`messages tracked: ${c}`,`messages replaced by a block: ${m.size}`,`messages sent: ${Math.max(0,c-m.size)}`,`active blocks: ${a.length}`,`compressed tokens total: ${i.stats.totalCompressTokens}`,`pruned tool calls: ${Object.keys(i.prune.tools).length} (${Rp(p)} chars)`].join(`
121
- `)}case"decompress":{let a=e.trim().split(/\s+/)[1],m=a===void 0?null:/^b?(\d+)$/i.exec(a);if(!m)return"dcp: give a block id, e.g. /dcp decompress b2";let c=Number(m[1]),p=i.prune.messages.blocks,f=p.find(g=>g.blockId===c);if(!f)return`dcp: no block b${c}`;let d=p.filter(g=>g.active&&g.consumedBlockIds.includes(c));if(d.length>0){let g=d.map(y=>`b${y.blockId}`).join(", ");return`dcp: b${c} was consumed by ${g}; decompress that one first`}if(!f.active)return`dcp: b${c} is already open`;f.active=!1,f.deactivatedByUser=!0,f.deactivatedAt=Date.now();for(let g of f.parentBlockIds){let y=p.find(I=>I.blockId===g);y&&(y.consumedBlockIds=y.consumedBlockIds.filter(I=>I!==c))}return gn(r),`dcp: b${c} reopened; ${f.coveredIndices.length} message(s) are back`}case"sweep":{let a=new Set(Object.keys(i.messageIds.refToKey).map(Number)),m=i.prune.messages.blocks,c=m.length,p=m.filter(d=>d.active&&!d.coveredIndices.some(g=>a.has(g)));for(let d of p)d.active=!1,d.deactivatedAt=Date.now();i.prune.messages.blocks=m.filter(d=>d.active||d.deactivatedByUser);let f=c-i.prune.messages.blocks.length;return gn(r),p.length===0?"dcp: nothing to sweep":`dcp: ${p.length} orphaned block(s) closed, ${f} dropped from state`}default:return`dcp: unknown subcommand '${o}'. try: ${Object.keys(Qk).join(", ")}`}}import{Type as Tm}from"@netrodev/hxf-ai";import{defineTool as oT}from"@netrodev/hxf-coding-agent";import{promises as iD}from"node:dns";var sD=/^(127\.|10\.|192\.168\.|169\.254\.|0\.)/;function Pp(e){if(sD.test(e))return!0;let t=/^172\.(\d+)\./.exec(e);if(!t)return!1;let r=Number(t[1]);return r>=16&&r<=31}function Ap(e){let t=/^100\.(\d+)\.(\d+)\.(\d+)$/.exec(e);if(t){let n=Number(t[1]);return n>=64&&n<=127}let r=/^198\.(\d+)\./.exec(e);return r!==null&&(Number(r[1])===18||Number(r[1])===19)}function Zk(e){let t=e.toLowerCase().replace(/^\[|\]$/g,"").split("%")[0];if(t==="localhost"||t.endsWith(".localhost"))return!0;let r=/^::ffff:(\d+\.\d+\.\d+\.\d+)$/.exec(t);if(r){let o=r[1];return Pp(o)||Ap(o)||o==="0.0.0.0"}let n=/^::ffff:([0-9a-f]{1,4}):([0-9a-f]{1,4})$/.exec(t);if(n){let o=Number.parseInt(n[1],16),i=Number.parseInt(n[2],16),a=`${o>>8&255}.${o&255}.${i>>8&255}.${i&255}`;return Pp(a)||Ap(a)||a==="0.0.0.0"}return t.includes(":")?!!(t==="::1"||t==="::"||/^f[cd][0-9a-f]{2}:/.test(t)||/^fe[89ab][0-9a-f]:/.test(t)):t==="0.0.0.0"?!0:Pp(t)||Ap(t)}var Op=8e4,Mp=8;function km(e){let t;try{t=new URL(e)}catch{return{ok:!1,reason:"not a URL"}}if(t.protocol!=="http:"&&t.protocol!=="https:")return{ok:!1,reason:`refused protocol ${t.protocol}`};let r=t.hostname.toLowerCase();return r==="localhost"||r.endsWith(".localhost")||r==="::1"||r==="[::1]"?{ok:!1,reason:"refused loopback host"}:Zk(r)?{ok:!1,reason:"refused private address"}:{ok:!0,url:t}}function eT(e){let t=e.replace(/<script[\s\S]*?<\/script>/gi," ").replace(/<style[\s\S]*?<\/style>/gi," ").replace(/<noscript[\s\S]*?<\/noscript>/gi," ").replace(/<[^>]+>/g," ").replace(/&nbsp;/g," ").replace(/&amp;/g,"&").replace(/&lt;/g,"<").replace(/&gt;/g,">").replace(/&quot;/g,'"').replace(/&#39;/g,"'").replace(/\s+/g," ").trim();return t.length>Op?t.slice(0,Op):t}function aD(e){let t=[],r=/class="result__a"[^>]*href="([^"]+)"[^>]*>([\s\S]*?)<\/a>/gi,n;for(;(n=r.exec(e))&&t.length<Mp;){let o=n[1]??"",i=eT(n[2]??""),a=o,m=/[?&]uddg=([^&]+)/.exec(o);if(m)try{a=decodeURIComponent(m[1])}catch{a=o}else o.startsWith("//")&&(a=`https:${o}`);let c=km(a);!c.ok||!i||t.push({title:i,url:c.url.toString(),snippet:""})}return t}var tT="HowToCode (https://howtofix.id)";async function rT(e,t={}){let r=e.trim();if(!r)return{ok:!1,error:"empty query"};let n=t.fetchFn??fetch,o=t.timeoutMs??15e3,i={"user-agent":t.userAgent??tT,accept:"text/html, application/json"};try{if(t.braveKey){let p=`https://api.search.brave.com/res/v1/web/search?q=${encodeURIComponent(r)}&count=${Mp}`,f=await n(p,{headers:{...i,accept:"application/json","x-subscription-token":t.braveKey},signal:AbortSignal.timeout(o)});return f.ok?{ok:!0,hits:mD(await f.json()),provider:"brave"}:{ok:!1,error:`brave ${f.status}`}}let a=`https://html.duckduckgo.com/html/?q=${encodeURIComponent(r)}`,m=await n(a,{headers:i,signal:AbortSignal.timeout(o)});return m.ok?{ok:!0,hits:aD(await m.text()),provider:"ddg"}:{ok:!1,error:`search ${m.status}`}}catch(a){return{ok:!1,error:a instanceof Error?a.message:String(a)}}}function mD(e){let t=[];if(e&&typeof e=="object"&&"web"in e){let n=e.web;n&&typeof n=="object"&&"results"in n&&Array.isArray(n.results)&&(t=n.results)}let r=[];for(let n of t){if(!n||typeof n!="object"||!("url"in n)||!("title"in n))continue;let o=n.url,i=n.title;if(typeof o!="string"||typeof i!="string")continue;let a=km(o);if(!a.ok)continue;let m="description"in n?n.description:void 0;if(r.push({title:i,url:a.url.toString(),snippet:typeof m=="string"?m:""}),r.length>=Mp)break}return r}var Xk=5,uD=new Set([301,302,303,307,308]);async function cD(e,t){let r=e.toLowerCase().replace(/^\[|\]$/g,"");if(r.includes(":")||/^[\d.]+$/.test(r))return{ok:!0,addresses:[r]};let n;try{n=await t(r)}catch(i){return{ok:!1,error:`could not resolve ${e}: ${i instanceof Error?i.message:String(i)}`}}if(n.length===0)return{ok:!1,error:`could not resolve ${e}`};let o=n.find(i=>Zk(i));return o!==void 0?{ok:!1,error:`refused ${e}: resolves to private address ${o}`}:{ok:!0,addresses:n}}async function nT(e,t={}){let r=km(e);if(!r.ok)return{ok:!1,error:r.reason};let n=t.fetchFn??fetch,o=t.lookup??(c=>iD.lookup(c,{all:!0}).then(p=>p.map(f=>f.address))),i=AbortSignal.timeout(t.timeoutMs??2e4),a={"user-agent":t.userAgent??tT,accept:"text/html, text/plain, application/json"},m;try{let{Agent:c}=await import("undici"),p=[],f=((g,y,I)=>{let h=p.map(b=>({address:b,family:b.includes(":")?6:4}));y?.all?I(null,h):I(null,h[0].address,h[0].family)});m=new c({connect:{lookup:f}});let d=r.url;for(let g=0;g<=Xk;g++){let y=km(d.toString());if(!y.ok)return{ok:!1,error:`redirect refused: ${y.reason}`};let I=await cD(y.url.hostname,o);if(!I.ok)return{ok:!1,error:I.error};p=I.addresses;let h=await n(y.url,{headers:a,signal:i,redirect:"manual",dispatcher:m});if(uD.has(h.status)){let P=h.headers.get("location");if(!P)return{ok:!1,error:`HTTP ${h.status} without a location`};try{d=new URL(P,y.url)}catch{return{ok:!1,error:"redirect location is not a URL"}}continue}if(!h.ok)return{ok:!1,error:`HTTP ${h.status}`};let b=h.headers.get("content-type")??"",k=await h.text(),j=/html/i.test(b)?eT(k):k.slice(0,Op);return{ok:!0,url:d.toString(),contentType:b,text:j}}return{ok:!1,error:`too many redirects (max ${Xk})`}}catch(c){return{ok:!1,error:c instanceof Error?c.message:String(c)}}finally{await m?.close()}}function pD(e){return e.length===0?"no results":e.map((t,r)=>`${r+1}. ${t.title}
122
- ${t.url}${t.snippet?`
123
- ${t.snippet}`:""}`).join(`
124
- `)}var iT=oT({name:"web_search",label:"web_search",description:"Search the public web. Use for current docs, changelogs, error messages, and anything not in this repo. Returns titles, URLs, and snippets. Follow a URL with web_fetch.",promptSnippet:"web_search: search the public web",parameters:Tm.Object({query:Tm.String({description:"Search query"})}),async execute(e,t){let r=await rT(t.query,{braveKey:process.env.BRAVE_API_KEY});return r.ok?{content:[{type:"text",text:pD(r.hits)}],details:{count:r.hits.length,provider:r.provider}}:{content:[{type:"text",text:r.error}],details:{error:r.error},isError:!0}}}),sT=oT({name:"web_fetch",label:"web_fetch",description:"Fetch a public http(s) URL and return its text. HTML is stripped to visible text. Local, loopback, and private addresses are refused.",promptSnippet:"web_fetch: read a public URL as text",parameters:Tm.Object({url:Tm.String({description:"http(s) URL"})}),async execute(e,t){let r=await nT(t.url);return r.ok?{content:[{type:"text",text:r.text}],details:{url:r.url,contentType:r.contentType,chars:r.text.length}}:{content:[{type:"text",text:r.error}],details:{error:r.error},isError:!0}}});import{spawn as fD}from"node:child_process";import{existsSync as wm,readFileSync as uT}from"node:fs";import{delimiter as cT,isAbsolute as pT,join as Cm}from"node:path";import{fileURLToPath as dD,pathToFileURL as Gr}from"node:url";function aT(e){let t=JSON.stringify(e);return`Content-Length: ${Buffer.byteLength(t,"utf8")}\r
125
- \r
126
- ${t}`}var lD=32*1024*1024;function gD(e){let t=[],r=0;for(;r<e.length;){let n=e.indexOf(`\r
127
- \r
128
- `,r);if(n===-1)break;let o=e.subarray(r,n).toString("utf8"),i=/Content-Length:\s*(\d+)/i.exec(o);if(!i)break;let a=Number(i[1]);if(!Number.isSafeInteger(a)||a<0||a>lD)throw new Error(`lsp frame of ${i[1]} bytes refused`);let m=n+4,c=m+a;if(c>e.length)break;let p=e.subarray(m,c).toString("utf8");try{let f=JSON.parse(p);f&&typeof f=="object"&&t.push(f)}catch{}r=c}return{messages:t,rest:e.subarray(r)}}var vp=class{constructor(t){this.io=t;t.stdout.on("data",r=>{if(this.broken)return;this.buffer=Buffer.concat([this.buffer,r]);let n;try{n=gD(this.buffer)}catch(o){this.buffer=Buffer.alloc(0),this.fail(o instanceof Error?o:new Error(String(o)));return}this.buffer=n.rest;for(let o of n.messages)this.dispatch(o)}),t.stdin.on("error",r=>{this.fail(r instanceof Error?r:new Error(String(r)))})}io;nextId=1;pending=new Map;buffer=Buffer.alloc(0);broken=null;opened=new Set;versions=new Map;diagnosticsByUri=new Map;diagnosticsWaiters=new Map;fail(t){if(!this.broken){this.broken=t;for(let[r,n]of this.pending)this.pending.delete(r),n.reject(t)}}dispatch(t){if(t.method==="textDocument/publishDiagnostics"){let n=t.params;if(n?.uri){let o=Array.isArray(n.diagnostics)?n.diagnostics:[];this.diagnosticsByUri.set(n.uri,o);let i=this.diagnosticsWaiters.get(n.uri);if(i){this.diagnosticsWaiters.delete(n.uri);for(let a of i)a(o)}}return}if(t.id===void 0)return;let r=this.pending.get(Number(t.id));r&&(this.pending.delete(Number(t.id)),t.error?r.reject(new Error(t.error.message)):r.resolve(t.result))}request(t,r,n=1e4){if(this.broken)return Promise.reject(this.broken);let o=this.nextId++,i=aT({jsonrpc:"2.0",id:o,method:t,params:r}),{promise:a,resolve:m,reject:c}=Promise.withResolvers(),p=setTimeout(()=>{this.pending.delete(o),c(new Error(`lsp ${t} timed out`))},n);this.pending.set(o,{resolve:f=>{clearTimeout(p),m(f)},reject:f=>{clearTimeout(p),c(f)}});try{this.io.stdin.write(i)}catch(f){let d=f instanceof Error?f:new Error(String(f));this.pending.delete(o),clearTimeout(p),c(d),this.fail(d)}return a}notify(t,r){if(!this.broken)try{this.io.stdin.write(aT({jsonrpc:"2.0",method:t,params:r}))}catch(n){this.fail(n instanceof Error?n:new Error(String(n)))}}async initialize(){await this.request("initialize",{processId:null,rootUri:Gr(this.io.root).toString(),capabilities:{textDocument:{hover:{},definition:{},references:{},documentSymbol:{},publishDiagnostics:{}}}}),this.notify("initialized",{})}async hover(t,r,n){return(await this.request("textDocument/hover",{textDocument:{uri:Gr(t).toString()},position:{line:r,character:n}}))?.contents?.value}async definition(t,r,n){let o=await this.request("textDocument/definition",{textDocument:{uri:Gr(t).toString()},position:{line:r,character:n}});return Array.isArray(o)?o[0]:o??void 0}async references(t,r,n){let o=await this.request("textDocument/references",{textDocument:{uri:Gr(t).toString()},position:{line:r,character:n},context:{includeDeclaration:!0}});return Array.isArray(o)?o:[]}async documentSymbols(t){let r=await this.request("textDocument/documentSymbol",{textDocument:{uri:Gr(t).toString()}});return Array.isArray(r)?r:[]}diagnostics(t,r=2e3){let n=Gr(t).toString(),o=this.diagnosticsByUri.get(n);if(o)return Promise.resolve(o);let{promise:i,resolve:a}=Promise.withResolvers(),m=setTimeout(()=>{let p=this.diagnosticsWaiters.get(n);if(p){this.diagnosticsWaiters.delete(n);for(let f of p)f(this.diagnosticsByUri.get(n)??[])}},r),c=this.diagnosticsWaiters.get(n)??[];return c.push(p=>{clearTimeout(m),a(p)}),this.diagnosticsWaiters.set(n,c),i}async ensureOpen(t,r,n){let o=Gr(t).toString();this.opened.has(o)||(this.versions.set(o,1),this.notify("textDocument/didOpen",{textDocument:{uri:o,languageId:n,version:1,text:r}}),this.opened.add(o))}isOpen(t){return this.opened.has(Gr(t).toString())}notifyChange(t,r,n){let o=Gr(t).toString();if(!this.opened.has(o)){this.versions.set(o,1),this.opened.add(o),this.notify("textDocument/didOpen",{textDocument:{uri:o,languageId:n,version:1,text:r}});return}let i=(this.versions.get(o)??1)+1;this.versions.set(o,i),this.diagnosticsByUri.delete(o),this.notify("textDocument/didChange",{textDocument:{uri:o,version:i},contentChanges:[{text:r}]})}dispose(){for(let[t,r]of this.pending)r.reject(new Error("lsp client disposed")),this.pending.delete(t);for(let[t,r]of this.diagnosticsWaiters){let n=this.diagnosticsByUri.get(t)??[];this.diagnosticsWaiters.delete(t);for(let o of r)o(n)}}},yD=[{command:"typescript-language-server",args:["--stdio"],languageId:"typescript",match:e=>/\.(ts|tsx|js|jsx|mts|cts)$/.test(e)},{command:"rust-analyzer",args:[],languageId:"rust",match:e=>e.endsWith(".rs")},{command:"gopls",args:[],languageId:"go",match:e=>e.endsWith(".go")},{command:"pylsp",args:[],languageId:"python",match:e=>e.endsWith(".py")}];function fT(e){return yD.find(t=>t.match(e))}var Kr=new Map;async function dT(e,t){let r=Kr.get(e.command);if(r)return await r.ready,r.client;let n=fD(e.command,e.args,{cwd:t,stdio:["pipe","pipe","ignore"]}),o=n.stdin,i=n.stdout;if(!o||!i)throw n.kill(),new Error(`${e.command}: stdio pipes unavailable`);let a=new vp({stdin:o,stdout:i,root:t});n.on("error",()=>{let c=Kr.get(e.command);c?.child===n&&Kr.delete(e.command),c?.client.dispose()}),n.on("exit",()=>{Kr.get(e.command)?.child===n&&Kr.delete(e.command),a.dispose()});let m=a.initialize().catch(c=>{throw Kr.delete(e.command),n.kill(),c});return Kr.set(e.command,{client:a,child:n,ready:m}),await m,a}function xD(){for(let[e,t]of Kr)Kr.delete(e),t.client.dispose(),t.child.kill()}process.on("exit",xD);async function Fve(e,t,r={}){let n=fT(e);if(!n)return{diagnostics:[],unavailable:"no language server configured for this file type"};if(!(n.command.includes("/")?wm(n.command):(process.env.PATH??"").split(cT).some(i=>wm(Cm(i,n.command)))))return{diagnostics:[],unavailable:`${n.command} is not on PATH`};try{let i=pT(e)?e:Cm(t,e),a=await dT(n,t);return a.notifyChange(i,uT(i,"utf8"),n.languageId),{diagnostics:(await a.diagnostics(i,r.waitMs??1500)).map(c=>`${c.range.start.line+1}:${c.range.start.character+1} ${lT[c.severity??3]??"info"} ${c.message}`)}}catch(i){return{diagnostics:[],unavailable:i instanceof Error?i.message:String(i)}}}var lT={1:"error",2:"warning",3:"info",4:"hint"};function mT(e){let t=e.uri;try{t=dD(e.uri)}catch{}let r=e.range?.start;return r?`${t}:${r.line+1}:${r.character+1}`:t}function gT(e,t=0){let r=[];for(let n of e){let o=(n.selectionRange??n.range)?.start.line;r.push(`${" ".repeat(t)}${n.name}${o===void 0?"":` :${o+1}`}`),n.children&&r.push(...gT(n.children,t+1))}return r}async function yT(e){try{let t=fT(e.file);if(!t)return{ok:!1,error:`no language server configured for ${e.file}`};if((e.action==="definition"||e.action==="references"||e.action==="hover")&&(e.line===void 0||!Number.isInteger(e.line)||e.line<1))return{ok:!1,error:`line required (1-based) for ${e.action}`};if(!(t.command.includes("/")?wm(t.command):(process.env.PATH??"").split(cT).some(p=>wm(Cm(p,t.command)))))return{ok:!1,error:`${t.command} is not on PATH. Install it to use lsp on ${e.file}.`};let o=pT(e.file)?e.file:Cm(e.root,e.file),i=uT(o,"utf8"),a=await dT(t,e.root);await a.ensureOpen(o,i,t.languageId);let m=(e.line??1)-1,c=0;if(e.symbol){let p=(i.split(`
129
- `)[m]??"").indexOf(e.symbol);p>=0&&(c=p)}switch(e.action){case"definition":{let p=await a.definition(o,m,c);return p?{ok:!0,text:mT(p),count:1}:{ok:!0,text:"no definition found",count:0}}case"references":{let f=(await a.references(o,m,c)).map(mT);return{ok:!0,text:f.length>0?f.join(`
130
- `):"no references found",count:f.length}}case"hover":{let p=(await a.hover(o,m,c))?.trim();return{ok:!0,text:p||"no hover at that position"}}case"symbols":{let p=gT(await a.documentSymbols(o));return{ok:!0,text:p.length>0?p.join(`
131
- `):"no symbols in this file",count:p.length}}case"diagnostics":{let f=(await a.diagnostics(o)).map(d=>`${d.range.start.line+1}:${d.range.start.character+1} ${lT[d.severity??3]??"info"} ${d.message}`);return{ok:!0,text:f.length>0?f.join(`
132
- `):"no diagnostics",count:f.length}}}}catch(t){return{ok:!1,error:t instanceof Error?t.message:String(t)}}}import{StringEnum as hD}from"@netrodev/hxf-ai";import{defineTool as ID}from"@netrodev/hxf-coding-agent";var xT=ID({name:"lsp",label:"lsp",description:"Language-server query: definition, references, hover, symbols, or diagnostics for a file. Line is 1-based. Does not edit. If the server binary is missing the result says so; do not pretend grep is a substitute without telling the user.",promptSnippet:"lsp: definition, references, hover, symbols, diagnostics",parameters:D.Object({action:hD(["diagnostics","definition","references","hover","symbols"],{description:"Which language-server query to run"}),file:D.String({description:"File to query, relative to the project root"}),line:D.Optional(D.Number({description:"1-based line (definition, references, hover)"})),symbol:D.Optional(D.String({description:"Substring to locate on that line when column is omitted"}))}),async execute(e,t,r,n,o){let i=await yT({action:t.action,file:t.file,line:t.line,symbol:t.symbol,root:o.cwd});return i.ok?{content:[{type:"text",text:i.text}],details:{action:t.action,count:i.count}}:{content:[{type:"text",text:i.error}],details:{error:i.error},isError:!0}}});import{defineTool as YD}from"@netrodev/hxf-coding-agent";import{API as bD}from"typescript/unstable/async";import{SyntaxKind as Wt,visitEachChild as hT}from"typescript/unstable/ast";var IT=new Set([Wt.FunctionDeclaration,Wt.FunctionExpression,Wt.ArrowFunction,Wt.MethodDeclaration,Wt.Constructor,Wt.GetAccessor,Wt.SetAccessor]);function Oo(e){return IT.has(e)}var $D=new Set([Wt.AmpersandAmpersandToken,Wt.BarBarToken,Wt.QuestionQuestionToken]);function Rm(e){if(e.kind!==Wt.BinaryExpression)return!1;let t=rt(e,"operatorToken");return t!==void 0&&$D.has(t.kind)}function rt(e,t){let r=e[t];if(r&&typeof r=="object"&&typeof r.kind=="number")return r}function _i(e,t){let r=e[t];return Array.isArray(r)?r:[]}function bT(e,t){return _i(e,"modifiers").some(r=>r.kind===t)}function Ao(e){if(!e)return;let t=e.text;return typeof t=="string"?t:void 0}function ED(e,t){return e.getLineAndCharacterOfPosition(t).line+1}function Fp(e,t){let r=e.getLineAndCharacterOfPosition(t.getStart(e)),n=e.getLineAndCharacterOfPosition(t.end);return{startLine:r.line+1,startColumn:r.character+1,endLine:n.line+1,endColumn:n.character+1}}function Pm(e,t){t(e),hT(e,r=>(Pm(r,t),r))}function Ui(e,t){t(e),hT(e,r=>(Oo(r.kind)||Ui(r,t),r))}var SD=IT;function kD(e){let t=Ao(rt(e,"name"));if(t)return t;let r=rt(e,"parent");for(;r&&!SD.has(r.kind);){if(r.kind===Wt.VariableDeclaration||r.kind===Wt.PropertyAssignment){let n=Ao(rt(r,"name"));if(n)return n}r=rt(r,"parent")}return"<anonymous>"}function TD(e){let t=[];return Pm(e,r=>{if(!Oo(r.kind))return;let n=Fp(e,r);t.push({name:kD(r),node:r,startLine:n.startLine,endLine:n.endLine})}),t}async function $T(e){let t=new Map;if(e.length===0)return t;let r=new bD({cwd:process.cwd()});try{let n=await r.updateSnapshot({openFiles:[...e]});for(let o of e)try{let i=await n.getDefaultProjectForFile(o);if(!i){t.set(o,{ok:!1,error:"no TypeScript project contains this file"});continue}let a=await i.program.getSourceFile(o);if(!a){t.set(o,{ok:!1,error:"the compiler could not read this file"});continue}let m=await i.program.getSyntacticDiagnostics(o);if(m.length>0){let c=m[0],p=ED(a,c.pos);t.set(o,{ok:!1,error:`line ${p}: ${c.text} (TS${c.code})`});continue}t.set(o,{ok:!0,sourceFile:a,functions:TD(a)})}catch(i){t.set(o,{ok:!1,error:i instanceof Error?i.message:String(i)})}}finally{await r.close()}return t}import{SyntaxKind as Mr,visitEachChild as ET}from"typescript/unstable/ast";var wD=new Set([Mr.IfStatement,Mr.SwitchStatement,Mr.ForStatement,Mr.ForInStatement,Mr.ForOfStatement,Mr.WhileStatement,Mr.DoStatement,Mr.CatchClause]);function ST(e){let t=0,r=(o,i)=>{if(!Oo(o.kind)){if(o.kind===Mr.IfStatement){n(o,i,!1);return}if(wD.has(o.kind)){t+=1+i,ET(o,a=>(r(a,i+1),a));return}Rm(o)&&(t+=1),ET(o,a=>(r(a,i),a))}},n=(o,i,a)=>{a||(t+=1+i);let m=rt(o,"expression");m&&r(m,i);let c=rt(o,"thenStatement");c&&r(c,i+1);let p=rt(o,"alternate");p&&(t+=1,p.kind===Mr.IfStatement?n(p,i,!0):r(p,i+1))};return r(e,0),t}import{SyntaxKind as Hr}from"typescript/unstable/ast";var CD=new Set([Hr.IfStatement,Hr.ConditionalExpression,Hr.WhileStatement,Hr.DoStatement,Hr.ForStatement,Hr.ForInStatement,Hr.ForOfStatement,Hr.CatchClause,Hr.CaseClause]);function kT(e){let t=1;return Ui(e,r=>{(CD.has(r.kind)||Rm(r))&&(t+=1)}),t}import{SyntaxKind as ue}from"typescript/unstable/ast";var RD=new Set([ue.BinaryExpression,ue.PrefixUnaryExpression,ue.PostfixUnaryExpression,ue.ConditionalExpression,ue.CallExpression,ue.NewExpression,ue.PropertyAccessExpression,ue.ElementAccessExpression,ue.AwaitExpression,ue.YieldExpression,ue.SpreadElement,ue.IfStatement,ue.WhileStatement,ue.DoStatement,ue.ForStatement,ue.ForInStatement,ue.ForOfStatement,ue.SwitchStatement,ue.ReturnStatement,ue.ThrowStatement,ue.TryStatement,ue.BreakStatement,ue.ContinueStatement]),PD=new Set([ue.StringLiteral,ue.NumericLiteral,ue.BigIntLiteral,ue.RegularExpressionLiteral,ue.NoSubstitutionTemplateLiteral]);function Lp(e,t){e.set(t,(e.get(t)??0)+1)}function TT(e){let t=new Map,r=new Map;Ui(e,i=>{if(RD.has(i.kind)){let m=rt(i,"operatorToken");Lp(t,ue[i.kind]+(m?`:${ue[m.kind]}`:""));return}let a=Ao(i);a!==void 0&&(i.kind===ue.Identifier||i.kind===ue.PrivateIdentifier?Lp(r,`id:${a}`):PD.has(i.kind)&&Lp(r,`lit:${a}`))});let n=t.size+r.size;if(n===0)return 0;let o=0;for(let i of t.values())o+=i;for(let i of r.values())o+=i;return Math.round(o*Math.log2(n)*100)/100}function wT(e){return e.endLine-e.startLine+1}function CT(e,t,r){let n=171-5.2*Math.log(Math.max(e,1))-.23*t-16.2*Math.log(Math.max(r,1));return Math.round(Math.max(0,n*100/171)*10)/10}import{SyntaxKind as pr,visitEachChild as AD}from"typescript/unstable/ast";var OD=new Set([pr.IfStatement,pr.SwitchStatement,pr.WhileStatement,pr.DoStatement,pr.ForStatement,pr.ForInStatement,pr.ForOfStatement,pr.TryStatement,pr.CatchClause]);function RT(e){let t=0,r=(n,o)=>{if(Oo(n.kind))return;let i=o;if(OD.has(n.kind)&&(i=o+1,i>t&&(t=i)),n.kind===pr.IfStatement){let a=rt(n,"expression");a&&r(a,i);let m=rt(n,"thenStatement");m&&r(m,i);let c=rt(n,"alternate");c&&r(c,c.kind===pr.IfStatement?o:i);return}AD(n,a=>(r(a,i),a))};return r(e,0),t}import{spawnSync as MD}from"node:child_process";import{mkdirSync as aFe,readdirSync as vD,readFileSync as FD,statSync as LD,writeFileSync as mFe}from"node:fs";import{extname as Np,join as LT,relative as DT,resolve as DD}from"node:path";import{SyntaxKind as Am}from"typescript/unstable/ast";var PT={"god-function":"split it into smaller functions, one job each",incomprehensible:"extract helpers and simplify the flow before touching it",bloated:"long but linear; extract helpers","deeply-tangled":"nesting, not branching; flatten with early returns",fragile:"many branches; add guard clauses and tests around it"};function AT(e,t){let r=[];return t.cyclomatic>=1&&t.length>=1&&t.nesting>=1&&r.push({id:"god-function",label:"God Function",reason:`high cyclomatic complexity (${e.cyclomatic}), long body (${e.length} lines), and deep nesting (${e.nesting}) \u2014 likely doing too many things`}),t.cognitive>=1&&t.halstead>=1&&t.mi>=1&&r.push({id:"incomprehensible",label:"Incomprehensible",reason:`high cognitive complexity (${e.cognitive}) and Halstead volume (${e.halstead}) with MI ${e.mi} \u2014 very hard to understand`}),t.length>=1&&t.halstead>=1&&t.cyclomatic===0&&r.push({id:"bloated",label:"Bloated",reason:`large function (${e.length} lines) with high vocabulary (Halstead ${e.halstead}) but low branching \u2014 consider extracting helpers`}),t.nesting>=1&&t.cognitive>=1&&t.cyclomatic===0&&r.push({id:"deeply-tangled",label:"Deeply Tangled",reason:`nesting depth ${e.nesting} drives cognitive complexity ${e.cognitive} \u2014 flatten with early returns or extracted helpers`}),t.cyclomatic>=1&&t.mi>=1&&t.length===0&&r.push({id:"fragile",label:"Fragile",reason:`high cyclomatic complexity (${e.cyclomatic}) with MI ${e.mi} \u2014 many branches, hard to change safely`}),r}var jD=["ok","warn","error"],Bp=["cyclomatic","cognitive","nesting","length","halstead","mi","parameters","booleanParameters"];var zr={cyclomatic:{warn:15,error:25},cognitive:{warn:12,error:20},nesting:{warn:4,error:5},length:{warn:60,error:120},halstead:{warn:500,error:1e3},mi:{warn:65,error:20},fileLines:{warn:400,error:800},exports:{warn:20,error:30},parameters:{warn:5,error:8}};function jT(){let e={cyclomatic:{...zr.cyclomatic},cognitive:{...zr.cognitive},nesting:{...zr.nesting},length:{...zr.length},halstead:{...zr.halstead},mi:{...zr.mi},fileLines:{...zr.fileLines},exports:{...zr.exports},parameters:{...zr.parameters}};return{ignore:[],thresholds:e,ci:{failBelow:65,mode:"advisory"}}}var ND=["cyclomatic","cognitive","nesting","length","halstead","mi","fileLines","exports","parameters"];function Dp(e){return typeof e=="number"&&Number.isFinite(e)}function Gp(e){let t=jT(),r;try{r=JSON.parse(FD(LT(e,".howtocode","quality.json"),"utf8"))}catch{return t}if(typeof r!="object"||r===null)return t;let n=r;if(typeof n.enabled=="boolean"&&(t.enabled=n.enabled),Array.isArray(n.ignore)&&(t.ignore=n.ignore.filter(o=>typeof o=="string")),typeof n.thresholds=="object"&&n.thresholds!==null){let o=n.thresholds;for(let i of ND){let a=o[i];if(typeof a!="object"||a===null)continue;let m=a;Dp(m.warn)&&(t.thresholds[i].warn=m.warn),Dp(m.error)&&(t.thresholds[i].error=m.error)}}if(typeof n.ci=="object"&&n.ci!==null){let o=n.ci;Dp(o.failBelow)&&(t.ci.failBelow=o.failBelow),(o.mode==="advisory"||o.mode==="blocking")&&(t.ci.mode=o.mode)}return t}function NT(e,t){let r=process.env.HOWTOCODE_QUALITY;if(r!==void 0){let o=r.trim().toLowerCase();return o==="0"||o==="false"?{enabled:!1,source:"env"}:{enabled:!0,source:"env"}}let n=Gp(e).enabled;return n!==void 0?{enabled:n,source:"config"}:t!==void 0?{enabled:t,source:"runtime"}:{enabled:!0,source:"default"}}function yn(e,t){return e>t.error?2:e>t.warn?1:0}function qT(e,t){return e<t.error?2:e<t.warn?1:0}function qD(e){let t=[];for(let r of _i(e.node,"parameters"))rt(r,"type")?.kind===Am.BooleanKeyword&&t.push(Ao(rt(r,"name"))??"<pattern>");return t}function _D(e,t,r,n){let o=n.thresholds,i=rt(e.node,"body")??e.node,a={cyclomatic:kT(i),cognitive:ST(i),nesting:RT(i),length:wT(e),halstead:TT(i),mi:0};a.mi=CT(a.halstead,a.cyclomatic,a.length);let m=qD(e),c=_i(e.node,"parameters").length,p={cyclomatic:{value:a.cyclomatic,rank:yn(a.cyclomatic,o.cyclomatic)},cognitive:{value:a.cognitive,rank:yn(a.cognitive,o.cognitive)},nesting:{value:a.nesting,rank:yn(a.nesting,o.nesting)},length:{value:a.length,rank:yn(a.length,o.length)},halstead:{value:a.halstead,rank:yn(a.halstead,o.halstead)},mi:{value:a.mi,rank:qT(a.mi,o.mi)},parameters:{value:c,rank:yn(c,o.parameters)},booleanParameters:{value:m.length,rank:m.length>0?1:0}},f={cyclomatic:p.cyclomatic.rank,cognitive:p.cognitive.rank,nesting:p.nesting.rank,length:p.length.rank,halstead:p.halstead.rank,mi:p.mi.rank},d=Fp(t,e.node),g=0;for(let y of Bp)p[y].rank>g&&(g=p[y].rank);return{path:r,name:e.name,startLine:d.startLine,endLine:d.endLine,startColumn:d.startColumn,endColumn:d.endColumn,metrics:p,booleanParameterNames:m,smells:AT(a,f),worstRank:g}}function UD(e){let t=0;return Pm(e,r=>{if(r.kind===Am.ExportDeclaration){let n=rt(r,"exportClause"),o=n?_i(n,"elements"):[];t+=o.length>0?o.length:1;return}if(r.kind===Am.ExportAssignment){t+=1;return}bT(r,Am.ExportKeyword)&&(t+=1)}),t}function BD(e){if(e.length===0)return 0;let t=1;for(let r=0;r<e.length;r+=1)e.charCodeAt(r)===10&&(t+=1);return e.charCodeAt(e.length-1)===10&&(t-=1),t}var OT={value:0,rank:0};function MT(e,t){return{path:e,ok:!1,error:t,lines:0,metrics:{lines:OT,exports:OT,mi:{value:100,rank:0}},functions:[]}}function jp(e,t,r,n,o,i,a){i.rank!==0&&e.push({path:t.path,metric:o,detail:o==="booleanParameters"?r?.booleanParameterNames.join(", ")??String(i.value):`${i.value} (limit ${a})`,rank:i.rank,line:n.line,endLine:n.endLine,startColumn:n.startColumn,endColumn:n.endColumn,...r?{function:r.name}:{}})}async function _T(e,t=jT()){let r=await $T(e),n=new Map,o=[],i=t.thresholds;for(let a of e){let m=r.get(a);if(!m){let b=MT(a,"internal: file missing from the parse result");n.set(a,b),o.push({path:a,metric:"parse error",detail:b.error??"",rank:2,line:1,endLine:1,startColumn:1,endColumn:1});continue}if(!m.ok){let b=MT(a,m.error);n.set(a,b),o.push({path:a,metric:"parse error",detail:m.error,rank:2,line:1,endLine:1,startColumn:1,endColumn:1});continue}let{sourceFile:c}=m,p=m.functions.map(b=>_D(b,c,a,t)),f=BD(c.text),d=UD(c),g=p.reduce((b,k)=>b+k.metrics.length.value,0),y=g===0?100:Math.round(p.reduce((b,k)=>b+k.metrics.mi.value*k.metrics.length.value,0)/g*10)/10,I={path:a,ok:!0,lines:f,metrics:{lines:{value:f,rank:yn(f,i.fileLines)},exports:{value:d,rank:yn(d,i.exports)},mi:{value:y,rank:qT(y,i.mi)}},functions:p};n.set(a,I);let h={line:1,endLine:Math.max(f,1),startColumn:1,endColumn:1};jp(o,I,void 0,h,"file lines",I.metrics.lines,i.fileLines.warn),jp(o,I,void 0,h,"exports",I.metrics.exports,i.exports.warn);for(let b of p){let k={line:b.startLine,endLine:b.endLine,startColumn:b.startColumn,endColumn:b.endColumn};for(let j of Bp)jp(o,I,b,k,j,b.metrics[j],UT(j,i));for(let j of b.smells)o.push({path:a,metric:"smell",detail:`${j.label}: ${j.reason}`,rank:1,line:b.startLine,endLine:b.endLine,startColumn:b.startColumn,endColumn:b.endColumn,function:b.name})}}return{files:n,findings:o}}function Kp(e){let t=0,r=0;for(let n of e.files.values())if(n.ok)for(let o of n.functions)t+=o.metrics.length.value,r+=o.metrics.mi.value*o.metrics.length.value;return t===0?100:Math.round(r/t*10)/10}function Hp(e){let t=0,r=0,n=0,o=0;for(let i of e.files.values())i.ok||(t+=1),r+=i.functions.length;for(let i of e.findings)i.rank>=2?o+=1:n+=1;return{files:e.files.size,errorFiles:t,functions:r,findings:e.findings.length,warn:n,error:o,score:Kp(e)}}var GD=["ok","\u26A0","\u2717"],KD=[["cyclomatic","cyclomatic"],["cognitive","cognitive"],["nesting","nesting"],["length","length"],["halstead","halstead"],["mi","MI"],["parameters","parameters"],["booleanParameters","boolean params"]];function UT(e,t){return e==="mi"?t.mi.warn:e==="booleanParameters"?t.parameters.warn:t[e].warn}function qp(e,t,r,n){return`${e}${t.padEnd(15)} ${r.value} (limit ${n}) ${jD[r.rank]}`}function HD(e,t){let r=[` ${e.name.padEnd(30)} L${e.startLine}-${e.endLine}`];for(let[n,o]of KD){let i=e.metrics[n];if(i.rank!==0){if(n==="booleanParameters"){r.push(` ${o.padEnd(15)} ${e.booleanParameterNames.join(", ")} warn`);continue}r.push(qp(" ",o,i,UT(n,t.thresholds)))}}if(e.smells.length>0){r.push(` ${"smells".padEnd(15)} ${e.smells.map(n=>n.id).join(", ")}`);for(let n of e.smells)r.push(` \u2192 ${PT[n.id]??n.label}`)}return r}function vT(e){let t=e.smells.length;for(let r of Bp)e.metrics[r].rank>0&&(t+=1);return t}function zD(e,t){let r=[];for(let o of e.files.values())for(let i of o.functions)i.worstRank>0&&r.push(i);r.sort((o,i)=>{if(o.worstRank!==i.worstRank)return i.worstRank-o.worstRank;let a=vT(i)-vT(o);if(a!==0)return a;let m=i.metrics.cyclomatic.value-o.metrics.cyclomatic.value;return m!==0?m:`${o.path}:${o.name}`.localeCompare(`${i.path}:${i.name}`)});let n=new Map;for(let o of r.slice(0,t)){let i=n.get(o.path)??new Set;i.add(`${o.name}@${o.startLine}`),n.set(o.path,i)}return n}function BT(e,t,r={}){let n=Hp(e),o=r.top&&r.top>0?zD(e,r.top):void 0,i=[...e.files.values()].filter(p=>!o||(o.get(p.path)?.size??0)>0),a=Math.max(40,...i.map(p=>p.path.length)),m=[];for(let p of i){if(!p.ok){m.push(`${p.path.padEnd(a)} parse error`),m.push(` ${p.error}`);continue}m.push(`${p.path.padEnd(a)} MI ${p.metrics.mi.value} ${GD[p.metrics.mi.rank]}`),p.metrics.lines.rank>0&&m.push(qp(" ","file lines",p.metrics.lines,t.thresholds.fileLines.warn)),p.metrics.exports.rank>0&&m.push(qp(" ","exports",p.metrics.exports,t.thresholds.exports.warn));for(let f of p.functions)o&&!o.get(p.path)?.has(`${f.name}@${f.startLine}`)||f.worstRank===0&&f.smells.length===0||m.push(...HD(f,t))}m.length>0&&m.push("");let c=n.errorFiles>0?`, ${n.errorFiles} parse error(s)`:"";return m.push(`${n.findings} findings in ${n.files} files${c} \xB7 ${n.functions} functions \xB7 score ${n.score}`),m.join(`
133
- `)}var _p=new Set([".ts",".tsx",".mts",".cts"]),WD=new Set(["node_modules","dist","coverage"]);function Up(e,t,r){for(let n of vD(e,{withFileTypes:!0})){let o=LT(e,n.name);if(n.isDirectory()){if(n.name.startsWith(".")||WD.has(n.name))continue;Up(o,t,r);continue}n.isFile()&&_p.has(Np(n.name))&&r.push(DT(t,o))}}function FT(e,t){let r=MD("git",["-C",e,...t],{encoding:"utf8"});if(r.error||r.status!==0){let n=r.error?r.error.message:r.stderr.trim()||`exit ${r.status}`;throw new Error(`git ${t.join(" ")} failed: ${n}`)}return r.stdout.split(`
134
- `).filter(n=>n.trim().length>0)}function VD(e,t){let r=FT(e,["diff","--name-only","--diff-filter=ACMR",t]),n=FT(e,["ls-files","--others","--exclude-standard"]);return[...r,...n]}function JD(e,t){if(!t.includes("*")){let n=t.endsWith("/")?t:`${t}/`;return e===t||e.startsWith(n)}let r=t.replace(/[.+^${}()|[\]\\]/g,"\\$&").replace(/\*\*/g,"\0").replace(/\*/g,"[^/]*").replace(/\u0000/g,".*");return new RegExp(`^${r}$`).test(e)}function GT(e,t,r=[]){let n;if(t.changes)n=VD(e,t.base??"HEAD");else if(t.target){let i=DD(e,t.target),a=LD(i,{throwIfNoEntry:!1});if(!a)throw new Error(`no such path: ${t.target}`);if(a.isDirectory())n=[],Up(i,e,n);else{if(!_p.has(Np(i)))throw new Error(`not a TypeScript source file: ${t.target}`);n=[DT(e,i)]}}else n=[],Up(e,e,n);let o=new Set;for(let i of n)_p.has(Np(i))&&(r.some(a=>JD(i,a))||o.add(i));return[...o].sort()}var KT=6e3,HT=YD({name:"quality",label:"quality",description:"Measure code quality: cyclomatic and cognitive complexity, nesting depth, function length, Halstead volume, maintainability index, and compound smells like god-function and deeply-tangled. Read-only. Use it before reporting a task finished, especially on functions you just wrote or changed; it reports concrete numbers with line numbers and a suggested next step, so 'is this too complex' stops being a guess. Defaults to the changed files; pass a path to narrow it further.",promptSnippet:"quality: complexity and maintainability metrics for changed code",parameters:D.Object({path:D.Optional(D.String({description:"One file or directory, relative to the project root. Omit to scan the changed set."})),changes:D.Optional(D.Boolean({description:"Scan only files changed against the base ref. Default true when path is omitted."})),base:D.Optional(D.String({description:"Git ref for `changes`. Defaults to HEAD."})),top:D.Optional(D.Number({description:"Only report the N worst functions."}))}),async execute(e,t,r,n,o){let i=o.cwd??process.cwd(),a=NT(i);if(!a.enabled)return{content:[{type:"text",text:`quality metrics are off (source: ${a.source})`}],details:{off:!0}};let m=Gp(i),c=t.changes??t.path===void 0,p=GT(i,{changes:c,base:t.base,target:t.path},m.ignore);if(p.length===0)return{content:[{type:"text",text:c?"no changed files to measure":"no source files found"}],details:{files:0}};let f=await _T(p,m),d=Hp(f),g=BT(f,m,{top:t.top});return{content:[{type:"text",text:g.length>KT?`${g.slice(0,KT)}
135
- \u2026 (truncated; run the quality script for the full report)`:g}],details:{files:d.files,functions:d.functions,findings:d.findings,score:Kp(f)}}}});import{availableParallelism as QD}from"node:os";var XD=4;function ZD(){let e=df(it).agents;return e!==void 0?e:Math.max(1,Math.min(XD,QD()-2))}var zp=0,zT=[];async function Om(){for(;zp>=ZD();)await new Promise(t=>zT.push(t));zp+=1;let e=!1;return()=>{e||(e=!0,zp-=1,zT.shift()?.())}}function WT(e,t){let r=e.find(o=>`${o.provider}/${o.id}`===t||o.id===t);if(r)return r;let n=t.toLowerCase();return e.find(o=>o.id.toLowerCase().includes(n)||`${o.provider}/${o.id}`.toLowerCase().includes(n))}var ej=["deepseek","qwen","claude","gpt-5","gpt-4","gemini","glm","mimo","kimi","llama"],tj=/(image|embedding|embed|whisper|tts|audio|video|rerank|moderation|dall-e|stable-diffusion|sora)/i;function rj(e){let t=r=>{if(tj.test(r))return 100;let n=ej.findIndex(o=>r.toLowerCase().includes(o));return n===-1?50:n};return e.map((r,n)=>({id:r,index:n})).sort((r,n)=>t(r.id)-t(n.id)||r.index-n.index).map(r=>r.id)}function NFe(e,t=[]){if(e.length===0)return;let r=e.filter(i=>t.includes(i.provider)),n=r.length>0?r:e,o=rj(n.map(i=>i.id))[0];return n.find(i=>i.id===o)??n[0]}import{mkdirSync as nj,readdirSync as oj,readFileSync as ij,unlinkSync as sj}from"node:fs";import{join as Vp}from"node:path";import{createAgentSession as aj,DefaultResourceLoader as mj,SessionManager as uj}from"@netrodev/hxf-coding-agent";var Wp=["You are one agent on a shared task; siblings may be editing the same working tree right now.","Stay inside the files your assignment names. A file another agent owns is theirs to change: report what you need changed instead of changing it yourself, and never edit a file two agents were both given.","Never run project-wide validation (full builds, whole test suites, formatters, linters) unless your assignment explicitly tells you to.","Siblings' unfinished edits will make those runs fail for reasons that are not yours. Prove your own change with a scoped test, a targeted repro, or a smoke run instead."],cj=`You are a software architect planning an implementation. Your job is to explore the codebase and return a plan, not to write code.
136
-
137
- ## Read-only, by construction
138
- You have no edit tool, no write tool, and no shell. Do not attempt to modify, create, move, or delete anything \u2014 the call would fail. Your output is text.
139
-
140
- ## Your process
141
- 1. Understand the requirement. If it is ambiguous in a way that changes the design, say so and name the options rather than silently picking one.
142
- 2. Explore: read the files involved, find the existing patterns and conventions with grep/find/ls, and trace the code paths the change touches. Follow the codebase's existing approach instead of inventing a new one.
143
- 3. Design: state the approach you recommend, not every alternative you considered. Note the trade-off that decided it.
144
- 4. Sequence: give the implementation as ordered steps, naming the files and functions to change at each one, and what to verify after each.
145
-
146
- ## Required output
147
- End your reply with exactly this section, listing the 3-5 files most critical to the implementation, most important first:
148
-
149
- ### Critical Files for Implementation
150
- - path/to/file.ts
151
- - path/to/file.ts
152
-
153
- Keep the plan concrete enough to execute without re-deriving it: name real paths and real function names you saw while exploring. If you could not confirm something, say which part you are unsure of instead of guessing.`,xn=new Map([["scout",{name:"scout",description:"read-only lookup",tools:["read","grep","find","ls","context","web_search","web_fetch","lsp"],prompt:["Inspect only what the task needs. Do not edit.",...Wp].join(`
154
- `),effort:"low"}],["architect",{name:"architect",description:"designs an implementation plan",tools:["read","grep","find","ls","context","web_search","web_fetch","lsp"],prompt:cj,effort:"high"}],["task",{name:"task",description:"implements the assignment",tools:["read","bash","edit","write","grep","find","ls","context","todo","web_search","web_fetch","lsp"],prompt:["Do the assignment, then report files changed.",...Wp].join(`
155
- `),effort:"medium"}],["reviewer",{name:"reviewer",description:"finds concrete issues",tools:["read","grep","find","ls","context","web_search","web_fetch","lsp"],prompt:["Return issues with file evidence. Do not edit.",...Wp].join(`
156
- `),effort:"medium"}]]),r1e=new Set(xn.keys());function pj(e){return e>=1e3?`${(e/1e3).toFixed(1)}k`:String(e)}function fj(e){return e<6e4?`${(e/1e3).toFixed(1)}s`:`${Math.floor(e/6e4)}m ${(e%6e4/1e3).toFixed(1)}s`}function n1e(e){let t=e.status==="parked"?"done":e.status==="error"?"failed":e.status,r=[];return e.model&&r.push(e.model),typeof e.toolUses=="number"&&r.push(`${e.toolUses} tool use${e.toolUses===1?"":"s"}`),typeof e.tokens=="number"&&e.tokens>0&&r.push(pj(e.tokens)),e.startedAt&&e.endedAt&&r.push(fj(e.endedAt-e.startedAt)),`## ${e.agent}#${e.id} ${t}${r.length>0?` (${r.join(" \xB7 ")})`:""}`}var jt=[],dj=3,VT=8,o1e=6,Mm=12;function vm(e){nj(Un,{recursive:!0}),dr(Vp(Un,`${e.id}.json`),JSON.stringify({...e,session:void 0},null,1))}function Jp(){let e;try{e=oj(Un)}catch{return}for(let t of e)if(t.endsWith(".json"))try{let r=JSON.parse(ij(Vp(Un,t),"utf8"));if(r.status!=="parked"||jt.some(n=>n.id===r.id))continue;jt.push({...r,mail:r.mail??[]})}catch{}if(jt.length>Mm){let t=jt.splice(0,jt.length-Mm);for(let r of t){let n=r.session;r.session=void 0,n&&n.dispose();try{sj(Vp(Un,`${r.id}.json`))}catch{}}}}function i1e(){if(Jp(),jt.length===0)return"no agents";let e=jt.map(t=>`${t.id} ${t.agent} ${t.status}${t.model?` model=${t.model}`:""}${t.background?" background":""} requests=${t.requests} ${t.task}`);return Mo&&e.unshift("background work in flight"),e.join(`
157
- `)}function s1e(e){Jp();let t=jt.find(r=>r.id===e);return t?`${t.agent}#${t.id} ${t.status}
158
- ${t.result??t.task}`:`no agent ${e}`}async function Fm(e){let t=xn.get(e.agent);if(!t)throw new Error(`unknown agent ${e.agent}`);let r=e.worktree||e.cwd||process.cwd(),n=new mj({cwd:r,agentDir:it,appendSystemPrompt:[t.prompt],additionalSkillPaths:pf(r),extensionFactories:[ff({interactive:!1}),Ek()]});await n.reload();let{session:o}=await aj({cwd:r,agentDir:it,sessionManager:uj.inMemory(r),resourceLoader:n,tools:t.tools,customTools:[uk,ik,iT,sT,xT,HT,rk],thinkingLevel:e.effort}),i=lj(e,t);if(i){let a=await o.modelRuntime.getAvailable(),m=WT(a,i);if(!m){o.dispose();let c=e.model?"asked for by the task":t.model?`named by the ${e.agent} definition${t.source?` (${t.source})`:""}`:"inherited from the parent session";throw new Error(`unknown model '${i}' ${c}. /model lists what this account can reach.`)}await o.setModel(m)}return o}async function a1e(e,t){Jp();let r=jt.find(o=>o.id===e);if(!r)return`no agent ${e}`;let n=r.session??await Fm(r);if(r.session=n,r.status==="running"||n.isStreaming)return r.mail.push(t),vm(r),`queued for ${e}`;if(r.requests>=VT)return`${e} is out of budget (${r.requests} requests)`;r.status="running";try{await n.prompt(t),r.requests+=1,r.result=jo(n.getLastAssistantText()??"")||r.result,r.status="parked"}catch(o){r.result=o instanceof Error?o.message:String(o),r.status="error"}return vm(r),`${e} ${r.status}`}function lj(e,t){for(let r of[e.model,t.model,e.parentModel]){let n=r?.trim();if(n)return n}}function JT(e){if(!(!e?.provider||!e.id))return`${e.provider}/${e.id}`}async function m1e(e){let t=xn.get(e.agent);if(!t)throw new Error(`unknown agent ${e.agent}. known: ${[...xn.keys()].join(", ")}`);if(jt.length>=Mm)throw new Error(`${Mm} agents is the limit (${jt.length} live or parked). Finish with the existing ones, or clear them with /agents, before spawning more.`);let r={id:`${Date.now().toString(36)}-${jt.length+1}`,cwd:e.cwd,agent:t.name,task:e.task.trim(),effort:e.effort||t.effort,model:(e.model||t.model)?.trim()||void 0,parentModel:e.parentModel?.trim()||void 0,background:e.background,status:"queued",requests:0,mail:[],worktree:e.worktree};return jt.push(r),vm(r),r}async function gj(e,t){if(!xn.get(e.agent))return;let n=e.session??await Fm(e);e.session=n,e.startedAt=Date.now();try{let o=e.mail.splice(0).join(`
159
- `);for(await n.prompt(`Task:
160
- ${e.task}${o?`
161
-
162
- Messages:
163
- ${o}`:""}`),e.requests+=1;e.mail.length>0&&e.requests<VT;)await n.followUp(e.mail.splice(0).join(`
164
- `)),e.requests+=1;if(t?.aborted)throw new Error("aborted");let i=jo(n.getLastAssistantText()??""),a=n.getSessionStats?.();if(!i&&(a?.toolCalls??0)===0)throw new Error(`agent produced no output (model ${n.model?.provider}/${n.model?.id} answered nothing; 0 tool calls). Check that the provider is reachable and the model is configured.`);e.result=i,e.status="parked"}catch(o){e.result=o instanceof Error?o.message:String(o),e.status="error"}finally{e.endedAt=Date.now();let o=n.getSessionStats?.();e.toolUses=o?.toolCalls,e.tokens=o?.tokens?.total,e.session=void 0,n.dispose(),vm(e);try{YT?.(e)}catch{}}}var YT;function u1e(e){YT=e}var Mo;function c1e(){Mo||(Mo=yj().catch(()=>{}).finally(()=>{Mo=void 0}))}async function yj(e){Mo&&await Mo.catch(()=>{});let t=()=>jt.find(n=>n.status==="queued"),r=async()=>{for(;;){if(e?.aborted)throw new Error("aborted");let n=t();if(!n)return;n.status="running";let o=await Om();try{await gj(n,e)}finally{o()}}};if(await Promise.all(Array.from({length:dj},r)),e?.aborted)throw new Error("aborted")}import{execFile as xj}from"node:child_process";import{cp as hj,readdir as Ij,stat as QT}from"node:fs/promises";import{promisify as bj}from"node:util";import{tmpdir as $j}from"node:os";import{join as Lm}from"node:path";var XT=bj(xj);async function tr(e,t){try{let{stdout:r}=await XT("git",t,{cwd:e,encoding:"utf8",maxBuffer:8388608});return{ok:!0,output:r.trim()}}catch(r){let n=r&&typeof r=="object"&&"stderr"in r&&typeof r.stderr=="string"?r.stderr.trim():"",o=r instanceof Error?r.message:String(r);return{ok:!1,output:n||o}}}async function Ej(e){return(await tr(e,["rev-parse","--is-inside-work-tree"])).output==="true"}async function x1e(e){return(await tr(e,["status","--porcelain"])).output.length>0}async function h1e(e,t){let r=await tr(e,["add","-A"]);if(!r.ok)return r;let n=await tr(e,["commit","-m",t]);return n.ok?{ok:!0,output:(await tr(e,["log","-1","--oneline"])).output||n.output}:n}async function I1e(e){let t=await tr(e,["reset","--soft","HEAD~1"]);return t.ok?{ok:!0,output:(await tr(e,["log","-1","--oneline"])).output||"reset to the previous commit"}:t}async function b1e(e){let t=(await tr(e,["diff"])).output,r=(await tr(e,["diff","--cached"])).output;return[t,r].filter(Boolean).join(`
165
- `)}function $1e(e,t=60){let r=e.split(`
166
- `);if(r.length<=t)return e;let n=r.slice(0,t),o=r.length-t;return[...n,`\u2026 ${o} more line${o===1?"":"s"} not shown \u2014 /copy puts the full diff on the clipboard`].join(`
167
- `)}var Sj=["node_modules","vendor","target",".venv","venv","__pycache__",".pnpm-store","dist","build"],ZT=1024*1024*1024;async function ew(e){let t=0,r;try{r=await Ij(e,{withFileTypes:!0})}catch{return 0}for(let n of r){let o=Lm(e,n.name);if(n.isDirectory())t+=await ew(o);else if(n.isFile())try{t+=(await QT(o)).size}catch{}if(t>ZT)return t}return t}async function kj(e,t){let r=[];for(let n of Sj){let o=Lm(e,n),i=Lm(t,n);try{if(!(await QT(o)).isDirectory())continue}catch{continue}if(await ew(o)>ZT){r.push(n);continue}await Tj(o,i)||r.push(n)}return r}async function Tj(e,t){if(process.platform!=="win32")try{return await XT("cp",["-a",e,t],{maxBuffer:8*1024*1024}),!0}catch{}try{return await hj(e,t,{recursive:!0,force:!0,errorOnExist:!1,dereference:!1}),!0}catch{return!1}}async function tw(e,t){if(!await Ej(e))return null;let r=t.replace(/[^A-Za-z0-9._-]/g,"-").slice(0,40)||"agent",n=Lm($j(),`howtocode-wt-${process.pid}-${Date.now()}-${r}`);if(!(await tr(e,["worktree","add","--detach",n,"HEAD"])).ok)return null;let i=await kj(e,n);return{path:n,skipped:i,async remove(){await tr(e,["worktree","remove","--force",n]),await tr(e,["worktree","prune"])}}}import{detectCapabilities as wj,getTerminalColorMode as Cj,parseColor as Wr,styleText as rw}from"@netrodev/hxf-tui";function Rj(){let e=process.env.NO_COLOR;if(e!==void 0&&e!=="")return"256color";try{return Cj(wj())}catch{return"256color"}}var nw=Rj();function Pj(){let e=process.env.NO_COLOR;return e!==void 0&&e!==""}var Ve={text:Wr("#e6e6e6"),mute:Wr("#8b8b8b"),dim:Wr("#5c5c5c"),user:Wr("#d0d0d0"),accent:Wr("#c4b5fd"),tool:Wr("#6ee7b7"),bad:Wr("#f0a8a4"),warn:Wr("#e6b15a"),line:Wr("#3a3a3a")};function Aj(e,t){if(Pj()){let{bold:r,dim:n,italic:o,underline:i,strikethrough:a}=t;return!r&&!n&&!o&&!i&&!a?e:rw(e,{bold:r,dim:n,italic:o,underline:i,strikethrough:a},nw)}return rw(e,t,nw)}function ht(e,t,r){return Aj(e,{...r,fg:t})}var k1e={heading:e=>ht(e,Ve.text,{bold:!0}),link:e=>ht(e,Ve.accent,{underline:!0}),linkUrl:e=>ht(e,Ve.mute),code:e=>ht(e,Ve.text),codeBlock:e=>ht(e,Ve.text),codeBlockBorder:e=>ht(e,Ve.line),quote:e=>ht(e,Ve.mute,{italic:!0}),quoteBorder:e=>ht(e,Ve.line),hr:e=>ht(e,Ve.line),listBullet:e=>ht(e,Ve.mute),bold:e=>ht(e,Ve.text,{bold:!0}),italic:e=>ht(e,Ve.text,{italic:!0}),strikethrough:e=>ht(e,Ve.mute,{strikethrough:!0}),underline:e=>ht(e,Ve.text,{underline:!0})};import{truncateToWidth as Gi,visibleWidth as fr}from"@netrodev/hxf-tui";var ow={text:Ve.text,muted:Ve.mute,dim:Ve.dim,accent:Ve.accent,success:Ve.tool,error:Ve.bad,border:Ve.line},ce=(e,t,r=!1)=>r?ht(t,ow[e],{bold:!0}):ht(t,ow[e]),Oj=25,Mj=15e5,sw=420;function Fo(e){let t=Math.max(0,Math.round(e/1e3)),r=Math.floor(t/3600),n=Math.floor(t%3600/60),o=t%60;return r>0?`${r}h${String(n).padStart(2,"0")}m`:n>0?`${n}m${String(o).padStart(2,"0")}s`:`${o}s`}function R1e(e){let t=Math.max(0,Math.floor(e/1e3));return t<60?`${t}s`:t<3600?`${Math.floor(t/60)}m`:`${Math.floor(t/3600)}h`}function Xp(e){return e>=1e6?`${(e/1e6).toFixed(1)}M`:e>=1e3?`${(e/1e3).toFixed(1)}k`:String(e)}var Bi=(e,t,r)=>Math.max(t,Math.min(r,e)),vo=(e,t)=>fr(e)>t?Gi(e,Math.max(0,t),"\u2026"):e;function Dm(e,t,r="left"){if(t<=0)return"";let n=fr(e);if(n>t)return Gi(e,t);let o=" ".repeat(t-n);return r==="right"?o+e:e+o}function Zp(e,t,r,n=1){if(r<=0)return"";let o=fr(t);if(o>=r)return Gi(t,r);let i=r-o-n;if(i<=0)return Dm(t,r,"right");let a=fr(e)>i?Gi(e,i):e,m=" ".repeat(r-fr(a)-o);return a+m+t}function Yp(e,t,r){let n=vo(e,Math.max(0,r-2)),o=Math.max(1,r-1-fr(n)),i=ce("border","\u250C\u2500 ")+ce("accent",n)+ce("border",` ${"\u2500".repeat(o)}\u2510`),a=ce("border",`\u2514${"\u2500".repeat(r+2)}\u2518`),m=ce("border","\u2502"),c=t.map(p=>`${m} ${Dm(p,r)} ${m}`);return[i,...c,a]}function vj(e,t,r,n){let o=n?.gap??1,i=n?.leftWidth??Bi(Math.round(r*.38),28,44),a=r-i-o,m=Math.max(e.rows.length,t.rows.length),c=g=>{let y=[...g];for(;y.length<m;)y.push("");return y},p=Yp(e.title,c(e.rows),i-4),f=Yp(t.title,c(t.rows),a-4),d=" ".repeat(o);return p.map((g,y)=>g+d+(f[y]??Dm("",a)))}function aw(e,t,r){switch(e){case"running":return ce(t||r?"accent":"muted","\u25CF");case"failed":return ce("error","\u2717");default:return ce("success","\u2713")}}function mw(e,t,r,n=Date.now(),o=0){return t?n-o<sw?ce("success","\u2713",!0):ce("success","\u2713"):ce(r?"accent":"dim",String(e))}var iw="Workflow";function ef(e,t=Date.now()){let r=e.phases.map(o=>o.title),n=new Map(e.phases.map(o=>[o.title,o.detail]));for(let o of e.steps){let i=o.phase||iw;r.includes(i)||r.push(i)}return r.map((o,i)=>{let a=e.steps.filter(I=>(I.phase||iw)===o).map(I=>({...I,phaseIndex:i})),m=a.filter(I=>I.status!=="running").length,c=a.filter(I=>I.status==="failed").length,p=a.reduce((I,h)=>{let b=h.endedAt??t;return Math.max(I,b-h.startedAt)},0),f=-1;for(let I=0;I<a.length;I++){let h=a[I];h.status==="running"&&(f<0||h.startedAt>=a[f].startedAt)&&(f=I)}let d=n.get(o),g=a.length>0&&m===a.length&&c===0,y=g?a.reduce((I,h)=>Math.max(I,h.endedAt??0),0):0;return{title:o,...d?{detail:d}:{},agents:a,done:m,failed:c,outputTokens:a.reduce((I,h)=>I+h.outputTokens,0),elapsedMs:p,allDone:g,finishedAt:y,anchor:f}})}function tf(e){return e.steps.reduce((t,r)=>t+r.outputTokens,0)}function Fj(e){return e.steps.reduce((t,r)=>t+(r.toolCalls??0),0)}function uw(e,t=Date.now()){return Math.max(0,(e.endedAt??t)-e.startedAt)}function Lj(e){return e.steps.length>Oj||tf(e)>Mj}function Dj(e){if(e.length===0)return 0;let t=e.map((r,n)=>({group:r,index:n})).filter(r=>r.group.anchor>=0);if(t.length>0)return t.reduce((r,n)=>{let o=n.group.agents[n.group.anchor],i=r.group.agents[r.group.anchor];return o.startedAt>=i.startedAt?n:r}).index;for(let r=e.length-1;r>=0;r--)if(e[r].agents.length>0)return r;return e.length-1}function cw(e,t=Date.now()){let r=ef(e,t),n=e.steps.length,o=e.steps.filter(p=>p.status!=="running").length,i=e.steps.filter(p=>p.status==="failed").length,a=[e.name],m=r.find(p=>p.anchor>=0);m?a.push(`${m.title} ${m.done}/${m.agents.length}`):r.length>0&&a.push(`${r[r.length-1].title} done`),a.push(`${o}/${n} agents`),a.push(`${Xp(tf(e))} tok`),a.push(Fo(uw(e,t))),i>0&&a.push(`${i} failed`);let c=a.join(" \xB7 ");return Lj(e)?`large workflow \xB7 ${c}`:c}var pw=16,jj=12,Nj=18,qj=72,_j=24;function fw(e,t){if(e.status==="running"&&e.outputTokens===0)return[`idle ${Fo(t-e.startedAt)}`,"idle"];let r=Xp(e.outputTokens),n=e.toolCalls??0,o=Fo((e.endedAt??t)-e.startedAt);return[`${r} tok \xB7 ${n} tools \xB7 ${o}`,`${r} tok \xB7 ${n} tools`,`${r} tok`]}var Uj=e=>e.status==="running"&&e.outputTokens===0;function Qp(e,t,r){if(e.length<=r)return{slice:e,start:0,more:0};let n=Math.max(1,r-1),o=Bi(t-Math.floor(n/2),0,e.length-n),i=e.slice(o,o+n);return{slice:i,start:o,more:e.length-i.length}}function Bj(e,t,r,n,o){let i=`${e.done}/${e.agents.length}`,a=r?ce("accent","\u276F"):" ",m=mw(t+1,e.allDone,r,o,e.finishedAt),c=Math.max(0,n-4-fr(i)),p=fr(e.title)>c?Gi(e.title,c,"\u2026"):e.title,f=e.allDone&&o-e.finishedAt<sw,d=ce(f&&!r?"success":r?"accent":"text",p),g=`${a}${m} ${d}`,y=ce(r?"accent":"muted",i);return Zp(g,y,n,1)}function Gj(e,t,r,n,o,i){let a=t?ce("accent","\u276F"):" ",m=aw(e.status,t,r),c=ce(t?"accent":"text",Dm(e.label,n)),p=`${a}${m} ${c}`,f=Math.max(0,o-fr(p)-1),d=fw(e,i).find(y=>fr(y)<=f)??"",g=ce(t?"accent":Uj(e)?"dim":"muted",d);return Zp(p,g,o,1)}function Kj(e,t,r,n){let o=[];return e.forEach((i,a)=>{let c=`${mw(a+1,i.allDone,a===r,n,i.finishedAt)} ${ce(a===r?"accent":"text",i.title)} ${ce("muted",`${i.done}/${i.agents.length}`)}`;o.push(vo(c,t));let{slice:p,more:f}=Qp(i.agents,0,pw);p.forEach((d,g)=>{let y=aw(d.status,!1,g===i.anchor),I=fw(d,n)[0]??"";o.push(vo(` ${y} ${ce("text",d.label)} ${ce("muted",I)}`,t))}),f>0&&o.push(vo(` ${ce("dim",`\u2026+${f} more`)}`,t))}),o}function Hj(e,t,r){let n=r?.now??Date.now(),o=ef(e,n),i=e.steps,a=i.filter(F=>F.status!=="running").length,m=i.filter(F=>F.status==="failed").length,c=[`${a}/${i.length} agents`,`${Xp(tf(e))} tok`,`${Fj(e)} tools`,Fo(uw(e,n)),...m>0?[`${m} failed`]:[]].join(" \xB7 "),p=[Zp(ce("accent",e.name,!0),ce("muted",c),t,2),...e.description?[ce("muted",vo(e.description,t))]:[]],f=r?.footer?[ce("muted",vo(r.footerText??zj(),t))]:[];if(o.length===0)return[...p,...Yp("Phases",["(no agents yet)"],Math.max(0,t-4)),...f];let d=Bi(r?.selectedPhase??Dj(o),0,Math.max(0,o.length-1)),g=Bi(Math.round(t*.38),28,44),y=t-g-1-4;if(t<qj||y<_j)return[...p,...Kj(o,t,d,n),...f];let I=o[d],{slice:h,start:b,more:k}=Qp(o,d,jj),j=h.map((F,R)=>Bj(F,b+R,b+R===d,g-4,n));k>0&&j.push(ce("dim",`\u2026+${k} more`));let P=r?.filter?r.filter(I.agents):I.agents,Je=P.length?Bi(Math.max(...P.map(F=>fr(F.label))),6,Nj):6,{slice:Ce,more:ae}=Qp(P,0,r?.agentWindow??pw),Q=Ce.map((F,R)=>Gj(F,!1,R===I.anchor,Je,y,n));ae>0&&Q.push(ce("dim",`\u2026+${ae} more`));let E=vj({title:"Phases",rows:j},{title:`${I.title} \xB7 ${P.length} agents${r?.filterLabel??""}`,rows:Q},t,{leftWidth:g,gap:1});return[...p,...E,...f]}function P1e(e,t=[],r=96,n,o){let i=Hj(e,r,{now:e.endedAt??Date.now(),footer:!0,...n===void 0?{}:{selectedPhase:n},...o?.filter?{filter:o.filter}:{},...o?.footerText?{footerText:o.footerText}:{},...o?.filterLabel?{filterLabel:o.filterLabel}:{}}),a=new Set(t);if(o?.drill){let c=ef(e,e.endedAt??Date.now()),p=c[Math.max(0,Math.min(c.length-1,n??0))];for(let f of p?.agents??[])a.add(f.label)}if(a.size===0)return i;let m=[];for(let c of e.steps)if(a.has(c.label)){for(let p of c.tasks??[]){let f=p.status==="completed"?"[x]":p.status==="in_progress"?"[>]":"[ ]";m.push(` ${ce("muted",f)} ${ce("text",p.content)}`)}c.detail&&m.push(` ${ce("dim",c.detail)}`)}return m.length===0?i:[...i.slice(0,-1),...m,i[i.length-1]]}function zj(){return"\u2191/\u2193 phase \xB7 Enter drill in \xB7 Esc back out \xB7 f filter by status \xB7 p pause \xB7 x stop \xB7 s save script"}import{readFileSync as eN}from"node:fs";import{basename as tN}from"node:path";import{StringEnum as rN}from"@netrodev/hxf-ai";import{defineTool as nN}from"@netrodev/hxf-coding-agent";var _n=e=>typeof e=="object"&&e!==null&&!Array.isArray(e);function dw(e){return e===null?"null":Array.isArray(e)?"array":Number.isInteger(e)?"integer":typeof e}function Wj(e,t){let r=dw(e);return t==="number"?r==="number"||r==="integer":t==="integer"?r==="integer":r===t}function Vj(e,t){if(typeof t!="string"||!t.startsWith("#/"))return;let r=e;for(let n of t.slice(2).split("/")){let o=n.replace(/~1/g,"/").replace(/~0/g,"~");if(!_n(r)&&!Array.isArray(r))return;r=r[o]}return _n(r)?r:void 0}function hn(e,t,r,n,o){if(!_n(t))return;if(t.$ref!==void 0){let a=Vj(r,t.$ref);a&&hn(e,a,r,n,o);return}if(Array.isArray(t.allOf))for(let a of t.allOf)hn(e,a,r,n,o);for(let a of["anyOf","oneOf"]){let m=t[a];if(!Array.isArray(m)||m.length===0)continue;let c=m.filter(p=>{let f=[];return hn(e,p,r,n,f),f.length===0}).length;a==="anyOf"&&c===0&&o.push({path:n,message:"does not match any allowed shape"}),a==="oneOf"&&c!==1&&o.push({path:n,message:`must match exactly one shape (matched ${c})`})}let i=t.type;if(i!==void 0){let a=Array.isArray(i)?i.map(String):[String(i)];if(!a.some(m=>Wj(e,m))){o.push({path:n,message:`expected ${a.join(" or ")}, got ${dw(e)}`});return}}if(Array.isArray(t.enum)&&!t.enum.some(a=>JSON.stringify(a)===JSON.stringify(e))&&o.push({path:n,message:`must be one of ${t.enum.map(a=>JSON.stringify(a)).join(", ")}`}),_n(e)){let a=_n(t.properties)?t.properties:{};if(Array.isArray(t.required))for(let m of t.required.map(String))m in e||o.push({path:n?`${n}.${m}`:m,message:"is required"});for(let[m,c]of Object.entries(a))m in e&&hn(e[m],c,r,n?`${n}.${m}`:m,o);if(t.additionalProperties===!1)for(let m of Object.keys(e))m in a||o.push({path:n?`${n}.${m}`:m,message:"is not an allowed property"});else if(_n(t.additionalProperties))for(let[m,c]of Object.entries(e))m in a||hn(c,t.additionalProperties,r,n?`${n}.${m}`:m,o)}if(Array.isArray(e)&&t.items!==void 0){let a=t.items;Array.isArray(a)?e.forEach((m,c)=>{c<a.length&&hn(m,a[c],r,`${n}[${c}]`,o)}):e.forEach((m,c)=>hn(m,a,r,`${n}[${c}]`,o))}if(typeof e=="string"&&(typeof t.minLength=="number"&&e.length<t.minLength&&o.push({path:n,message:`is shorter than ${t.minLength} characters`}),typeof t.pattern=="string"))try{new RegExp(t.pattern).test(e)||o.push({path:n,message:`does not match ${t.pattern}`})}catch{}typeof e=="number"&&(typeof t.minimum=="number"&&e<t.minimum&&o.push({path:n,message:`is below ${t.minimum}`}),typeof t.maximum=="number"&&e>t.maximum&&o.push({path:n,message:`is above ${t.maximum}`}))}function lw(e,t){if(!_n(t))return[];let r=[];return hn(e,t,t,"",r),r}function gw(e){return e.map(t=>`- ${t.path||"(root)"}: ${t.message}`).join(`
168
- `)}function yw(e){let t=e.trim(),r=/```(?:json)?\s*([\s\S]*?)```/.exec(t),n=[t,r?.[1]?.trim()].filter(o=>!!o);for(let o of n){try{return JSON.parse(o)}catch{}for(let i=0;i<o.length;i++){let a=o[i];if(a!=="{"&&a!=="[")continue;let m=a==="{"?"}":"]",c=0,p=!1,f=!1;for(let d=i;d<o.length;d++){let g=o[d];if(p){f?f=!1:g==="\\"?f=!0:g==='"'&&(p=!1);continue}if(g==='"')p=!0;else if(g===a)c++;else if(g===m&&(c--,c===0))try{return JSON.parse(o.slice(i,d+1))}catch{break}}}}}var Jj=1e3,Yj=4096,xw=100,hw=300*1e3;async function Qj(e,t=xw,r=hw){let n=Date.now()+r;for(;e.isPaused?.();){if(e.signal?.aborted||Date.now()>=n)return!1;await new Promise(o=>setTimeout(o,t))}return!0}var nt=class extends Error{constructor(t){super(t),this.name="WorkflowError"}};function Xj(e){let t=0,r=[];return async function(){t>=e&&await new Promise(i=>r.push(i)),t++;let o=!1;return()=>{o||(o=!0,t--,r.shift()?.())}}}function Iw(e){let t=e.lifetimeCap??Jj,r=e.fanoutCap??Yj,n=e.concurrency?Xj(e.concurrency):null,o=async()=>{let k=await Om();if(!n)return k;let j=await n();return()=>{j(),k()}},i=0,a=0,m=0,c="",p=k=>e.onEvent?.(k),f=new Map,d=()=>e.onProgress?.([...f.values()]),g=async(k,j)=>{let P=j??{},Je=typeof P.label=="string"?P.label:`agent-${i+1}`,Ce=typeof P.phase=="string"?P.phase:c,ae=typeof P.agentType=="string"?P.agentType:"task",Q=typeof P.effort=="string"?P.effort:void 0,E=typeof P.model=="string"?P.model:void 0,F=typeof P.isolation=="string"?P.isolation:void 0,R=P.schema;if(e.budgetTotal!=null&&a+m>=e.budgetTotal)throw new nt(`budget exhausted: spent ${a+m} of ${e.budgetTotal} output tokens`);if(i>=t)throw new nt(`lifetime cap reached: ${t} agent calls in one run`);i++;let A=i;if(e.isPaused?.()&&!await Qj(e,xw,hw))return null;let H=e.budgetTotal==null?0:Math.max(0,e.budgetTotal-a-m);m+=H;let le=await o();try{if(e.signal?.aborted)return null;p({kind:"agent_start",label:Je,phase:Ce,ordinal:i}),f.set(A,{label:Je,phase:Ce,agentType:ae,status:"running",outputTokens:0,...E?{model:E}:{},startedAt:Date.now()}),d();let pe=(Jt,he,ot)=>{let qt=f.get(A);qt&&(qt.status=Jt,qt.outputTokens=he.outputTokens,qt.endedAt=Date.now(),he.toolCalls!==void 0&&(qt.toolCalls=he.toolCalls),he.model!==void 0&&(qt.model=he.model),ot&&(qt.detail=ot)),p({kind:"agent_end",label:Je,ok:Jt==="ok",outputTokens:he.outputTokens}),d()},ft=R===void 0?1:2;for(let Jt=0;Jt<ft;Jt++){let he=Jt===0?String(k):void 0,ot=await I(he??Zj(String(k),y),{label:Je,phase:Ce,agentType:ae,effort:Q,model:E,isolation:F});if(ot===null)return pe("failed",{text:"",outputTokens:0}),null;if(a+=ot.outputTokens,R===void 0)return pe("ok",ot,rf(ot.text)),ot.text;let qt=yw(ot.text),cf=qt===void 0?[{path:"",message:"reply was not JSON"}]:lw(qt,R);if(cf.length===0)return pe("ok",ot,rf(ot.text)),qt;if(y=gw(cf),Jt===ft-1)return pe("failed",ot,`schema: ${rf(y)}`),null}return null}finally{m=Math.max(0,m-H),le()}},y="",I=async(k,j)=>{try{return await e.invoke({prompt:k,...j})}catch{return null}};return{agent:(k,j)=>g(k,j),parallel:async k=>{if(k.length>r)throw new nt(`fan-out cap exceeded: ${k.length} items (max ${r})`);return await Promise.all(k.map(async P=>{try{return await P()}catch{return null}}))},pipeline:async(k,...j)=>{if(k.length>r)throw new nt(`fan-out cap exceeded: ${k.length} items (max ${r})`);return await Promise.all(k.map(async(Je,Ce)=>{let ae=Je;for(let Q of j)try{ae=await Q(ae,Je,Ce)}catch{return null}return ae}))},phase:k=>{c=String(k),p({kind:"phase",title:c})},log:k=>p({kind:"log",message:String(k)}),args:e.args,budget:{total:e.budgetTotal??null,spent:()=>a+m,remaining:()=>e.budgetTotal==null?1/0:Math.max(0,e.budgetTotal-a-m)}}}function Zj(e,t){return`${e}
169
-
170
- Your previous reply did not satisfy the required schema:
171
- ${t}
172
-
173
- Reply with ONLY a corrected JSON value.`}function rf(e,t=80){let r=e.split(`
174
- `).map(n=>n.trim()).find(n=>n.length>0)??"";return r.length>t?`${r.slice(0,t)}\u2026`:r}var nf="workflow",bw=null;function H1e(e){bw=e}var oN=600*1e3;function iN(e){let t=e.replace(/^(?:\s+|\/\/[^\n]*\n|\/\*[\s\S]*?\*\/)*/,""),r=/^export\s+const\s+meta\s*=\s*/.exec(t);if(!r)throw new nt("a workflow script must start with `export const meta = { name, description }`");let n=e.length-t.length,o=r[0].length,i=0,a=null,m=-1;for(let y=o;y<t.length;y++){let I=t[y];if(a){I==="\\"?y++:I===a&&(a=null);continue}if(I==='"'||I==="'"||I==="`")a=I;else if(I==="{"||I==="[")i++;else if((I==="}"||I==="]")&&(i--,i===0)){m=y+1;break}}if(m===-1)throw new nt("meta is not a closed literal object");let c=t.slice(o,m),p=e.slice(n+m).replace(/^\s*;/,"");if(/^\s*(import|export)\b/m.test(p))throw new nt("a workflow body must not contain import or export declarations");if(/\bimport\s*\(/.test(p))throw new nt("a workflow body must not use dynamic import()");let f;try{f=new Function(`"use strict"; return (${c});`)()}catch(y){throw new nt(`meta must be a literal object: ${y instanceof Error?y.message:String(y)}`)}if(typeof f!="object"||f===null)throw new nt("meta must be an object");let d=f;if(typeof d.name!="string"||!d.name.trim())throw new nt("meta.name is required");if(typeof d.description!="string"||!d.description.trim())throw new nt("meta.description is required");let g=Array.isArray(d.phases)?d.phases.filter(y=>typeof y=="object"&&y!==null).map(y=>({title:String(y.title??""),...typeof y.detail=="string"?{detail:y.detail}:{}})).filter(y=>y.title):void 0;return{meta:{name:d.name,description:d.description,...typeof d.whenToUse=="string"?{whenToUse:d.whenToUse}:{},...g?{phases:g}:{}},body:p}}function sN(e){let t=["agent","parallel","pipeline","phase","log","args","budget"],r=`"use strict"; return (async () => {
175
- ${e}
176
- })();`,n;try{n=new Function(...t,r)}catch(o){throw new nt(`workflow did not compile: ${o instanceof Error?o.message:String(o)}`)}return n}function aN(e){return jo(e.getLastAssistantText()??"")}function mN(e){return async({prompt:t,agentType:r,effort:n,model:o,isolation:i})=>{let a=xn.get(r)??xn.get("task");if(!a)throw new nt(`no agent named ${r}`);let m=i==="worktree"?await tw(process.cwd(),r):null,c=await Fm({agent:a.name,effort:n??a.effort,...o?{model:o}:{},...e?{parentModel:e}:{},...m?{worktree:m.path}:{}});try{await c.prompt(`${a.prompt}
177
-
178
- Task:
179
- ${t}`);let p=c.getSessionStats(),f=uN(c)??o;return{text:aN(c),outputTokens:p.tokens.output,toolCalls:p.toolCalls,...f?{model:f}:{}}}finally{c.dispose(),await m?.remove()}}}function uN(e){return e.model?.id??e.model?.name}var cN=D.Object({code:D.Optional(D.String({description:"The workflow script source"})),path:D.Optional(D.String({description:"Path to a workflow script, instead of code"})),agent:D.Optional(rN(["scout","task","reviewer"],{description:"Default agent profile for calls"})),budget:D.Optional(D.Number({description:"Output-token ceiling for the whole run"}))});function z1e(e){let t=()=>e??bw;return nN({name:"workflow",label:"workflow",description:"Run a JavaScript workflow that orchestrates many agents deterministically. Provide `code` (or `path`). The script starts with `export const meta = { name, description, phases }` and then uses the injected bindings: `agent(prompt, {label, phase, schema, effort, model, agentType, isolation})`, `parallel(thunks)`, `pipeline(items, ...stages)`, `phase(title)`, `log(msg)`, `args`, `budget`. `agent()` resolves null on failure and throws only when the budget or the call cap is exhausted, so null-check every result. `parallel()` takes thunks and never rejects; `pipeline()` has no barrier between items. Use it for fan-out, for builder-verifier loops that converge on a verdict, and for anything needing many agents whose order and count must be deterministic.",promptSnippet:"workflow: orchestrate many agents from one JavaScript script",parameters:cN,executionMode:"sequential",async execute(r,n,o,i,a){let m=n.path?eN(n.path,"utf8"):n.code??"";if(!m.trim())throw new nt("provide code or path");let{meta:c,body:p}=iN(m);if(n.path){let ae=tN(n.path).replace(/\.(js|mjs|cjs|ts)$/,"");if(ae!==c.name)throw new nt(`meta.name "${c.name}" must match the script filename "${ae}"`)}let f=sN(p),d=Date.now(),g=[],y=0,I=0,h=(ae,Q)=>({name:c.name,...c.description?{description:c.description}:{},ok:ae,agents:I,outputTokens:y,startedAt:d,phases:c.phases??[],steps:g,...Q?{error:Q}:{}}),b=(ae,Q)=>{a.ui.setStatus(nf,Q?void 0:cw(ae)),i?.({content:[],details:h(!1)})},k=ae=>{I=ae.length,y=ae.reduce((Q,E)=>Q+E.outputTokens,0),g.splice(0,g.length,...ae.map(Q=>({label:Q.label,phase:Q.phase,agent:Q.agentType,status:Q.status,outputTokens:Q.outputTokens,startedAt:Q.startedAt,...Q.toolCalls!==void 0?{toolCalls:Q.toolCalls}:{},...Q.model?{model:Q.model}:{},...Q.endedAt?{endedAt:Q.endedAt}:{},...Q.detail?{detail:Q.detail}:{},...Q.tasks?{tasks:Q.tasks}:{}}))),b({name:c.name,...c.description?{description:c.description}:{},phases:c.phases??[],steps:g,startedAt:d},!1)},j=mN(JT(a?.model)),P=Iw({invoke:n.agent?pN(j,n.agent):j,budgetTotal:n.budget??null,onProgress:k,...o?{signal:o}:{},...t()?.isPaused?{isPaused:t().isPaused}:{}}),Je=new AbortController,Ce=setTimeout(()=>Je.abort(),oN);o&&o.addEventListener("abort",()=>Je.abort(),{once:!0}),t()?.onStop?.(()=>Je.abort());try{let ae=await Promise.race([f(P.agent,P.parallel,P.pipeline,P.phase,P.log,P.args,P.budget),new Promise((E,F)=>Je.signal.addEventListener("abort",()=>F(new nt("workflow timed out or was aborted"))))]),Q=Date.now();return a.ui.setStatus(nf,void 0),{content:[{type:"text",text:`${c.name}: ${I} agent call(s), ${y} output tokens in ${Fo(Q-d)}
180
-
181
- ${fN(ae)}`}],details:{...h(!0),endedAt:Q}}}catch(ae){let Q=ae instanceof Error?ae.message:String(ae);return a.ui.setStatus(nf,void 0),{content:[{type:"text",text:`${c.name} failed after ${I} agent call(s): ${Q}`}],details:{...h(!1,Q),endedAt:Date.now()},isError:!0}}finally{clearTimeout(Ce),t()?.onStop?.(null)}}})}function pN(e,t){return r=>e({...r,agentType:t})}function fN(e){if(typeof e=="string")return e;try{return JSON.stringify(e,null,2)}catch{return String(e)}}import{createServer as dN}from"node:http";import{WebSocketServer as lN}from"ws";import{randomBytes as gN,timingSafeEqual as yN}from"node:crypto";var xN=9224,hN=3e4,IN=3e4;async function $w(e){let t=e.port??xN,r=e.token??gN(16).toString("hex"),n=e.log??(()=>{}),o=Date.now(),i=null,a=!1,m="",c="",p=[],f=1,d=new Map,g=E=>{let{promise:F,resolve:R,reject:A}=Promise.withResolvers();if(!i||i.readyState!==i.OPEN)return A(new Error("Browser relay extension is not connected. Run /browser-relay install and check the toolbar badge.")),F;let H=f++,le=setTimeout(()=>{d.delete(H),A(new Error(`Browser relay RPC timed out: ${E.op}`))},hN);return d.set(H,{resolve:R,reject:A,timer:le}),i.send(JSON.stringify({t:"rpc",id:H,...E})),F},y=(E,F)=>{let R;try{R=JSON.parse(F)}catch{return}switch(R.t){case"hello":a=!0,m=R.browserVersion,c=R.userAgent,p=R.tabs,n(`extension connected: ${R.tabs.length} tabs`);break;case"tabCreated":p=[...p.filter(A=>A.tabId!==R.tab.tabId),R.tab];break;case"tabUpdated":p=p.map(A=>A.tabId===R.tab.tabId?R.tab:A);break;case"tabRemoved":p=p.filter(A=>A.tabId!==R.tabId);break;case"rpcResult":{let A=d.get(R.id);if(!A)return;d.delete(R.id),clearTimeout(A.timer),R.ok?A.resolve(R.result):A.reject(new Error(R.error||`Browser relay RPC failed: ${R.id}`));break}case"cdpEvent":{for(let A of I.values()){let H=!1;for(let[le,pe]of A.sessions)pe===R.tabId&&(b(A,{method:R.method,params:R.params,sessionId:le}),H=!0);!H&&A.tabId===R.tabId&&b(A,{method:R.method,params:R.params})}break}case"detached":{for(let A of I.values()){let H=!1;for(let[le,pe]of A.sessions)pe===R.tabId&&(A.sessions.delete(le),b(A,{method:"Target.detachedFromTarget",params:{targetId:`tab:${R.tabId}`,sessionId:le,reason:R.reason}}),H=!0);!H&&A.tabId===R.tabId&&b(A,{method:"Target.detachedFromTarget",params:{targetId:`tab:${R.tabId}`,reason:R.reason}})}break}case"ping":E.send(JSON.stringify({t:"pong"}));break;default:break}},I=new Map,h=1,b=(E,F)=>{E.ws.readyState===E.ws.OPEN&&E.ws.send(JSON.stringify(F))},k=E=>{let F=typeof E=="string"?E:"",R=F.startsWith("tab:")?F.slice(4):F,A=Number(R);return Number.isInteger(A)&&A>0?A:void 0},j=E=>({targetId:`tab:${E.tabId}`,type:"page",title:E.title,url:E.url,attached:!1,canAccessOpener:!1}),P=async(E,F,R)=>{await g({op:"attach",tabId:F});let H=[...E.sessions.entries()].find(([,le])=>le===F)?.[0]??`cdp-${E.nextSession++}`;if(E.sessions.set(H,F),R){let le=p.find(pe=>pe.tabId===F);le&&b(E,{method:"Target.attachedToTarget",params:{sessionId:H,targetInfo:j(le),waitingForDebugger:!1}})}return H},Je=(E,F)=>{let R;try{R=JSON.parse(F)}catch{return}if(typeof R.id!="number"||typeof R.method!="string")return;let A=R.id,H=R.method,le=R.params??{};(async()=>{try{if(H==="Browser.getVersion"){b(E,{id:A,result:{protocolVersion:"1.3",product:m||"HowToCode Browser Relay",revision:"",userAgent:c||"HowToCode",jsVersion:""}});return}if(H==="Target.getTargets"){b(E,{id:A,result:{targetInfos:p.map(j)}});return}if(H==="Target.getBrowserContexts"){b(E,{id:A,result:{browserContextIds:[]}});return}if(H==="Target.setDiscoverTargets"){b(E,{id:A,result:{}});for(let he of p)b(E,{method:"Target.targetCreated",params:{targetInfo:j(he)}});return}if(H==="Target.setAutoAttach"){E.autoAttach={flatten:le.flatten===!0},b(E,{id:A,result:{}});for(let he of p)await P(E,he.tabId,!0);return}if(H==="Target.getTargetInfo"){let he=k(le.targetId),ot=he===void 0?void 0:p.find(qt=>qt.tabId===he);if(!ot)throw new Error("Target.getTargetInfo needs a known targetId");b(E,{id:A,result:{targetInfo:j(ot)}});return}if(H==="Target.createTarget"){let he=await g({op:"createTab",url:String(le.url??"about:blank"),active:!1});if(!he?.tab)throw new Error("Chrome created no tab");b(E,{id:A,result:{targetId:`tab:${he.tab.tabId}`}}),b(E,{method:"Target.targetCreated",params:{targetInfo:j(he.tab)}}),E.autoAttach&&await P(E,he.tab.tabId,!0);return}if(H==="Target.disposeBrowserContext"){b(E,{id:A,result:{}});return}if(H==="Target.attachToTarget"){let he=k(le.targetId);if(he===void 0)throw new Error("Target.attachToTarget needs a tab targetId");let ot=await P(E,he,!1);b(E,{id:A,result:{sessionId:ot}});return}if(H==="Target.detachFromTarget"){let he=typeof le.sessionId=="string"?le.sessionId:"";E.sessions.delete(he),b(E,{id:A,result:{}});return}if(H==="Target.sendMessageToTarget"){if(typeof le.message!="string")throw new Error("Target.sendMessageToTarget needs a message");Je(E,le.message),b(E,{id:A,result:{}});return}let pe=typeof R.sessionId=="string"?R.sessionId:void 0,ft=pe?E.sessions.get(pe):E.tabId;if(ft===void 0)throw new Error("CDP command has no attached tab session");if(H==="Target.activateTarget"){await g({op:"activateTab",tabId:ft}),b(E,{id:A,result:{}});return}if(H==="Target.closeTarget"){await g({op:"removeTab",tabId:ft}),b(E,{id:A,result:{success:!0}});return}await g({op:"attach",tabId:ft});let Jt=await g({op:"send",tabId:ft,method:H,params:le});b(E,{id:A,result:Jt??{}})}catch(pe){b(E,{id:A,error:{code:-32e3,message:pe instanceof Error?pe.message:String(pe)}})}})()},Ce=dN((E,F)=>{let A=new URL(E.url??"/",`http://127.0.0.1:${t}`).pathname.replace(/\/+$/,"")||"/";if(E.headers.host!==`127.0.0.1:${t}`){F.writeHead(403).end("Forbidden");return}if(E.method!=="GET"){F.writeHead(405).end("Method not allowed");return}if(A==="/json/version"){let H=i!==null&&i.readyState===i.OPEN,le={Browser:m||"HowToCode Browser Relay","Protocol-Version":"1.3","User-Agent":c||"HowToCode",webSocketDebuggerUrl:`ws://127.0.0.1:${t}/cdp`,...H?{}:{error:"relay extension is not connected",extensionSeen:a,uptimeMs:Date.now()-o}};F.writeHead(H?200:503,{"content-type":"application/json"}).end(JSON.stringify(le));return}if(A==="/json"||A==="/json/list"){F.writeHead(200,{"content-type":"application/json"}).end(JSON.stringify(p.map(H=>({id:String(H.tabId),type:"page",title:H.title,url:H.url,webSocketDebuggerUrl:`ws://127.0.0.1:${t}/cdp?tab=${H.tabId}`}))));return}if(A==="/health"){F.writeHead(200,{"content-type":"application/json"}).end(JSON.stringify({ok:!0,ready:i!==null,tabs:p.length}));return}F.writeHead(404).end("Not found")}),ae=new lN({noServer:!0});Ce.on("upgrade",(E,F,R)=>{let A=new URL(E.url??"/",`http://127.0.0.1:${t}`),H=A.pathname.replace(/\/+$/,"")||"/";if(E.headers.host!==`127.0.0.1:${t}`){F.write(`HTTP/1.1 403 Forbidden\r
182
- \r
183
- `),F.destroy();return}let le=E.headers.origin;if(H==="/ext"){if(le&&!le.startsWith("chrome-extension://")){F.write(`HTTP/1.1 403 Forbidden\r
184
- \r
185
- `),F.destroy();return}let pe=Buffer.from(A.searchParams.get("token")??""),ft=Buffer.from(r);if(pe.length!==ft.length||!yN(pe,ft)){F.write(`HTTP/1.1 401 Unauthorized\r
186
- \r
187
- `),F.destroy();return}}else if(H==="/cdp"){if(le){F.write(`HTTP/1.1 403 Forbidden\r
188
- \r
189
- `),F.destroy();return}}else{F.write(`HTTP/1.1 404 Not Found\r
190
- \r
191
- `),F.destroy();return}ae.handleUpgrade(E,F,R,pe=>{if(H==="/ext")i?.close(),i=pe,pe.on("message",ft=>y(pe,ft.toString())),pe.on("close",()=>{i===pe&&(i=null)});else if(H==="/cdp"){let ft=Number(A.searchParams.get("tab")??""),Jt={ws:pe,tabId:Number.isInteger(ft)&&ft>0?ft:void 0,sessions:new Map,nextSession:1},he=h++;I.set(he,Jt),pe.on("message",ot=>Je(Jt,ot.toString())),pe.on("close",()=>I.delete(he))}})}),await new Promise((E,F)=>{Ce.once("error",F),Ce.listen(t,"127.0.0.1",()=>{Ce.off("error",F);let R=Ce.address();R&&typeof R=="object"&&(t=R.port),E()})});let Q=setInterval(()=>{for(let E of ae.clients)E.readyState===E.OPEN&&E.ping()},IN);return Q.unref?.(),n(`relay listening on 127.0.0.1:${t}`),{port:t,token:r,state:()=>({extensionConnected:i!==null&&i.readyState===i.OPEN,extensionSeen:a,browserVersion:m,userAgent:c,tabs:p,uptimeMs:Date.now()-o,port:t}),rpc:g,ready:()=>i!==null&&i.readyState===i.OPEN,stop:async()=>{clearInterval(Q);for(let E of d.values())clearTimeout(E.timer),E.reject(new Error("Browser relay stopped"));d.clear();for(let E of ae.clients)E.terminate();await new Promise(E=>ae.close(()=>E())),await new Promise(E=>Ce.close(()=>E()))}}}import{existsSync as Pw,readFileSync as Aw}from"node:fs";import{randomBytes as bN}from"node:crypto";import{existsSync as kw,mkdirSync as Tw,readFileSync as of,renameSync as $N,writeFileSync as EN}from"node:fs";import{dirname as Cw,join as Lo}from"node:path";import{fileURLToPath as SN}from"node:url";function Ew(e,t,r){let n=r?`void chrome.storage.local.get({ token: "" }).then((stored) => { if (!stored.token) return chrome.storage.local.set({ token: ${JSON.stringify(r)} }); });
192
- `:"";return`const OMP_INSTALL_VERSION = ${JSON.stringify(t)};
193
- ${n}${e}`}function Sw(e,t){let r=JSON.parse(e);return`${JSON.stringify({...r,name:"HowToCode Browser Relay",description:"Lets HowToCode CLI drive your existing tabs through a local CDP relay.",homepage_url:"https://howtofix.id",version_name:t,action:{default_title:"HowToCode Browser Relay (click for settings)"}},null," ")}
194
- `}function jm(e){return e.replaceAll("OMP Browser Relay","HowToCode Browser Relay").replaceAll("omp-browser-relay","howtocode-browser-relay").replaceAll("omp-relay-keepalive","howtocode-relay-keepalive")}var kN=Lo(Cw(SN(import.meta.url)),"assets");function Nm(e){let t=Lo(e,"browser-relay");return{extensionDir:Lo(t,"extension"),tokenPath:Lo(t,"token")}}function Ki(e){return of(Lo(kN,`${e}.txt`),"utf8")}function ww(e,t,r){let n=`${e}.${process.pid}.tmp`;EN(n,t,r===void 0?void 0:{mode:r}),$N(n,e)}function Rw(e,t){let{extensionDir:r,tokenPath:n}=Nm(e);Tw(r,{recursive:!0,mode:448});let o="";kw(n)?o=of(n,"utf8").trim():(o=bN(24).toString("hex"),Tw(Cw(n),{recursive:!0}),ww(n,`${o}
195
- `,384));let i={"manifest.json":Sw(Ki("manifest.json"),t),"options.html":jm(Ki("options.html")),"options.js":jm(Ki("options.js")),LICENSE:Ki("LICENSE"),"background.js":jm(Ew(Ki("background.js"),t,o))},a=[];for(let[m,c]of Object.entries(i)){let p=Lo(r,m);(kw(p)?of(p,"utf8"):null)!==c&&(ww(p,c,m==="background.js"?384:void 0),a.push(m))}return{extensionDir:r,tokenPath:n,token:o,wrote:a}}var zi=null,Hi=null;function Ow(){try{return JSON.parse(Aw(new URL("../../package.json",import.meta.url),"utf8")).version??"0.0.0"}catch{return"0.0.0"}}function uLe(){let e=Rw(it,Ow());return{token:e.token,extensionDir:e.extensionDir,tokenPath:e.tokenPath,wrote:e.wrote}}async function cLe(){if(zi)return zi;if(Hi)return Hi;Hi=(async()=>{let{tokenPath:e}=Nm(it);if(!Pw(e))throw new Error("Browser relay is not installed. Run /browser-relay install and load the extension in Chrome first.");let t=Aw(e,"utf8").trim();if(!t)throw new Error("Browser relay token file is empty. Run /browser-relay install again.");let r=process.env.HOWTOCODE_BROWSER_RELAY_PORT?.trim(),n=r&&/^\d+$/.test(r)?Number(r):void 0,o=await $w({token:t,port:n,productVersion:Ow()});return zi=o,o})();try{return await Hi}finally{Hi=null}}async function pLe(){let{extensionDir:e,tokenPath:t}=Nm(it);return{running:zi!==null,state:zi?.state()??null,tokenConfigured:Pw(t),extensionDir:e}}import{execFile as TN,execFileSync as Wi}from"node:child_process";import{promisify as wN}from"node:util";import{createHash as Lw}from"node:crypto";import{copyFileSync as CN,existsSync as qm,mkdirSync as _m,readFileSync as mf,readdirSync as RN,rmSync as PN,statSync as sf}from"node:fs";import{dirname as Dw,join as Nt,resolve as Um}from"node:path";var af=Nt(it,"rewind"),Vi="refs/howtocode",Mw="refs/howtofix",vw=100,jw=30,Nw="project.json",qw="checkpoints.json",Fw=!1;function AN(e){let t=Um(e);for(;;){if(qm(Nt(t,".git")))return!0;let r=Dw(t);if(r===t)return!1;t=r}}var ON=wN(TN);async function Vt(e,t){let r={...process.env};for(let o of["GIT_DIR","GIT_WORK_TREE","GIT_INDEX_FILE","GIT_OBJECT_DIRECTORY","GIT_ALTERNATE_OBJECT_DIRECTORIES","GIT_NAMESPACE","GIT_COMMON_DIR"])delete r[o];r.GIT_DIR=e.gitDir,r.GIT_WORK_TREE=e.root,r.GIT_AUTHOR_NAME=r.GIT_COMMITTER_NAME="howtocode",r.GIT_AUTHOR_EMAIL=r.GIT_COMMITTER_EMAIL="howtocode@local";let{stdout:n}=await ON("git",t,{cwd:e.root,env:r,encoding:"utf8",maxBuffer:8*1024*1024});return n.trim()}function MN(e){return Lw("sha1").update(e).digest("hex").slice(0,16)}function vN(e){let t={...process.env,GIT_DIR:e.gitDir,GIT_WORK_TREE:e.root};try{let r=Wi("git",["for-each-ref","--format=%(refname)",`${Mw}/`],{env:t,encoding:"utf8",stdio:["ignore","pipe","ignore"]}).trim();for(let n of r.split(`
196
- `).filter(Boolean)){let o=`${Vi}/${n.slice(Mw.length+1)}`;try{let i=Wi("git",["rev-parse",n],{env:t,encoding:"utf8",stdio:["ignore","pipe","ignore"]}).trim();Wi("git",["update-ref",o,i],{env:t,stdio:"ignore"}),Wi("git",["update-ref","-d",n],{env:t,stdio:"ignore"})}catch{}}}catch{}}function bLe(e){let t=Um(e).replace(/\/+$/,"")||"/",r=Nt(af,MN(t)),n=Nt(r,"git"),o={root:t,gitDir:n,metaFile:Nt(r,qw),disabled:!1};return!qm(Nt(n,"HEAD"))&&!AN(t)?(o.disabled=!0,o):(_m(r,{recursive:!0}),qm(Nt(n,"HEAD"))||(_m(n,{recursive:!0}),Wi("git",["init","--quiet","--initial-branch=howtocode"],{env:{...process.env,GIT_DIR:n},stdio:["ignore","ignore","pipe"]})),FN(t,n),vN(o),LN(r,t),Fw||(Fw=!0,jN({keep:r})),o)}function FN(e,t){let r=Nt(e,".git","info","exclude");try{if(!sf(r).isFile())return;_m(Nt(t,"info"),{recursive:!0}),CN(r,Nt(t,"info","exclude"))}catch{}}function LN(e,t){let r=Nt(e,Nw),n=`${JSON.stringify({version:1,root:t})}
197
- `;try{if(mf(r,"utf8")===n)return}catch{}try{dr(r,n)}catch{}}function Bm(e){try{let t=JSON.parse(mf(e.metaFile,"utf8"));if(t?.version===1&&t.sessions)return t}catch{}return{version:1,sessions:{}}}function uf(e,t){_m(Dw(e.metaFile),{recursive:!0}),dr(e.metaFile,`${JSON.stringify(t,null,1)}
198
- `)}function DN(e,t){return e.disabled?[]:[...Bm(e).sessions[t]??[]].sort((r,n)=>r.at-n.at)}async function $Le(e,t,r){if(e.disabled)return null;let n;try{await Vt(e,["add","-A","--ignore-errors","--"]),n=await Vt(e,["write-tree"])}catch{return null}let i=DN(e,t).find(g=>g.tree===n),a=Date.now(),m=`${a.toString(36)}-${Lw("sha1").update(`${n}:${a}`).digest("hex").slice(0,6)}`,c=i?.commit;if(!c){let g=["howtocode checkpoint",`session ${t}`,`created ${new Date(a).toISOString()}`,`prompt ${r.slice(0,200)}`].join(`
199
- `);c=await Vt(e,["commit-tree",n,"-m",g]),await Vt(e,["update-ref",`${Vi}/${m}`,c])}let p={id:m,tree:n,commit:c,prompt:r,at:a},f=Bm(e),d=[...f.sessions[t]??[],p];for(let g of d.slice(0,Math.max(0,d.length-vw)))try{await Vt(e,["update-ref","-d",`${Vi}/${g.id}`])}catch{}return f.sessions[t]=d.slice(-vw),uf(e,f),p}async function ELe(e,t){let r=[];if(e.disabled)return{ok:!1,output:"checkpoints are off: this directory is not a git repository",removed:r};try{await Vt(e,["read-tree","--reset","-u",t.tree])}catch(n){return{ok:!1,output:n instanceof Error?n.message:String(n),removed:r}}try{let n=await Vt(e,["clean","-fd"]);for(let o of n.split(`
200
- `)){let i=/^Removing\s+(.+)$/.exec(o.trim());i?.[1]&&r.push(i[1])}}catch{}return{ok:!0,output:`restored ${t.prompt||"the checkpoint"}`,removed:r}}async function SLe(e,t){if(e.disabled)return[];try{await Vt(e,["add","-A","--ignore-errors","--"]);let r=await Vt(e,["write-tree"]);return r===t.tree?[]:(await Vt(e,["diff-tree","-r","--name-status","--no-commit-id",t.tree,r])).split(`
201
- `).filter(Boolean).map(o=>{let[i,...a]=o.split(" ");return`${i?.[0]??"?"} ${a.at(-1)??""}`})}catch{return[]}}async function kLe(e,t={}){let r={droppedSessions:0,droppedRefs:0};if(e.disabled)return r;let n=(t.now??Date.now())-jw*24*60*60*1e3,o=Bm(e),i=!1;for(let[a,m]of Object.entries(o.sessions))if(!(a===t.keep||m.reduce((p,f)=>Math.max(p,f.at),0)>=n)){delete o.sessions[a],i=!0,r.droppedSessions+=1;for(let p of m)try{await Vt(e,["update-ref","-d",`${Vi}/${p.id}`]),r.droppedRefs+=1}catch{}}if(!i)return r;uf(e,o);try{await Vt(e,["gc","--quiet","--prune=now"])}catch{}return r}function jN(e={}){let t={removedDirs:0,failed:[]},r;try{r=RN(af,{withFileTypes:!0})}catch{return t}let n=(e.now??Date.now())-jw*24*60*60*1e3,o=e.keep?Um(e.keep):void 0;for(let i of r){if(!i.isDirectory())continue;let a=Nt(af,i.name);if(Um(a)!==o)try{(NN(a)||qN(a)<n)&&(PN(a,{recursive:!0,force:!0}),t.removedDirs+=1)}catch{t.failed.push(i.name)}}return t}function NN(e){try{let t=JSON.parse(mf(Nt(e,Nw),"utf8"));return typeof t?.root!="string"||t.root.length===0?!1:!qm(t.root)}catch{return!1}}function qN(e){try{return sf(Nt(e,qw)).mtimeMs}catch{return sf(e).mtimeMs}}async function TLe(e,t){if(e.disabled)return;let r=Bm(e);for(let n of r.sessions[t]??[])try{await Vt(e,["update-ref","-d",`${Vi}/${n.id}`])}catch{}delete r.sessions[t],uf(e,r)}export{Co as a,hm as b,A1 as c,NPe as d,qPe as e,_Pe as f,UPe as g,zPe as h,WPe as i,G1 as j,QPe as k,XPe as l,ZPe as m,pAe as n,fAe as o,dAe as p,lAe as q,gAe as r,rk as s,D as t,ik as u,GOe as v,uk as w,ck as x,VOe as y,yL as z,JOe as A,YOe as B,QOe as C,XOe as D,xL as E,ZOe as F,hL as G,IL as H,eMe as I,aMe as J,mMe as K,uMe as L,cMe as M,pMe as N,fMe as O,up as P,dMe as Q,lMe as R,gMe as S,yMe as T,Ek as U,LL as V,qi as W,_L as X,YL as Y,QL as Z,XL as _,ZL as $,oD as aa,iT as ba,sT as ca,xD as da,Fve as ea,xT as fa,HT as ga,XD as ha,ZD as ia,WT as ja,rj as ka,NFe as la,xn as ma,r1e as na,n1e as oa,jt as pa,o1e as qa,i1e as ra,s1e as sa,a1e as ta,JT as ua,m1e as va,u1e as wa,c1e as xa,yj as ya,Ej as za,x1e as Aa,h1e as Ba,I1e as Ca,b1e as Da,$1e as Ea,tw as Fa,nw as Ga,Ve as Ha,Aj as Ia,ht as Ja,k1e as Ka,sw as La,Fo as Ma,R1e as Na,ef as Oa,P1e as Pa,H1e as Qa,z1e as Ra,xN as Sa,uLe as Ta,cLe as Ua,pLe as Va,jw as Wa,bLe as Xa,DN as Ya,$Le as Za,ELe as _a,SLe as $a,kLe as ab,TLe as bb};