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.
@@ -0,0 +1,187 @@
1
+ import{t as uf}from"./chunk-ZJL4OEXX.js";import{b as cf}from"./chunk-XODGJSB3.js";import{a as qm,b as af,d as mf}from"./chunk-DBPJZUIT.js";import{H as Ve,K as sf,L as Dn,a as Gi}from"./chunk-5FIFNXLT.js";import{a as sr}from"./chunk-UTYFLLSM.js";import{a as Lm,b as jn,c as Nn,d as Dm,e as jm,f as Oo,g as Nm,h as Br,j as Mo}from"./chunk-MVVEYKN6.js";import{a as At}from"./chunk-WOT6VMZA.js";import{spawn as x1}from"node:child_process";import{existsSync as y1,readFileSync as h1}from"node:fs";import{join as I1}from"node:path";var U={};At(U,{Match:()=>AC});function AC(e,t){return t[e.length]?.(...e)??(()=>{throw Error("Invalid Arguments")})()}var Ae={};At(Ae,{Get:()=>Qi,Reset:()=>Cw,Set:()=>ww});var s={};At(s,{CodePointCount:()=>HC,Counted:()=>XC,Entries:()=>tw,EntriesRegExp:()=>ew,Every:()=>VC,EveryAll:()=>JC,GraphemeCount:()=>KC,HasPropertyKey:()=>ZC,IsArray:()=>Fo,IsBigInt:()=>vo,IsBoolean:()=>xf,IsClassInstance:()=>GC,IsConstructor:()=>jC,IsDeepEqual:()=>Bm,IsEqual:()=>J,IsFunction:()=>yf,IsGreaterEqualThan:()=>If,IsGreaterThan:()=>_C,IsInteger:()=>_m,IsLessEqualThan:()=>hf,IsLessThan:()=>UC,IsMaxLength:()=>zC,IsMinLength:()=>WC,IsMultipleOf:()=>BC,IsNull:()=>Wi,IsNumber:()=>Vi,IsObject:()=>Lo,IsObjectNotArray:()=>NC,IsString:()=>Ji,IsSymbol:()=>qC,IsUndefined:()=>Um,IsUnsafePropertyKey:()=>$f,IsValueLike:()=>bf,Keys:()=>zi,ShiftLeft:()=>Yi,Some:()=>YC,SomeAll:()=>QC,Symbols:()=>rw,Values:()=>nw});function qn(e,t,r){return e>=t&&e<=r}function OC(e){return e===8205}function pf(e){return qn(e,127462,127487)}function MC(e){return qn(e,65024,65039)}function vC(e){return qn(e,768,879)||qn(e,6832,6911)||qn(e,7616,7679)||qn(e,65056,65071)}function Ki(e){return e>65535?2:1}function ff(e,t){for(;t<e.length;){let r=e.codePointAt(t);if(vC(r)||MC(r))t+=Ki(r);else break}return t}function FC(e,t){let r=e.codePointAt(t),n=t+Ki(r);for(n=ff(e,n);n<e.length-1&&OC(e.codePointAt(n));){let o=e.codePointAt(n+1);n+=1+Ki(o),n=ff(e,n)}return pf(r)&&n<e.length&&pf(e.codePointAt(n))&&(n+=Ki(e.codePointAt(n))),n}function df(e){let t=0,r=0;for(;r<e.length;)r=FC(e,r),t++;return t}function Hi(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 lf(e,t){return e.length<=t||e.length<=t<<1&&Hi(e)<=t}function gf(e,t){return e.length>=t<<1||e.length>=t&&Hi(e)>=t}function Fo(e){return Array.isArray(e)}function vo(e){return J(typeof e,"bigint")}function xf(e){return J(typeof e,"boolean")}function jC(e){if(Um(e)||!yf(e))return!1;let t=Function.prototype.toString.call(e);return!!(/^class\s/.test(t)||/\[native code\]/.test(t))}function yf(e){return J(typeof e,"function")}function _m(e){return Number.isInteger(e)}function Wi(e){return J(e,null)}function Vi(e){return Number.isFinite(e)}function NC(e){return Lo(e)&&!Fo(e)}function Lo(e){return J(typeof e,"object")&&!Wi(e)}function Ji(e){return J(typeof e,"string")}function qC(e){return J(typeof e,"symbol")}function Um(e){return J(e,void 0)}function J(e,t){return e===t}function _C(e,t){return e>t}function UC(e,t){return e<t}function hf(e,t){return e<=t}function If(e,t){return e>=t}function BC(e,t){if(vo(e)||vo(t))return BigInt(e)%BigInt(t)===0n;let r=1e-10;if(!Vi(e)||_m(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 GC(e){if(!Lo(e))return!1;let t=globalThis.Object.getPrototypeOf(e);return Wi(t)?!1:J(typeof t.constructor,"function")&&!(J(t.constructor,globalThis.Object)||J(t.constructor.name,"Object"))}function bf(e){return vo(e)||xf(e)||Wi(e)||Vi(e)||Ji(e)||Um(e)}function KC(e){return df(e)}function HC(e){return Hi(e)}function zC(e,t){return lf(e,t)}function WC(e,t){return gf(e,t)}function VC(e,t,r){return e.every((n,o)=>o<t||r(n,o))}function JC(e,t,r){let n=!0;return e.forEach((o,i)=>{i>=t&&!r(o,i)&&(n=!1)}),n}function YC(e,t){return e.some((r,n)=>t(r,n))}function QC(e,t){let r=!1;return e.forEach((n,o)=>{t(n,o)&&(r=!0)}),r}function XC(e,t){return e.reduce((r,n,o)=>t(n,o)?++r:r,0)}function Yi(e,t,r){return J(e.length,0)?r():t(e[0],e.slice(1))}function $f(e){return J(e,"__proto__")||J(e,"constructor")||J(e,"prototype")}function ZC(e,t){return $f(t)?Object.prototype.hasOwnProperty.call(e,t):t in e}function ew(e){return zi(e).map(t=>[new RegExp(`^${t}$`),e[t]])}function tw(e){return Object.entries(e)}function zi(e){return Object.getOwnPropertyNames(e)}function rw(e){return Object.getOwnPropertySymbols(e)}function nw(e){return Object.values(e)}function ow(e,t){if(!Lo(t))return!1;let r=zi(e);return J(r.length,zi(t).length)&&r.every(n=>Bm(e[n],t[n]))}function iw(e,t){return Fo(t)&&J(e.length,t.length)&&e.every((r,n)=>Bm(e[n],t[n]))}function Bm(e,t){return Fo(e)?iw(e,t):Lo(e)?ow(e,t):J(e,t)}var Le={};At(Le,{IsBigInt64Array:()=>Iw,IsBigUint64Array:()=>bw,IsBoolean:()=>sw,IsDate:()=>Ew,IsFloat32Array:()=>yw,IsFloat64Array:()=>hw,IsInt16Array:()=>dw,IsInt32Array:()=>gw,IsInt8Array:()=>cw,IsMap:()=>kw,IsNumber:()=>aw,IsRegExp:()=>$w,IsSet:()=>Sw,IsString:()=>mw,IsTypeArray:()=>uw,IsUint16Array:()=>lw,IsUint32Array:()=>xw,IsUint8Array:()=>pw,IsUint8ClampedArray:()=>fw});function sw(e){return e instanceof Boolean}function aw(e){return e instanceof Number}function mw(e){return e instanceof String}function uw(e){return globalThis.ArrayBuffer.isView(e)}function cw(e){return e instanceof globalThis.Int8Array}function pw(e){return e instanceof globalThis.Uint8Array}function fw(e){return e instanceof globalThis.Uint8ClampedArray}function dw(e){return e instanceof globalThis.Int16Array}function lw(e){return e instanceof globalThis.Uint16Array}function gw(e){return e instanceof globalThis.Int32Array}function xw(e){return e instanceof globalThis.Uint32Array}function yw(e){return e instanceof globalThis.Float32Array}function hw(e){return e instanceof globalThis.Float64Array}function Iw(e){return e instanceof globalThis.BigInt64Array}function bw(e){return e instanceof globalThis.BigUint64Array}function $w(e){return e instanceof globalThis.RegExp}function Ew(e){return e instanceof globalThis.Date}function Sw(e){return e instanceof globalThis.Set}function kw(e){return e instanceof globalThis.Map}var Ef=s;var Wt={immutableTypes:!1,maxErrors:8,maxParseErrors:1,maxInstantiationCount:128,useAcceleration:!0,exactOptionalPropertyTypes:!1,enumerableKind:!1,correctiveParse:!1,unionPrioritySort:!0};function Cw(){Wt.immutableTypes=!1,Wt.maxErrors=8,Wt.maxParseErrors=1,Wt.maxInstantiationCount=128,Wt.useAcceleration=!0,Wt.exactOptionalPropertyTypes=!1,Wt.enumerableKind=!1,Wt.correctiveParse=!1,Wt.unionPrioritySort=!0}function ww(e){for(let t of s.Keys(e)){let r=e[t];r!==void 0&&Object.defineProperty(Wt,t,{value:r})}}function Qi(){return Wt}function Xi(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 gt(e){return s.IsObject(e)&&!s.IsArray(e)}function ln(e){return s.IsBoolean(e)}function F(e){return gt(e)||ln(e)}function Zi(e){return s.HasPropertyKey(e,"additionalItems")&&F(e.additionalItems)}function _t(e){return s.HasPropertyKey(e,"additionalProperties")&&F(e.additionalProperties)}function es(e){return s.HasPropertyKey(e,"allOf")&&s.IsArray(e.allOf)&&e.allOf.every(t=>F(t))}function Sf(e){return s.HasPropertyKey(e,"$anchor")&&s.IsString(e.$anchor)}function ts(e){return s.HasPropertyKey(e,"anyOf")&&s.IsArray(e.anyOf)&&e.anyOf.every(t=>F(t))}function Gm(e){return s.HasPropertyKey(e,"const")}function Gr(e){return s.HasPropertyKey(e,"contains")&&F(e.contains)}function bt(e){return s.HasPropertyKey(e,"default")}function Km(e){return s.HasPropertyKey(e,"dependencies")&&s.IsObject(e.dependencies)&&Object.values(e.dependencies).every(t=>F(t)||s.IsArray(t)&&t.every(r=>s.IsString(r)))}function Hm(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 rs(e){return s.HasPropertyKey(e,"dependentSchemas")&&s.IsObject(e.dependentSchemas)&&Object.values(e.dependentSchemas).every(t=>F(t))}function Kr(e){return s.HasPropertyKey(e,"$dynamicAnchor")&&s.IsString(e.$dynamicAnchor)}function ns(e){return s.HasPropertyKey(e,"$dynamicRef")&&s.IsString(e.$dynamicRef)}function os(e){return s.HasPropertyKey(e,"else")&&F(e.else)}function zm(e){return s.HasPropertyKey(e,"enum")&&s.IsArray(e.enum)}function Wm(e){return s.HasPropertyKey(e,"exclusiveMaximum")&&(s.IsNumber(e.exclusiveMaximum)||s.IsBigInt(e.exclusiveMaximum))}function Cr(e){return s.HasPropertyKey(e,"exclusiveMinimum")&&(s.IsNumber(e.exclusiveMinimum)||s.IsBigInt(e.exclusiveMinimum))}function Do(e){return s.HasPropertyKey(e,"format")&&s.IsString(e.format)}function ut(e){return s.HasPropertyKey(e,"$id")&&s.IsString(e.$id)}function is(e){return s.HasPropertyKey(e,"if")&&F(e.if)}function gn(e){return s.HasPropertyKey(e,"items")&&(F(e.items)||s.IsArray(e.items)&&e.items.every(t=>F(t)))}function ss(e){return gn(e)&&s.IsArray(e.items)}function Vm(e){return s.HasPropertyKey(e,"maximum")&&(s.IsNumber(e.maximum)||s.IsBigInt(e.maximum))}function Jm(e){return s.HasPropertyKey(e,"maxContains")&&s.IsNumber(e.maxContains)}function jo(e){return s.HasPropertyKey(e,"maxItems")&&s.IsNumber(e.maxItems)}function Ym(e){return s.HasPropertyKey(e,"maxLength")&&s.IsNumber(e.maxLength)}function Qm(e){return s.HasPropertyKey(e,"maxProperties")&&s.IsNumber(e.maxProperties)}function wr(e){return s.HasPropertyKey(e,"minimum")&&(s.IsNumber(e.minimum)||s.IsBigInt(e.minimum))}function xn(e){return s.HasPropertyKey(e,"minContains")&&s.IsNumber(e.minContains)}function yn(e){return s.HasPropertyKey(e,"minItems")&&s.IsNumber(e.minItems)}function No(e){return s.HasPropertyKey(e,"minLength")&&s.IsNumber(e.minLength)}function qo(e){return s.HasPropertyKey(e,"minProperties")&&s.IsNumber(e.minProperties)}function Xm(e){return s.HasPropertyKey(e,"multipleOf")&&(s.IsNumber(e.multipleOf)||s.IsBigInt(e.multipleOf))}function as(e){return s.HasPropertyKey(e,"not")&&F(e.not)}function ms(e){return s.HasPropertyKey(e,"oneOf")&&s.IsArray(e.oneOf)&&e.oneOf.every(t=>F(t))}function _o(e){return s.HasPropertyKey(e,"pattern")&&(s.IsString(e.pattern)||e.pattern instanceof RegExp)}function _n(e){return s.HasPropertyKey(e,"patternProperties")&&s.IsObject(e.patternProperties)&&Object.values(e.patternProperties).every(t=>F(t))}function hn(e){return s.HasPropertyKey(e,"prefixItems")&&s.IsArray(e.prefixItems)&&e.prefixItems.every(t=>F(t))}function Un(e){return s.HasPropertyKey(e,"properties")&&s.IsObject(e.properties)&&Object.values(e.properties).every(t=>F(t))}function us(e){return s.HasPropertyKey(e,"propertyNames")&&(s.IsObject(e.propertyNames)||F(e.propertyNames))}function Rw(e){return s.HasPropertyKey(e,"$recursiveAnchor")&&s.IsBoolean(e.$recursiveAnchor)}function Uo(e){return Rw(e)&&s.IsEqual(e.$recursiveAnchor,!0)}function cs(e){return s.HasPropertyKey(e,"$recursiveRef")&&s.IsString(e.$recursiveRef)}function ps(e){return s.HasPropertyKey(e,"$ref")&&s.IsString(e.$ref)}function In(e){return s.HasPropertyKey(e,"required")&&s.IsArray(e.required)&&e.required.every(t=>s.IsString(t))}function fs(e){return s.HasPropertyKey(e,"then")&&F(e.then)}function Zm(e){return s.HasPropertyKey(e,"type")&&(s.IsString(e.type)||s.IsArray(e.type)&&e.type.every(t=>s.IsString(t)))}function Hr(e){return s.HasPropertyKey(e,"uniqueItems")&&s.IsBoolean(e.uniqueItems)}function Bo(e){return s.HasPropertyKey(e,"unevaluatedItems")&&F(e.unevaluatedItems)}function Go(e){return s.HasPropertyKey(e,"unevaluatedProperties")&&F(e.unevaluatedProperties)}var ct=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}},Ze=class extends ct{constructor(){super(),this.errors=[]}AtCapacity(){return this.errors.length>=Ae.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 kf(e,t,r,n){return s.Every(r["~refine"],0,(o,i)=>o.check(n))}function Tf(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 Ko="urn:typebox:root";function Rr(e,t){return URL.canParse(e,t)?new URL(e,t):s.IsEqual(t,Ko)?new URL(`${t}:${e}`):new URL(`${t.slice(0,t.lastIndexOf(":"))}:${e}`)}function Gn(e,t){let r=gt(t)&&ut(t)?Rr(t.$id,Ko).href:Ko;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 eu(e,t,r=!0){if(ln(t))return e;if(Array.isArray(t))return t.reduce((o,i)=>eu(o,i,!1),e);if(!gt(t)||!r&&ut(t))return e;let n=!r&&Kr(t)?[...e,t]:e;return Object.keys(t).reduce((o,i)=>eu(o,t[i],!1),n)}function Ho(e,t){return e.resourceEntries.get(t)}function Cf(e,t){return e.enteredResource||Ho(e,t)!==void 0}function Pw(e){return!/^[A-Za-z][A-Za-z0-9+.-]*:/.test(e.$id)}function Aw(e,t){return ut(t)?[...e.ids,t]:e.ids}function Ow(e,t){return e.recursiveAnchor??(Uo(t)?t:void 0)}function Mw(e,t){let r=ut(t)?eu(e.dynamicAnchors,t):e.dynamicAnchors;return Kr(t)?[...r,t]:r}function vw(e,t){return ut(t)?!1:e.pendingResource}function wf(e,t){let r=Ho(e,t);return r?r.base:ut(t)?Rr(t.$id,e.lexicalBase).href:e.lexicalBase}function Rf(e,t){let r=Ho(e,t);return r?r.base:ut(t)&&e.pendingResource?Rr(t.$id,e.resourceBase).href:e.resourceBase}function Pf(e,t){return ut(t)?!Pw(t):e.useResourceBaseForReference}function Fw(e,t){let r=Cf(e,t),n=Pf(e,t);return r||n?Rf(e,t):wf(e,t)}function Lw(e,t){let r=Ho(e,t);return r?r.root:ut(t)?t:e.lexicalSchema}function Dw(e,t){return gt(t)&&(ut(t)||Kr(t)||s.IsUndefined(e.recursiveAnchor)&&Uo(t)||!s.IsUndefined(Ho(e,t)))}function Kn(e,t){return Dw(e,t)?{...e,ids:Aw(e,t),dynamicAnchors:Mw(e,t),recursiveAnchor:Ow(e,t),pendingResource:vw(e,t),lexicalBase:wf(e,t),resourceBase:Rf(e,t),useResourceBaseForReference:Pf(e,t),referenceBase:Fw(e,t),lexicalSchema:Lw(e,t),enteredResource:Cf(e,t)}:e}function Af(e){return gn(e)&&s.IsArray(e.items)}function Of(e,t,r,n){return Af(r)?s.Every(n,0,(i,a)=>s.IsLessThan(a,r.items.length)||Ot(e,t,r.additionalItems,i)&&t.AddIndex(a)):!0}function Mf(e,t,r,n,o,i){return Af(o)?s.Every(i,0,(m,c)=>{let p=`${r}/additionalItems`,f=`${n}/${c}`;return s.IsLessThan(c,o.items.length)||Mt(e,t,p,f,o.additionalItems,m)&&t.AddIndex(c)}):!0}function $t(e){return e.replace(/~/g,"~0").replace(/\//g,"~1")}function zr(e){return new RegExp(e,"u")}function jw(e){return`^${e.replace(/[.*+?^${}()|[\]\\]/g,"\\$&")}$`}function vf(e){let t=[];return _n(e)&&t.push(...s.Keys(e.patternProperties)),Un(e)&&t.push(...s.Keys(e.properties).map(jw)),s.IsEqual(t.length,0)?"(?!)":`(${t.join("|")})`}function Ff(e,t,r,n){let o=zr(vf(r));return s.Every(s.Keys(n),0,(a,m)=>o.test(a)||Ot(e,t,r.additionalProperties,n[a])&&t.AddKey(a))}function Lf(e,t,r,n,o,i){let a=zr(vf(o)),m=[];return s.EveryAll(s.Keys(i),0,(p,f)=>{let d=`${r}/additionalProperties`,g=`${n}/${$t(p)}`,x=a.test(p)||Mt(e,t,d,g,o.additionalProperties,i[p])&&t.AddKey(p);return x||m.push(p),x})||t.AddError("additionalProperties",r,n,{additionalProperties:m})}function Df(e,t,r,n){let o=r.allOf.reduce((i,a)=>{let m=new ct;return Y(e,m,a,n)?[...i,m]:i},[]);return s.IsEqual(o.length,r.allOf.length)&&t.Merge(o)}function jf(e,t,r,n,o,i){let a=[],m=o.allOf.reduce((p,f,d)=>{let g=`${r}/allOf/${d}`,x=new Ze,I=ae(e,x,g,n,f,i);return I||a.push(x),I?[...p,x]:p},[]),c=s.IsEqual(m.length,o.allOf.length)&&t.Merge(m);return c||a.forEach(p=>t.AddErrors(p.GetErrors())),c}function Nf(e,t,r,n){let o=r.anyOf.reduce((i,a)=>{let m=new ct;return Y(e,m,a,n)?[...i,m]:i},[]);return s.IsGreaterThan(o.length,0)&&t.Merge(o)}function qf(e,t,r,n,o,i){let a=[],m=o.anyOf.reduce((p,f,d)=>{let g=new Ze,x=`${r}/anyOf/${d}`,I=ae(e,g,x,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 nu(e,t,r,n){return r}function _f(e,t,r,n,o,i){return nu(e,t,o,i)||t.AddError("boolean",r,n,{})}function ou(e,t,r,n){return s.IsValueLike(r.const)?s.IsEqual(n,r.const):s.IsDeepEqual(n,r.const)}function Uf(e,t,r,n,o,i){return ou(e,t,o,i)||t.AddError("const",r,n,{allowedValue:o.const})}function Nw(e){return!(xn(e)&&s.IsEqual(e.minContains,0))}function iu(e,t,r,n){return Nw(r)?!s.IsEqual(n.length,0)&&s.SomeAll(n,(o,i)=>Y(e,t,r.contains,o)&&t.AddIndex(i)):!0}function Bf(e,t,r,n,o,i){return iu(e,t,o,i)||t.AddError("contains",r,n,{minContains:1})}function Gf(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)):Y(e,t,m,n)));return o||i}function Kf(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/${$t(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})):ae(e,t,f,n,p,i))});return a||m}function Hf(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 zf(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 Wf(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)||Y(e,t,m,n));return o||i}function Vf(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/${$t(c)}`;return!s.HasPropertyKey(i,c)||ae(e,t,f,n,p,i)});return a||m}var Ut={};At(Ut,{DynamicRef:()=>gR,RecursiveRef:()=>fR,Ref:()=>cR});var mr={};At(mr,{Delete:()=>Bw,Get:()=>_w,Has:()=>qw,Indices:()=>Wo,Set:()=>Uw});function Yf(e){throw Error(e)}function Jf(){Yf("Pointer contains unsafe property key")}function su(){Yf("Cannot set value")}function Wo(e){let t=e.split("/").map(r=>r.replace(/~1/g,"/").replace(/~0/g,"~"));return t[0]===""?t.slice(1):t}function qw(e,t){let r=e;for(let n of Wo(t)){if(!s.IsObject(r)||!s.HasPropertyKey(r,n))return!1;r=r[n]}return!0}function _w(e,t){let r=e;for(let n of Wo(t)){if(!s.IsObject(r)||s.IsUnsafePropertyKey(n))return;r=r[n]}return r}function Qf(e,t,r){let n=e;for(let o of t)s.IsUnsafePropertyKey(o)&&Jf(),n=s.IsObject(n)?n[o]:void 0;return s.IsUnsafePropertyKey(r)&&Jf(),s.IsObject(n)||su(),n}function Uw(e,t,r){let n=Wo(t),o=n.pop();return s.IsUndefined(o)&&su(),Qf(e,n,o)[o]=r,e}function Bw(e,t){let r=Wo(t),n=r.pop();s.IsUndefined(n)&&su();let o=Qf(e,r,n);return s.IsArray(o)&&/^(0|[1-9]\d*)$/.test(n)?o.splice(Number(n),1):delete o[n],e}function uu(e,t){return gt(e)&&ut(e)?Rr(e.$id,t.href):t}function cu(e){return Rr(e,Ko)}function au(e){return e.href.split("#")[0]}function Gw(e,t,r){return mu(e,cu(t),r)}function Kw(e,t){return t.$ref.startsWith("#")||e.enteredResource?e.lexicalSchema:e.schema}function Hw(e){return e.startsWith("#/")}function Xf(e,t){if(s.IsObject(e)&&Kr(e)&&s.IsEqual(e.$dynamicAnchor,t))return e;if(s.IsObject(e))for(let r of s.Keys(e)){let n=Xf(e[r],t);if(n)return n}}function mu(e,t,r){if(s.IsEqual(e,r))return t.href;let n=uu(e,t);if(s.IsArray(e))for(let o of e){let i=mu(o,n,r);if(!s.IsUndefined(i))return i}else if(s.IsObject(e))for(let o of s.Keys(e)){let i=mu(e[o],n,r);if(!s.IsUndefined(i))return i}}function Zf(e,t){if(t.href.endsWith("#"))return e;if(!t.hash.startsWith("#"))return;let r=decodeURIComponent(t.hash.slice(1));if(r.startsWith("/"))return mr.Get(e,r)}function zw(e,t,r){if(!ut(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("#")?Zf(e,r):e}function Ww(e,t,r){if(!Sf(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 Vw(e,t,r){if(!Kr(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 Jw(e,t,r){if(gt(e))return zw(e,t,r)??Ww(e,t,r)??Vw(e,t,r)??Zf(e,r)}function Yw(e,t,r){if(s.IsArray(e))return e.reduce((n,o)=>{let i=ds(o,t,r);return s.IsUndefined(i)?n:i},void 0)}function Qw(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=ds(e[o],t,r);return s.IsUndefined(i)?n:i},void 0)}function ds(e,t,r){let n=uu(e,t);return Jw(e,n,r)??Yw(e,n,r)??Qw(e,n,r)}function Xw(e,t,r,n){let o=ls(e,t,r,n);return gt(o)&&ut(o)?o:void 0}function Zw(e,t,r){if(!t.$ref.startsWith("#")||!gt(e.schema)||s.HasPropertyKey(e.schema,"$schema"))return;let n=Gw(e.lexicalSchema,e.referenceBase,r);if(!(s.IsUndefined(n)||s.IsEqual(n,e.referenceBase)))return{target:r,base:n,root:e.lexicalSchema}}function eR(e,t,r){let n=e.context[t];if(gt(n))return{target:r,base:t,root:n}}function tR(e,t,r,n,o){let i=o?eR(e,n,r):void 0;return s.IsUndefined(i)?Zw(e,t,r):i}function rR(e,t,r){if(ut(r))return;let n=Xw(e.context,e.schema,e.referenceBase,t);if(!(!n||e.ids.includes(n)))return{resource:n}}function nR(e,t){return s.HasPropertyKey(e,t)?e[t]:void 0}function oR(e,t,r){return ds(e,t,r)}function iR(e,t,r){let n=au(r);if(!s.HasPropertyKey(e,n)||s.IsEqual(n,au(t)))return;let o=e[n],i=uu(o,new URL(n));return s.IsEqual(r.hash,"")?o:ds(o,i,r)}function ls(e,t,r,n){let o=cu(r),i=Rr(n,o.href);return nR(e,n)??oR(t,o,i)??iR(e,o,i)}function sR(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 aR(e,t){return t?Kn(e,t.resource):e}function ed(e,t,r,n){let o=sR({...e,pendingResource:t},r);return aR(o,n)}function mR(e,t,r){let n=au(Rr(t.$ref,e.referenceBase)),o=!s.IsEqual(n,e.resourceBase),i=tR(e,t,r,n,o),a=o?rR(e,n,r):void 0;return{schema:r,stack:ed(e,!0,i,a)}}function uR(e,t){return{schema:t,stack:ed(e,!s.IsUndefined(t))}}function cR(e,t){let r=ls(e.context,Kw(e,t),e.referenceBase,t.$ref);return gt(r)?mR(e,t,r):uR(e,r)}function pR(e){return gt(e.lexicalSchema)&&Uo(e.lexicalSchema)}function fR(e,t){let r=pR(e)?e.recursiveAnchor:e.lexicalSchema;return ls(e.context,r,e.lexicalBase,t.$recursiveRef)}function td(e,t){return Rr(t.$dynamicRef,cu(e.lexicalBase).href).hash}function rd(e,t){return e.dynamicAnchors.find(r=>s.IsEqual(r.$dynamicAnchor,t))??Xf(e.schema,t)}function dR(e,t,r){if(!gt(r)||!Kr(r))return r;let n=td(e,t);return Hw(n)?r:rd(e,r.$dynamicAnchor)}function lR(e,t){let r=td(e,t);return rd(e,decodeURIComponent(r.slice(1)))}function gR(e,t){let r=t.$dynamicRef.startsWith("#")?e.lexicalSchema:e.schema,n=ls(e.context,r,e.lexicalBase,t.$dynamicRef);return s.IsUndefined(n)?lR(e,t):dR(e,t,n)}function nd(e,t,r,n){let o=Ut.DynamicRef(e,r)??!1,i=o?{...e,pendingResource:!0}:e;return F(o)&&Y(i,t,o,n)}function od(e,t,r,n,o,i){let a=Ut.DynamicRef(e,o)??!1,m=a?{...e,pendingResource:!0}:e;return F(a)&&ae(m,t,r,n,a,i)}function du(e,t,r,n){return s.Some(r.enum,o=>s.IsValueLike(o)?s.IsEqual(n,o):s.IsDeepEqual(n,o))}function id(e,t,r,n,o,i){return du(e,t,o,i)||t.AddError("enum",r,n,{allowedValues:o.enum})}function lu(e,t,r,n){return s.IsLessThan(n,r.exclusiveMaximum)}function sd(e,t,r,n,o,i){return lu(e,t,o,i)||t.AddError("exclusiveMaximum",r,n,{comparison:"<",limit:o.exclusiveMaximum})}function gu(e,t,r,n){return s.IsGreaterThan(n,r.exclusiveMinimum)}function ad(e,t,r,n,o,i){return gu(e,t,o,i)||t.AddError("exclusiveMinimum",r,n,{comparison:">",limit:o.exclusiveMinimum})}var Qo={};At(Qo,{Clear:()=>Fd,Entries:()=>o0,Get:()=>a0,Has:()=>s0,IsDate:()=>zn,IsDateTime:()=>gs,IsDuration:()=>xs,IsEmail:()=>ys,IsHostname:()=>Ts,IsIPv4:()=>Rs,IsIPv6:()=>Ps,IsIdnEmail:()=>Cs,IsIdnHostname:()=>ws,IsIri:()=>Os,IsIriReference:()=>As,IsJsonPointer:()=>vs,IsJsonPointerUriFragment:()=>Ms,IsRegex:()=>Fs,IsRelativeJsonPointer:()=>Ls,IsTime:()=>Wn,IsUri:()=>Ns,IsUriReference:()=>Ds,IsUriTemplate:()=>js,IsUrl:()=>qs,IsUuid:()=>_s,Reset:()=>Ld,Set:()=>i0,Test:()=>m0});var xR=[0,31,28,31,30,31,30,31,31,30,31,30,31],yR=/^(\d\d\d\d)-(\d\d)-(\d\d)$/;function hR(e){return e%4===0&&(e%100!==0||e%400===0)}function zn(e){let t=yR.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&&hR(r)?29:xR[n])}var IR=/^(\d\d):(\d\d):(\d\d)(?:\.\d+)?(?:([Zz])|([+-])(\d\d):(\d\d))?$/;function Wn(e,t=!0){let r=IR.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 bR=/^(?:\[!?(?:(?!\.{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 gs(e){let t=e.indexOf("["),r=t===-1?e:e.slice(0,t);if(t!==-1&&!bR.test(e.slice(t)))return!1;let n=r.split(/T/i);return n.length===2&&zn(n[0])&&Wn(n[1])}var $R=/^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 xs(e){return $R.test(e)}var ER=/^(?:[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 ys(e){return ER.test(e)}var md=/^(?!-).*(?<!-)$/,ud=/^(?!..--)/,cd=/^[a-zA-Z0-9-]*$/,GB=new RegExp("^\\p{ASCII}*$","u"),Vn=/[^\p{ASCII}]/u;var SR=/[0-9]/,pd=/[\u{0660}-\u{0669}]/u,kR=/[\u{06f0}-\u{06f9}]/u,TR=/[\u{002e}\u{002c}\u{003a}\u{002f}]/u,CR=/[\u{002d}\u{002b}]/u,xu=new RegExp("\\p{Mn}","u"),wR=new RegExp("\\p{Mc}","u"),KB=new RegExp("\\p{Me}","u"),fd=/[\p{Mn}\p{Mc}\p{Me}]/u,yu=new RegExp("\\p{L}","u"),RR=new RegExp("\\p{Nd}","u"),dd=new RegExp("\\p{Script=Greek}","u"),hs=new RegExp("\\p{Script=Hebrew}","u"),ld=/[\p{Script=Hiragana}\p{Script=Katakana}\p{Script=Han}]/u,gd=/[\p{Script=Arabic}\p{Script=Syriac}\p{Script=Thaana}\p{Script=Mandaic}]/u,hu=/[\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,xd=/[\u{0640}\u{07fa}\u{302e}\u{302f}\u{3031}\u{3032}\u{3033}\u{3034}\u{3035}\u{303b}]/u,PR=/[\u{00b7}\u{0375}\u{05f3}\u{05f4}\u{200c}\u{200d}\u{30fb}]/u,AR=/[\u{00df}\u{03c2}\u{06fd}\u{06fe}\u{0f0b}\u{3007}]/u,yd=new RegExp([SR,kR].map(e=>e.source).join("|"),"u"),hd=new RegExp([yu,CR,TR,RR,xu,wR,PR,AR].map(e=>e.source).join("|"),"u");function Id(e){return md.test(e)&&ud.test(e)&&cd.test(e)}var Jt=36,Jo=1,Yo=26,MR=38,vR=700,$d=72,Ed=128;function Iu(){throw null}function Is(e){return e.toLowerCase().startsWith("xn--")}function Sd(e,t,r){e=r?Math.floor(e/vR):e>>1,e+=Math.floor(e/t);let n=0;for(;e>(Jt-Jo)*Yo>>1;)e=Math.floor(e/(Jt-Jo)),n+=Jt;return n+Math.floor((Jt-Jo+1)*e/(e+MR))}function bs(e){let t=[],r=Ed,n=0,o=$d,i=e.lastIndexOf("-");if(i>0)for(let m=0;m<i;m++){let c=e.charCodeAt(m);c>=128&&Iu(),t.push(c)}let a=i<0?0:i+1;for(;a<e.length;){let m=n,c=1,p=Jt;for(;;){a>=e.length&&Iu();let d=e.charCodeAt(a++),g;d>=97&&d<=122?g=d-97:d>=48&&d<=57?g=d-48+26:Iu(),n+=g*c;let x=p<=o?Jo:p>=o+Yo?Yo:p-o;if(g<x)break;c*=Jt-x,p+=Jt}let f=t.length+1;o=Sd(n-m,f,m===0),r+=Math.floor(n/f),n%=f,t.splice(n,0,r),n++}return String.fromCodePoint(...t)}function bd(e){return e<26?String.fromCharCode(e+97):String.fromCharCode(e-26+48)}var FR=new RegExp(Vn.source,"gu");function kd(e){let t=e.replace(FR,""),r=t.length,n=r>0?[t,"-"]:[],o=Array.from(e,p=>p.codePointAt(0)),i=Ed,a=0,m=$d,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=Jt;;g+=Jt){let x=g<=m?Jo:g>=m+Yo?Yo:g-m;if(d<x)break;let I=x+(d-x)%(Jt-x);n.push(bd(I)),d=Math.floor((d-x)/(Jt-x))}n.push(bd(d)),m=Sd(a,c+1,c===r),a=0,c++}a++,i++}return n.join("")}var LR=/^(?:R|AL|AN|EN|ES|CS|ET|ON|BN|NSM)$/,Td=/^(?:L|EN|ES|CS|ET|ON|BN|NSM)$/,DR=/^(?:R|AL|AN)$/;function Cd(e){if(Is(e))try{return $s(bs(e.slice(4).toLowerCase()))}catch{return!1}return $s(e)}function wd(e){let t=String.fromCodePoint(e);return yd.test(t)?"EN":pd.test(t)?"AN":xu.test(t)?"NSM":hs.test(t)?"R":gd.test(t)?"AL":yu.test(t)?"L":"ON"}function $s(e){for(let t of e)if(DR.test(wd(t.codePointAt(0))))return!0;return!1}function Es(e){let t=!1,r=Td,n=!1,o=!1,i=!0;for(let a of e){let m=wd(a.codePointAt(0));if(i){if(m!=="L"&&m!=="R"&&m!=="AL")return!1;t=m==="R"||m==="AL",r=t?LR:Td,i=!1}if(!r.test(m))return!1;m==="EN"?n=!0:m==="AN"&&(o=!0)}return!(t&&n&&o)}function jR(e){return Vn.test(e)&&kd(e).length+4>63}function NR(e){return e[0]==="-"||e[e.length-1]==="-"?!0:e.slice(2).join("").startsWith("--")}function Ss(e){if(jR(e)||$s(e)&&!Es(e))return!1;let t=[...e],r=t.map(i=>i.codePointAt(0)),n=r.length;if(NR(t)||fd.test(t[0]))return!1;let o=!1;for(let i=0;i<n;i++){let a=r[i],m=t[i];if(xd.test(m)||!hd.test(m))return!1;ld.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||!dd.test(t[i+1]))return!1;break;case 1523:case 1524:if(!c||!hs.test(t[i-1]))return!1;break;case 8204:if(!c||c<128&&!hu.test(t[i-1]))return!1;break;case 8205:if(!c||!hu.test(t[i-1]))return!1;break;case 12539:break}}return!(e.includes("\u30FB")&&!o)}function ks(e){if(!Is(e))return!1;try{let t=e.slice(4).toLowerCase();if(t.lastIndexOf("-")===0)return!1;let r=bs(t);return Vn.test(r)?Ss(r):!1}catch{return!1}}function qR(e){return e.length>0&&e.length<=63}function _R(e){return qR(e)&&(ks(e)||Id(e))}function Od(e){return e.length===0||e.length>253||e.charCodeAt(e.length-1)===46?!1:e.split(".").every(t=>_R(t))}function UR(e){return e.length>0&&e.length<=63}function BR(e){return UR(e)&&(ks(e)||Ss(e))}function GR(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 Md(e){if(e.length===0||e.includes(" "))return!1;let t=GR(e);if(t.length>253)return!1;let r=t.split("."),n=r.some(o=>Cd(o));return r.every(o=>BR(o)&&(!n||Es(o)))}function Ts(e){return Od(e)}var KR=/^(?:[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 Cs(e){return KR.test(e.normalize("NFC"))}function ws(e){return Md(e)}var HR=/^(?:(?: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 Rs(e){return HR.test(e)}var zR=/^(?:(?:(?:[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 Ps(e){return zR.test(e)}var WR=/[\x00-\x20\x7F\\]|%(?![0-9a-fA-F]{2})/,VR=/^[a-zA-Z][a-zA-Z0-9+\-.]*\/\//;function As(e){return!WR.test(e)&&!VR.test(e)&&URL.canParse(e,"http://example.com")}var JR=/[\x00-\x20<>\^`{|}\\]/,YR=/%(?![0-9a-fA-F]{2})/;function Os(e){return JR.test(e)||YR.test(e)?!1:URL.canParse(e)}var QR=/^#(?:\/(?:[a-z0-9_\-.!$&'()*+,;:=@]|%[0-9a-f]{2}|~0|~1)*)*$/i;function Ms(e){return QR.test(e)}var XR=/^(?:\/(?:[^~/]|~0|~1)*)*$/;function vs(e){return XR.test(e)}function Fs(e){try{return new RegExp(e,"u"),!0}catch{return!1}}var ZR=/^(?:0|[1-9][0-9]*)(?:#|(?:\/(?:[^~/]|~0|~1)*)*)$/;function Ls(e){return ZR.test(e)}var e0=/^(?:[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 Ds(e){return e0.test(e)}var t0=/^(?:(?:[^\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 js(e){return t0.test(e)}var r0=/^[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 Ns(e){return r0.test(e)}function qs(e){return URL.canParse(e)}var n0=/^[0-9a-f]{8}-(?:[0-9a-f]{4}-){3}[0-9a-f]{12}$/i;function _s(e){return n0.test(e)}var fe=new Map;function Fd(){fe.clear()}function o0(){return[...fe.entries()]}function i0(e,t){fe.set(e,t)}function s0(e){return fe.has(e)}function a0(e){return fe.get(e)}function m0(e,t){return fe.get(e)?.(t)??!0}function Ld(){Fd(),fe.set("date-time",gs),fe.set("date",zn),fe.set("duration",xs),fe.set("email",ys),fe.set("hostname",Ts),fe.set("idn-email",Cs),fe.set("idn-hostname",ws),fe.set("ipv4",Rs),fe.set("ipv6",Ps),fe.set("iri-reference",As),fe.set("iri",Os),fe.set("json-pointer-uri-fragment",Ms),fe.set("json-pointer",vs),fe.set("regex",Fs),fe.set("relative-json-pointer",Ls),fe.set("time",Wn),fe.set("uri-reference",Ds),fe.set("uri-template",js),fe.set("uri",Ns),fe.set("url",qs),fe.set("uuid",_s)}Ld();function $u(e,t,r,n){return Qo.Test(r.format,n)}function Dd(e,t,r,n,o,i){return $u(e,t,o,i)||t.AddError("format",r,n,{format:o.format})}function jd(e,t,r,n){let o=fs(r)?r.then:!0,i=os(r)?r.else:!0;return Y(e,t,r.if,n)?Y(e,t,o,n):Y(e,t,i,n)}function Nd(e,t,r,n,o,i){let a=fs(o)?o.then:!0,m=os(o)?o.else:!0,c=new Ze,p=ae(e,c,`${r}/if`,n,o.if,i)?ae(e,c,`${r}/then`,n,a,i)||t.AddError("if",r,n,{failingKeyword:"then"}):ae(e,t,`${r}/else`,n,m,i)||t.AddError("if",r,n,{failingKeyword:"else"});return p&&t.Merge([c]),p}function u0(e,t,r,n){return s.Every(r.items,0,(o,i)=>s.IsLessEqualThan(n.length,i)||Ot(e,t,o,n[i])&&t.AddIndex(i))}function c0(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)||Mt(e,t,c,p,a,i[m])&&t.AddIndex(m)})}function p0(e,t,r,n){let o=hn(r)?r.prefixItems.length:0;return s.Every(n,o,(i,a)=>Ot(e,t,r.items,i)&&t.AddIndex(a))}function f0(e,t,r,n,o,i){let a=hn(o)?o.prefixItems.length:0;return s.EveryAll(i,a,(m,c)=>{let p=`${r}/items`,f=`${n}/${c}`;return Mt(e,t,p,f,o.items,m)&&t.AddIndex(c)})}function qd(e,t,r,n){return ss(r)?u0(e,t,r,n):p0(e,t,r,n)}function _d(e,t,r,n,o,i){return ss(o)?c0(e,t,r,n,o,i):f0(e,t,r,n,o,i)}function d0(e){return Gr(e)}function Eu(e,t,r,n){if(!d0(r))return!0;let o=s.Counted(n,i=>Y(e,t,r.contains,i));return s.IsLessEqualThan(o,r.maxContains)}function Ud(e,t,r,n,o,i){let a=xn(o)?o.minContains:1;return Eu(e,t,o,i)||t.AddError("contains",r,n,{minContains:a,maxContains:o.maxContains})}function Su(e,t,r,n){return s.IsLessEqualThan(n,r.maximum)}function Bd(e,t,r,n,o,i){return Su(e,t,o,i)||t.AddError("maximum",r,n,{comparison:"<=",limit:o.maximum})}function ku(e,t,r,n){return s.IsLessEqualThan(n.length,r.maxItems)}function Gd(e,t,r,n,o,i){return ku(e,t,o,i)||t.AddError("maxItems",r,n,{limit:o.maxItems})}function Tu(e,t,r,n){return s.IsMaxLength(n,r.maxLength)}function Kd(e,t,r,n,o,i){return Tu(e,t,o,i)||t.AddError("maxLength",r,n,{limit:o.maxLength})}function Cu(e,t,r,n){return s.IsLessEqualThan(s.Keys(n).length,r.maxProperties)}function Hd(e,t,r,n,o,i){return Cu(e,t,o,i)||t.AddError("maxProperties",r,n,{limit:o.maxProperties})}function l0(e){return Gr(e)}function wu(e,t,r,n){if(!l0(r))return!0;let o=s.Counted(n,(i,a)=>Y(e,t,r.contains,i)&&t.AddIndex(a));return s.IsGreaterEqualThan(o,r.minContains)}function zd(e,t,r,n,o,i){return wu(e,t,o,i)||t.AddError("contains",r,n,{minContains:o.minContains})}function Ru(e,t,r,n){return s.IsGreaterEqualThan(n,r.minimum)}function Wd(e,t,r,n,o,i){return Ru(e,t,o,i)||t.AddError("minimum",r,n,{comparison:">=",limit:o.minimum})}function Pu(e,t,r,n){return s.IsGreaterEqualThan(n.length,r.minItems)}function Vd(e,t,r,n,o,i){return Pu(e,t,o,i)||t.AddError("minItems",r,n,{limit:o.minItems})}function Au(e,t,r,n){return s.IsMinLength(n,r.minLength)}function Jd(e,t,r,n,o,i){return Au(e,t,o,i)||t.AddError("minLength",r,n,{limit:o.minLength})}function Ou(e,t,r,n){return s.IsGreaterEqualThan(s.Keys(n).length,r.minProperties)}function Yd(e,t,r,n,o,i){return Ou(e,t,o,i)||t.AddError("minProperties",r,n,{limit:o.minProperties})}function Mu(e,t,r,n){return s.IsMultipleOf(n,r.multipleOf)}function Qd(e,t,r,n,o,i){return Mu(e,t,o,i)||t.AddError("multipleOf",r,n,{multipleOf:o.multipleOf})}function vu(e,t,r,n){let o=new ct;return!Y(e,o,r.not,n)&&t.Merge([o])}function Xd(e,t,r,n,o,i){return vu(e,t,o,i)||t.AddError("not",r,n,{})}function Zd(e,t,r,n){let o=r.oneOf.reduce((i,a)=>{let m=new ct;return Y(e,m,a,n)?[...i,m]:i},[]);return s.IsEqual(o.length,1)&&t.Merge(o)}function el(e,t,r,n,o,i){let a=[],m=[],c=o.oneOf.reduce((f,d,g)=>{let x=new Ze,I=`${r}/oneOf/${g}`,h=ae(e,x,I,n,d,i);return h&&m.push(g),h||a.push(x),h?[...f,x]: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 Fu(e,t,r,n){return(s.IsString(r.pattern)?zr(r.pattern):r.pattern).test(n)}function tl(e,t,r,n,o,i){return Fu(e,t,o,i)||t.AddError("pattern",r,n,{pattern:o.pattern})}function rl(e,t,r,n){return s.Every(s.Entries(r.patternProperties),0,([o,i])=>{let a=zr(o);return s.Every(s.Entries(n),0,([m,c])=>!a.test(m)||Ot(e,t,i,c)&&t.AddKey(m))})}function nl(e,t,r,n,o,i){return s.EveryAll(s.Entries(o.patternProperties),0,([a,m])=>{let c=`${r}/patternProperties/${$t(a)}`,p=zr(a);return s.EveryAll(s.Entries(i),0,([f,d])=>{let g=`${n}/${$t(f)}`;return!p.test(f)||Mt(e,t,c,g,m,d)&&t.AddKey(f)})})}function ol(e,t,r,n){return s.IsEqual(n.length,0)||s.Every(r.prefixItems,0,(o,i)=>s.IsLessEqualThan(n.length,i)||Ot(e,t,o,n[i])&&t.AddIndex(i))}function il(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)||Mt(e,t,c,p,a,i[m])&&t.AddIndex(m)})}function Lu(e,t){return e.includes(t)||Ae.Get().exactOptionalPropertyTypes}function Du(e,t){return s.IsUndefined(e[t])}function sl(e,t,r,n){let o=In(r)?r.required:[];return s.Every(s.Entries(r.properties),0,([a,m])=>{let c=!s.HasPropertyKey(n,a)||Ot(e,t,m,n[a])&&t.AddKey(a);return Lu(o,a)?c:Du(n,a)||c})}function al(e,t,r,n,o,i){let a=In(o)?o.required:[];return s.EveryAll(s.Entries(o.properties),0,([c,p])=>{let f=`${r}/properties/${$t(c)}`,d=`${n}/${$t(c)}`,g=()=>!s.HasPropertyKey(i,c)||Mt(e,t,f,d,p,i[c])&&t.AddKey(c);return Lu(a,c)?g():Du(i,c)||g()})}function ml(e,t,r,n){return s.Every(s.Keys(n),0,(o,i)=>Y(e,t,r.propertyNames,o))}function ul(e,t,r,n,o,i){let a=[];return s.EveryAll(s.Keys(i),0,(c,p)=>{let f=`${n}/${$t(c)}`,d=`${r}/propertyNames`,g=ae(e,t,d,f,o.propertyNames,c);return g||a.push(c),g})||t.AddError("propertyNames",r,n,{propertyNames:a})}function cl(e,t,r,n){let o=Ut.RecursiveRef(e,r)??!1,i=o?{...e,pendingResource:!0}:e;return F(o)&&Y(i,t,o,n)}function pl(e,t,r,n,o,i){let a=Ut.RecursiveRef(e,o)??!1,m=a?{...e,pendingResource:!0}:e;return F(a)&&ae(m,t,r,n,a,i)}function fl(e,t,r,n){let o=Ut.Ref(e,r),i=o.schema??!1,a=new ct,m=F(i)&&Y(o.stack,a,i,n);return m&&t.Merge([a]),m}function dl(e,t,r,n,o,i){let a=Ut.Ref(e,o),m=a.schema??!1,c=new Ze,p=F(m)&&ae(a.stack,c,r,n,m,i);return p&&t.Merge([c]),p||t.AddErrors(c.GetErrors()),p}function ll(e,t,r,n){return s.Every(r.required,0,o=>s.HasPropertyKey(n,o))}function gl(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 ju(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 xl(e,t,r,n,o){return s.Some(r,i=>ju(e,t,i,n,o))}function yl(e,t,r,n){return s.IsArray(r.type)?xl(e,t,r.type,r,n):ju(e,t,r.type,r,n)}function hl(e,t,r,n,o,i){return(s.IsArray(o.type)?xl(e,t,o.type,o,i):ju(e,t,o.type,o,i))||t.AddError("type",r,n,{type:o.type})}function Il(e,t,r,n){let o=t.GetIndices();return s.Every(n,0,(i,a)=>(o.has(a)||Y(e,t,r.unevaluatedItems,i))&&t.AddIndex(a))}function bl(e,t,r,n,o,i){let a=t.GetIndices(),m=[];return s.EveryAll(i,0,(p,f)=>{let d=new Ze,g=(a.has(f)||ae(e,d,r,n,o.unevaluatedItems,p))&&t.AddIndex(f);return g||m.push(f),g})||t.AddError("unevaluatedItems",r,n,{unevaluatedItems:m})}function $l(e,t,r,n){let o=t.GetKeys();return s.Every(s.Entries(n),0,([i,a])=>o.has(i)||Y(e,t,r.unevaluatedProperties,a)&&t.AddKey(i))}function El(e,t,r,n,o,i){let a=t.GetKeys(),m=[];return s.EveryAll(s.Entries(i),0,([p,f])=>{let d=new Ze,g=a.has(p)||ae(e,d,r,n,o.unevaluatedProperties,f)&&t.AddKey(p);return g||m.push(p),g})||t.AddError("unevaluatedProperties",r,n,{unevaluatedProperties:m})}var Pr={};At(Pr,{Hash:()=>Rl,HashCode:()=>P0});function Ie(){throw new Error("Unreachable")}function g0(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 x0(e){return typeof e=="number"}var St={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},Bs=8997,Xo=33826,Gs=40164,Ks=52210,Tl=new Float64Array(1),Cl=new DataView(Tl.buffer),wl=new Uint8Array(Tl.buffer);function Ue(e){let t=Bs^e,r=t*435,n=Xo*435+(r>>>16),o=Gs*435+(n>>>16)+(t<<8),i=Ks*435+(o>>>16)+(Xo<<8);Bs=r&65535,Xo=n&65535,Gs=o&65535,Ks=i&65535}function y0(e){Ue(St.Array);for(let t of e)Wr(t)}function h0(e){Ue(St.BigInt),Cl.setBigInt64(0,e);for(let t of wl)Ue(t)}function Sl(e){Ue(St.Boolean),Ue(e?1:0)}function I0(e){Ue(St.Constructor),Wr(e.toString())}function b0(e){Ue(St.Date),Wr(e.getTime())}function $0(e){Ue(St.Function),Wr(e.toString())}function E0(e){Ue(St.Null)}function kl(e){Ue(St.Number),Cl.setFloat64(0,e,!0);for(let t of wl)Ue(t)}function S0(e){Ue(St.Object);for(let t of g0(e).sort())Wr(t),Wr(e[t])}function k0(e){Ue(St.RegExp),Nu(e.toString())}var T0=new TextEncoder;function Nu(e){Ue(St.String);for(let t=0;t<e.length;t++){let r=e.charCodeAt(t);if(r>127){for(let n of T0.encode(e.slice(t)))Ue(n);return}Ue(r)}}function C0(e){Ue(St.Symbol),Wr(e.toString())}function w0(e){Ue(St.TypeArray);let t=new Uint8Array(e.buffer);for(let r=0;r<t.length;r++)Ue(t[r])}function R0(e){return Ue(St.Undefined)}function Wr(e){return Le.IsTypeArray(e)?w0(e):Le.IsDate(e)?b0(e):Le.IsRegExp(e)?k0(e):Le.IsBoolean(e)?Sl(e.valueOf()):Le.IsString(e)?Nu(e.valueOf()):Le.IsNumber(e)?kl(e.valueOf()):x0(e)?kl(e):s.IsArray(e)?y0(e):s.IsBoolean(e)?Sl(e):s.IsBigInt(e)?h0(e):s.IsConstructor(e)?I0(e):s.IsNull(e)?E0(e):s.IsObject(e)?S0(e):s.IsString(e)?Nu(e):s.IsSymbol(e)?C0(e):s.IsUndefined(e)?R0(e):s.IsFunction(e)?$0(e):Ie()}function Us(e){return e.toString(16).padStart(4,"0")}function P0(e){return BigInt(`0x${Rl(e)}`)}function Rl(e){return Bs=8997,Xo=33826,Gs=40164,Ks=52210,Wr(e),`${Us(Ks)}${Us(Gs)}${Us(Xo)}${Us(Bs)}`}function Pl(e){return!s.IsEqual(e.uniqueItems,!1)}function Al(e,t,r,n){if(!Pl(r))return!0;let o=new Set(n.map(Pr.Hash)).size,i=n.length;return s.IsEqual(o,i)}function Ol(e,t,r,n,o,i){if(!Pl(o))return!0;let a=new Set,m=i.reduce((p,f,d)=>{let g=Pr.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 Ot(e,t,r,n){return t.Push()&&Y(e,t,r,n)&&t.Pop()}function Y(e,t,r,n){let o=Kn(e,r);return ln(r)?nu(o,t,r,n):(!Zm(r)||yl(o,t,r,n))&&(!(s.IsObject(n)&&!s.IsArray(n))||(!In(r)||ll(o,t,r,n))&&(!_t(r)||Ff(o,t,r,n))&&(!Km(r)||Gf(o,t,r,n))&&(!Hm(r)||Hf(o,t,r,n))&&(!rs(r)||Wf(o,t,r,n))&&(!_n(r)||rl(o,t,r,n))&&(!Un(r)||sl(o,t,r,n))&&(!us(r)||ml(o,t,r,n))&&(!qo(r)||Ou(o,t,r,n))&&(!Qm(r)||Cu(o,t,r,n)))&&(!s.IsArray(n)||(!Zi(r)||Of(o,t,r,n))&&(!Gr(r)||iu(o,t,r,n))&&(!gn(r)||qd(o,t,r,n))&&(!xn(r)||wu(o,t,r,n))&&(!Jm(r)||Eu(o,t,r,n))&&(!yn(r)||Pu(o,t,r,n))&&(!jo(r)||ku(o,t,r,n))&&(!hn(r)||ol(o,t,r,n))&&(!Hr(r)||Al(o,t,r,n)))&&(!s.IsString(n)||(!No(r)||Au(o,t,r,n))&&(!Ym(r)||Tu(o,t,r,n))&&(!Do(r)||$u(o,t,r,n))&&(!_o(r)||Fu(o,t,r,n)))&&(!(s.IsNumber(n)||s.IsBigInt(n))||(!Cr(r)||gu(o,t,r,n))&&(!Wm(r)||lu(o,t,r,n))&&(!wr(r)||Ru(o,t,r,n))&&(!Vm(r)||Su(o,t,r,n))&&(!Xm(r)||Mu(o,t,r,n)))&&(!ps(r)||fl(o,t,r,n))&&(!cs(r)||cl(o,t,r,n))&&(!ns(r)||nd(o,t,r,n))&&(!Gm(r)||ou(o,t,r,n))&&(!zm(r)||du(o,t,r,n))&&(!is(r)||jd(o,t,r,n))&&(!as(r)||vu(o,t,r,n))&&(!es(r)||Df(o,t,r,n))&&(!ts(r)||Nf(o,t,r,n))&&(!ms(r)||Zd(o,t,r,n))&&(!Bo(r)||!s.IsArray(n)||Il(o,t,r,n))&&(!Go(r)||!s.IsObject(n)||$l(o,t,r,n))&&(!Xi(r)||kf(o,t,r,n))}function Mt(e,t,r,n,o,i){return t.Push()&&ae(e,t,r,n,o,i)&&t.Pop()}function ae(e,t,r,n,o,i){if(t.AtCapacity())return!1;let a=Kn(e,o);return ln(o)?_f(a,t,r,n,o,i):!!(+(!Zm(o)||hl(a,t,r,n,o,i))&+(!(s.IsObject(i)&&!s.IsArray(i))||!!(+(!In(o)||gl(a,t,r,n,o,i))&+(!_t(o)||Lf(a,t,r,n,o,i))&+(!Km(o)||Kf(a,t,r,n,o,i))&+(!Hm(o)||zf(a,t,r,n,o,i))&+(!rs(o)||Vf(a,t,r,n,o,i))&+(!_n(o)||nl(a,t,r,n,o,i))&+(!Un(o)||al(a,t,r,n,o,i))&+(!us(o)||ul(a,t,r,n,o,i))&+(!qo(o)||Yd(a,t,r,n,o,i))&+(!Qm(o)||Hd(a,t,r,n,o,i))))&+(!s.IsArray(i)||!!(+(!Zi(o)||Mf(a,t,r,n,o,i))&+(!Gr(o)||Bf(a,t,r,n,o,i))&+(!gn(o)||_d(a,t,r,n,o,i))&+(!xn(o)||zd(a,t,r,n,o,i))&+(!Jm(o)||Ud(a,t,r,n,o,i))&+(!yn(o)||Vd(a,t,r,n,o,i))&+(!jo(o)||Gd(a,t,r,n,o,i))&+(!hn(o)||il(a,t,r,n,o,i))&+(!Hr(o)||Ol(a,t,r,n,o,i))))&+(!s.IsString(i)||!!(+(!No(o)||Jd(a,t,r,n,o,i))&+(!Ym(o)||Kd(a,t,r,n,o,i))&+(!Do(o)||Dd(a,t,r,n,o,i))&+(!_o(o)||tl(a,t,r,n,o,i))))&+(!(s.IsNumber(i)||s.IsBigInt(i))||!!(+(!Cr(o)||ad(a,t,r,n,o,i))&+(!Wm(o)||sd(a,t,r,n,o,i))&+(!wr(o)||Wd(a,t,r,n,o,i))&+(!Vm(o)||Bd(a,t,r,n,o,i))&+(!Xm(o)||Qd(a,t,r,n,o,i))))&+(!ps(o)||dl(a,t,r,n,o,i))&+(!cs(o)||pl(a,t,r,n,o,i))&+(!ns(o)||od(a,t,r,n,o,i))&+(!Gm(o)||Uf(a,t,r,n,o,i))&+(!zm(o)||id(a,t,r,n,o,i))&+(!is(o)||Nd(a,t,r,n,o,i))&+(!as(o)||Xd(a,t,r,n,o,i))&+(!es(o)||jf(a,t,r,n,o,i))&+(!ts(o)||qf(a,t,r,n,o,i))&+(!ms(o)||el(a,t,r,n,o,i))&+(!Bo(o)||!s.IsArray(i)||bl(a,t,r,n,o,i))&+(!Go(o)||!s.IsObject(i)||El(a,t,r,n,o,i)))&&(!Xi(o)||Tf(a,t,r,n,o,i))}function vl(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 A0=vl;function Fl(){return A0}var l={};At(l,{Assign:()=>M0,Clone:()=>v0,Create:()=>L0,Discard:()=>D0,Metrics:()=>Yt,Update:()=>_0});var Yt={assign:0,create:0,clone:0,discard:0,update:0};function vt(e){return[...s.Keys(e),...s.Symbols(e)]}function Ll(e,t){if(!t.has(e)){t.add(e);for(let r of vt(e)){let n=Object.getOwnPropertyDescriptor(e,r);!n||!("value"in n)||s.IsObject(n.value)&&Ll(n.value,t)}Object.freeze(e)}}function Vr(e){return Ae.Get().immutableTypes&&Ll(e,new WeakSet),e}function M0(e,t){Yt.assign+=1;let r={},n=vt(t),o=vt(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 Vr(r)}function v0(e){Yt.clone+=1;let t={};for(let r of vt(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 Dl(e,t){return{...e,...t}}function F0(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 L0(e,t,r={}){Yt.create+=1;let n=Dl(t,r),o=Ae.Get().enumerableKind?Dl(n,e):F0(n,e);return Vr(o)}function D0(e,t){Yt.discard+=1;let r={};for(let n of vt(e)){if(t.includes(n))continue;let o=Object.getOwnPropertyDescriptor(e,n);Object.defineProperty(r,n,o)}return Vr(r)}function j0(e,t,r,n){for(let o of vt(e)){if(s.IsUnsafePropertyKey(o)||t.includes(o)||r.includes(o))continue;let i=Object.getOwnPropertyDescriptor(e,o);Object.defineProperty(n,o,i)}}function N0(e,t,r){let n=Ae.Get().enumerableKind;for(let o of t)s.IsUnsafePropertyKey(o)||Object.defineProperty(r,o,{configurable:!0,writable:!0,enumerable:n,value:e[o]})}function q0(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 _0(e,t,r){Yt.update+=1;let n={},o=vt(t),i=vt(r);return j0(e,o,i,n),N0(t,o,n),q0(r,i,n),Vr(n)}function Hs(...e){let[t,r,n]=U.Match(e,{3:(f,d,g)=>[f,d,g],2:(f,d)=>[{},f,d]}),o=Gn(t,r),i=new Ze,a=ae(o,i,"#","",r,n),m=i.GetErrors(),c=Fl(),p=m.map(f=>({...f,message:c(f)}));return[a,p]}var Nl=0;function zs(){let e=Qi();Nl=e.maxErrors,e.maxErrors=e.maxParseErrors}function Ws(){let e=Qi();e.maxErrors=Nl}function _u(...e){let[t,r,n]=U.Match(e,{3:(a,m,c)=>[a,m,c],2:(a,m)=>[{},a,m]}),o=Gn(t,r),i=new ct;return Y(o,i,r,n)}function G(...e){let[t,r,n]=U.Match(e,{3:(o,i,a)=>[o,i,a],2:(o,i)=>[{},o,i]});return _u(t,r,n)}function Qt(...e){let[t,r,n]=U.Match(e,{3:(a,m,c)=>[a,m,c],2:(a,m)=>[{},a,m]}),[o,i]=Hs(t,r,n);return i}var Ar=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 Vs(...e){let[t,r,n]=U.Match(e,{3:(i,a,m)=>[i,a,m],2:(i,a)=>[{},i,a]});if(!G(t,r,n))throw new Ar("Assert",n,Qt(t,r,n))}function T(e,t){return s.IsObject(e)&&s.HasPropertyKey(e,"~kind")&&s.IsEqual(e["~kind"],t)}function le(e){return s.IsObject(e)}function C(e,t,r){return l.Create({"~kind":"Deferred"},{type:"deferred",action:e,parameters:t,options:r},{})}function Jr(e){return T(e,"Deferred")}function ur(e,t){return l.Update(e,{"~readonly":!0},t)}function ql(e,t,r,n){let o=b(e,t,r);return ur(o,n)}function cr(e,t){return l.Update(e,{"~optional":!0},t)}function _l(e,t,r,n){let o=b(e,t,r);return cr(o,n)}function xt(e,t){return l.Create({"~kind":"Array"},{type:"array",items:e},t)}function H(e){return T(e,"Array")}function Jn(e){return l.Discard(e,["~kind","type","items"])}function pr(e,t,r={}){return l.Create({"~kind":"Constructor"},{type:"constructor",parameters:e,instanceType:t},r)}function be(e){return T(e,"Constructor")}function Ul(e){return l.Discard(e,["~kind","type","parameters","instanceType"])}function fr(e,t,r={}){return l.Create({"~kind":"Function"},{type:"function",parameters:e,returnType:t},r)}function $e(e){return T(e,"Function")}function Bl(e){return l.Discard(e,["~kind","type","parameters","returnType"])}function _e(e,t){return l.Create({"~kind":"Ref"},{$ref:e},t)}function Z(e){return T(e,"Ref")}function Yr(e,t){return l.Create({"~kind":"Generic"},{type:"generic",parameters:e,expression:t})}function Yn(e){return T(e,"Generic")}function Qn(e){return l.Create({"~kind":"Any"},{},e)}function ye(e){return T(e,"Any")}var Gl="(?!)";function re(e){return l.Create({"~kind":"Never"},{not:{}},e)}function yt(e){return T(e,"Never")}function dr(e,t={}){return C("AddOptional",[e],t)}function Js(e,t={}){return cr(e,t)}function Kl(e){return Js(e)}function Oe(e){return le(e)&&s.HasPropertyKey(e,"~optional")}function Hl(e){return s.Keys(e).filter(t=>!Oe(e[t]))}function Ys(e){return s.Keys(e)}function Qs(e){return s.Values(e)}function O(e,t={}){let r=Hl(e),n=r.length>0?{required:r}:{};return l.Create({"~kind":"Object"},{type:"object",...n,properties:e},t)}function R(e){return T(e,"Object")}function zl(e){return l.Discard(e,["~kind","type","properties","required"])}function De(e){return l.Create({"~kind":"Unknown"},{},e)}function Me(e){return T(e,"Unknown")}function lr(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 ie(e){return T(e,"Cyclic")}function Wl(e){return l.Update(e,{"~unsafe":null},{})}function Xs(e){return s.IsObjectNotArray(e)&&s.HasPropertyKey(e,"~unsafe")&&s.IsNull(e["~unsafe"])}function Zo(...e){let[t,r]=U.Match(e,{2:(n,o)=>[n,o,o],1:n=>[n,De(),De()]});return l.Create({"~kind":"Infer"},{type:"infer",name:t,extends:r},{})}function ve(e){return T(e,"Infer")}function $n(e,t,r,n={}){return l.Create({"~kind":"Dependent"},{if:e,then:t,else:r},n)}function Ee(e){return T(e,"Dependent")}function Vl(e){return l.Discard(e,["~kind","if","then","else"])}function Jl(e){return s.IsObjectNotArray(e)}function Yl(e){return s.Keys(e).filter(r=>isNaN(r)).reduce((r,n)=>[...r,e[n]],[])}function Ql(e){return s.IsString(e)||s.IsNumber(e)}function Xl(e,t){let r=Jl(e)?Yl(e):e;return l.Create({"~kind":"Enum"},{enum:r},t)}function Se(e){return T(e,"Enum")}function ot(e,t={}){return l.Create({"~kind":"Intersect"},{allOf:e},t)}function P(e){return T(e,"Intersect")}function Zl(e){return l.Discard(e,["~kind","allOf"])}var ei=class{constructor(t,r){this.type=t,this.decode=r}Encode(t){let r=this.type,n=pt(r)?a=>this.decode(r["~codec"].decode(a)):this.decode,o=pt(r)?a=>r["~codec"].encode(t(a)):t,i={decode:n,encode:o};return l.Update(this.type,{"~codec":i},{})}},ti=class{constructor(t){this.type=t}Decode(t){return new ei(this.type,t)}};function Zs(e){return new ti(e)}function eg(e,t){return Zs(e).Decode(t).Encode(()=>{throw Error("Encode not implemented")})}function tg(e,t){return Zs(e).Decode(()=>{throw Error("Decode not implemented")}).Encode(t)}function pt(e){return le(e)&&s.HasPropertyKey(e,"~codec")&&s.IsObject(e["~codec"])&&s.HasPropertyKey(e["~codec"],"encode")&&s.HasPropertyKey(e["~codec"],"decode")}function rg(e){return Xn(e)}function En(e){return le(e)&&s.HasPropertyKey(e,"~immutable")}function gr(e,t={}){return C("AddReadonly",[e],t)}function ea(e,t={}){return ur(e,t)}function ng(e){return ea(e)}function Or(e){return le(e)&&s.HasPropertyKey(e,"~readonly")}function G0(e,t){let r=ri(e)?[...e["~refine"],t]:[t];return l.Update(e,{"~refine":r},{})}function og(...e){let[t,r,n]=U.Match(e,{3:(o,i,a)=>[o,i,a],2:(o,i)=>[o,i,()=>"Refine Error"]});return G0(t,{check:r,error:n})}function K0(e){return s.IsObjectNotArray(e)&&s.HasPropertyKey(e,"check")&&s.HasPropertyKey(e,"error")&&s.IsFunction(e.check)&&s.IsFunction(e.error)}function ri(e){return le(e)&&s.HasPropertyKey(e,"~refine")&&s.IsArray(e["~refine"])&&s.Every(e["~refine"],0,t=>K0(t))}var ig="-?(?:0|[1-9][0-9]*)n";function ni(e){return l.Create({"~kind":"BigInt"},{type:"bigint"},e)}function kt(e){return T(e,"BigInt")}function ta(e){return l.Create({"~kind":"Boolean"},{type:"boolean"},e)}function ft(e){return T(e,"Boolean")}function oi(e){return l.Create({"~kind":"Identifier"},{name:e})}function sg(e){return T(e,"Identifier")}var ra="-?(?:0|[1-9][0-9]*)";function Sn(e){return l.Create({"~kind":"Integer"},{type:"integer"},e)}function Be(e){return T(e,"Integer")}var Uu=class extends Error{constructor(t){super("Invalid Literal value"),Object.defineProperty(this,"cause",{value:{value:t},writable:!1,configurable:!1,enumerable:!1})}};function H0(e){return s.IsBigInt(e)?"bigint":s.IsBoolean(e)?"boolean":s.IsNumber(e)?"number":s.IsString(e)?"string":(()=>{throw new Uu(e)})()}function B(e,t){return l.Create({"~kind":"Literal"},{type:H0(e),const:e},t)}function na(e){return s.IsBigInt(e)||s.IsBoolean(e)||s.IsNumber(e)||s.IsString(e)}function ag(e){return K(e)&&s.IsBigInt(e.const)}function mg(e){return K(e)&&s.IsBoolean(e.const)}function oa(e){return K(e)&&s.IsNumber(e.const)}function ia(e){return K(e)&&s.IsString(e.const)}function K(e){return T(e,"Literal")}function Zn(e){return l.Create({"~kind":"Null"},{type:"null"},e)}function xr(e){return T(e,"Null")}var sa="-?(?:0|[1-9][0-9]*)(?:\\.[0-9]+)?";function Tt(e){return l.Create({"~kind":"Number"},{type:"number"},e)}function ge(e){return T(e,"Number")}function eo(e){return l.Create({"~kind":"Symbol"},{type:"symbol"},e)}function yr(e){return T(e,"Symbol")}function kn(...e){let[t,r,n]=U.Match(e,{3:(o,i,a)=>[o,i,a],2:(o,i)=>[o,i,i],1:o=>[o,De(),De()]});return l.Create({"~kind":"Parameter"},{name:t,extends:r,equals:n},{})}function ug(e){return T(e,"Parameter")}var aa=".*";function et(e){return l.Create({"~kind":"String"},{type:"string"},e)}function je(e){return T(e,"String")}function L(e,t={}){return l.Create({"~kind":"Union"},{anyOf:e},t)}function E(e){return T(e,"Union")}function cg(e){return l.Discard(e,["~kind","anyOf"])}function ii(e){let t=pg(e);return s.IsEqual(t.length,2)?t[0]:[]}function z0(e){return!0}function fg(e){return s.ShiftLeft(e,(t,r)=>W0(t)?fg(r):!1,()=>!0)}function dg(e){return s.IsEqual(e.length,0)?!1:fg(e)}function W0(e){return E(e)?dg(e.anyOf):K(e)?z0(e.const):!1}function ma(e){return dg(e)}function ua(e){return l.Create({"~kind":"TemplateLiteral"},{type:"string",pattern:e},{})}function lg(e,t,r=[]){return s.ShiftLeft(e,(n,o)=>lg(o,t,[...r,`${n}${t}`]),()=>r)}function V0(e,t){return s.IsEqual(e.length,0)?[`${t}`]:lg(e,t)}function gg(e,t,r=[]){return s.ShiftLeft(t,(n,o)=>gg(e,o,[...r,...xg(e,n)]),()=>r)}function xg(e,t){return E(t)?gg(e,t.anyOf):K(t)?V0(e,t.const):Ie()}function yg(e,t){return s.ShiftLeft(t,(r,n)=>yg(xg(e,r),n),()=>e)}function J0(e){return e.map(t=>B(t))}function Y0(e){let t=yg([],e),r=J0(t);return L(r)}function Q0(e){return s.IsEqual(e.length,0)?Ie():s.IsEqual(e.length,1)&&K(e[0])?e[0]:Y0(e)}function Bu(e){let t=ii(e);return s.IsEqual(t.length,0)?et():ma(t)?Q0(t):ua(e)}function to(e){let t=Bu(e);return se(t)?et():t}function ht(e,t){let r="object",n={[e]:t};return l.Create({"~kind":"Record"},{type:r,patternProperties:n})}function hg(e){return ht(Xt,e)}function Ig(e){return O({true:e,false:e})}function ke(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 N(e){return T(e,"Tuple")}function bg(e){return l.Discard(e,["~kind","type","items","minItems","additionalItems"])}function Gu(e){return e.reduceRight((r,n,o)=>({[o]:n,...r}),{})}function $g(e){let t=Gu(e.items);return O(t)}function X0(e){return l.Discard(e,["~optional"])}function Tn(e,t){return l.Update(X0(e),{},t)}function Eg(e,t,r,n){let o=b(e,t,r);return Tn(o,n)}function Z0(e){return l.Discard(e,["~readonly"])}function ro(e,t){return l.Update(Z0(e),{},t)}function Sg(e,t,r,n){let o=b(e,t,r);return ro(o,n)}function ca(e,t){let r=Or(e)&&Or(t),n=Oe(e)&&Oe(t),o=Te([e,t]),i=ro(Tn(o,{}),{});return r&&n?ur(cr(i,{}),{}):r?ur(i,{}):n?cr(i,{}):i}function kg(e,t){let r=Or(e)||Or(t),n=Oe(e)||Oe(t),o=ro(Tn(e,{}),{}),i=ro(Tn(t,{}),{}),a=It([o,i]);return r&&n?ur(cr(a,{}),{}):r?ur(a,{}):n?cr(a,{}):a}function eP(e,t,r){return r in e?r in t?ca(e[r],t[r]):e[r]:r in t?t[r]:re()}function tP(e,t){return[...new Set([...s.Keys(e),...s.Keys(t)])].reduce((o,i)=>({...o,[i]:eP(e,t,i)}),{})}function Tg(e){return R(e)?e.properties:N(e)?Gu(e.items):{}}function Cg(e,t){let r=Tg(e),n=Tg(t),o=tP(r,n);return O(o)}function rP(e,t){let r=no(e,t);return s.IsEqual(r,ai)?e:s.IsEqual(r,mi)||s.IsEqual(r,si)?t:re()}function wg(e){return R(e)||N(e)}function nP(e,t){let r=wg(e),n=wg(t);return r&&n?Cg(e,t):r&&!n?e:!r&&n?t:rP(e,t)}function Rg(e,t){return yt(e)||ye(e)?e:Me(e)||yt(t)||ye(t)?t:Me(t)?e:nP(e,t)}function oP(e,t){return E(e)||E(t)}function iP(e,t){let r=Bt(e),n=Bt(t);return oP(r,n)?Te([r,n]):Rg(r,n)}function Pg(e,t,r=[]){return s.ShiftLeft(t,(n,o)=>Pg(e,o,[...r,iP(n,e)]),()=>s.IsEqual(r.length,0)?[e]:r)}function Ag(e,t,r=[]){return s.ShiftLeft(e,(n,o)=>Ag(o,t,[...r,...ui([n],t)]),()=>r)}function ui(e,t=[]){return s.ShiftLeft(e,(r,n)=>E(r)?ui(n,Ag(r.anyOf,t)):ui(n,Pg(r,t)),()=>t)}function sP(e,t){let r=tt({},e,t);return v.IsExtendsTrueLike(r)?[]:[e]}function Og(e,t,r=[]){return s.ShiftLeft(e,(n,o)=>Og(o,t,[...r,...sP(n,t)]),()=>r)}function pa(e,t){let r=Bt(e),n=E(r)?r.anyOf:[r],o=Og(n,t);return It(o)}function Zt(e,t,r){let n=Te([e,t]),o=pa(r,e);return It([n,o])}function dt(e,t=[]){return s.ShiftLeft(e,(r,n)=>dt(n,[...t,B(r)]),()=>It(t))}function Te(e){let t=ui(e),r=Ku(t);return It(r)}function it(e){let t=to(e);return Bt(t)}function It(e){let t=Ku(e);return Qr(t)}function Bt(e){return Ee(e)?Zt(e.if,e.then,e.else):Se(e)?dt(e.enum):P(e)?Te(e.allOf):se(e)?it(e.pattern):E(e)?It(e.anyOf):e}function Qr(e){return s.IsEqual(e.length,1)?e[0]:s.IsEqual(e.length,0)?re():L(e)}function Mg(e,t){let r=dt(e);return Xr(r,t)}function vg(e,t){return ht(Zr,t)}function Fg(e,t){let r=Te(e);return Xr(r,t)}function Lg(e,t){return s.IsString(e)||s.IsNumber(e)?O({[e]:t}):s.IsEqual(e,!1)?O({false:t}):s.IsEqual(e,!0)?O({true:t}):O({})}function Dg(e,t){return ht(oo,t)}function jg(e,t){return s.HasPropertyKey(e,"pattern")&&(s.IsString(e.pattern)||e.pattern instanceof RegExp)?ht(e.pattern.toString(),t):ht(Xt,t)}function Ng(e,t){let r=ii(e);return ma(r)?Xr(it(e),t):ht(e,t)}function aP(e){return E(e)?en(e.anyOf):[e]}function en(e,t=[]){return s.ShiftLeft(e,(r,n)=>en(n,[...t,...aP(r)]),()=>t)}function mP(e){return e.some(t=>je(t)||ge(t)||Be(t))}function uP(e,t){return s.IsEqual(mP(e),!0)?ht(Xt,t):void 0}function cP(e,t){return e.reduce((r,n)=>K(n)&&(s.IsString(n.const)||s.IsNumber(n.const))?{...r,[n.const]:t}:r,{})}function pP(e,t){let r=cP(e,t);return O(r)}function qg(e,t){let r=en(e),n=uP(r,t);return le(n)?n:pP(r,t)}function Xr(e,t){return ye(e)?hg(t):ft(e)?Ig(t):Se(e)?Mg(e.enum,t):Be(e)?vg(e,t):P(e)?Fg(e.allOf,t):K(e)?Lg(e.const,t):ge(e)?Dg(e,t):E(e)?qg(e.anyOf,t):je(e)?jg(e,t):se(e)?Ng(e.pattern,t):O({})}function Hu(e,t,r){return q([e])?l.Update(Xr(e,t),{},r):fa(e,t,r)}function _g(e,t,r,n,o){let i=b(e,t,r),a=b(e,t,n);return Hu(i,a,o)}var Zr=`^${ra}$`,oo=`^${sa}$`,Xt=`^${aa}$`;function fa(e,t,r={}){return C("Record",[e,t],r)}function io(e,t,r={}){return Hu(e,t,r)}function Ug(e,t){return ht(e,t)}function da(e){return s.IsEqual(e,Xt)?et():s.IsEqual(e,Zr)?Sn():s.IsEqual(e,oo)?Tt():Bu(e)}function Fe(e){return s.Keys(e.patternProperties)[0]}function so(e){let t=Fe(e);return da(t)}function me(e){return e.patternProperties[Fe(e)]}function te(e){return T(e,"Record")}function Cn(e){return l.Create({"~kind":"Rest"},{type:"rest",items:e},{})}function tn(e){return T(e,"Rest")}function la(e){return l.Create({"~kind":"This"},{$ref:"#"},e)}function ga(e){return T(e,"This")}function ao(e){return l.Create({"~kind":"Undefined"},{type:"undefined"},e)}function Gt(e){return T(e,"Undefined")}function xa(e){return l.Create({"~kind":"Void"},{type:"void"},e)}function Ct(e){return T(e,"Void")}function dP(e,t){return s.IsEqual(e,"Array")?xt(t[0]):s.IsEqual(e,"Capitalize")?ha(t[0]):s.IsEqual(e,"ConstructorParameters")?Sa(t[0]):s.IsEqual(e,"Evaluate")?Ky(t[0]):s.IsEqual(e,"Exclude")?ka(t[0],t[1]):s.IsEqual(e,"Extract")?Ta(t[0],t[1]):s.IsEqual(e,"Index")?di(t[0],t[1]):s.IsEqual(e,"InstanceType")?Ca(t[0]):s.IsEqual(e,"Lowercase")?Ia(t[0]):s.IsEqual(e,"NonNullable")?wa(t[0]):s.IsEqual(e,"Omit")?Ra(t[0],t[1]):s.IsEqual(e,"Parameters")?Pa(t[0]):s.IsEqual(e,"Partial")?Aa(t[0]):s.IsEqual(e,"Pick")?Oa(t[0],t[1]):s.IsEqual(e,"Readonly")?Ma(t[0]):s.IsEqual(e,"KeyOf")?li(t[0]):s.IsEqual(e,"Record")?fa(t[0],t[1]):s.IsEqual(e,"Required")?va(t[0]):s.IsEqual(e,"ReturnType")?Fa(t[0]):s.IsEqual(e,"Uncapitalize")?ba(t[0]):s.IsEqual(e,"Uppercase")?$a(t[0]):fi(_e(e),t)}function wn(){throw Error("Unreachable")}function zg(e,t=[]){return s.ShiftLeft(e,(r,n)=>zg(n,[...t,r[1]]),()=>t)}function Mr(e){return s.IsEqual(e.length,3)?[e[0],...zg(e[1])]:[]}function Wg(e){return kn(e[0],e[2],e[4])}function Vg(e){return kn(e[0],e[2],e[2])}function Jg(e){return kn(e[0],De(),e[2])}function Yg(e){return kn(e,De(),De())}function Qg(e){return Mr(e)}function Xg(e){return e[1]}function Zg(e){return Mr(e)}function ex(e){return e[1]}function tx(e){return dP(e[0],e[1])}function rx(e){return null}function nx(e){return et()}function ox(e){return Tt()}function ix(e){return ta()}function sx(e){return ao()}function ax(e){return Zn()}function mx(e){return Sn()}function ux(e){return ni()}function cx(e){return De()}function px(e){return Qn()}function fx(e){return O({})}function dx(e){return re()}function lx(e){return eo()}function gx(e){return xa()}function xx(e){return la()}function yx(e){return B(BigInt(e))}function hx(e){return B(s.IsEqual(e,"true"))}function Ix(e){return B(parseFloat(e))}function bx(e){return B(e)}function $x(e){return e[1]}function Ex(e){return B(e)}function Sx(e){return s.IsEqual(e.length,3)?[e[0],e[1],...e[2]]:[e[0]]}function kx(e){return e[1]}function Tx(e){return ya(e)}function Cx(e){return s.IsEqual(e.length,6)?$n(e[1],e[3],e[5]):$n(e[1],e[3],De())}function wx(e){return e.length>0}function Rx(e){return e.reduce((t,r)=>s.IsEqual(r.length,3)?[...t,[r[1]]]:[...t,[]],[])}function Px(e){return s.IsEqual(e.length,6)?[e[1],e[3],e[5]]:[]}function Ax(e){return s.IsArray(e)&&s.IsEqual(e.length,3)?e[1]:e}function Ox(e){return s.IsEqual(e.length,2)?e[1]:[]}function Bg(e,t){return t.reduce((r,n)=>{let o=n;return s.IsEqual(o.length,1)?di(r,o[0]):s.IsEqual(o.length,0)?xt(r):wn()},e)}function Gg(e,t){return s.IsEqual(t.length,3)?Ea(e,t[0],t[1],t[2]):e}function lP(e,t){return s.IsArray(t)&&s.IsEqual(t.length,0)?e:La(e,t)}function Mx(e){let[t,r,n,o,i]=e;return lP(Gg(t?li(Bg(r,n)):Bg(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 P(i)?ot([e,...i.allOf]):ot([e,i]);if(s.IsEqual(r,"|"))return E(i)?L([e,...i.anyOf]):L([e,i]);wn()})():e}function vx(e){let[t,r]=e;return zu(t,r)}function Fx(e){let[t,r]=e;return zu(t,r)}function Lx(e){return By(e[1])}function Dx(e){return e[1]}function jx(e){return Yr(e[0],e[2])}function Nx(e){return s.IsEqual(e.length,4)?Zo(e[1],e[3]):s.IsEqual(e.length,2)?Zo(e[1],De()):wn()}function qx(e){return`${e}`}function _x(e){return Be(e[3])?Zr:ge(e[3])?oo:yr(e[3])?Xt:je(e[3])?Xt:wn()}function Ux(e){return e.length>0}function Bx(e){return e.length>0}function Gx(e){let[t,r,n,o,i]=e;return{[r]:t&&n?gr(dr(i)):t&&!n?gr(i):!t&&n?dr(i):i}}function Kx(e){return Mr(e)}function Hx(e){return e.reduce((t,r)=>s.HasPropertyKey(r,Zr)||s.HasPropertyKey(r,oo)||s.HasPropertyKey(r,Xt)?[t[0],l.Assign(t[1],r)]:[l.Assign(t[0],r),t[1]],[{},{}])}function zx(e){return Hx(e[1])}function Wx(e){let[t,r]=e,n=s.IsEqual(s.Keys(r).length,0)?{}:{patternProperties:r};return O(t,n)}function Vx(e){return s.IsEqual(e.length,5)?gr(dr(e[4])):s.IsEqual(e.length,3)?e[2]:s.IsEqual(e.length,4)?s.IsEqual(e[2],"readonly")?gr(e[3]):dr(e[3]):wn()}function Jx(e){if(!s.IsArray(e)||!s.IsEqual(e.length,3))return e;let[t,r,n]=e;return t&&n?gr(dr(r)):t&&!n?gr(r):!t&&n?dr(r):r}function Yx(e){return s.IsEqual(e.length,2)?Cn(e[1]):s.IsEqual(e.length,1)?e[0]:wn()}function Qx(e){return Mr(e)}function Xx(e){return ke(e[1])}function Zx(e){return gr(dr(e[4]))}function ey(e){return gr(e[3])}function ty(e){return dr(e[3])}function ry(e){return e[2]}function ny(e){return s.IsEqual(e.length,2)?Cn(e[1]):s.IsEqual(e.length,1)?e[0]:wn()}function oy(e){return Mr(e)}function iy(e){return fr(e[1],e[4])}function sy(e){return pr(e[2],e[5])}function Kg(e,t){return s.IsEqual(e,"remove")?Gy(t):s.IsEqual(e,"add")?gr(t):t}function ay(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 Hg(e,t){return s.IsEqual(e,"remove")?Uy(t):s.IsEqual(e,"add")?dr(t):t}function my(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 uy(e){return s.IsEqual(e.length,2)?[e[1]]:[]}function cy(e){return s.IsArray(e[6])&&s.IsEqual(e[6].length,1)?ci(oi(e[3]),e[5],e[6][0],Kg(e[1],Hg(e[8],e[10]))):ci(oi(e[3]),e[5],_e(e[3]),Kg(e[1],Hg(e[8],e[10])))}function py(e){return _e(e)}function fy(e){return BigInt(e)}function dy(e){return parseFloat(e)}function ly(e){return s.IsEqual(e,"true")}function gy(e){return null}function xy(e){return{[e[0]]:e[2]}}function yy(e){return Mr(e)}function gP(e){return e.reduce((t,r)=>l.Assign(t,r),{})}function hy(e){return gP(e[1])}function Iy(e){return Mr(e)}function by(e){return e[1]}function $y(e){return ni()}function Ey(e){return et()}function Sy(e){return Tt()}function ky(e){return Sn()}function Ty(e){return re()}function Cy(e){return B(e)}function wy(e){return L(e[1])}function Ry(e){return e.length===3?[...e[0],...e[2]]:e.length===1?[...e[0]]:[]}function Py(e){return[e[0],...e[1]]}function Ay(e){return e[1]}function Oy(e){return Mr(e)}function My(e){return s.IsEqual(e.length,2)?e[1]:[]}function vy(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]]:Yr(t,pi(r,n,i))}}function Fy(e){let t=e[2],[r,n]=e[3],o=s.IsEqual(s.Keys(n).length,0)?{}:{patternProperties:n};return{[e[1]]:pi(t,r,o)}}function Ly(e){return{[e[1]]:Yr(e[2],e[4])}}function Dy(e){return{[e[1]]:e[3]}}function jy(e){return null}function Ny(e){return Mr(e)}function qy(e){return e[1]}function _y(e){let[t,r]=[e[0],e[1]];return Hy(l.Assign(t,Hx(r)[0]))}function gi(e){return J(e.length,2)}function z(e,t,r){return gi(e)?t(e[0],e[1]):r()}function hP(e,t){return J(t.indexOf(e),0)?[e,t.slice(e.length)]:[]}function he(e,t){for(let r=0;r<e.length;r++){let n=hP(e[r],t);if(gi(n))return n}return[]}function Wu(e,t){return Array.from({length:t-e+1},(r,n)=>String.fromCharCode(e+n))}var zy=[...Wu(97,122),...Wu(65,90)],Vu="0",Ju=Wu(49,57),mo=[Vu,...Ju],Wy=" ",uo=`
2
+ `;var rn="_",Da=".",Vy="$",ja="-";var Jy="//",Yy="/*",bP="*/";function Qy(e){let t=e.indexOf(bP);return J(t,-1)?"":e.slice(t+2)}function Xy(e){let t=e.indexOf(uo);return J(t,-1)?"":e.slice(t)}function $P(e){return e.replace(/^[ \t\r\f\v]+/,"")}function Na(e){let t=$P(e);return t.startsWith(Yy)?Na(Qy(t.slice(2))):t.startsWith(Jy)?Na(Xy(t.slice(2))):t}function Je(e){let t=e.trimStart();return t.startsWith(Yy)?Je(Qy(t.slice(2))):t.startsWith(Jy)?Je(Xy(t.slice(2))):t}function qa(e,t){return z(he([e],t),(r,n)=>[r,n],()=>["",t])}function EP(e,t){return e.includes(t)}function co(e,t,r,n=""){return z(he(e,r),(o,i)=>EP(t,o)?co(e,t,i,n):co(e,t,i,`${n}${o}`),()=>[n,r])}function SP(e){return he(Ju,e)}var kP=[...mo,rn];function TP(e){return co(kP,[rn],e)}function CP(e){return z(he([Vu],e),(t,r)=>[t,r],()=>z(SP(e),(t,r)=>z(TP(r),(n,o)=>[`${t}${n}`,o],()=>[]),()=>[]))}function _a(e){return CP(Je(e))}function wP(e){return qa(ja,e)}function RP(e){return z(wP(e),(t,r)=>z(_a(r),(n,o)=>[`${t}${n}`,o],()=>[]),()=>[])}function Zy(e){return RP(Je(e))}function PP(e){return z(Zy(e),(t,r)=>z(he(["n"],r),(n,o)=>[`${t}`,o],()=>[]),()=>[])}function Yu(e){return PP(e)}function Qu(e,t){return he([e],t)}function y(e,t){return J(e,"")?["",t]:e.startsWith(uo)?Qu(e,Na(t)):e.startsWith(Wy)?Qu(e,t):Qu(e,Je(t))}var eh=[...zy,rn,Vy];function AP(e){return he(eh,e)}var OP=[...eh,...mo];function th(e,t=""){return z(he(OP,e),(r,n)=>th(n,`${t}${r}`),()=>[t,e])}function MP(e){return z(AP(e),(t,r)=>z(th(r),(n,o)=>[`${t}${n}`,o],()=>[]),()=>[])}function Ce(e){return MP(Je(e))}var vP=[...mo,rn];function FP(e){return gi(he([Da],e))}function rh(e){return z(co(vP,[rn],e),(t,r)=>J(t,"")?[]:[t,r],()=>[])}function LP(e){return z(he([Da],e),(t,r)=>z(rh(r),(n,o)=>[`0${t}${n}`,o],()=>[]),()=>[])}function DP(e){return z(_a(e),(t,r)=>z(he([Da],r),(n,o)=>z(rh(o),(i,a)=>[`${t}${n}${i}`,a],()=>[`${t}`,o]),()=>[`${t}`,r]),()=>[])}function jP(e){return FP(e)?LP(e):DP(e)}function nh(e){return jP(Je(e))}function NP(e){return qa(ja,e)}function qP(e){return z(NP(e),(t,r)=>z(nh(r),(n,o)=>[`${t}${n}`,o],()=>[]),()=>[])}function Ua(e){return qP(Je(e))}function _P(e){return J(e,"")?[]:[e.slice(0,1),e.slice(1)]}function oh(e,t){return Yi(e,(r,n)=>t.startsWith(r)?!0:oh(n,t),()=>!1)}function nn(e,t,r=""){return z(_P(t),(n,o)=>oh(e,t)?[r,t]:nn(e,o,`${r}${n}`),()=>[])}function UP(e,t,r){return z(he([e],r),(n,o)=>z(nn([t],o),(i,a)=>z(he([t],a),(m,c)=>[`${i}`,c],()=>[]),()=>[]),()=>[])}function BP(e,t,r){return z(he([e],r),(n,o)=>z(nn([uo,t],o),(i,a)=>z(he([t],a),(m,c)=>[`${i}`,c],()=>[]),()=>[]),()=>[])}function ih(e,t,r,n){return r?UP(e,t,Je(n)):BP(e,t,Je(n))}function GP(e,t){return he(e,t)}function KP(e,t){return ih(e,e,!1,t)}function HP(e,t){return z(GP(e,t),(r,n)=>KP(r,`${r}${n}`),()=>[])}function Ba(e,t){return HP(e,Je(t))}function sh(e,t){return z(nn(e,t),(r,n)=>J(r,"")?[]:[r,n],()=>[])}var u=(e,t,r=()=>[])=>e.length===2?t(e):r(),WP=e=>u(u(Ce(e),([t,r])=>u(y("extends",r),([n,o])=>u(Q(o),([i,a])=>u(y("=",a),([m,c])=>u(Q(c),([p,f])=>[[t,n,i,m,p],f]))))),([t,r])=>[Wg(t),r]),VP=e=>u(u(Ce(e),([t,r])=>u(y("extends",r),([n,o])=>u(Q(o),([i,a])=>[[t,n,i],a]))),([t,r])=>[Vg(t),r]),JP=e=>u(u(Ce(e),([t,r])=>u(y("=",r),([n,o])=>u(Q(o),([i,a])=>[[t,n,i],a]))),([t,r])=>[Jg(t),r]),YP=e=>u(Ce(e),([t,r])=>[Yg(t),r]),uh=e=>u(u(WP(e),([t,r])=>[t,r],()=>u(VP(e),([t,r])=>[t,r],()=>u(JP(e),([t,r])=>[t,r],()=>u(YP(e),([t,r])=>[t,r],()=>[])))),([t,r])=>[t,r]),ch=(e,t=[])=>u(u(y(",",e),([r,n])=>u(uh(n),([o,i])=>[[r,o],i])),([r,n])=>ch(n,[...t,r]),()=>[t,e]),QP=e=>u(u(u(uh(e),([t,r])=>u(ch(r),([n,o])=>u(u(y(",",o),([i,a])=>[[i],a],()=>[[],o]),([i,a])=>[[t,n,i],a]))),([t,r])=>[t,r],()=>u([[],e],([t,r])=>[t,r],()=>[])),([t,r])=>[Qg(t),r]),ec=e=>u(u(y("<",e),([t,r])=>u(QP(r),([n,o])=>u(y(">",o),([i,a])=>[[t,n,i],a]))),([t,r])=>[Xg(t),r]),ph=(e,t=[])=>u(u(y(",",e),([r,n])=>u(Q(n),([o,i])=>[[r,o],i])),([r,n])=>ph(n,[...t,r]),()=>[t,e]),XP=e=>u(u(u(Q(e),([t,r])=>u(ph(r),([n,o])=>u(u(y(",",o),([i,a])=>[[i],a],()=>[[],o]),([i,a])=>[[t,n,i],a]))),([t,r])=>[t,r],()=>u([[],e],([t,r])=>[t,r],()=>[])),([t,r])=>[Zg(t),r]),ZP=e=>u(u(y("<",e),([t,r])=>u(XP(r),([n,o])=>u(y(">",o),([i,a])=>[[t,n,i],a]))),([t,r])=>[ex(t),r]),eA=e=>u(u(Ce(e),([t,r])=>u(ZP(r),([n,o])=>[[t,n],o])),([t,r])=>[tx(t),r]),fh=e=>u(u(u(y(";",e),([t,r])=>[[t],r]),([t,r])=>[t,r],()=>u([[],e],([t,r])=>[t,r],()=>[])),([t,r])=>[rx(t),r]),dh=e=>u(y("string",e),([t,r])=>[nx(t),r]),lh=e=>u(y("number",e),([t,r])=>[ox(t),r]),tA=e=>u(y("boolean",e),([t,r])=>[ix(t),r]),rA=e=>u(y("undefined",e),([t,r])=>[sx(t),r]),nA=e=>u(y("null",e),([t,r])=>[ax(t),r]),gh=e=>u(y("integer",e),([t,r])=>[mx(t),r]),oA=e=>u(y("bigint",e),([t,r])=>[ux(t),r]),iA=e=>u(y("unknown",e),([t,r])=>[cx(t),r]),sA=e=>u(y("any",e),([t,r])=>[px(t),r]),aA=e=>u(y("object",e),([t,r])=>[fx(t),r]),mA=e=>u(y("never",e),([t,r])=>[dx(t),r]),xh=e=>u(y("symbol",e),([t,r])=>[lx(t),r]),uA=e=>u(y("void",e),([t,r])=>[gx(t),r]),cA=e=>u(y("this",e),([t,r])=>[xx(t),r]),pA=e=>u(u(y("${",e),([t,r])=>u(Q(r),([n,o])=>u(y("}",o),([i,a])=>[[t,n,i],a]))),([t,r])=>[$x(t),r]),Xu=e=>u(nn(["${","`"],e),([t,r])=>[Ex(t),r]),yh=e=>u(u(u(Xu(e),([t,r])=>u(pA(r),([n,o])=>u(yh(o),([i,a])=>[[t,n,i],a]))),([t,r])=>[t,r],()=>u(u(Xu(e),([t,r])=>[[t],r]),([t,r])=>[t,r],()=>u(u(Xu(e),([t,r])=>[[t],r]),([t,r])=>[t,r],()=>[]))),([t,r])=>[Sx(t),r]),tc=e=>u(u(y("`",e),([t,r])=>u(yh(r),([n,o])=>u(y("`",o),([i,a])=>[[t,n,i],a]))),([t,r])=>[kx(t),r]),fA=e=>u(tc(e),([t,r])=>[Tx(t),r]),dA=e=>u(u(u(y("if",e),([t,r])=>u(Q(r),([n,o])=>u(y("then",o),([i,a])=>u(Q(a),([m,c])=>u(y("else",c),([p,f])=>u(Q(f),([d,g])=>[[t,n,i,m,p,d],g])))))),([t,r])=>[t,r],()=>u(u(y("if",e),([t,r])=>u(Q(r),([n,o])=>u(y("then",o),([i,a])=>u(Q(a),([m,c])=>[[t,n,i,m],c])))),([t,r])=>[t,r],()=>[])),([t,r])=>[Cx(t),r]),lA=e=>u(Yu(e),([t,r])=>[yx(t),r]),gA=e=>u(u(y("true",e),([t,r])=>[t,r],()=>u(y("false",e),([t,r])=>[t,r],()=>[])),([t,r])=>[hx(t),r]),xA=e=>u(Ua(e),([t,r])=>[Ix(t),r]),yA=e=>u(Ba(["'",'"'],e),([t,r])=>[bx(t),r]),hA=e=>u(u(u(y("keyof",e),([t,r])=>[[t],r]),([t,r])=>[t,r],()=>u([[],e],([t,r])=>[t,r],()=>[])),([t,r])=>[wx(t),r]),hh=(e,t=[])=>u(u(u(y("[",e),([r,n])=>u(Q(n),([o,i])=>u(y("]",i),([a,m])=>[[r,o,a],m]))),([r,n])=>[r,n],()=>u(u(y("[",e),([r,n])=>u(y("]",n),([o,i])=>[[r,o],i])),([r,n])=>[r,n],()=>[])),([r,n])=>hh(n,[...t,r]),()=>[t,e]),IA=e=>u(hh(e),([t,r])=>[Rx(t),r]),bA=e=>u(u(u(y("extends",e),([t,r])=>u(Q(r),([n,o])=>u(y("?",o),([i,a])=>u(Q(a),([m,c])=>u(y(":",c),([p,f])=>u(Q(f),([d,g])=>[[t,n,i,m,p,d],g])))))),([t,r])=>[t,r],()=>u([[],e],([t,r])=>[t,r],()=>[])),([t,r])=>[Px(t),r]),$A=e=>u(u(u(y("(",e),([t,r])=>u(Q(r),([n,o])=>u(y(")",o),([i,a])=>[[t,n,i],a]))),([t,r])=>[t,r],()=>u(dh(e),([t,r])=>[t,r],()=>u(lh(e),([t,r])=>[t,r],()=>u(tA(e),([t,r])=>[t,r],()=>u(rA(e),([t,r])=>[t,r],()=>u(nA(e),([t,r])=>[t,r],()=>u(gh(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],()=>u(aA(e),([t,r])=>[t,r],()=>u(mA(e),([t,r])=>[t,r],()=>u(xh(e),([t,r])=>[t,r],()=>u(uA(e),([t,r])=>[t,r],()=>u(cA(e),([t,r])=>[t,r],()=>u(lA(e),([t,r])=>[t,r],()=>u(gA(e),([t,r])=>[t,r],()=>u(xA(e),([t,r])=>[t,r],()=>u(yA(e),([t,r])=>[t,r],()=>u(fA(e),([t,r])=>[t,r],()=>u(dA(e),([t,r])=>[t,r],()=>u(MA(e),([t,r])=>[t,r],()=>u(LA(e),([t,r])=>[t,r],()=>u(UA(e),([t,r])=>[t,r],()=>u(_A(e),([t,r])=>[t,r],()=>u(HA(e),([t,r])=>[t,r],()=>u(eA(e),([t,r])=>[t,r],()=>u(zA(e),([t,r])=>[t,r],()=>[])))))))))))))))))))))))))))),([t,r])=>[Ax(t),r]),EA=e=>u(u(u(y("with",e),([t,r])=>u(Lh(r),([n,o])=>[[t,n],o])),([t,r])=>[t,r],()=>u([[],e],([t,r])=>[t,r],()=>[])),([t,r])=>[Ox(t),r]),Ih=e=>u(u(hA(e),([t,r])=>u($A(r),([n,o])=>u(IA(o),([i,a])=>u(bA(a),([m,c])=>u(EA(c),([p,f])=>[[t,n,i,m,p],f]))))),([t,r])=>[Mx(t),r]),bh=e=>u(u(u(y("&",e),([t,r])=>u(Ih(r),([n,o])=>u(bh(o),([i,a])=>[[t,n,i],a]))),([t,r])=>[t,r],()=>u([[],e],([t,r])=>[t,r],()=>[])),([t,r])=>[t,r]),$h=e=>u(u(Ih(e),([t,r])=>u(bh(r),([n,o])=>[[t,n],o])),([t,r])=>[vx(t),r]),Eh=e=>u(u(u(y("|",e),([t,r])=>u($h(r),([n,o])=>u(Eh(o),([i,a])=>[[t,n,i],a]))),([t,r])=>[t,r],()=>u([[],e],([t,r])=>[t,r],()=>[])),([t,r])=>[t,r]),Ga=e=>u(u($h(e),([t,r])=>u(Eh(r),([n,o])=>[[t,n],o])),([t,r])=>[Fx(t),r]),SA=e=>u(u(y("readonly",e),([t,r])=>u(Ga(r),([n,o])=>[[t,n],o])),([t,r])=>[Lx(t),r]),kA=e=>u(u(y("|",e),([t,r])=>u(Ga(r),([n,o])=>[[t,n],o])),([t,r])=>[Dx(t),r]),TA=e=>u(u(ec(e),([t,r])=>u(y("=",r),([n,o])=>u(Q(o),([i,a])=>[[t,n,i],a]))),([t,r])=>[jx(t),r]),CA=e=>u(u(u(y("infer",e),([t,r])=>u(Ce(r),([n,o])=>u(y("extends",o),([i,a])=>u(Ga(a),([m,c])=>[[t,n,i,m],c])))),([t,r])=>[t,r],()=>u(u(y("infer",e),([t,r])=>u(Ce(r),([n,o])=>[[t,n],o])),([t,r])=>[t,r],()=>[])),([t,r])=>[Nx(t),r]),Q=e=>u(u(CA(e),([t,r])=>[t,r],()=>u(kA(e),([t,r])=>[t,r],()=>u(SA(e),([t,r])=>[t,r],()=>u(Ga(e),([t,r])=>[t,r],()=>[])))),([t,r])=>[t,r]),wA=e=>u(Ua(e),([t,r])=>[qx(t),r]),RA=e=>u(Ce(e),([t,r])=>[t,r]),PA=e=>u(Ba(["'",'"'],e),([t,r])=>[t,r]),AA=e=>u(u(y("[",e),([t,r])=>u(Ce(r),([n,o])=>u(y(":",o),([i,a])=>u(u(gh(a),([m,c])=>[m,c],()=>u(lh(a),([m,c])=>[m,c],()=>u(dh(a),([m,c])=>[m,c],()=>u(xh(a),([m,c])=>[m,c],()=>[])))),([m,c])=>u(y("]",c),([p,f])=>[[t,n,i,m,p],f]))))),([t,r])=>[_x(t),r]),Sh=e=>u(u(wA(e),([t,r])=>[t,r],()=>u(RA(e),([t,r])=>[t,r],()=>u(PA(e),([t,r])=>[t,r],()=>u(AA(e),([t,r])=>[t,r],()=>[])))),([t,r])=>[t,r]),kh=e=>u(u(u(y("readonly",e),([t,r])=>[[t],r]),([t,r])=>[t,r],()=>u([[],e],([t,r])=>[t,r],()=>[])),([t,r])=>[Ux(t),r]),Th=e=>u(u(u(y("?",e),([t,r])=>[[t],r]),([t,r])=>[t,r],()=>u([[],e],([t,r])=>[t,r],()=>[])),([t,r])=>[Bx(t),r]),Ch=e=>u(u(kh(e),([t,r])=>u(Sh(r),([n,o])=>u(Th(o),([i,a])=>u(y(":",a),([m,c])=>u(Q(c),([p,f])=>[[t,n,i,m,p],f]))))),([t,r])=>[Gx(t),r]),Ka=e=>u(u(u(y(",",e),([t,r])=>u(y(`
3
+ `,r),([n,o])=>[[t,n],o])),([t,r])=>[t,r],()=>u(u(y(";",e),([t,r])=>u(y(`
4
+ `,r),([n,o])=>[[t,n],o])),([t,r])=>[t,r],()=>u(u(y(",",e),([t,r])=>[[t],r]),([t,r])=>[t,r],()=>u(u(y(";",e),([t,r])=>[[t],r]),([t,r])=>[t,r],()=>u(u(y(`
5
+ `,e),([t,r])=>[[t],r]),([t,r])=>[t,r],()=>[]))))),([t,r])=>[t,r]),wh=(e,t=[])=>u(u(Ka(e),([r,n])=>u(Ch(n),([o,i])=>[[r,o],i])),([r,n])=>wh(n,[...t,r]),()=>[t,e]),OA=e=>u(u(u(Ch(e),([t,r])=>u(wh(r),([n,o])=>u(u(Ka(o),([i,a])=>[[i],a],()=>[[],o]),([i,a])=>[[t,n,i],a]))),([t,r])=>[t,r],()=>u([[],e],([t,r])=>[t,r],()=>[])),([t,r])=>[Kx(t),r]),rc=e=>u(u(y("{",e),([t,r])=>u(OA(r),([n,o])=>u(y("}",o),([i,a])=>[[t,n,i],a]))),([t,r])=>[zx(t),r]),MA=e=>u(rc(e),([t,r])=>[Wx(t),r]),vA=e=>u(u(u(Ce(e),([t,r])=>u(y("?",r),([n,o])=>u(y(":",o),([i,a])=>u(y("readonly",a),([m,c])=>u(Q(c),([p,f])=>[[t,n,i,m,p],f]))))),([t,r])=>[t,r],()=>u(u(Ce(e),([t,r])=>u(y(":",r),([n,o])=>u(y("readonly",o),([i,a])=>u(Q(a),([m,c])=>[[t,n,i,m],c])))),([t,r])=>[t,r],()=>u(u(Ce(e),([t,r])=>u(y("?",r),([n,o])=>u(y(":",o),([i,a])=>u(Q(a),([m,c])=>[[t,n,i,m],c])))),([t,r])=>[t,r],()=>u(u(Ce(e),([t,r])=>u(y(":",r),([n,o])=>u(Q(o),([i,a])=>[[t,n,i],a]))),([t,r])=>[t,r],()=>[])))),([t,r])=>[Vx(t),r]),ah=e=>u(u(vA(e),([t,r])=>[t,r],()=>u(u(kh(e),([t,r])=>u(Q(r),([n,o])=>u(Th(o),([i,a])=>[[t,n,i],a]))),([t,r])=>[t,r],()=>[])),([t,r])=>[Jx(t),r]),Rh=e=>u(u(u(y("...",e),([t,r])=>u(ah(r),([n,o])=>[[t,n],o])),([t,r])=>[t,r],()=>u(u(ah(e),([t,r])=>[[t],r]),([t,r])=>[t,r],()=>[])),([t,r])=>[Yx(t),r]),Ph=(e,t=[])=>u(u(y(",",e),([r,n])=>u(Rh(n),([o,i])=>[[r,o],i])),([r,n])=>Ph(n,[...t,r]),()=>[t,e]),FA=e=>u(u(u(Rh(e),([t,r])=>u(Ph(r),([n,o])=>u(u(y(",",o),([i,a])=>[[i],a],()=>[[],o]),([i,a])=>[[t,n,i],a]))),([t,r])=>[t,r],()=>u([[],e],([t,r])=>[t,r],()=>[])),([t,r])=>[Qx(t),r]),LA=e=>u(u(y("[",e),([t,r])=>u(FA(r),([n,o])=>u(y("]",o),([i,a])=>[[t,n,i],a]))),([t,r])=>[Xx(t),r]),DA=e=>u(u(Ce(e),([t,r])=>u(y("?",r),([n,o])=>u(y(":",o),([i,a])=>u(y("readonly",a),([m,c])=>u(Q(c),([p,f])=>[[t,n,i,m,p],f]))))),([t,r])=>[Zx(t),r]),jA=e=>u(u(Ce(e),([t,r])=>u(y(":",r),([n,o])=>u(y("readonly",o),([i,a])=>u(Q(a),([m,c])=>[[t,n,i,m],c])))),([t,r])=>[ey(t),r]),NA=e=>u(u(Ce(e),([t,r])=>u(y("?",r),([n,o])=>u(y(":",o),([i,a])=>u(Q(a),([m,c])=>[[t,n,i,m],c])))),([t,r])=>[ty(t),r]),qA=e=>u(u(Ce(e),([t,r])=>u(y(":",r),([n,o])=>u(Q(o),([i,a])=>[[t,n,i],a]))),([t,r])=>[ry(t),r]),mh=e=>u(u(DA(e),([t,r])=>[t,r],()=>u(jA(e),([t,r])=>[t,r],()=>u(NA(e),([t,r])=>[t,r],()=>u(qA(e),([t,r])=>[t,r],()=>[])))),([t,r])=>[t,r]),Ah=e=>u(u(u(y("...",e),([t,r])=>u(mh(r),([n,o])=>[[t,n],o])),([t,r])=>[t,r],()=>u(u(mh(e),([t,r])=>[[t],r]),([t,r])=>[t,r],()=>[])),([t,r])=>[ny(t),r]),Oh=(e,t=[])=>u(u(y(",",e),([r,n])=>u(Ah(n),([o,i])=>[[r,o],i])),([r,n])=>Oh(n,[...t,r]),()=>[t,e]),Mh=e=>u(u(u(Ah(e),([t,r])=>u(Oh(r),([n,o])=>u(u(y(",",o),([i,a])=>[[i],a],()=>[[],o]),([i,a])=>[[t,n,i],a]))),([t,r])=>[t,r],()=>u([[],e],([t,r])=>[t,r],()=>[])),([t,r])=>[oy(t),r]),_A=e=>u(u(y("(",e),([t,r])=>u(Mh(r),([n,o])=>u(y(")",o),([i,a])=>u(y("=>",a),([m,c])=>u(Q(c),([p,f])=>[[t,n,i,m,p],f]))))),([t,r])=>[iy(t),r]),UA=e=>u(u(y("new",e),([t,r])=>u(y("(",r),([n,o])=>u(Mh(o),([i,a])=>u(y(")",a),([m,c])=>u(y("=>",c),([p,f])=>u(Q(f),([d,g])=>[[t,n,i,m,p,d],g])))))),([t,r])=>[sy(t),r]),BA=e=>u(u(u(y("+",e),([t,r])=>u(y("readonly",r),([n,o])=>[[t,n],o])),([t,r])=>[t,r],()=>u(u(y("-",e),([t,r])=>u(y("readonly",r),([n,o])=>[[t,n],o])),([t,r])=>[t,r],()=>u(u(y("readonly",e),([t,r])=>[[t],r]),([t,r])=>[t,r],()=>u([[],e],([t,r])=>[t,r],()=>[])))),([t,r])=>[ay(t),r]),GA=e=>u(u(u(y("+",e),([t,r])=>u(y("?",r),([n,o])=>[[t,n],o])),([t,r])=>[t,r],()=>u(u(y("-",e),([t,r])=>u(y("?",r),([n,o])=>[[t,n],o])),([t,r])=>[t,r],()=>u(u(y("?",e),([t,r])=>[[t],r]),([t,r])=>[t,r],()=>u([[],e],([t,r])=>[t,r],()=>[])))),([t,r])=>[my(t),r]),KA=e=>u(u(u(y("as",e),([t,r])=>u(Q(r),([n,o])=>[[t,n],o])),([t,r])=>[t,r],()=>u([[],e],([t,r])=>[t,r],()=>[])),([t,r])=>[uy(t),r]),HA=e=>u(u(y("{",e),([t,r])=>u(BA(r),([n,o])=>u(y("[",o),([i,a])=>u(Ce(a),([m,c])=>u(y("in",c),([p,f])=>u(Q(f),([d,g])=>u(KA(g),([x,I])=>u(y("]",I),([h,$])=>u(GA($),([S,_])=>u(y(":",_),([A,Xe])=>u(Q(Xe),([rt,ce])=>u(fh(ce),([V,or])=>u(y("}",or),([lt,ir])=>[[t,n,i,m,p,d,x,h,S,A,rt,V,lt],ir]))))))))))))),([t,r])=>[cy(t),r]),zA=e=>u(Ce(e),([t,r])=>[py(t),r]),WA=e=>u(Yu(e),([t,r])=>[fy(t),r]),VA=e=>u(Ua(e),([t,r])=>[dy(t),r]),JA=e=>u(u(y("true",e),([t,r])=>[t,r],()=>u(y("false",e),([t,r])=>[t,r],()=>[])),([t,r])=>[ly(t),r]),YA=e=>u(Ba(['"',"'"],e),([t,r])=>[t,r]),QA=e=>u(y("null",e),([t,r])=>[gy(t),r]),XA=e=>u(y("undefined",e),([t,r])=>[void 0,r]),vh=e=>u(u(Sh(e),([t,r])=>u(y(":",r),([n,o])=>u(nc(o),([i,a])=>[[t,n,i],a]))),([t,r])=>[xy(t),r]),Fh=(e,t=[])=>u(u(Ka(e),([r,n])=>u(vh(n),([o,i])=>[[r,o],i])),([r,n])=>Fh(n,[...t,r]),()=>[t,e]),ZA=e=>u(u(u(vh(e),([t,r])=>u(Fh(r),([n,o])=>u(u(Ka(o),([i,a])=>[[i],a],()=>[[],o]),([i,a])=>[[t,n,i],a]))),([t,r])=>[t,r],()=>u([[],e],([t,r])=>[t,r],()=>[])),([t,r])=>[yy(t),r]),Lh=e=>u(u(y("{",e),([t,r])=>u(ZA(r),([n,o])=>u(y("}",o),([i,a])=>[[t,n,i],a]))),([t,r])=>[hy(t),r]),Dh=(e,t=[])=>u(u(y(",",e),([r,n])=>u(nc(n),([o,i])=>[[r,o],i])),([r,n])=>Dh(n,[...t,r]),()=>[t,e]),eO=e=>u(u(u(nc(e),([t,r])=>u(Dh(r),([n,o])=>u(u(y(",",o),([i,a])=>[[i],a],()=>[[],o]),([i,a])=>[[t,n,i],a]))),([t,r])=>[t,r],()=>u([[],e],([t,r])=>[t,r],()=>[])),([t,r])=>[Iy(t),r]),tO=e=>u(u(y("[",e),([t,r])=>u(eO(r),([n,o])=>u(y("]",o),([i,a])=>[[t,n,i],a]))),([t,r])=>[by(t),r]),nc=e=>u(u(WA(e),([t,r])=>[t,r],()=>u(VA(e),([t,r])=>[t,r],()=>u(JA(e),([t,r])=>[t,r],()=>u(YA(e),([t,r])=>[t,r],()=>u(QA(e),([t,r])=>[t,r],()=>u(XA(e),([t,r])=>[t,r],()=>u(Lh(e),([t,r])=>[t,r],()=>u(tO(e),([t,r])=>[t,r],()=>[])))))))),([t,r])=>[t,r]),rO=e=>u(y("-?(?:0|[1-9][0-9]*)n",e),([t,r])=>[$y(t),r]),nO=e=>u(y(".*",e),([t,r])=>[Ey(t),r]),oO=e=>u(y("-?(?:0|[1-9][0-9]*)(?:\\.[0-9]+)?",e),([t,r])=>[Sy(t),r]),iO=e=>u(y("-?(?:0|[1-9][0-9]*)",e),([t,r])=>[ky(t),r]),sO=e=>u(y("(?!)",e),([t,r])=>[Ty(t),r]),aO=e=>u(sh(["-?(?:0|[1-9][0-9]*)n",".*","-?(?:0|[1-9][0-9]*)(?:\\.[0-9]+)?","-?(?:0|[1-9][0-9]*)","(?!)","(",")","$","|"],e),([t,r])=>[Cy(t),r]),mO=e=>u(u(rO(e),([t,r])=>[t,r],()=>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(uO(e),([t,r])=>[t,r],()=>u(aO(e),([t,r])=>[t,r],()=>[]))))))),([t,r])=>[t,r]),uO=e=>u(u(y("(",e),([t,r])=>u(oc(r),([n,o])=>u(y(")",o),([i,a])=>[[t,n,i],a]))),([t,r])=>[wy(t),r]),jh=e=>u(u(u(Zu(e),([t,r])=>u(y("|",r),([n,o])=>u(jh(o),([i,a])=>[[t,n,i],a]))),([t,r])=>[t,r],()=>u(u(Zu(e),([t,r])=>[[t],r]),([t,r])=>[t,r],()=>u([[],e],([t,r])=>[t,r],()=>[]))),([t,r])=>[Ry(t),r]),Zu=e=>u(u(mO(e),([t,r])=>u(oc(r),([n,o])=>[[t,n],o])),([t,r])=>[Py(t),r]),oc=e=>u(u(jh(e),([t,r])=>[t,r],()=>u(Zu(e),([t,r])=>[t,r],()=>[])),([t,r])=>[t,r]),pg=e=>u(u(y("^",e),([t,r])=>u(oc(r),([n,o])=>u(y("$",o),([i,a])=>[[t,n,i],a]))),([t,r])=>[Ay(t),r]),Nh=(e,t=[])=>u(u(y(",",e),([r,n])=>u(Q(n),([o,i])=>[[r,o],i])),([r,n])=>Nh(n,[...t,r]),()=>[t,e]),cO=e=>u(u(u(Q(e),([t,r])=>u(Nh(r),([n,o])=>u(u(y(",",o),([i,a])=>[[i],a],()=>[[],o]),([i,a])=>[[t,n,i],a]))),([t,r])=>[t,r],()=>u([[],e],([t,r])=>[t,r],()=>[])),([t,r])=>[Oy(t),r]),qh=e=>u(u(u(y("extends",e),([t,r])=>u(cO(r),([n,o])=>[[t,n],o])),([t,r])=>[t,r],()=>u([[],e],([t,r])=>[t,r],()=>[])),([t,r])=>[My(t),r]),pO=e=>u(u(y("interface",e),([t,r])=>u(Ce(r),([n,o])=>u(ec(o),([i,a])=>u(qh(a),([m,c])=>u(rc(c),([p,f])=>[[t,n,i,m,p],f]))))),([t,r])=>[vy(t),r]),fO=e=>u(u(y("interface",e),([t,r])=>u(Ce(r),([n,o])=>u(qh(o),([i,a])=>u(rc(a),([m,c])=>[[t,n,i,m],c])))),([t,r])=>[Fy(t),r]),dO=e=>u(u(y("type",e),([t,r])=>u(Ce(r),([n,o])=>u(ec(o),([i,a])=>u(y("=",a),([m,c])=>u(Q(c),([p,f])=>[[t,n,i,m,p],f]))))),([t,r])=>[Ly(t),r]),lO=e=>u(u(y("type",e),([t,r])=>u(Ce(r),([n,o])=>u(y("=",o),([i,a])=>u(Q(a),([m,c])=>[[t,n,i,m],c])))),([t,r])=>[Dy(t),r]),gO=e=>u(u(u(y("export",e),([t,r])=>[[t],r]),([t,r])=>[t,r],()=>u([[],e],([t,r])=>[t,r],()=>[])),([t,r])=>[jy(t),r]),_h=e=>u(u(u(y(";",e),([t,r])=>u(y(`
6
+ `,r),([n,o])=>[[t,n],o])),([t,r])=>[t,r],()=>u(u(y(";",e),([t,r])=>[[t],r]),([t,r])=>[t,r],()=>u(u(y(`
7
+ `,e),([t,r])=>[[t],r]),([t,r])=>[t,r],()=>[]))),([t,r])=>[t,r]),Uh=(e,t=[])=>u(u(_h(e),([r,n])=>u(ic(n),([o,i])=>[[r,o],i])),([r,n])=>Uh(n,[...t,r]),()=>[t,e]),xO=e=>u(u(u(ic(e),([t,r])=>u(Uh(r),([n,o])=>u(u(_h(o),([i,a])=>[[i],a],()=>[[],o]),([i,a])=>[[t,n,i],a]))),([t,r])=>[t,r],()=>u([[],e],([t,r])=>[t,r],()=>[])),([t,r])=>[Ny(t),r]),ic=e=>u(u(gO(e),([t,r])=>u(u(pO(r),([n,o])=>[n,o],()=>u(fO(r),([n,o])=>[n,o],()=>u(dO(r),([n,o])=>[n,o],()=>u(lO(r),([n,o])=>[n,o],()=>[])))),([n,o])=>u(fh(o),([i,a])=>[[t,n,i],a]))),([t,r])=>[qy(t),r]),yO=e=>u(u(ic(e),([t,r])=>u(xO(r),([n,o])=>[[t,n],o])),([t,r])=>[_y(t),r]),Bh=e=>u(u(yO(e),([t,r])=>[t,r],()=>u(TA(e),([t,r])=>[t,r],()=>u(Q(e),([t,r])=>[t,r],()=>[]))),([t,r])=>[t,r]);function Gh(e){let t=tc(`\`${e}\``);return s.IsEqual(t.length,2)?t[0]:Ie()}function IO(e){return e.join("|")}function bO(e){return e.slice(1,e.length-1)}function $O(e,t,r){return on(t,`${r}${e}`)}function EO(e,t){return on(e,`${t}${ig}`)}function SO(e,t){return on(e,`${t}${ra}`)}function kO(e,t){return on(e,`${t}${sa}`)}function TO(e,t){return xi(L([B("false"),B("true")]),e,t)}function CO(e,t){return on(e,`${t}${aa}`)}function wO(e,t,r){return on(t,`${r}${bO(e)}`)}function RO(e,t,r){let n=yi(e,{});return xi(n,t,r)}function PO(e,t,r){let n=dt(e);return xi(n,t,r)}function Kh(e,t,r,n=[]){return s.ShiftLeft(e,(o,i)=>Kh(i,t,r,[...n,xi(o,[],"")]),()=>on(t,`${r}(${IO(n)})`))}function xi(e,t,r){return Se(e)?PO(e.enum,t,r):Be(e)?SO(t,r):K(e)?$O(e.const,t,r):kt(e)?EO(t,r):ft(e)?TO(t,r):ge(e)?kO(t,r):je(e)?CO(t,r):se(e)?wO(e.pattern,t,r):zh(e)?RO(e.parameters[0],t,r):E(e)?Kh(e.anyOf,t,r):Gl}function on(e,t){return s.ShiftLeft(e,(r,n)=>xi(r,n,t),()=>t)}function AO(e){return`^${on(e,"")}$`}function Hh(e){let t=AO(e);return ua(t)}function yi(e,t){return q(e)?l.Update(Hh(e),{},t):ya(e,t)}function Wh(e,t,r,n){let o=Ft(e,t,r);return yi(o,n)}function ya(e,t={}){return C("TemplateLiteral",[e],t)}function zh(e){return le(e)&&s.HasPropertyKey(e,"action")&&s.IsEqual(e.action,"TemplateLiteral")}function Vh(e){return yi(e,{})}function OO(e){let t=Gh(e);return Vh(t)}function Jh(e,t={}){let r=s.IsString(e)?OO(e):Vh(e);return l.Update(r,{},t)}function se(e){return T(e,"TemplateLiteral")}var v={};At(v,{ExtendsFalse:()=>j,ExtendsTrue:()=>k,ExtendsUnion:()=>sc,IsExtendsFalse:()=>MO,IsExtendsTrue:()=>Qh,IsExtendsTrueLike:()=>hr,IsExtendsUnion:()=>Yh,Match:()=>we});function sc(e){return l.Create({"~kind":"ExtendsUnion"},{inferred:e})}function Yh(e){return s.IsObject(e)&&s.HasPropertyKey(e,"~kind")&&s.HasPropertyKey(e,"inferred")&&s.IsEqual(e["~kind"],"ExtendsUnion")&&s.IsObject(e.inferred)}function k(e){return l.Create({"~kind":"ExtendsTrue"},{inferred:e})}function Qh(e){return s.IsObject(e)&&s.HasPropertyKey(e,"~kind")&&s.HasPropertyKey(e,"inferred")&&s.IsEqual(e["~kind"],"ExtendsTrue")&&s.IsObject(e.inferred)}function j(){return l.Create({"~kind":"ExtendsFalse"},{})}function MO(e){return s.IsObject(e)&&s.HasPropertyKey(e,"~kind")&&s.IsEqual(e["~kind"],"ExtendsFalse")}function hr(e){return Yh(e)||Qh(e)}function we(e,t,r){return hr(e)?t(e.inferred):r()}function vO(e,t,r,n){return we(W(e,r,n),o=>k(l.Assign(l.Assign(e,o),{[t]:r})),()=>j())}function FO(e,t){return k(e)}function LO(e,t,r,n,o){return we(W(e,t,r),i=>we(W(i,t,n),a=>k(a),()=>j()),()=>we(W(e,t,o),i=>k(i),()=>j()))}function DO(e,t,r){let n=dt(r);return W(e,t,n)}function Xh(e,t,r){return s.ShiftLeft(r,(n,o)=>we(W(e,t,n),i=>Xh(i,t,o),()=>j()),()=>k(e))}function jO(e,t,r){let n=it(r);return W(e,t,n)}function Zh(e,t,r){return s.ShiftLeft(r,(n,o)=>we(W(e,t,n),i=>k(i),()=>Zh(e,t,o)),()=>j())}function ee(e,t,r){return ye(r)?FO(e,t):Ee(r)?LO(e,t,r.if,r.then,r.else):Se(r)?DO(e,t,r.enum):ve(r)?vO(e,r.name,t,r.extends):P(r)?Xh(e,t,r.allOf):se(r)?jO(e,t,r.pattern):E(r)?Zh(e,t,r.anyOf):Me(r)?k(e):j()}function eI(e,t,r){return ve(r)?ee(e,t,r):ye(r)?k(e):Me(r)?k(e):sc(e)}function NO(e,t){let r=En(e),n=En(t);return r&&n||!r&&n?!0:!(r&&!n)}function tI(e,t,r,n){return H(n)?NO(t,n)?W(e,r,n.items):j():ee(e,t,n)}function rI(e,t,r){return kt(r)?k(e):ee(e,t,r)}function nI(e,t,r){return ft(r)?k(e):ee(e,t,r)}function qO(e,t,r,n,o){let i=ve(n)?t:n,a=ve(n)?n:t,m=Oe(t),c=Oe(n);return!m&&c?j():we(W(e,i,a),p=>hi(p,r,o),()=>j())}function _O(e,t,r,n){return s.ShiftLeft(n,(o,i)=>qO(e,t,r,o,i),()=>Oe(t)?k(e):j())}function UO(e,t,r){return s.ShiftLeft(t,(n,o)=>_O(e,n,o,r),()=>k(e))}function hi(e,t,r){return UO(e,t,r)}function Ha(e,t,r){return Ct(r)?k(e):W(e,t,r)}function oI(e,t,r,n){return ye(n)?k(e):Me(n)?k(e):be(n)?we(hi(e,t,n.parameters),o=>Ha(o,r,n.instanceType),()=>j()):j()}function iI(e,t,r,n,o){return we(W(e,t,o),()=>W(e,r,o),()=>W(e,n,o))}function sI(e,t,r){let n=dt(t);return W(e,n,r)}function aI(e,t,r,n){return ye(n)?k(e):Me(n)?k(e):$e(n)?we(hi(e,t,n.parameters),o=>Ha(o,r,n.returnType),()=>j()):j()}function mI(e,t,r){return Be(r)?k(e):ge(r)?k(e):ee(e,t,r)}function uI(e,t,r){let n=Te(t);return W(e,n,r)}function za(e,t,r){return t===r?k(e):j()}function BO(e,t,r){return K(r)?za(e,t,r.const):kt(r)?k(e):ee(e,B(t),r)}function GO(e,t,r){return K(r)?za(e,t,r.const):ft(r)?k(e):ee(e,B(t),r)}function KO(e,t,r){return K(r)?za(e,t,r.const):ge(r)?k(e):ee(e,B(t),r)}function HO(e,t,r){return K(r)?za(e,t,r.const):je(r)?k(e):ee(e,B(t),r)}function cI(e,t,r){return s.IsBigInt(t.const)?BO(e,t.const,r):s.IsBoolean(t.const)?GO(e,t.const,r):s.IsNumber(t.const)?KO(e,t.const,r):s.IsString(t.const)?HO(e,t.const,r):Ie()}function pI(e,t,r){return ve(r)?ee(e,t,r):k(e)}function fI(e,t,r){return xr(r)?k(e):ee(e,t,r)}function dI(e,t,r){return ge(r)?k(e):ee(e,t,r)}function zO(e,t,r){return Oe(t)?Oe(r)?k(e):j():k(e)}function WO(e,t,r){return ve(r)&&yt(r.extends)?j():we(W(e,t,r),n=>zO(n,t,r),()=>j())}function VO(e,t){return e.reduce((r,n)=>n in t?hr(t[n])?{...r,...t[n].inferred}:Ie():Ie(),{})}function JO(e,t,r){let n={};for(let a of s.Keys(r))n[a]=a in t?WO({},t[a],r[a]):Oe(r[a])?ve(r[a])?k(l.Assign(e,{[r[a].name]:r[a].extends})):k(e):j();let o=s.Values(n).every(a=>hr(a)),i=o?VO(s.Keys(n),n):{};return o?k(i):j()}function YO(e,t,r){let n=JO(e,t,r);return hr(n)?k(l.Assign(e,n.inferred)):j()}function QO(e,t,r){return YO(e,t,r)}function XO(e,t){return s.Keys(t).reduce((r,n)=>({...r,[n]:s.HasPropertyKey(e,n)?E(r[n])?L([...r[n].anyOf,t[n]]):L([e[n],t[n]]):t[n]}),e)}function lI(e,t,r,n){return s.ShiftLeft(t,(o,i)=>we(W({},e[o],r),a=>lI(e,i,r,XO(n,a)),()=>j()),()=>k(n))}function ZO(e,t,r,n){let o=s.Keys(t);return lI(t,o,n,e)}function gI(e,t,r){return te(r)?ZO(e,t,Fe(r),me(r)):R(r)?QO(e,t,r.properties):ee(e,O(t),r)}function eM(e,t){return s.IsEqual(s.Keys(t).length,0)?k(e):j()}function tM(e,t,r,n,o){return W(e,r,o)}function xI(e,t,r,n){return te(n)?tM(e,da(t),r,da(Fe(n)),me(n)):R(n)?eM(e,n.properties):ye(n)?k(e):Me(n)?k(e):j()}function yI(e,t,r){return je(r)?k(e):ee(e,t,r)}function hI(e,t,r){return yr(r)?k(e):ee(e,t,r)}function II(e,t,r){let n=it(t);return W(e,n,r)}function ac(e,t){return l.Create({"~kind":"Inferrable"},{name:e,type:t},{})}function Ii(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 mc(e){return tn(e)?ve(e.items)?H(e.items.extends)?ac(e.items.name,e.items.extends.items):Me(e.items.extends)?ac(e.items.name,e.items.extends):void 0:Ie():void 0}function Wa(e){return ve(e)?ac(e.name,e.extends):void 0}function bI(e,t){let r=[];for(let n of e){if(!hr(W({},n,t)))return;r.push(n)}return r}function $I(e,t,r,n){let o=bI(r,n);return s.IsArray(o)?k(l.Assign(e,{[t]:ke(o)})):j()}function Va(e,t,r,n){let o=bI(r,n);return s.IsArray(o)?k(l.Assign(e,{[t]:L(o)})):j()}function rM(e){return[...e].reverse()}function uc(e,t){return t?rM(e):e}function nM(e){let t=e.length>0?e[0]:void 0,r=le(t)?mc(t):void 0;return le(r)}function oM(e,t,r,n,o,i){return we(W(e,r,o),a=>EI(a,t,n,i),()=>j())}function iM(e,t,r,n,o){let i=mc(n);return Ii(i)?$I(e,i.name,uc(r,t),i.type):s.ShiftLeft(r,(a,m)=>oM(e,t,a,m,n,o),()=>j())}function sM(e,t,r,n){return s.ShiftLeft(n,(o,i)=>iM(e,t,r,o,i),()=>s.IsEqual(r.length,0)?k(e):j())}function EI(e,t,r,n){return sM(e,t,r,n)}function aM(e,t,r){let n=sn(e,pe([],[]),r),o=nM(n);return EI(e,o,uc(t,o),uc(n,o))}function mM(e,t,r){for(let n of t){let o=W(e,n,r);if(!hr(o))return o;e=o.inferred}return k(e)}function uM(e,t,r){let n=Wa(r);return Ii(n)?Va(e,n.name,t,n.type):mM(e,t,r)}function SI(e,t,r){let n=sn(e,pe([],[]),t);return N(r)?aM(e,n,r.items):H(r)?uM(e,n,r.items):ee(e,ke(n),r)}function kI(e,t,r){return Ct(r)?k(e):Gt(r)?k(e):ee(e,t,r)}function TI(e,t,r){return s.ShiftLeft(r,(n,o)=>we(W(e,t,n),i=>k(i),()=>TI(e,t,o)),()=>j())}function cc(e,t,r){return s.ShiftLeft(t,(n,o)=>we(TI(e,n,r),i=>cc(i,o,r),()=>j()),()=>k(e))}function CI(e,t,r){let n=Wa(r);return Ii(n)?Va(e,n.name,t,n.type):E(r)?cc(e,t,r.anyOf):cc(e,t,[r])}function wI(e,t,r){return ve(r)?ee(e,t,r):ye(r)?k(e):Me(r)?k(e):j()}function RI(e,t,r){return Ct(r)?k(e):ee(e,t,r)}function W(e,t,r){return ye(t)?eI(e,t,r):H(t)?tI(e,t,t.items,r):kt(t)?rI(e,t,r):ft(t)?nI(e,t,r):be(t)?oI(e,t.parameters,t.instanceType,r):Ee(t)?iI(e,t.if,t.then,t.else,r):Se(t)?sI(e,t.enum,r):$e(t)?aI(e,t.parameters,t.returnType,r):Be(t)?mI(e,t,r):P(t)?uI(e,t.allOf,r):K(t)?cI(e,t,r):yt(t)?pI(e,t,r):xr(t)?fI(e,t,r):ge(t)?dI(e,t,r):R(t)?gI(e,t.properties,r):te(t)?xI(e,Fe(t),me(t),r):je(t)?yI(e,t,r):yr(t)?hI(e,t,r):se(t)?II(e,t.pattern,r):N(t)?SI(e,t.items,r):Gt(t)?kI(e,t,r):E(t)?CI(e,t.anyOf,r):Me(t)?wI(e,t,r):Ct(t)?RI(e,t,r):j()}function cM(e,t){return Te([...e,O(t)])}function pc(e,t,r){return q(e)?l.Update(cM(e,t),{},r):pi(e,t,r)}function PI(e,t,r,n,o){let i=Ft(e,t,r),a=bi(e,t,n);return pc(i,a,o)}function pi(e,t,r={}){return C("Interface",[e,t],r)}function po(e){return le(e)&&s.HasPropertyKey(e,"action")&&s.IsEqual(e.action,"Interface")}function AI(e,t,r={}){return pc(e,t,r)}function pM(e,t,r){return e.includes(r)?!0:$i([...e,r],t,t[r])}function OI(e,t,r){let n=Qs(r);return Rn(e,t,n)}function Rn(e,t,r){return s.ShiftLeft(r,(n,o)=>$i(e,t,n)?!0:Rn(e,t,o),()=>!1)}function $i(e,t,r){return Z(r)?pM(e,t,r.$ref):H(r)?$i(e,t,r.items):be(r)?Rn(e,t,[...r.parameters,r.instanceType]):$e(r)?Rn(e,t,[...r.parameters,r.returnType]):po(r)?OI(e,t,r.parameters[1]):P(r)?Rn(e,t,r.allOf):R(r)?OI(e,t,r.properties):E(r)?Rn(e,t,r.anyOf):N(r)?Rn(e,t,r.items):te(r)?$i(e,t,me(r)):!1}function MI(e,t,r){return $i(e,t,r)}function fM(e,t){return t.reduce((r,n)=>MI([n],e,e[n])?[...r,n]:r,[])}function vI(e){let t=Ys(e);return fM(e,t)}function dM(e,t,r){return r.includes(t)?r:t in e?Ei(e,e[t],[...r,t]):Ie()}function FI(e,t,r){let n=Qs(t);return fo(e,n,r)}function fo(e,t,r){return t.reduce((n,o)=>Ei(e,o,n),r)}function Ei(e,t,r){return Z(t)?dM(e,t.$ref,r):H(t)?Ei(e,t.items,r):be(t)?fo(e,[...t.parameters,t.instanceType],r):$e(t)?fo(e,[...t.parameters,t.returnType],r):po(t)?FI(e,t.parameters[1],r):P(t)?fo(e,t.allOf,r):R(t)?FI(e,t.properties,r):E(t)?fo(e,t.anyOf,r):N(t)?fo(e,t.items,r):te(t)?Ei(e,me(t),r):r}function LI(e,t,r){return Ei(e,r,[t])}function lM(e){return Qn()}function gM(e){return s.Keys(e).reduce((t,r)=>({...t,[r]:Pn(e[r])}),{})}function Si(e){return e.reduce((t,r)=>[...t,Pn(r)],[])}function Pn(e){return Z(e)?lM(e.$ref):H(e)?xt(Pn(e.items),Jn(e)):be(e)?pr(Si(e.parameters),Pn(e.instanceType)):$e(e)?fr(Si(e.parameters),Pn(e.returnType)):P(e)?ot(Si(e.allOf)):R(e)?O(gM(e.properties)):te(e)?io(so(e),Pn(me(e))):E(e)?L(Si(e.anyOf)):N(e)?ke(Si(e.items)):e}function xM(e,t){return t in e?Pn(e[t]):De()}function DI(e){return xM(e.$defs,e.$ref)}function yM(e,t,r){let n=Ft(e,pe([],[]),t),o=bi({},pe([],[]),r);return Te([...n,O(o)])}function hM(e,t){return s.Keys(e).filter(n=>t.includes(n)).reduce((n,o)=>{let i=e[o],a=po(i)?yM(e,i.parameters[0],i.parameters[1]):i;return{...n,[o]:a}},{})}function jI(e,t,r){let n=LI(e,t,r),o=hM(e,n);return lr(o,t)}function NI(e,t){return t in e?Z(e[t])?NI(e,e[t].$ref):e[t]:re()}function Ir(e,t){return NI(e,t)}function qI(e){return ie(e)?DI(e):Xs(e)?De():e}function tt(e,t,r){let n=qI(t),o=qI(r);return W(e,n,o)}var si=0,ki=1,ai=2,mi=3;function no(e,t){let r=[tt({},e,t),tt({},t,e)];return v.IsExtendsTrueLike(r[0])&&v.IsExtendsTrueLike(r[1])?si:v.IsExtendsTrueLike(r[0])&&v.IsExtendsFalse(r[1])?ai:v.IsExtendsFalse(r[0])&&v.IsExtendsTrueLike(r[1])?mi:ki}function fc(e,t,r=[],n=t){return s.ShiftLeft(t,(o,i)=>{let a=no(e,o);return s.IsEqual(a,ai)||s.IsEqual(a,si)?n:s.IsEqual(a,ki)?fc(e,i,[...r,o],n):fc(e,i,r,n)},()=>[...r,e])}function IM(e,t,r){let n=Bt(e);return ye(n)?[n]:Me(n)?[n]:yt(n)?Ja(t,r):R(n)?Ja(t,[...r,n]):Ja(t,fc(n,r))}function Ja(e,t=[]){return s.ShiftLeft(e,(r,n)=>IM(r,n,t),()=>t)}function Ku(e){let t=Ja(e);return en(t)}function dc(e,t){return l.Update(Bt(e),{},t)}function _I(e,t,r,n){let o=b(e,t,r);return dc(o,n)}function Ti(e,t=[]){return Jr(e)&&s.IsEqual(e.action,"Conditional")?Z(e.parameters[0])?Ti(e.parameters[2],Ti(e.parameters[3],[...t,e.parameters[0].$ref])):Ti(e.parameters[2],Ti(e.parameters[3],t)):Jr(e)&&s.IsEqual(e.action,"Mapped")&&Jr(e.parameters[1])&&s.IsEqual(e.parameters[1].action,"KeyOf")&&Z(e.parameters[1].parameters[0])?[...t,e.parameters[1].parameters[0].$ref]:t}function bM(e,t){return e.reduce((r,n)=>[...r,t.includes(n.name)],[])}function GI(e,t,r=[]){return s.ShiftLeft(e,(n,o)=>s.ShiftLeft(t,(i,a)=>GI(o,a,[...r,[i,n]]),()=>r),()=>r)}function $M(e){return se(e)?it(e.pattern):Se(e)?dt(e.enum):e}function EM(e){let t=$M(e);return E(t)?[...t.anyOf]:[t]}function SM(e,t){return e.reduce((r,n)=>[...r,[...n,t]],[])}function UI(e,t){return t.reduce((r,n)=>[...r,...SM(e,n)],[])}function BI(e){return e.reduce((t,r)=>s.IsEqual(r[0],!0)?UI(t,EM(r[1])):UI(t,[r[1]]),[[]])}function KI(e,t,r){let n=Ti(r),o=bM(e,n),i=GI(t,o);return Jr(r)&&s.IsEqual(r.action,"Conditional")||Jr(r)&&s.IsEqual(r.action,"Mapped")?BI(i):[t]}function kM(){return["(not-resolvable)",re()]}function TM(){return["(not-generic)",re()]}function CM(e,t,r){return[e,Yr(t,r)]}function wM(e,t,r){return t in e?HI(e,t,e[t],r):kM()}function HI(e,t,r,n){return Yn(r)?CM(t,r.parameters,r.expression):Z(r)?wM(e,r.$ref,n):TM()}function zI(e,t,r){return HI(e,"(anonymous)",t,r)}function RM(e,t,r){if(ve(t)||lo(t)||v.IsExtendsTrueLike(tt({},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 WI(e,t,r,n,o){let i=b(e,t,o);return RM(r,i,n),l.Assign(e,{[r]:i})}function PM(e,t,r,n,o){let i=b(e,t,r.extends),a=b(e,t,r.equals);return s.ShiftLeft(o,(m,c)=>lc(WI(e,t,r.name,i,m),t,n,c),()=>lc(WI(e,t,r.name,i,a),t,n,[]))}function lc(e,t,r,n){return s.ShiftLeft(r,(o,i)=>PM(e,t,o,i,n),()=>e)}function VI(e,t,r,n){return lc(e,t,r,n)}var gc=0,xc=0;function AM(){if(!s.IsLessThan(xc,Ae.Get().maxInstantiationCount))throw Error("Type instantiation is excessively deep and possibly infinite")}function OM(){AM(),xc++,gc++}function MM(){gc--,s.IsEqual(gc,0)&&(xc=0)}function vM(e){return s.IsGreaterThan(e.callstack.length,0)?e.callstack[e.callstack.length-1]:""}function FM(e,t){return s.IsEqual(vM(e),t)}function LM(e,t,r,n,o,i){OM();try{let a=VI(e,t,n,i),m=b(a,pe([...t.callstack,r.$ref],t.visited),o);return b(a,pe([],[]),m)}finally{MM()}}function DM(e,t,r,n,o,i){return i.reduce((a,m)=>{let c=LM(e,t,r,n,o,m);return[...a,c]},[])}function jM(e,t,r,n,o,i){let a=KI(n,i,o),m=DM(e,t,r,n,o,a);return s.IsEqual(m.length,1)?m[0]:It(m)}function Ya(e,t,r,n){let o=Ft(e,t,n),i=zI(e,r,n),a=i[0],m=i[1];return Yn(m)?FM(t,a)?fi(_e(a),o):jM(e,t,_e(a),m.parameters,m.expression,o):fi(r,o)}function fi(e,t){return l.Create({"~kind":"Call"},{type:"call",target:e,arguments:t},{})}function JI(e,t){return Ya({},pe([],[]),e,t)}function lo(e){return T(e,"Call")}function NM(e){return l.Discard(e,["~immutable"])}function YI(e,t){return l.Update(NM(e),{},t)}function QI(e,t,r,n){let o=b(e,t,r);return YI(o,n)}function XI(e,t){return e(t)}function ZI(e,t){return s.IsString(t)?B(XI(e,t)):B(t)}function eb(e,t){let r=it(t);return vr(e,r)}function tb(e,t){let r=t.map(n=>vr(e,n));return L(r)}function vr(e,t){return K(t)?ZI(e,t.const):se(t)?eb(e,t.pattern):E(t)?tb(e,t.anyOf):t}function ha(e,t={}){return C("Capitalize",[e],t)}function rb(e,t={}){return yc(e,t)}function Ia(e,t={}){return C("Lowercase",[e],t)}function nb(e,t={}){return hc(e,t)}function ba(e,t={}){return C("Uncapitalize",[e],t)}function ob(e,t={}){return Ic(e,t)}function $a(e,t={}){return C("Uppercase",[e],t)}function ib(e,t={}){return bc(e,t)}var qM=e=>e[0].toUpperCase()+e.slice(1),_M=e=>e.toLowerCase(),UM=e=>e[0].toLowerCase()+e.slice(1),BM=e=>e.toUpperCase();function yc(e,t){return q([e])?l.Update(vr(qM,e),{},t):ha(e,t)}function hc(e,t){return q([e])?l.Update(vr(_M,e),{},t):Ia(e,t)}function Ic(e,t){return q([e])?l.Update(vr(UM,e),{},t):ba(e,t)}function bc(e,t){return q([e])?l.Update(vr(BM,e),{},t):$a(e,t)}function sb(e,t,r,n){let o=b(e,t,r);return yc(o,n)}function ab(e,t,r,n){let o=b(e,t,r);return hc(o,n)}function mb(e,t,r,n){let o=b(e,t,r);return Ic(o,n)}function ub(e,t,r,n){let o=b(e,t,r);return bc(o,n)}function Ea(e,t,r,n,o={}){return C("Conditional",[e,t,r,n],o)}function cb(e,t,r,n,o={}){return $c({},pe([],[]),e,t,r,n,o)}function GM(e,t,r,n,o,i){let a=tt(e,r,n);return v.IsExtendsUnion(a)?L([b(a.inferred,t,o),b(e,t,i)]):v.IsExtendsTrue(a)?b(a.inferred,t,o):b(e,t,i)}function $c(e,t,r,n,o,i,a){return q([r,n])?l.Update(GM(e,t,r,n,o,i),{},a):Ea(r,n,o,i,a)}function pb(e,t,r,n,o,i,a){let m=b(e,t,r),c=b(e,t,n);return $c(e,t,m,c,o,i,a)}function Sa(e,t={}){return C("ConstructorParameters",[e],t)}function fb(e,t={}){return Ec(e,t)}function KM(e){let t=be(e)?e.parameters:[],r=sn({},pe([],[]),t);return ke(r)}function Ec(e,t){return q([e])?l.Update(KM(e),{},t):Sa(e,t)}function db(e,t,r,n){let o=b(e,t,r);return Ec(o,n)}function ka(e,t,r={}){return C("Exclude",[e,t],r)}function lb(e,t,r={}){return Ci(e,t,r)}function Ci(e,t,r){return q([e,t])?l.Update(pa(e,t),{},r):ka(e,t,r)}function gb(e,t,r,n,o){let i=b(e,t,r),a=b(e,t,n);return Ci(i,a,o)}function Ta(e,t,r={}){return C("Extract",[e,t],r)}function xb(e,t,r={}){return Sc(e,t,r)}function HM(e,t){let r=tt({},e,t);return v.IsExtendsTrueLike(r)?[e]:[]}function yb(e,t,r=[]){return s.ShiftLeft(e,(n,o)=>yb(o,t,[...r,...HM(n,t)]),()=>r)}function hb(e,t){let r=Bt(e),n=E(r)?r.anyOf:[r],o=yb(n,t);return It(o)}function Sc(e,t,r){return q([e,t])?l.Update(hb(e,t),{},r):Ta(e,t,r)}function Ib(e,t,r,n,o){let i=b(e,t,r),a=b(e,t,n);return Sc(i,a,o)}function zM(e){return e.reduce((t,r)=>na(r)?[...t,B(r)]:t,[])}function go(e){let t=zM(e);return L(t)}function di(e,t,r={}){return C("Index",[e,t],r)}function bb(e,t,r={}){let n=s.IsArray(t)?go(t):t;return kc(e,n,r)}function $b(e,t){let r=Ir(e,t);return Lt(r)}function Eb(e,t,r){let n=Zt(e,t,r);return Lt(n)}function WM(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]:ca(e[d],t[d])}),{}),c=l.Assign(i,a);return l.Assign(c,m)}function Sb(e){return e.reduce((t,r)=>WM(t,Lt(r)),{})}function kb(e){let t=$g(ke(e));return Lt(t)}function VM(e,t){return s.Keys(e).filter(o=>o in t).reduce((o,i)=>({...o,[i]:kg(e[i],t[i])}),{})}function Tb(e,t){return s.ShiftLeft(e,(r,n)=>Tb(n,VM(t,Lt(r))),()=>t)}function Cb(e){return s.ShiftLeft(e,(t,r)=>Tb(r,Lt(t)),()=>Ie())}function Lt(e){return ie(e)?$b(e.$defs,e.$ref):Ee(e)?Eb(e.if,e.then,e.else):P(e)?Sb(e.allOf):E(e)?Cb(e.anyOf):N(e)?kb(e.items):R(e)?e.properties:{}}function xo(e){let t=Lt(e);return O(t)}var JM=new RegExp("^(?:0|[1-9][0-9]*)$");function yo(e){let t=`${e}`;return JM.test(t)?parseInt(t):e}function YM(e){return B(yo(e))}function wb(e){return e.map(t=>Rb(t))}function Rb(e){return P(e)?ot(wb(e.allOf)):E(e)?L(wb(e.anyOf)):K(e)?YM(e.const):e}function Pb(e,t){let r=Rb(t),n=tt({},r,Tt());return v.IsExtendsTrueLike(n)?e:K(t)&&s.IsEqual(t.const,"length")?Tt():re()}function Ab(e,t){let r=Ir(e,t);return wt(r)}function Ob(e,t,r){let n=Zt(e,t,r);return wt(n)}function Mb(e){let t=dt(e);return wt(t)}function vb(e){let t=Te(e);return wt(t)}function Fb(e){return[`${e}`]}function Lb(e){let t=it(e);return wt(t)}function Db(e){return e.reduce((t,r)=>[...t,...wt(r)],[])}function wt(e){return ie(e)?Ab(e.$defs,e.$ref):Ee(e)?Ob(e.if,e.then,e.else):Se(e)?Mb(e.enum):P(e)?vb(e.allOf):K(e)?Fb(e.const):se(e)?Lb(e.pattern):E(e)?Db(e.anyOf):[]}function ho(e){return wt(e)}function wi(e,t){return t.map(r=>Ri(e,r))}function Ri(e,t){return H(t)?xt(Ri(e,t.items)):be(t)?pr(wi(e,t.parameters),Ri(e,t.instanceType)):$e(t)?fr(wi(e,t.parameters),Ri(e,t.returnType)):N(t)?ke(wi(e,t.items)):E(t)?L(wi(e,t.anyOf)):P(t)?ot(wi(e,t.allOf)):ga(t)?O(e):t}function jb(e,t){return Ri(e,t)}function QM(e,t){let r=t in e?e[t]:re();return jb(e,r)}function Nb(e,t){return t.reduce((r,n)=>[...r,QM(e,n)],[])}function XM(e,t){let r=ho(t),n=Nb(e,r);return It(n)}var ZM=new RegExp(Zr);function ev(e){return e.filter(r=>ZM.test(r))}function tv(e){let t=Ys(e),r=ev(t),n=Nb(e,r);return It(n)}function qb(e,t){return ge(t)?tv(e):XM(e,t)}function rv(e){return B(yo(e))}function _b(e){return e.map(t=>Tc(t))}function Tc(e){return P(e)?ot(_b(e.allOf)):E(e)?L(_b(e.anyOf)):K(e)?rv(e.const):e}function nv(e,t){return e.reduceRight((r,n,o)=>{let i=tt({},B(o),t);return v.IsExtendsTrueLike(i)?[n,...r]:r},[])}function ov(e,t){let r=Tc(t),n=nv(e,r);return Qr(n)}function iv(e){return Qr(e)}function Ub(e,t){return K(t)&&s.IsEqual(t.const,"length")?B(e.length):ge(t)||Be(t)?iv(e):ov(e,t)}function Bb(e,t){return H(e)?Pb(e.items,t):R(e)?qb(e.properties,t):N(e)?Ub(e.items,t):re()}function sv(e){return ie(e)||Ee(e)||P(e)||E(e)?xo(e):e}function kc(e,t,r){return q([e,t])?l.Update(Bb(sv(e),t),{},r):di(e,t,r)}function Gb(e,t,r,n,o){let i=b(e,t,r),a=b(e,t,n);return kc(i,a,o)}function Ca(e,t={}){return C("InstanceType",[e],t)}function Kb(e,t={}){return Cc(e,t)}function av(e){return be(e)?e.instanceType:re()}function Cc(e,t){return q([e])?l.Update(av(e),{},t):Ca(e,t)}function Hb(e,t,r,n={}){let o=b(e,t,r);return Cc(o,n)}function li(e,t={}){return C("KeyOf",[e],t)}function zb(e,t={}){return wc(e,t)}function Wb(){return L([Tt(),et(),eo()])}function Vb(e){return Tt()}function mv(e){return e.reduce((r,n)=>na(n)?[...r,B(yo(n))]:Ie(),[])}function Jb(e){let t=s.Keys(e),r=mv(t);return Qr(r)}function Yb(e){return so(e)}function Qb(e){let t=e.map((r,n)=>B(n));return Qr(t)}function Xb(e){return ye(e)?Wb():H(e)?Vb(e.items):R(e)?Jb(e.properties):te(e)?Yb(e):N(e)?Qb(e.items):re()}function uv(e){return ie(e)||Ee(e)||P(e)||E(e)?xo(e):e}function wc(e,t){return q([e])?l.Update(Xb(uv(e)),{},t):li(e,t)}function Zb(e,t,r,n){let o=b(e,t,r);return wc(o,n)}function ci(e,t,r,n,o={}){return C("Mapped",[e,t,r,n],o)}function e$(e,t,r,n,o={}){return Rc({},pe([],[]),e,t,r,n,o)}function cv(e){let t=it(e);return Qa(t)}function pv(e){return e.reduce((t,r)=>[...t,...Qa(r)],[])}function fv(e){let t=dt(e);return Qa(t)}function dv(e){return s.IsNumber(e)?[B(`${e}`)]:[B(e)]}function Qa(e){return Se(e)?fv(e.enum):K(e)?dv(e.const):se(e)?cv(e.pattern):E(e)?pv(e.anyOf):[e]}function t$(e){return Qa(e)}function lv(e){return se(e)?it(e.pattern):e}function gv(e,t,r,n,o,i){let a=l.Assign(e,{[r.name]:n}),m=b(a,t,o),c=lv(m),p=b(a,t,i);return oa(c)||ia(c)?{[c.const]:p}:{}}function xv(e,t,r,n,o,i){return n.reduce((a,m)=>[...a,gv(e,t,r,m,o,i)],[])}function yv(e){return e.reduce((t,r)=>[...t,O(r)],[])}function r$(e,t,r,n,o,i){let a=t$(n),m=xv(e,t,r,a,o,i),c=yv(m);return Te(c)}function Rc(e,t,r,n,o,i,a){return q([n])?l.Update(r$(e,t,r,n,o,i),{},a):ci(r,n,o,i,a)}function n$(e,t,r,n,o,i,a){let m=b(e,t,n);return Rc(e,t,r,m,o,i,a)}function hv(e,t,r){let n=l.Assign(e,t);return s.Keys(t).filter(i=>r.includes(i)).reduce((i,a)=>({...i,[a]:jI(n,a,t[a])}),{})}function Iv(e,t,r){let n=l.Assign(e,t);return s.Keys(t).filter(i=>!r.includes(i)).reduce((i,a)=>({...i,[a]:b(n,pe([],[]),t[a])}),{})}function bv(e,t,r){let n=vI(t),o=hv(e,t,n),i=Iv(e,t,n),a={...o,...i};return l.Update(a,{},r)}function Xa(e,t,r,n){return bv(e,r,n)}function wa(e,t={}){return C("NonNullable",[e],t)}function o$(e,t={}){return Pc(e,t)}function $v(e){let t=L([Zn(),ao()]);return Ci(e,t,{})}function Pc(e,t){return q([e])?l.Update($v(e),{},t):wa(e,t)}function i$(e,t,r,n){let o=b(e,t,r);return Pc(o,n)}function Ra(e,t,r={}){return C("Omit",[e,t],r)}function s$(e,t,r={}){let n=s.IsArray(t)?go(t):t;return Ac(e,n,r)}function Za(e){let t=xo(e);return R(t)?t.properties:Ie()}function Ev(e,t){return s.Keys(e).reduce((n,o)=>t.includes(o)?n:{...n,[o]:e[o]},{})}function a$(e,t){let r=Za(e),n=ho(t),o=Ev(r,n);return O(o)}function Ac(e,t,r){return q([e,t])?l.Update(a$(e,t),{},r):Ra(e,t,r)}function m$(e,t,r,n,o){let i=b(e,t,r),a=b(e,t,n);return Ac(i,a,o)}function Pa(e,t={}){return C("Parameters",[e],t)}function u$(e,t={}){return Oc(e,t)}function Sv(e){let t=$e(e)?e.parameters:[],r=sn({},pe([],[]),t);return ke(r)}function Oc(e,t){return q([e])?l.Update(Sv(e),{},t):Pa(e,t)}function c$(e,t,r,n){let o=b(e,t,r);return Oc(o,n)}function Aa(e,t={}){return C("Partial",[e],t)}function p$(e,t={}){return Mc(e,t)}function f$(e,t){let r=Ir(e,t),n=br(r);return lr(l.Assign(e,{[t]:n}),t)}function d$(e,t,r){let n=Zt(e,t,r);return br(n)}function l$(e){let t=Te(e);return br(t)}function g$(e){let t=e.map(r=>br(r));return L(t)}function x$(e){let t=s.Keys(e).reduce((n,o)=>({...n,[o]:Js(e[o])}),{});return O(t)}function br(e){return ie(e)?f$(e.$defs,e.$ref):Ee(e)?d$(e.if,e.then,e.else):P(e)?l$(e.allOf):E(e)?g$(e.anyOf):R(e)?x$(e.properties):O({})}function Mc(e,t){return q([e])?l.Update(br(e),{},t):Aa(e,t)}function y$(e,t,r,n){let o=b(e,t,r);return Mc(o,n)}function Oa(e,t,r={}){return C("Pick",[e,t],r)}function h$(e,t,r={}){let n=s.IsArray(t)?go(t):t;return vc(e,n,r)}function kv(e,t){return s.Keys(e).reduce((n,o)=>t.includes(o)?l.Assign(n,{[o]:e[o]}):n,{})}function I$(e,t){let r=Za(e),n=ho(t),o=kv(r,n);return O(o)}function vc(e,t,r){return q([e,t])?l.Update(I$(e,t),{},r):Oa(e,t,r)}function b$(e,t,r,n,o){let i=b(e,t,r),a=b(e,t,n);return vc(i,a,o)}function Ma(e,t={}){return C("ReadonlyObject",[e],t)}function Fc(e,t={}){return Lc(e,t)}var $$=Fc;function E$(e){return Xn(xt(e))}function S$(e,t){let r=Ir(e,t),n=$r(r);return lr(l.Assign(e,{[t]:n}),t)}function k$(e,t,r){let n=Zt(e,t,r);return $r(n)}function T$(e){let t=Te(e);return $r(t)}function C$(e){let t=s.Keys(e).reduce((n,o)=>({...n,[o]:ea(e[o])}),{});return O(t)}function w$(e){return Xn(ke(e))}function R$(e){let t=e.map(r=>$r(r));return L(t)}function $r(e){return H(e)?E$(e.items):ie(e)?S$(e.$defs,e.$ref):Ee(e)?k$(e.if,e.then,e.else):P(e)?T$(e.allOf):R(e)?C$(e.properties):N(e)?w$(e.items):E(e)?R$(e.anyOf):e}function Lc(e,t){return q([e])?l.Update($r(e),{},t):Ma(e)}function P$(e,t,r,n){let o=b(e,t,r);return Lc(o,n)}function A$(e,t,r,n){return t.visited.includes(n)?r:n in e?b(e,pe(t.callstack,[...t.visited,n]),e[n]):r}function O$(e,t){let r=Ir(e,t),n=Er(r);return lr(l.Assign(e,{[t]:n}),t)}function M$(e,t,r){let n=Zt(e,t,r);return Er(n)}function v$(e){let t=Te(e);return Er(t)}function F$(e){let t=e.map(r=>Er(r));return L(t)}function Uy(e,t={}){return C("RemoveOptional",[e],t)}function L$(e,t={}){return Tn(e,t)}function D$(e){let t=s.Keys(e).reduce((n,o)=>({...n,[o]:L$(e[o])}),{});return O(t)}function Er(e){return ie(e)?O$(e.$defs,e.$ref):Ee(e)?M$(e.if,e.then,e.else):P(e)?v$(e.allOf):E(e)?F$(e.anyOf):R(e)?D$(e.properties):O({})}function va(e,t={}){return C("Required",[e],t)}function j$(e,t={}){return Dc(e,t)}function Dc(e,t){return q([e])?l.Update(Er(e),{},t):va(e,t)}function N$(e,t,r,n){let o=b(e,t,r);return Dc(o,n)}function Fa(e,t={}){return C("ReturnType",[e],t)}function q$(e,t={}){return jc(e,t)}function Tv(e){return $e(e)?e.returnType:re()}function jc(e,t){return q([e])?l.Update(Tv(e),{},t):Fa(e,t)}function _$(e,t,r,n={}){let o=b(e,t,r);return jc(o,n)}function La(e,t){return C("With",[e,t],{})}function em(e,t){return Nc(e,t)}function Nc(e,t){return q([e])?l.Update(e,{},t):La(e,t)}function U$(e,t,r,n){let o=b(e,t,r);return Nc(o,n)}function Cv(e){return tn(e)?N(e.items)?qc(e.items.items):ve(e.items)?[e]:Z(e.items)?[e]:[re()]:[e]}function qc(e){return e.reduce((r,n)=>[...r,...Cv(n)],[])}function pe(e,t){return{callstack:e,visited:t}}function q(e){return s.ShiftLeft(e,(t,r)=>Z(t)?!1:q(r),()=>!0)}function bi(e,t,r){return s.Keys(r).reduce((n,o)=>({...n,[o]:b(e,t,r[o])}),{})}function sn(e,t,r){let n=Ft(e,t,r);return qc(n)}function Ft(e,t,r){return r.map(n=>b(e,t,n))}function wv(e,t){let r=Oe(e)?cr(t,{}):t,n=Or(e)?ur(r,{}):r;return En(e)?Pi(n,{}):n}function Rv(e,t,r,n,o){return s.IsEqual(r,"AddImmutable")?B$(e,t,n[0],o):s.IsEqual(r,"RemoveImmutable")?QI(e,t,n[0],o):s.IsEqual(r,"AddReadonly")?ql(e,t,n[0],o):s.IsEqual(r,"RemoveReadonly")?Sg(e,t,n[0],o):s.IsEqual(r,"AddOptional")?_l(e,t,n[0],o):s.IsEqual(r,"RemoveOptional")?Eg(e,t,n[0],o):s.IsEqual(r,"Capitalize")?sb(e,t,n[0],o):s.IsEqual(r,"Conditional")?pb(e,t,n[0],n[1],n[2],n[3],o):s.IsEqual(r,"ConstructorParameters")?db(e,t,n[0],o):s.IsEqual(r,"Evaluate")?_I(e,t,n[0],o):s.IsEqual(r,"Exclude")?gb(e,t,n[0],n[1],o):s.IsEqual(r,"Extract")?Ib(e,t,n[0],n[1],o):s.IsEqual(r,"Index")?Gb(e,t,n[0],n[1],o):s.IsEqual(r,"InstanceType")?Hb(e,t,n[0],o):s.IsEqual(r,"Interface")?PI(e,t,n[0],n[1],o):s.IsEqual(r,"KeyOf")?Zb(e,t,n[0],o):s.IsEqual(r,"Lowercase")?ab(e,t,n[0],o):s.IsEqual(r,"Mapped")?n$(e,t,n[0],n[1],n[2],n[3],o):s.IsEqual(r,"Module")?Xa(e,t,n[0],o):s.IsEqual(r,"NonNullable")?i$(e,t,n[0],o):s.IsEqual(r,"Pick")?b$(e,t,n[0],n[1],o):s.IsEqual(r,"Parameters")?c$(e,t,n[0],o):s.IsEqual(r,"Partial")?y$(e,t,n[0],o):s.IsEqual(r,"Omit")?m$(e,t,n[0],n[1],o):s.IsEqual(r,"ReadonlyObject")?P$(e,t,n[0],o):s.IsEqual(r,"Record")?_g(e,t,n[0],n[1],o):s.IsEqual(r,"Required")?N$(e,t,n[0],o):s.IsEqual(r,"ReturnType")?_$(e,t,n[0],o):s.IsEqual(r,"TemplateLiteral")?Wh(e,t,n[0],o):s.IsEqual(r,"Uncapitalize")?mb(e,t,n[0],o):s.IsEqual(r,"Uppercase")?ub(e,t,n[0],o):s.IsEqual(r,"With")?U$(e,t,n[0],n[1]):C(r,n,o)}function Pv(e,t,r){let n=Z(r)?A$(e,t,r,r.$ref):H(r)?xt(b(e,t,r.items),Jn(r)):lo(r)?Ya(e,t,r.target,r.arguments):be(r)?pr(Ft(e,t,r.parameters),b(e,t,r.instanceType),Ul(r)):$e(r)?fr(Ft(e,t,r.parameters),b(e,t,r.returnType),Bl(r)):Ee(r)?$n(b(e,t,r.if),b(e,t,r.then),b(e,t,r.else),Vl(r)):P(r)?ot(Ft(e,t,r.allOf),Zl(r)):R(r)?O(bi(e,t,r.properties),zl(r)):te(r)?Ug(Fe(r),b(e,t,me(r))):tn(r)?Cn(b(e,t,r.items)):N(r)?ke(sn(e,t,r.items),bg(r)):E(r)?L(Ft(e,t,r.anyOf),cg(r)):r;return wv(r,n)}function b(e,t,r){return Jr(r)?Rv(e,t,r.action,r.parameters,r.options):Pv(e,t,r)}function Dt(e,t){return b(e,pe([],[]),t)}function Pi(e,t){return l.Update(e,{"~immutable":!0},t)}function B$(e,t,r,n){let o=b(e,t,r);return Pi(o,n)}function By(e,t={}){return C("AddImmutable",[e],t)}function Xn(e,t={}){return Pi(e,t)}function Gy(e,t={}){return C("RemoveReadonly",[e],t)}function Ky(e,t={}){return C("Evaluate",[e],t)}function Ge(e,t={}){return dc(e,t)}function Hy(e,t={}){return C("Module",[e],t)}function G$(e,t={}){return Xa({},pe([],[]),e,t)}function Av(e,t){let r=no(e,t);return s.IsEqual(r,mi)||s.IsEqual(r,ki)?1:0}function K$(e,t,r=[]){return s.ShiftLeft(t,(n,o)=>s.IsEqual(Av(e,n),1)?K$(e,o,[...r,n]):[...r,e,...t],()=>[...r,e])}function H$(e,t=[]){return s.ShiftLeft(e,(r,n)=>H$(n,K$(r,t)),()=>t)}function z$(e){return H$(e)}function W$(...e){let[t,r,n]=U.Match(e,{2:(a,m)=>s.IsString(a)?[{},a,m]:[a,m,{}],3:(a,m,c)=>[a,m,c],1:a=>[{},a,{}]}),o=Bh(r),i=s.IsArray(o)&&s.IsEqual(o.length,2)?b(t,pe([],[]),o[0]):re();return l.Update(i,{},n)}function V$(e,t,r){return s.IsArray(r)?r.map(n=>Ke(e,t.items,n)):r}function J$(e,t,r){return Ke({...e,...t.$defs},_e(t.$ref),r)}function Ov(e,t){let r=s.HasPropertyKey(t,"unevaluatedProperties")?{additionalProperties:t.unevaluatedProperties}:{},n=Dt(e,t),o=Ge(n);return R(o)?em(o,r):o}function Y$(e,t,r){let n=Ov(e,t);return Ke(e,n,r)}function tm(e){return s.HasPropertyKey(e,"additionalProperties")?e.additionalProperties:void 0}function Q$(e,t,r){if(!s.IsObject(r)||s.IsArray(r))return r;let n=tm(t);for(let o of s.Keys(r)){if(s.HasPropertyKey(t.properties,o)&&le(t.properties[o])){r[o]=Ke(e,t.properties[o],r[o]);continue}if(s.IsBoolean(n)&&s.IsEqual(n,!0)||le(n)&&G(e,n,r[o])){r[o]=Ke(e,n,r[o]);continue}delete r[o]}return r}function X$(e,t,r){if(!s.IsObject(r))return r;let n=tm(t),[o,i]=[new RegExp(Fe(t)),me(t)];for(let a of s.Keys(r)){if(o.test(a)){r[a]=Ke(e,i,r[a]);continue}if(s.IsBoolean(n)&&s.IsEqual(n,!0)||le(n)&&G(e,n,r[a])){r[a]=Ke(e,n,r[a]);continue}delete r[a]}return r}function Z$(e,t,r){return s.HasPropertyKey(e,t.$ref)?Ke(e,e[t.$ref],r):r}function eE(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]=Ke(e,t.items[o],r[o]);return s.IsGreaterThan(r.length,n)?r.slice(0,n):r}function Mv(e){return s.HasPropertyKey(e,"~kind")||s.HasPropertyKey(e,"~unsafe")}function vv(e){let t={};for(let r of s.Keys(e)){if(s.IsUnsafePropertyKey(r))continue;let n=Object.getOwnPropertyDescriptor(e,r);n.value=On(n.value),s.IsEqual(n.enumerable,!0)?t[r]=n.value:Object.defineProperty(t,r,n)}return t}function Fv(e){let t={};for(let r of s.Keys(e))s.IsUnsafePropertyKey(r)||(t[r]=On(e[r]));for(let r of s.Symbols(e))t[r]=On(e[r]);return t}function Lv(e){return s.IsClassInstance(e)?e:Mv(e)?vv(e):Fv(e)}function Dv(e){return e.map(t=>On(t))}function jv(e){return e.slice()}function Nv(e){return new RegExp(e.source,e.flags)}function qv(e){return new Map(On([...e.entries()]))}function _v(e){return new Set(On([...e.values()]))}function On(e){return Le.IsTypeArray(e)?jv(e):Le.IsRegExp(e)?Nv(e):Le.IsMap(e)?qv(e):Le.IsSet(e)?_v(e):s.IsArray(e)?Dv(e):s.IsObject(e)?Lv(e):e}function tE(e){return On(e)}function ue(e){return tE(e)}function rE(e,t,r){for(let n of t.anyOf){let o=Ke(e,n,ue(r));if(G(e,n,o))return o}return r}function Ke(e,t,r){return H(t)?V$(e,t,r):ie(t)?J$(e,t,r):P(t)?Y$(e,t,r):R(t)?Q$(e,t,r):te(t)?X$(e,t,r):Z(t)?Z$(e,t,r):N(t)?eE(e,t,r):E(t)?rE(e,t,r):r}function Uv(e,t){return l.Assign(e,t)}function Bv(e){let t={};for(let r of Ef.Keys(e))t[r]=Ai(e[r]);return t}function Gv(e){return et({pattern:Fe(e)})}function Kv(e){return _c(z$(e))}function _c(e){return e.map(t=>Ai(t))}function Ai(e){let t=H(e)?xt(Ai(e.items),Jn(e)):P(e)?ot(_c(e.allOf)):E(e)?L(Kv(e.anyOf)):R(e)?O(Bv(e.properties)):te(e)?io(Gv(e),Ai(me(e))):N(e)?ke(_c(e.items)):e;return Uv(e,t)}function Io(e){return Ai(e)}function er(...e){let[t,r,n]=U.Match(e,{3:(i,a,m)=>[i,a,m],2:(i,a)=>[{},i,a]}),o=Ae.Get().unionPrioritySort?Io(r):r;return Ke(t,o,n)}var X={};At(X,{Fail:()=>Mn,IsOk:()=>Uc,Ok:()=>w,TryArray:()=>Hv,TryBigInt:()=>Bc,TryBoolean:()=>nF,TryNull:()=>mF,TryNumber:()=>fF,TryString:()=>dF,TryUndefined:()=>hF});function Uc(e){return s.IsObject(e)&&s.HasPropertyKey(e,"value")}function w(e){return{value:e}}function Mn(){}function Hv(e){return s.IsArray(e)?w(e):w([e])}function zv(e){return s.IsEqual(e,!0)?w(BigInt(1)):w(BigInt(0))}var Wv=/^-?(0|[1-9]\d*)n$/,Vv=/^-?(0|[1-9]\d*)\.\d+$/,Jv=/^-?(0|[1-9]\d*)$/;function Yv(e){return Wv.test(e)}function Qv(e){return Vv.test(e)}function Xv(e){return Jv.test(e)}function Zv(e){let t=e.toLowerCase();return Yv(e)?w(BigInt(e.slice(0,e.length-1))):Qv(e)?w(BigInt(e.split(".")[0])):Xv(e)?w(BigInt(e)):s.IsEqual(t,"false")?w(BigInt(0)):s.IsEqual(t,"true")?w(BigInt(1)):void 0}function Bc(e){return s.IsBigInt(e)?w(e):s.IsBoolean(e)?zv(e):s.IsNumber(e)?w(BigInt(Math.trunc(e))):s.IsNull(e)?w(BigInt(0)):s.IsString(e)?Zv(e):s.IsUndefined(e)?w(BigInt(0)):void 0}function eF(e){return s.IsEqual(e,BigInt(0))?w(!1):s.IsEqual(e,BigInt(1))?w(!0):void 0}function tF(e){return s.IsEqual(e,0)?w(!1):s.IsEqual(e,1)?w(!0):void 0}function rF(e){return s.IsEqual(e.toLowerCase(),"false")?w(!1):s.IsEqual(e.toLowerCase(),"true")?w(!0):s.IsEqual(e,"0")?w(!1):s.IsEqual(e,"1")?w(!0):void 0}function nF(e){return s.IsBigInt(e)?eF(e):s.IsBoolean(e)?w(e):s.IsNumber(e)?tF(e):s.IsNull(e)?w(!1):s.IsString(e)?rF(e):s.IsUndefined(e)?w(!1):void 0}function oF(e){return s.IsEqual(e,BigInt(0))?w(null):void 0}function iF(e){return s.IsEqual(e,!1)?w(null):void 0}function sF(e){return s.IsEqual(e,0)?w(null):void 0}function aF(e){let t=e.toLowerCase();return s.IsEqual(t,"undefined")||s.IsEqual(t,"null")||s.IsEqual(e,"")||s.IsEqual(e,"0")?w(null):void 0}function mF(e){return s.IsBigInt(e)?oF(e):s.IsBoolean(e)?iF(e):s.IsNumber(e)?sF(e):s.IsNull(e)?w(null):s.IsString(e)?aF(e):s.IsUndefined(e)?w(null):void 0}var nE=BigInt(Number.MAX_SAFE_INTEGER),oE=BigInt(Number.MIN_SAFE_INTEGER);function uF(e){return e<=nE&&e>=oE?w(Number(e)):void 0}function cF(e){return w(e?1:0)}function pF(e){let t=+e;if(s.IsNumber(t))return w(t);let r=e.toLowerCase();if(s.IsEqual(r,"false"))return w(0);if(s.IsEqual(r,"true"))return w(1);let n=Bc(e);return Uc(n)?n.value<=nE&&n.value>=oE?w(Number(n.value)):void 0:void 0}function fF(e){return s.IsBigInt(e)?uF(e):s.IsBoolean(e)?cF(e):s.IsNumber(e)?w(e):s.IsNull(e)?w(0):s.IsString(e)?pF(e):s.IsUndefined(e)?w(0):void 0}function dF(e){return s.IsBigInt(e)?w(e.toString()):s.IsBoolean(e)?w(e.toString()):s.IsNumber(e)?w(e.toString()):s.IsNull(e)?w("null"):s.IsString(e)?w(e):s.IsUndefined(e)?w(""):void 0}function lF(e){return s.IsEqual(e,BigInt(0))?w(void 0):void 0}function gF(e){return s.IsEqual(e,!1)?w(void 0):void 0}function xF(e){return s.IsEqual(e,0)?w(void 0):void 0}function yF(e){let t=e.toLowerCase();return s.IsEqual(t,"undefined")||s.IsEqual(t,"null")||s.IsEqual(e,"")||s.IsEqual(e,"0")?w(void 0):void 0}function hF(e){return s.IsBigInt(e)?lF(e):s.IsBoolean(e)?gF(e):s.IsNumber(e)?xF(e):s.IsNull(e)?w(void 0):s.IsString(e)?yF(e):s.IsUndefined(e)?w(e):void 0}function iE(e,t,r){return X.TryArray(r).value.map(o=>Re(e,t.items,o))}function sE(e,t,r){let n=X.TryBigInt(r);return X.IsOk(n)?n.value:r}function aE(e,t,r){let n=X.TryBoolean(r);return X.IsOk(n)?n.value:r}function mE(e,t,r){return Re({...e,...t.$defs},_e(t.$ref),r)}function uE(e,t,r){return Re(e,Ge(t),r)}function cE(e,t,r){let n=X.TryNumber(r);return X.IsOk(n)?Math.trunc(n.value):r}function pE(e,t,r){let n=Dt(e,t),o=Ge(n);return Re(e,o,r)}function IF(e,t,r){let n=X.TryBigInt(r);return X.IsOk(n)&&s.IsEqual(t.const,n.value)?n.value:r}function bF(e,t,r){let n=X.TryBoolean(r);return X.IsOk(n)&&s.IsEqual(t.const,n.value)?n.value:r}function $F(e,t,r){let n=X.TryNumber(r);return X.IsOk(n)&&s.IsEqual(t.const,n.value)?n.value:r}function EF(e,t,r){let n=X.TryString(r);return X.IsOk(n)&&s.IsEqual(t.const,n.value)?n.value:r}function fE(e,t,r){return s.IsEqual(t.const,r)?r:ag(t)?IF(e,t,r):mg(t)?bF(e,t,r):oa(t)?$F(e,t,r):ia(t)?EF(e,t,r):Ie()}function dE(e,t,r){let n=X.TryNull(r);return X.IsOk(n)?n.value:r}function lE(e,t,r){let n=X.TryNumber(r);return X.IsOk(n)?n.value:r}function rm(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]=Re(e,r,n[m]));return n}function Oi(e,t,r){return Oe(e)&&s.IsUndefined(r[t])}function SF(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)||Oi(a,m,r)||(r[m]=Re(e,a,r[m]));return s.HasPropertyKey(t,"additionalProperties")&&s.IsObject(t.additionalProperties)?rm(e,n,t.additionalProperties,r):r}function gE(e,t,r){return s.IsObjectNotArray(r)?SF(e,t,r):r}function kF(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]=Re(e,a,r[m]));return s.HasPropertyKey(t,"additionalProperties")&&s.IsObject(t.additionalProperties)?rm(e,n,t.additionalProperties,r):r}function xE(e,t,r){return s.IsObjectNotArray(r)?kF(e,t,r):r}function yE(e,t,r){return s.HasPropertyKey(e,t.$ref)?Re(e,e[t.$ref],r):r}function hE(e,t,r){let n=X.TryString(r);return X.IsOk(n)?n.value:r}function IE(e,t,r){return Re(e,Ge(t),r)}function bE(e,t,r){if(!s.IsArray(r))return r;for(let n=0;n<Math.min(t.items.length,r.length);n++)r[n]=Re(e,t.items[n],r[n]);return r}function $E(e,t,r){let n=X.TryUndefined(r);return X.IsOk(n)?n.value:r}function EE(e,t,r){if(t.anyOf.some(a=>G(e,a,r)))return r;let i=t.anyOf.map(a=>Re(e,a,ue(r))).find(a=>G(e,t,a));return s.IsUndefined(i)?r:i}function SE(e,t,r){let n=X.TryUndefined(r);return X.IsOk(n)?void 0:r}function Re(e,t,r){return H(t)?iE(e,t,r):kt(t)?sE(e,t,r):ft(t)?aE(e,t,r):ie(t)?mE(e,t,r):Se(t)?uE(e,t,r):Be(t)?cE(e,t,r):P(t)?pE(e,t,r):K(t)?fE(e,t,r):xr(t)?dE(e,t,r):ge(t)?lE(e,t,r):R(t)?gE(e,t,r):te(t)?xE(e,t,r):Z(t)?yE(e,t,r):je(t)?hE(e,t,r):se(t)?IE(e,t,r):N(t)?bE(e,t,r):Gt(t)?$E(e,t,r):E(t)?EE(e,t,r):Ct(t)?SE(e,t,r):r}function Sr(...e){let[t,r,n]=U.Match(e,{3:(o,i,a)=>[o,i,a],2:(o,i)=>[{},o,i]});return Re(t,r,n)}function kE(e,t,r){if(!s.IsArray(r))return r;for(let n=0;n<r.length;n++)r[n]=He(e,t.items,r[n]);return r}function TE(e,t,r){return He({...e,...t.$defs},_e(t.$ref),r)}function CE(e,t){return s.IsUndefined(t)?s.IsFunction(e.default)?e.default():ue(e.default):t}function wE(e,t,r){let n=Dt(e,t),o=Ge(n);return He(e,o,r)}function RE(e,t,r){if(!s.IsObject(r))return r;let n=s.Keys(t.properties);for(let o of n){let i=He(e,t.properties[o],r[o]);s.IsUndefined(i)&&(Oe(t.properties[o])||!s.HasPropertyKey(t.properties[o],"default"))||(r[o]=i)}if(!_t(t)||s.IsBoolean(t.additionalProperties))return r;for(let o of s.Keys(r))n.includes(o)||(r[o]=He(e,t.additionalProperties,r[o]));return r}function PE(e,t,r){if(!s.IsObject(r))return r;let[n,o]=[new RegExp(Fe(t)),me(t)];for(let i of s.Keys(r))n.test(i)&&bt(o)&&(r[i]=He(e,o,r[i]));if(!_t(t))return r;for(let i of s.Keys(r))n.test(i)||(r[i]=He(e,t.additionalProperties,r[i]));return r}function AE(e,t,r){return s.HasPropertyKey(e,t.$ref)?He(e,e[t.$ref],r):r}function OE(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]=He(e,n[i],r[i]));return r}function ME(e,t,r){for(let n of t.anyOf){let o=He(e,n,ue(r));if(G(e,n,o))return o}return r}function He(e,t,r){let n=bt(t)?CE(t,r):r;return H(t)?kE(e,t,n):ie(t)?TE(e,t,n):P(t)?wE(e,t,n):R(t)?RE(e,t,n):te(t)?PE(e,t,n):Z(t)?AE(e,t,n):N(t)?OE(e,t,n):E(t)?ME(e,t,n):n}function an(...e){let[t,r,n]=U.Match(e,{3:(o,i,a)=>[o,i,a],2:(o,i)=>[{},o,i]});return He(t,r,n)}function bo(e){return(...t)=>{let[r,n,o]=U.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 TF(e,t,r){return t["~codec"].decode(r)}function CF(e,t,r){return t["~codec"].encode(r)}function de(e,t,r,n){return pt(r)?s.IsEqual(e,"Decode")?TF(t,r,n):CF(t,r,n):n}function wF(e,t,r,n){if(!s.IsArray(n))return n;for(let o=0;o<n.length;o++)n[o]=xe(e,t,r.items,n[o]);return de(e,t,r,n)}function RF(e,t,r,n){let o=de(e,t,r,n);if(!s.IsArray(o))return o;for(let i=0;i<o.length;i++)o[i]=xe(e,t,r.items,o[i]);return o}function vE(e,t,r,n){return s.IsEqual(e,"Decode")?wF(e,t,r,n):RF(e,t,r,n)}function FE(e,t,r,n){return n=xe(e,{...t,...r.$defs},_e(r.$ref),n),de(e,t,r,n)}function LE(e){return e.reduce((t,r)=>({...t,...r}),{})}function DE(e,t){for(let r of t)if(!s.IsDeepEqual(e,r))return r;return e}function PF(e,t,r,n){if(s.IsEqual(r.allOf.length,0))return de(e,t,r,n);let o=r.allOf.map(m=>xe(e,t,m,er(m,ue(n)))),a=o.every(m=>s.IsObject(m))?LE(o):DE(n,o);return de(e,t,r,a)}function AF(e,t,r,n){if(s.IsEqual(r.allOf.length,0))return de(e,t,r,n);let o=de(e,t,r,n),i=r.allOf.map(m=>xe(e,t,m,er(m,ue(o))));return i.every(m=>s.IsObject(m))?LE(i):DE(o,i)}function jE(e,t,r,n){return s.IsEqual(e,"Decode")?PF(e,t,r,n):AF(e,t,r,n)}function OF(e,t,r,n){if(!s.IsObjectNotArray(n))return n;for(let o of s.Keys(r.properties))!s.HasPropertyKey(n,o)||Oi(r.properties[o],o,n)||(n[o]=xe(e,t,r.properties[o],n[o]));return de(e,t,r,n)}function MF(e,t,r,n){let o=de(e,t,r,n);if(!s.IsObjectNotArray(o))return o;for(let i of s.Keys(r.properties))!s.HasPropertyKey(o,i)||Oi(r.properties[i],i,o)||(o[i]=xe(e,t,r.properties[i],o[i]));return o}function NE(e,t,r,n){return s.IsEqual(e,"Decode")?OF(e,t,r,n):MF(e,t,r,n)}function vF(e,t,r,n){if(!s.IsObjectNotArray(n))return n;let o=new RegExp(Fe(r));for(let i of s.Keys(n))o.test(i)&&(n[i]=xe(e,t,me(r),n[i]));return de(e,t,r,n)}function FF(e,t,r,n){let o=de(e,t,r,n);if(!s.IsObjectNotArray(o))return o;let i=new RegExp(Fe(r));for(let a of s.Keys(o))i.test(a)&&(o[a]=xe(e,t,me(r),o[a]));return o}function qE(e,t,r,n){return s.IsEqual(e,"Decode")?vF(e,t,r,n):FF(e,t,r,n)}function _E(e,t,r,n){return s.HasPropertyKey(t,r.$ref)?xe(e,t,t[r.$ref],n):n}function UE(e,t,r,n){return s.IsEqual(e,"Decode")?de(e,t,r,_E(e,t,r,n)):_E(e,t,r,de(e,t,r,n))}function LF(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]=xe(e,t,r.items[o],n[o]);return de(e,t,r,n)}function DF(e,t,r,n){let o=de(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]=xe(e,t,r.items[i],o[i]);return o}function BE(e,t,r,n){return s.IsEqual(e,"Decode")?LF(e,t,r,n):DF(e,t,r,n)}function jF(e,t,r,n){for(let o of r.anyOf){if(!G(t,o,n))continue;let i=xe(e,t,o,n);return de(e,t,r,i)}return n}function NF(e,t,r,n){let o=de(e,t,r,n);for(let i of r.anyOf){let a=xe(e,t,i,ue(o));if(G(t,i,a))return a}return o}function GE(e,t,r,n){return s.IsEqual(e,"Decode")?jF(e,t,r,n):NF(e,t,r,n)}function xe(e,t,r,n){return H(r)?vE(e,t,r,n):ie(r)?FE(e,t,r,n):P(r)?jE(e,t,r,n):R(r)?NE(e,t,r,n):te(r)?qE(e,t,r,n):Z(r)?UE(e,t,r,n):N(r)?BE(e,t,r,n):E(r)?GE(e,t,r,n):de(e,t,r,n)}var Gc=class extends Ar{constructor(t,r){super("Decode",t,r)}};function qF(e,t,r){if(!G(e,t,r))throw new Gc(r,Qt(e,t,r));return r}function _F(e,t,r){let n=Ae.Get().unionPrioritySort?Io(t):t;return xe("Decode",e,n,r)}var UF=bo([(e,t,r)=>ue(r),(e,t,r)=>an(e,t,r),(e,t,r)=>Sr(e,t,r),(e,t,r)=>er(e,t,r),(e,t,r)=>qF(e,t,r),(e,t,r)=>_F(e,t,r)]);function KE(...e){let[t,r,n]=U.Match(e,{3:(o,i,a)=>[o,i,a],2:(o,i)=>[{},o,i]});return UF(t,r,n)}var Kc=class extends Ar{constructor(t,r){super("Encode",t,r)}};function BF(e,t,r){if(!G(e,t,r))throw new Kc(r,Qt(e,t,r));return r}function GF(e,t,r){let n=Ae.Get().unionPrioritySort?Io(t):t;return xe("Encode",e,n,r)}var KF=bo([(e,t,r)=>ue(r),(e,t,r)=>GF(e,t,r),(e,t,r)=>an(e,t,r),(e,t,r)=>Sr(e,t,r),(e,t,r)=>er(e,t,r),(e,t,r)=>BF(e,t,r)]);function HE(...e){let[t,r,n]=U.Match(e,{3:(o,i,a)=>[o,i,a],2:(o,i)=>[{},o,i]});return KF(t,r,n)}function HF(e,t){return pt(t)||mn(e,t.items)}function zF(e,t){return pt(t)||zE({...e,...t.$defs},_e(t.$ref))}function WF(e,t){return pt(t)||t.allOf.some(r=>mn(e,r))}function VF(e,t){return pt(t)||s.Keys(t.properties).some(r=>mn(e,t.properties[r]))}function JF(e,t){return pt(t)||mn(e,me(t))}function zE(e,t){return Hc.has(t.$ref)?!1:(Hc.add(t.$ref),pt(t)||s.HasPropertyKey(e,t.$ref)&&mn(e,e[t.$ref]))}function YF(e,t){return pt(t)||t.items.some(r=>mn(e,r))}function QF(e,t){return pt(t)||t.anyOf.some(r=>mn(e,r))}function mn(e,t){return H(t)?HF(e,t):ie(t)?zF(e,t):P(t)?WF(e,t):R(t)?VF(e,t):te(t)?JF(e,t):Z(t)?zE(e,t):N(t)?YF(e,t):E(t)?QF(e,t):pt(t)}var Hc=new Set;function WE(...e){let[t,r]=U.Match(e,{2:(n,o)=>[n,o],1:n=>[{},n]});return Hc.clear(),mn(t,r)}var Kt=class extends Error{constructor(t,r){super(r),this.type=t}};function VE(e,t){return s.IsFunction(t.default)?t.default(t):s.IsObject(t.default)?ue(t.default):t.default}function JE(e,t){if(Hr(t)&&!bt(t))throw new Kt(t,"Arrays with uniqueItems constraints must specify a default annotation");let r=yn(t)?t.minItems:0;return Array.from({length:r},()=>Pe(e,t.items))}function YE(e,t){return Cr(t)?BigInt(t.exclusiveMinimum)+BigInt(1):wr(t)?BigInt(t.minimum):BigInt(0)}function QE(e,t){return!1}function XE(e,t){let r=Pe(e,t.instanceType);return class{constructor(){Object.assign(this,r)}}}function ZE(e,t){return Pe({...e,...t.$defs},_e(t.$ref))}function eS(e,t){return Pe(e,Ge(t))}function tS(e,t){let r=Pe(e,t.returnType);return()=>r}function rS(e,t){return Cr(t)&&s.IsNumber(t.exclusiveMinimum)?t.exclusiveMinimum+1:wr(t)?t.minimum:0}function nS(e,t){let r=Dt(e,t),n=Ge(r);return Pe(e,n)}function oS(e,t){return t.const}function iS(e,t){throw new Kt(t,"Cannot create TNever types")}function sS(e,t){return null}function aS(e,t){return Cr(t)&&s.IsNumber(t.exclusiveMinimum)?t.exclusiveMinimum+1:wr(t)?t.minimum:0}function mS(e,t){return(s.IsUndefined(t.required)?[]:t.required).reduce((n,o)=>({...n,[o]:Pe(e,t.properties[o])}),{})}function uS(e,t){if(qo(t)&&!bt(t))throw new Kt(t,"Record with the minProperties constraint must have a default annotation");return{}}function cS(e,t){return s.HasPropertyKey(e,t.$ref)?Pe(e,e[t.$ref]):(()=>{throw new Kt(t,"Unable to deref Ref")})()}function pS(e,t){if((_o(t)||Do(t))&&!bt(t))throw Error("Strings with format or pattern constraints must specify default");let n=No(t)?t.minLength:0;return"".padEnd(n)}function fS(e,t){return Symbol()}function dS(e,t){let r=to(t.pattern);if(je(r))throw new Kt(t,"Unable to create TemplateLiteral due to infinite type expansion");return Pe(e,r)}function lS(e,t){return Array.from({length:t.minItems},(r,n)=>Pe(e,t.items[n]))}function gS(e,t){if(s.IsEqual(t.anyOf.length,0))throw Error("Unable to create Union with no variants");return Pe(e,t.anyOf[0])}function Pe(e,t){return bt(t)?VE(e,t):H(t)?JE(e,t):kt(t)?YE(e,t):ft(t)?QE(e,t):be(t)?XE(e,t):ie(t)?ZE(e,t):Se(t)?eS(e,t):$e(t)?tS(e,t):Be(t)?rS(e,t):P(t)?nS(e,t):K(t)?oS(e,t):yt(t)?iS(e,t):xr(t)?sS(e,t):ge(t)?aS(e,t):R(t)?mS(e,t):te(t)?uS(e,t):Z(t)?cS(e,t):je(t)?pS(e,t):yr(t)?fS(e,t):se(t)?dS(e,t):N(t)?lS(e,t):Gt(t)?void 0:E(t)?gS(e,t):Ct(t)?void 0:void 0}function Ye(...e){let[t,r]=U.Match(e,{2:(n,o)=>[n,o],1:n=>[{},n]});return Pe(t,r)}function nm(e,t){return s.IsDeepEqual(e,t)}function om(e){return Pr.Hash(e)}var im=class extends Ar{constructor(t,r){super("Parse",t,r)}};function XF(e,t,r){zs();let n=Qt(e,t,r);if(Ws(),!G(e,t,r))throw new im(r,n);return r}var ZF=bo([(e,t,r)=>ue(r),(e,t,r)=>an(e,t,r),(e,t,r)=>Sr(e,t,r),(e,t,r)=>er(e,t,r),(e,t,r)=>XF(e,t,r)]);function xS(...e){let[t,r,n]=U.Match(e,{3:(a,m,c)=>[a,m,c],2:(a,m)=>[{},a,m]});if(G(t,r,n))return n;if(Ae.Get().correctiveParse)return ZF(t,r,n);zs();let i=Qt(t,r,n);throw Ws(),new im(n,i)}function sm(e,t){return{type:"update",path:e,value:t}}function hS(e,t){return{type:"insert",path:e,value:t}}function IS(e){return{type:"delete",path:e}}function yS(e){if(!(s.IsObject(e)&&s.IsEqual(s.Symbols(e).length,0)))throw new Error("Cannot create diffs for objects with symbols keys")}function*e1(e,t,r){if(!s.IsObject(r)||s.IsArray(r))return yield sm(e,r);yS(t),yS(r);let n=s.Keys(t),o=s.Keys(r);for(let i of o)s.HasPropertyKey(t,i)||s.IsUnsafePropertyKey(i)||(yield hS(`${e}/${i}`,r[i]));for(let i of n)s.HasPropertyKey(r,i)&&(s.IsUnsafePropertyKey(i)||nm(t,r)||(yield*am(`${e}/${i}`,t[i],r[i])));for(let i of n)s.HasPropertyKey(r,i)||s.IsUnsafePropertyKey(i)||(yield IS(`${e}/${i}`))}function*t1(e,t,r){if(!s.IsArray(r))return yield sm(e,r);for(let n=0;n<Math.min(t.length,r.length);n++)yield*am(`${e}/${n}`,t[n],r[n]);for(let n=0;n<r.length;n++)n<t.length||(yield hS(`${e}/${n}`,r[n]));for(let n=t.length-1;n>=0;n--)n<r.length||(yield IS(`${e}/${n}`))}function*r1(e,t,r){let n=globalThis.Object.getPrototypeOf(t).constructor.name,o=globalThis.Object.getPrototypeOf(r).constructor.name;if(Le.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*am(`${e}/${a}`,t[a],r[a]);else return yield sm(e,r)}function*n1(e,t,r){t!==r&&(yield sm(e,r))}function*am(e,t,r){return Le.IsTypeArray(t)?yield*r1(e,t,r):s.IsArray(t)?yield*t1(e,t,r):s.IsObject(t)?yield*e1(e,t,r):yield*n1(e,t,r)}function bS(e,t){return[...am("",e,t)]}var o1=O({type:B("insert"),path:et(),value:De()}),i1=Object({type:B("update"),path:et(),value:De()}),s1=O({type:B("delete"),path:et()}),Wwe=L([o1,i1,s1]);function a1(e){return e.length>0&&e[0].path===""&&e[0].type==="update"}function m1(e){return e.length===0}function $S(e,t){if(a1(t))return ue(t[0].value);if(m1(t))return ue(e);let r=ue(e);for(let n of t)switch(n.type){case"insert":{mr.Set(r,n.path,n.value);break}case"update":{mr.Set(r,n.path,n.value);break}case"delete":{mr.Delete(r,n.path);break}}return r}var Fr=class extends Error{constructor(t,r,n,o){super(o),this.context=t,this.type=r,this.value=n}};function u1(e){let[t,r]=[new Set,[]];for(let n of e){let o=om(n);t.has(o)||(t.add(o),r.push(n))}return r}function ES(e,t,r){if(G(e,t,r))return r;let n=s.IsArray(r)?r:Ye(e,t),o=yn(t)&&n.length<t.minItems?[...n,...Array.from({length:t.minItems-n.length},()=>Ye(e,t))]:n,a=(jo(t)&&o.length>t.maxItems?o.slice(0,t.maxItems):o).map(c=>Ne(e,t.items,c));if(!Hr(t)||Hr(t)&&!s.IsEqual(t.uniqueItems,!0))return a;let m=u1(a);if(!G(e,t,m))throw new Fr(e,t,r,"Failed to repair Array due to uniqueItems constraint");return m}function SS(e,t,r){return Ne(e,Ge(t),r)}function kS(e,t,r){let n=Dt(e,t),o=Ge(n);return Ne(e,o,r)}function TS(e,t,r){if(G(e,t,r))return r;if(!s.IsObjectNotArray(r))return Ye(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?Ne(e,m,r[a]):Ye(e,m));let i=s.Keys(t.properties);if(_t(t)&&s.IsObject(t.additionalProperties))for(let a of s.Keys(r))i.includes(a)||(o[a]=Ne(e,t.additionalProperties,r[a]));return o}function CS(e,t,r){if(G(e,t,r))return r;if(s.IsNull(r)||!s.IsObject(r)||s.IsArray(r))return Ye(e,t);let n=new RegExp(Fe(t)),o=me(t),i=new Set,a={};for(let[m,c]of s.Entries(r))n.test(m)&&(a[m]=Ne(e,o,c),i.add(m));if(_t(t))for(let m of s.Keys(r))i.has(m)||(a[m]=Ne(e,t.additionalProperties,r[m]));return a}function wS(e,t,r){return s.HasPropertyKey(e,t.$ref)?Ne(e,e[t.$ref],r):(()=>{throw new Fr(e,t,r,"Unable to de-reference target type")})()}function RS(e,t,r){let n=to(t.pattern);return Ne(e,n,r)}function PS(e,t,r){return G(e,t,r)?r:s.IsArray(r)?t.items.map((n,o)=>Ne(e,n,r[o])):Ye(e,t)}function AS(e,t,r){return Z(t)?s.HasPropertyKey(e,t.$ref)?AS(e,e[t.$ref],r):(()=>{throw new Error("Unable to Deref target")})():t}function c1(e,t,r){if(!(R(t)&&s.IsObject(r)))return 0;let n=s.Keys(r);return s.Entries(t.properties).reduce((i,[a,m])=>{let c=K(m)&&s.IsEqual(m.const,r[a])?100:0,p=G(e,m,r[a])?10:0,f=n.includes(a)?1:0;return i+(c+p+f)},0)}function OS(e,t,r){let n=t.anyOf.map(a=>AS(e,a,r)),[o,i]=[n[0],0];for(let a of n){let m=c1(e,a,r);m>i&&(o=a,i=m)}return o}function p1(e,t,r){let n=L(en(t.anyOf)),o=OS(e,n,r);return Ne(e,o,r)}function MS(e,t,r){return G(e,t,r)?ue(r):bt(t)?Ye(e,t):p1(e,t,r)}function vS(e,t,r){if(G(e,t,r))return r;let n=Sr(e,t,r);return G(e,t,n)?n:Ye(e,t)}function f1(e,t,r){if(Le.IsDate(r)||Le.IsMap(r)||Le.IsSet(r)||Le.IsTypeArray(r)||s.IsConstructor(r)||s.IsFunction(r))throw new Fr(e,t,r,"Value is not repairable")}function d1(e,t,r){if(be(t)||$e(t)||yt(t))throw new Fr(e,t,r,"Type is not repairable")}function l1(e,t,r){return s.IsUndefined(r)&&!Gt(t)?Ye(e,t):r}function g1(e,t,r){return ri(t)?G(e,t,r)?r:Ye(e,t):r}function Ne(e,t,r){f1(e,t,r),d1(e,t,r);let n=l1(e,t,r),o=H(t)?ES(e,t,n):Se(t)?SS(e,t,n):P(t)?kS(e,t,n):R(t)?TS(e,t,n):te(t)?CS(e,t,n):Z(t)?wS(e,t,n):se(t)?RS(e,t,n):N(t)?PS(e,t,n):E(t)?MS(e,t,n):vS(e,t,n);return g1(e,t,o)}function FS(...e){let[t,r,n]=U.Match(e,{3:(i,a,m)=>[i,a,m],2:(i,a)=>[{},i,a]}),o=Ne(t,r,n);return Vs(t,r,o),o}var $o={};At($o,{Assert:()=>Vs,Check:()=>G,Clean:()=>er,Clone:()=>ue,Convert:()=>Sr,Create:()=>Ye,Decode:()=>KE,Default:()=>an,Diff:()=>bS,Encode:()=>HE,Equal:()=>nm,Errors:()=>Qt,HasCodec:()=>WE,Hash:()=>om,Parse:()=>xS,Patch:()=>$S,Pointer:()=>mr,Repair:()=>FS});var b1=I1(Ve,"hooks.json"),LS=64*1024,NS=30,DS=["PreToolUse","PostToolUse","UserPromptSubmit","SessionStart","Stop","PreCompact","SessionEnd"];function xPe(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($o.Check(e,t))return;let r=[...$o.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 yPe(e=b1){let t=[],r={hooks:{}};try{if(!y1(e))return{config:r,diagnostics:t};let n=h1(e,"utf8");if(Buffer.byteLength(n,"utf8")>LS)return t.push({source:e,message:`skipped: larger than ${LS} bytes`}),{config:r,diagnostics:t};let o=JSON.parse(n),i=$1(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 $1(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(!DS.includes(o)){t.push(`unknown event \`${o}\` \u2014 supported: ${DS.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=E1(m,o,t);c&&a.push(c)}a.length&&(r.hooks[o]=a)}return{config:r,diagnostics:t}}function E1(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 S1(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 jS(e,t,r={cwd:process.cwd()}){let n=r.timeoutS??NS;return new Promise(o=>{let i="",a="",m=!1,c=!1,p=x1(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 k1(e){let{code:t,stdout:r,stderr:n,timedOut:o}=e,i=n.trim();if(o)return{block:!1,error:`timed out after ${NS}s and was killed`};let a=T1(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 T1(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 hPe(){zc.clear()}async function IPe(e,t,r,n){let o=S1(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){jS(d.command,r,{cwd:n.cwd,timeoutS:d.timeout}).catch(()=>{});continue}let g=await jS(d.command,r,{cwd:n.cwd,timeoutS:d.timeout}),x=k1(g);x.context&&i.push(x.context),x.error&&(c=x.error),x.updatedInput&&(p=x.updatedInput),x.block&&!m&&(m=x)}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 qS,readFileSync as C1}from"node:fs";function w1(e){return`${e}/.howtocode/mcp.json`}function Wc(e,t){if(!qS(e))return{};try{let n=JSON.parse(C1(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 kPe(e){let t=[];return Wc(Gi(e??Ve),t)}function TPe(e){let t=[],r=Wc(Gi(e.agentDir??Ve),t),n=w1(e.cwd),o=e.projectTrusted&&qS(n)?n:void 0,i=o?Wc(o,t):{},a=Gi(e.agentDir??Ve),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 R1,readdirSync as P1,readFileSync as A1,renameSync as O1,unlinkSync as _S,writeFileSync as M1}from"node:fs";import{join as US}from"node:path";var v1=180*1e3,PPe="presence";function BS(e,t){return US(e.dir,`${t.replace(/[^A-Za-z0-9._-]/g,"_")}.json`)}function F1(e,t=Date.now()){let r;try{r=P1(e.dir)}catch{return[]}let n=[];for(let o of r){if(!o.endsWith(".json"))continue;let i=US(e.dir,o),a;try{a=A1(i,"utf8")}catch{continue}let m;try{m=JSON.parse(a)}catch{Vc(i);continue}if(typeof m?.id!="string"||typeof m?.cwd!="string"||typeof m?.at!="number"){Vc(i);continue}if(t-m.at>=v1){Vc(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 APe(e,t){R1(e.dir,{recursive:!0});let r=BS(e,t.id),n=`${r}.${process.pid}.tmp`;M1(n,JSON.stringify(t,null,2)),O1(n,r)}function OPe(e,t){try{_S(BS(e,t))}catch{}}function GS(e,t,r,n=Date.now()){return F1(e,n).filter(o=>o.cwd===t&&o.id!==r)}function Vc(e){try{_S(e)}catch{}}import{Type as Qe}from"@netrodev/hxf-ai";import{defineTool as mm}from"@netrodev/hxf-coding-agent";import{relative as K1,join as H1}from"node:path";import{mkdirSync as z1,writeFileSync as W1}from"node:fs";import{existsSync as FPe,mkdirSync as L1,readFileSync as D1,renameSync as j1,writeFileSync as N1}from"node:fs";import{dirname as q1,isAbsolute as _1,join as zS,relative as U1,resolve as KS,sep as HS}from"node:path";var B1=1800*1e3,G1=zS(".howtocode","claims.json");function WS(e){return zS(e,G1)}function Yc(e,t){try{let r=D1(WS(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<B1)}catch{return[]}}function VS(e,t){let r=WS(e);L1(q1(r),{recursive:!0});let n=`${r}.${process.pid}.tmp`;N1(n,JSON.stringify({version:1,claims:[...t]},null,2)),j1(n,r)}function JS(e,t){return _1(t)?KS(t):KS(e,t)}function YS(e,t){if(e===t)return!0;let r=n=>n.endsWith(HS)?n:n+HS;return e.startsWith(r(t))||t.startsWith(r(e))}function QS(e){let t=e.now??Date.now(),r=Yc(e.root,t),n=[],o=[],i=[];for(let a of e.paths){if(!a.trim())continue;let m=JS(e.root,a.trim()),c=r.find(p=>p.holder!==e.holder&&YS(p.path,m));if(c){o.push({path:Jc(e.root,m),by:c.holder,reason:c.reason||"no reason given"});continue}n.push(Jc(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));VS(e.root,[...a,...i])}return{granted:n,conflicts:o}}function XS(e,t,r){let n=Date.now(),o=Yc(e,n),i=r?.length?r.map(c=>JS(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=>YS(c.path,d));p&&f?m.push(Jc(e,c.path)):a.push(c)}return VS(e,a),m}function Qc(e,t=Date.now()){return Yc(e,t)}function Jc(e,t){let r=U1(e,t);return r&&!r.startsWith("..")?r:t}var Xc;function GPe(e){Xc=e}var KPe=mm({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:Qe.Object({thoughts:Qe.String({description:"Private notes"})}),async execute(){return{content:[{type:"text",text:"noted"}],details:{recorded:!0}}}}),HPe=mm({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:Qe.Object({question:Qe.String(),options:Qe.Array(Qe.String(),{minItems:2})}),async execute(e,t){if(!Xc)return{content:[{type:"text",text:"cancelled"}],details:{answer:"cancelled"}};let r=await Xc(t.question,t.options);return{content:[{type:"text",text:r}],details:{answer:r}}}}),Mi;function zPe(e){Mi=e}var WPe=mm({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:Qe.Object({message:Qe.Optional(Qe.String({description:"Message text to leave for another session."})),to:Qe.Optional(Qe.String({description:"Session id to send the message to. Use `all` for every other session."}))}),async execute(e,t){let r=Mi,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=GS({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=H1(n,`${f.id.replace(/[^A-Za-z0-9._-]/g,"_")}.inbox`);try{z1(n,{recursive:!0}),W1(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=Qc(i).filter(x=>x.holder===`session:${c.id}`),d=c.activity?` \u2014 ${c.activity}`:"",g=f.length>0?`
13
+ holds:
14
+ ${f.map(x=>` ${ek(i,x.path)} \u2014 ${x.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 V1(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 ZS=mm({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:Qe.Object({paths:Qe.Optional(Qe.Array(Qe.String(),{description:"Files or directories to claim. Omit to list the current claims."})),reason:Qe.Optional(Qe.String({description:"Why you are taking them, shown to a refused agent."})),release:Qe.Optional(Qe.Boolean({description:"Release these paths instead of claiming them. Omit paths to release everything you hold."}))}),async execute(e,t){if(!Mi)return{content:[{type:"text",text:"claims are unavailable in this session"}],details:{},isError:!0};let r=Mi.root(),n=Mi.holder();if(t.release){let m=XS(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=Qc(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) ":""}${ek(r,p.path)} \u2014 ${p.reason}`).join(`
19
+ `)}],details:{claims:m}}}let o=QS({root:r,holder:n,reason:t.reason??"no reason given",paths:t.paths}),{text:i,isError:a}=V1(o);return{content:[{type:"text",text:i}],isError:a,details:o}}});function ek(e,t){let r=K1(e,t);return r&&!r.startsWith("..")?r:t}import{StringEnum as J1}from"@netrodev/hxf-ai";import{defineTool as Y1}from"@netrodev/hxf-coding-agent";var M={};At(M,{Any:()=>Qn,Array:()=>xt,BigInt:()=>ni,Boolean:()=>ta,Call:()=>JI,Capitalize:()=>rb,Codec:()=>Zs,Conditional:()=>cb,Constructor:()=>pr,ConstructorParameters:()=>fb,Cyclic:()=>lr,Decode:()=>eg,DecodeBuilder:()=>ti,Dependent:()=>$n,Encode:()=>tg,EncodeBuilder:()=>ei,Enum:()=>Xl,Evaluate:()=>Ge,Exclude:()=>lb,Extends:()=>tt,ExtendsResult:()=>v,Extract:()=>xb,Function:()=>fr,Generic:()=>Yr,Identifier:()=>oi,Immutable:()=>rg,Index:()=>bb,Infer:()=>Zo,InstanceType:()=>Kb,Instantiate:()=>Dt,Integer:()=>Sn,Interface:()=>AI,Intersect:()=>ot,IsAny:()=>ye,IsArray:()=>H,IsBigInt:()=>kt,IsBoolean:()=>ft,IsCall:()=>lo,IsCodec:()=>pt,IsConstructor:()=>be,IsCyclic:()=>ie,IsDependent:()=>Ee,IsEnum:()=>Se,IsEnumValue:()=>Ql,IsFunction:()=>$e,IsGeneric:()=>Yn,IsIdentifier:()=>sg,IsImmutable:()=>En,IsInfer:()=>ve,IsInteger:()=>Be,IsIntersect:()=>P,IsKind:()=>T,IsLiteral:()=>K,IsNever:()=>yt,IsNull:()=>xr,IsNumber:()=>ge,IsObject:()=>R,IsOptional:()=>Oe,IsParameter:()=>ug,IsReadonly:()=>Or,IsRecord:()=>te,IsRef:()=>Z,IsRefine:()=>ri,IsRest:()=>tn,IsSchema:()=>le,IsString:()=>je,IsSymbol:()=>yr,IsTemplateLiteral:()=>se,IsThis:()=>ga,IsTuple:()=>N,IsUndefined:()=>Gt,IsUnion:()=>E,IsUnknown:()=>Me,IsUnsafe:()=>Xs,IsVoid:()=>Ct,KeyOf:()=>zb,Literal:()=>B,Lowercase:()=>nb,Mapped:()=>e$,Module:()=>G$,Never:()=>re,NonNullable:()=>o$,Null:()=>Zn,Number:()=>Tt,Object:()=>O,Omit:()=>s$,Optional:()=>Kl,Parameter:()=>kn,Parameters:()=>u$,Partial:()=>p$,Pick:()=>h$,Readonly:()=>ng,ReadonlyObject:()=>Fc,ReadonlyType:()=>$$,Record:()=>io,RecordKey:()=>so,RecordPattern:()=>Fe,RecordValue:()=>me,Ref:()=>_e,Refine:()=>og,Required:()=>j$,Rest:()=>Cn,ReturnType:()=>q$,Script:()=>W$,String:()=>et,Symbol:()=>eo,TemplateLiteral:()=>Jh,This:()=>la,Tuple:()=>ke,Uncapitalize:()=>ob,Undefined:()=>ao,Union:()=>L,Unknown:()=>De,Unsafe:()=>Wl,Uppercase:()=>ib,Void:()=>xa,With:()=>em});var Q1={pending:"[ ]",in_progress:"[>]",completed:"[x]",dropped:"[-]"},X1=M.Object({op:J1(["init","start","done","drop","view"],{description:"init replaces the list; start/done/drop move one task; view reads it"}),items:M.Optional(M.Array(M.String(),{description:"Task labels for init. 5-10 words each, specific enough to execute without re-planning"})),task:M.Optional(M.String({description:"Exact label of the task to start, complete or drop"}))});function tk(e){if(e.length===0)return"Todo list is empty.";let t=e.filter(o=>o.status==="completed").length,r=e.map(o=>`${Q1[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 Z1(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 eL(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 rk=Y1({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:X1,async execute(e,t,r,n,o){let i=eL(o),{todos:a,error:m}=Z1(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
+ ${tk(a)}`:tk(a)}],details:c,...m?{isError:!0}:{}}}});import{StringEnum as tL}from"@netrodev/hxf-ai";import{defineTool as rL}from"@netrodev/hxf-coding-agent";var kr=new Map,nk=2e3,ok=80;function $Oe(){kr.clear()}function ik(){return kr.size===0?"":["<shared-notes>","Working notes recorded with the `context` tool. They survive compaction and are visible to every agent on this task.",...[...kr].map(([t,r])=>`- ${t}: ${r}`),"</shared-notes>"].join(`
22
+ `)}function nL(e,t,r){if(e==="list")return kr.size===0?{text:"No notes."}:{text:[...kr].map(([n,o])=>`${n} = ${o}`).join(`
23
+ `)};if(!t)return{text:"Error: key is required",error:"key required"};if(t.length>ok)return{text:`Error: key longer than ${ok} characters`,error:"key too long"};if(e==="forget")return{text:kr.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>nk?`${r.slice(0,nk)}\u2026`:r;return kr.set(t,n),{text:`Recorded ${t} (${kr.size} note${kr.size===1?"":"s"} held)`}}return{text:`Error: unknown op ${JSON.stringify(e)}`,error:"unknown op"}}var sk=rL({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:M.Object({op:tL(["set","list","forget"],{description:"set writes a note, list reads all, forget removes one"}),key:M.Optional(M.String({description:"Short lookup key, e.g. 'auth-entrypoint'"})),value:M.Optional(M.String({description:"The fact to keep (for set)"}))}),async execute(e,t){let{text:r,error:n}=nL(t.op,t.key,t.value);return{content:[{type:"text",text:r}],details:{op:t.op,notes:Object.fromEntries(kr)},...n?{isError:!0}:{}}}});import{StringEnum as oL}from"@netrodev/hxf-ai";import{defineTool as iL}from"@netrodev/hxf-coding-agent";var ak="howtocode.goal",COe="howtocode.goal.continue",mk=400,um=25,uk={active:"\u25CF",paused:"\u2016",done:"\u2713",cleared:"\u25CB"};function sL(e){if(!e||e.status==="cleared")return"No goal set.";let t=e.budget??um,r=[`${uk[e.status]} ${e.status}`,`${e.used}/${t} continuations`];return e.note&&r.push(e.note),`${r.join(" \xB7 ")}
24
+ ${e.text}`}function wOe(e){if(!e||e.status==="cleared"||e.status==="done")return"";let t=e.budget??um,r=e.text.length>48?`${e.text.slice(0,47)}\u2026`:e.text;return`goal ${uk[e.status]} ${e.used}/${t} \xB7 ${r}`}function ROe(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 POe(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??um}.`].join(`
26
+ `)}var ck;function AOe(){return ck}function aL(e){ck=e}function OOe(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??um;return e.used>=t?{action:"stop",reason:`budget exhausted (${t} continuations)`,close:!0}:{action:"continue"}}function mL(e,t,r,n,o){switch(t){case"view":return{goal:e};case"set":return r?.trim()?r.length>mk?{goal:e,error:`text longer than ${mk} 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 uL(e){let t;for(let r of e.sessionManager.getBranch()){if(r.type==="custom"&&r.customType===ak){t=r.data;continue}if(r.type==="custom_message"&&r.customType===ak){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 cL=M.Object({op:oL(["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:M.Optional(M.String({description:"The goal, in one sentence, as the user would state it (for set)"})),budget:M.Optional(M.Number({description:"Optional cap on automatic continuations before the run stops"})),note:M.Optional(M.String({description:"Evidence that the goal is met (required for complete)"}))}),MOe=iL({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:cL,async execute(e,t,r,n,o){let i=uL(o),{goal:a,error:m}=mL(i,t.op,t.text,t.budget,t.note);aL(a);let c=sL(a);return{content:[{type:"text",text:m?`Error: ${m}
27
+ ${c}`:c}],details:{op:t.op,goal:a},...m?{isError:!0}:{}}}});import{existsSync as tp,mkdirSync as pk,readFileSync as fk}from"node:fs";import{dirname as dk,join as lk}from"node:path";import{defineTool as gk}from"@netrodev/hxf-coding-agent";function cm(){return{state:"inactive",wasActive:!1}}function pL(e){return e?e.state==="pending"?{...e,state:"inactive"}:{...e}:cm()}function qOe(e){return e.state!=="inactive"?e:{...e,state:"pending"}}function fL(e){return e.state!=="pending"?e:{state:"active",wasActive:!0}}function dL(e){return e.state!=="inactive"?e:{state:"active",wasActive:!0}}function lL(e){return e.state!=="active"?e:{...e,state:"inactive"}}function _Oe(e){return e.state==="inactive"?e:{...e,state:"inactive"}}function pm(e){return e.state==="active"}function gL(e,t){return e===t}function xL(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 yL(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 st,at=cm(),ep;function UOe(){return at}function BOe(){return st}function GOe(){return pm(at)}function xk(){if(!(!st||!tp(st)))try{let e=fk(st,"utf8");return e.trim()?e:void 0}catch{return}}function yk(){return xk()!==void 0}function KOe(){return at.state==="inactive"?"":at.state==="pending"?"plan pending":yk()?"plan \u25CF ready":"plan \u25CF planning"}function hk(){return ep?lk(ep,"plan_mode.json"):void 0}function hL(){let e=hk();if(e)try{pk(dk(e),{recursive:!0}),sr(e,JSON.stringify(at))}catch{}}function IL(){let e=hk();if(!e||!tp(e))return cm();try{return pL(JSON.parse(fk(e,"utf8")))}catch{return cm()}}function bL(e){ep=e,st=lk(e,"plan.md"),at=IL()}function rp(e){return at=e,hL(),at}function HOe(){return e=>{e.on("tool_call",async t=>{if(!pm(at)||t.toolName!=="edit"&&t.toolName!=="write")return;let r=t.input?.path;if(typeof r=="string"&&!(!st||gL(r,st)))return{block:!0,reason:yL(st)}})}}function zOe(){return e=>{e.on("session_start",async(t,r)=>{bL(r.sessionManager.getSessionDir())}),e.on("before_agent_start",async()=>{at.state==="pending"&&rp(fL(at))}),e.on("context_with_system",async t=>{if(!pm(at)||!st)return;let r=t.messages[0];if(!r||r.role!=="system")return;let n=xL(st,yk()),o=`${typeof r.content=="string"?r.content:""}
29
+
30
+ ${n}`;return{messages:t.messages.map(a=>a===r?{...r,content:o}:a)}})}}var Zc=2e4;function $L(){if(st){try{pk(dk(st),{recursive:!0}),tp(st)||sr(st,"")}catch{return}return st}}var WOe=gk({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:M.Object({}),async execute(e,t,r,n,o){if(at.state!=="inactive")return{content:[{type:"text",text:`Plan mode is already ${at.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:{}};rp(dL(at));let a=$L();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}}}}),VOe=gk({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:M.Object({}),executionMode:"sequential",async execute(e,t,r,n,o){if(!pm(at))return{content:[{type:"text",text:"Plan mode is not active."}],details:{},isError:!0};let i=xk();if(!i)return{content:[{type:"text",text:`No plan has been written yet. Write it to ${st??"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>Zc?`${i.slice(0,Zc)}
32
+ \u2026 (${i.length-Zc} more characters)`:i;return await o.ui.confirm("Approve this plan?",a)?(rp(lL(at)),{content:[{type:"text",text:"Plan approved. You may now implement it."}],details:{approved:!0,planFile:st}}):{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 Eo(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 fm(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 Ik(){return e=>{e.on("context_with_system",async t=>{let r=ik();if(!r)return;let n=t.messages[0];if(!n||n.role!=="system")return;let o=`${Eo(n.content)}
34
+
35
+ ${r}`;return{messages:t.messages.map(a=>a===n?{...n,content:fm(n.content,o)}:a)}})}}import{Type as vn}from"@netrodev/hxf-ai";import{defineTool as EL}from"@netrodev/hxf-coding-agent";var So="[Compressed conversation section]";function vi(e){return Math.round(e.length/4)}function np(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 op(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 ip(e,t,r="xml"){let n=Oo(Nn(e,r),void 0,r),o=t.trim();return o.length===0?`${So}
36
+ ${n}`:`${So}
37
+ ${o}
38
+
39
+ ${n}`}function Lr(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 sp(e,t,r,n,o,i,a){let m=e.prune.messages,c=[...new Set(a.filter($=>Number.isInteger($)&&$>0))],p=new Set;for(let $ of m.blocks)if($.active)for(let S of $.coveredIndices)p.add(S);let f=new Set(r.indices);for(let $ of c){let S=m.blocks.find(_=>_.blockId===$);if(S)for(let _ of S.coveredIndices)f.add(_)}let d=[...f].sort(($,S)=>$-S),g=d.filter($=>!p.has($)),x=0;for(let $ of g)x+=r.tokenByIndex.get($)??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:x,summaryTokens:vi(i),coveredIndices:d,consumedBlockIds:c,parentBlockIds:[],createdAt:Date.now(),summary:i};m.blocks.push(I);let h=Date.now();for(let $ of c){let S=m.blocks.find(_=>_.blockId===$);!S||!S.active||(S.active=!1,S.deactivatedAt=h,S.deactivatedByBlockId=o,S.parentBlockIds.includes(o)||S.parentBlockIds.push(o))}return e.stats.totalCompressTokens+=x,{compressedTokens:x,coveredIndices:d,newlyCoveredIndices:g}}function $k(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 Ek(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 ap(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=bk(e,o,t.startId,"startId",n),m=bk(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 bk(e,t,r,n,o){let i=Dm(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 Sk(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:ap(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 kk(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=ap(t,m,r,n),p=new Set(c.requiredBlockIds),f=$k(m.summary,n),d=new Set,g=`content[${a}]`;for(let x of f){if(d.has(x.blockId))throw new Error(`${g}.summary duplicates placeholder ${x.raw}`);if(d.add(x.blockId),!p.has(x.blockId))throw new Error(o.has(x.blockId)?`${g}.summary references ${x.raw}, which is outside the selected range`:`${g}.summary references ${x.raw}, which is not an active compressed block`)}for(let x of c.requiredBlockIds)if(!d.has(x)){let I=n==="compact"?`@b${x}@`:`(b${x})`;throw new Error(`${g}.summary is missing the required placeholder ${I}`)}return f})}function Tk(e,t,r,n="xml"){return e.map((o,i)=>{let a={startId:o.startId.trim(),endId:o.endId.trim(),summary:o.summary},m=ap(t,a,r,n);return{index:i,entry:a,selection:m,anchorIndex:m.startIdx}})}function SL(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 kL(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+=SL(m.summary),o=a.endIndex,i.push(a.blockId)}return n+=e.slice(o),{expanded:n,consumedBlockIds:i}}function Ck(e,t,r,n="xml"){Ek(e),Sk(e.content,t,r,n);let o=kk(e.content,t,r,n),i=Tk(e.content,t,r,n),a=op(t),m=[];for(let[c,p]of i.entries()){let f=o[c]??[],{expanded:d,consumedBlockIds:g}=kL(p.entry.summary,f,t),x=np(t),I=ip(x,d,n),h=sp(t,{topic:e.topic,startId:p.entry.startId,endId:p.entry.endId,mode:"range",runId:a},p.selection,p.anchorIndex,x,I,g);m.push({blockId:x,runId:a,coveredCount:h.coveredIndices.length,compressedTokens:h.compressedTokens,summaryTokens:vi(I),expandedSummary:d})}return m}function TL(e){let t=e.format??"xml",r=jn(1,t),n=Nn(2,t);return EL({name:"compress",label:"compress",description:`Collapse conversation ranges into stored compressed summaries, each marked with "${So}". 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:vn.Object({topic:vn.String({description:"Short label (3-5 words) for display - e.g., 'Auth System Exploration'"}),content:vn.Array(vn.Object({startId:vn.String({description:`Message or block ID marking the beginning of range (e.g. ${r}, ${n})`}),endId:vn.String({description:`Message or block ID marking the end of range (e.g. ${jn(12,t)}, ${Nn(5,t)})`}),summary:vn.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=Ck(i,e.state(),e.messages(),t),m=a.map(g=>g.blockId),c=a.reduce((g,x)=>g+x.coveredCount,0),p=a.reduce((g,x)=>g+x.compressedTokens,0),f=a.reduce((g,x)=>g+x.summaryTokens,0),d=Math.max(0,p-f);return{content:[{type:"text",text:`Compressed ${c} messages into ${So}`+(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 wk,mkdirSync as CL,readFileSync as Rk,unlinkSync as wL}from"node:fs";import{dirname as RL,join as Pk}from"node:path";function mp(e){try{let t=Pk(e,".howtocode","dcp.json");if(!wk(t))return;let r=JSON.parse(Rk(t,"utf8"));if(typeof r!="object"||r===null)return;let n=r.enabled;return typeof n=="boolean"?n:void 0}catch{return}}function up(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 Ak(){return{messageIds:Lm(),prune:{tools:{},messages:{blocks:[],nextBlockId:1,nextRunId:1}},stats:{totalPruneTokens:0,totalCompressTokens:0}}}function lm(e){let t=e.replace(/[^A-Za-z0-9._-]/g,"_")||"session";return Pk(Ve,"dcp",`${t}.json`)}function PL(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 dm=new Map;function Fi(e){let t=dm.get(e);if(t)return t;let r;try{let o=lm(e);if(wk(o)){let i=JSON.parse(Rk(o,"utf8"));PL(i)&&(r=i)}}catch{r=void 0}let n=r??Ak();return dm.set(e,n),n}function un(e){let t=dm.get(e);if(!t)return;let r=lm(e);CL(RL(r),{recursive:!0}),sr(r,JSON.stringify(t))}function AL(e){dm.delete(e);try{wL(lm(e))}catch{}}function tr(e){return e.replaceAll("\\","/")}function OL(e){return/[\\.^$+{}()|\[\]]/.test(e)?`\\${e}`:e}function cp(e,t){if(!t)return!1;let r=tr(e),n=tr(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+=OL(a)}return o+="$",new RegExp(o).test(r)}function gm(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 Ok(e,t){return e.length===0||t.length===0?!1:e.some(r=>t.some(n=>cp(r,n)))}var ML=/[*?]/,Fn=["todo","goal","context","task"];function Mk(e,t){if(!e||t.length===0)return!1;let r=new Set,n=[];for(let o of t)ML.test(o)?n.push(o):r.add(o);return r.has(e)?!0:n.some(o=>cp(e,o))}function xm(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=>Mk(a.tool,r)||Ok(gm(a.tool,a.input),n))}function fp(e,t){return t==null?e:`${e}::${JSON.stringify(pp(vL(t)))}`}function vL(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 pp(e){if(typeof e!="object"||e===null)return e;if(Array.isArray(e))return e.map(pp);let t={};for(let r of Object.keys(e).sort())t[r]=pp(e[r]);return t}var ko="[Output removed to save context - information superseded or no longer needed]",dp="[input removed due to failed tool call]",Fk="[questions removed - see output for user's answers]",Lk=2e3,ym=["ask","question"],vk=["read","grep","ls"],FL=["edit","write","multiedit","apply_patch","patch"];function LL(e){return e.filter(t=>t.type==="text").map(t=>t.text).join("")}function DL(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 jL(e){return e.replace(/[.*+?^${}()|[\]\\]/g,"\\$&")}function lp(e,t,r){let n=r?.bigOutputChars??Lk,o=new Map,i=[];for(let h=0;h<e.length;h++){let $=e[h];if($.role==="assistant")for(let S of $.content)S.type==="toolCall"&&o.set(S.id,{name:S.name,args:S.arguments,callIndex:h});else if($.role==="toolResult"){let S=o.get($.toolCallId),_=$.toolName;i.push({index:h,callId:$.toolCallId,tool:_,isError:$.isError,text:LL($.content),paths:S?gm(_,S.args):[],signature:fp(_,S?.args),callIndex:S?.callIndex??-1})}}let a=t.planFile?tr(t.planFile):void 0,m=h=>h.index===0||Fn.includes(h.tool)||a!==void 0&&h.paths.some($=>tr($)===a),c=h=>h.callIndex<0||h.callIndex===0||Fn.includes(h.tool)||a!==void 0&&h.paths.some($=>tr($)===a),p=[],f=new Set,d=h=>{let $=`${h.kind}:${h.callId}`;f.has($)||(f.add($),p.push(h))},g=new Map;for(let h of i)if(!(h.isError||!vk.includes(h.tool)&&!FL.includes(h.tool)))for(let $ of h.paths){let S=tr($),_=g.get(S);(_===void 0||h.index>_)&&g.set(S,h.index)}for(let h of i){if(h.isError||!vk.includes(h.tool)||m(h)||h.text===ko)continue;h.paths.some(S=>(g.get(tr(S))??-1)>h.index)&&d({kind:"output",reason:"superseded-read",callId:h.callId,messageIndex:h.index,savedChars:Math.max(0,h.text.length-ko.length)})}let x=new Map;for(let h of i){if(h.isError)continue;let $=x.get(h.signature);($===void 0||h.index>$)&&x.set(h.signature,h.index)}for(let h of i){if(!h.isError||m(h))continue;let $=x.get(h.signature);if(!($===void 0||$<=h.index)&&(d({kind:"output",reason:"error-then-success",callId:h.callId,messageIndex:h.index,savedChars:Math.max(0,h.text.length-ko.length)}),!c(h))){let S=o.get(h.callId)?.args,{total:_,count:A}=DL(S);A>0&&d({kind:"failed-input",reason:"error-then-success",callId:h.callId,messageIndex:h.callIndex,savedChars:Math.max(0,_-A*dp.length)})}}if(t.files.length>0||t.identifiers.length>0){let h=[...t.files.map(tr),...a?[a]:[]],$=h.map(A=>A.split("/").pop()??"").filter(A=>A.length>0),S=t.identifiers.map(A=>new RegExp(`(?<![\\w.-])${jL(A)}(?![\\w.-])`)),_=A=>{let Xe=tr(A);return h.some(rt=>Xe.includes(rt))||$.some(rt=>A.includes(rt))?!0:S.some(rt=>rt.test(A))};for(let A of i)m(A)||ym.includes(A.tool)||A.text.length<=n||_(A.text)||d({kind:"output",reason:"unrelated-big-output",callId:A.callId,messageIndex:A.index,savedChars:Math.max(0,A.text.length-ko.length)})}let I=0;for(let h of p)I+=h.savedChars;return{ops:p,savedChars:I}}function gp(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 Nk(jk(Dk(e,r),n),o)}function Dk(e,t){return t.size===0?[...e]:e.map((r,n)=>n===0||r.role!=="toolResult"||!t.has(r.toolCallId)||ym.includes(r.toolName)?r:{...r,content:[{type:"text",text:ko}]})}function jk(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)||!ym.includes(m.name))return m;let c={...m.arguments},p=!1;for(let f of["question","questions","options"])f in c&&(c[f]=Fk,p=!0);return p?(i=!0,{...m,arguments:c}):m});return i?{...n,content:a}:n})}function Nk(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]=dp,p=!0):c[f]=d;return p?(i=!0,{...m,arguments:c}):m});return i?{...n,content:a}:n})}function xp(e,t,r){if(t.length===0)return[...e];let n=Br(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 x=o.get(d.anchorIndex)??(g.length>0?Math.min(...g):void 0);if(d.summary&&x!==void 0){let I=a.get(x);I?I.push(d.summary):a.set(x,[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 x of g.content)x.type==="toolCall"&&m.set(d,x.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 x=e[d];if(x?.role==="toolResult")for(let[I,h]of m)h===x.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 x=e[d];for(let I of g){let h={role:"user",content:I,timestamp:x.timestamp};f.push(h)}}i.has(d)||f.push(e[d])}return f}var yp={thresholdChars:8192,headChars:4096,tailChars:1024};function NL(e,t={}){let r=t.thresholdChars??yp.thresholdChars,n=t.headChars??yp.headChars,o=t.tailChars??yp.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 qk(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 x=NL(g.text,t);return x.prunedChars<=0?d:(p=!0,r+=x.prunedChars,{...d,text:x.text})});return p?(o=!0,n+=1,{...a,content:f}):a});return{messages:o?i:e,savedChars:r,prunedResults:n}}function hp(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 Ip(e,t,r,n){let o=new Map;if(t.idState){let m=Br(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 Lr(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 _k(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 Uk(e,t,r,n,o,i){if(!o)return e;let a=[];for(let p of Ip(t,r,n,i)){let f=r.messages[p];if(!f||f.role!=="user")continue;let d=_k(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 Bk(e,t,r,n,o,i){if(!o)return e;let a=[];for(let p of Ip(t,r,n,i)){let f=r.messages[p];if(!(!f||f.role!=="user"))for(let d of _k(f))a.push(...Gk(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 Gk(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 Kk(e,t,r,n,o=[],i=[],a){let m=new Map,c=[];for(let x of Ip(t,r,n,a)){let I=r.messages[x];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($=>$.type==="text").map($=>$.text).join("");h.trim()&&c.push({toolCallId:I.toolCallId,toolName:I.toolName,text:h})}}}if(c.length===0)return e;let p=[...new Set([...Fn,...o])],f=[...i],d=[];for(let x of c){let I=m.get(x.toolCallId);xm(x.toolName,I,p,f)&&d.push(`
112
+ ### Tool: ${x.toolName}
113
+ ${x.text}`)}return d.length===0?e:e+`
114
+
115
+ The following protected tools were used in this conversation as well:`+d.join("")}function Hk(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=Kk(Bk(Uk(t.summary,o,i,e,!0,t.blockId),o,i,e,!0,t.blockId),o,i,e,[],[],t.blockId);t.summary=a,t.summaryTokens=vi(a)}t.protectedEnriched=!0}function zk(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?Eo(i.content):"";r.push({index:o,tokenCount:Math.round(a.length/4)})}return r}var qL="COMPRESSED BLOCK PLACEHOLDERS",bp=new Map;function _L(e){return bp.get(e)??[]}function UL(e){bp.delete(e)}var Wk;function BL(){return Wk}function GL(e={}){return t=>{t.on("context_with_system",async(r,n)=>{let o=n?.sessionManager?.getSessionId()??"dcp-sessionless",i=Fi(o);if(i.enabled===!1)return;let a=r.messages,m=a[0];if(!m||m.role!=="system")return;Nm(i.messageIds,a);let c=Br(i.messageIds,a);bp.set(o,zk(c,a)),Wk=o;let p=KL(a),f=xp(p,Lr(i),i.messageIds),d=qk(f);d.prunedResults>0&&(f=[...d.messages]);let g=e.keepSet?.()??{files:[],identifiers:[]},x=lp(f,g);if(x.ops.length>0){f=gp(f,x.ops);for(let h of x.ops)i.prune.tools[h.callId]=(i.prune.tools[h.callId]??0)+h.savedChars;i.stats.totalPruneTokens=Object.values(i.prune.tools).reduce((h,$)=>h+$,0)}for(let h of i.prune.messages.blocks)h.active&&!h.protectedEnriched&&Hk(i,h,a);un(o);let I=f.map((h,$)=>{if($!==0||!("content"in h))return h;let S=Eo(h.content);return S.includes(qL)?h:{...h,content:fm(h.content,`${S}
116
+
117
+ ${hp()}`)}});return{messages:zL(I,i.messageIds)}})}}function KL(e){return e.map(t=>{if(t.role!=="assistant"||!("content"in t))return t;let r=HL(t.content);return r===t.content?t:{...t,content:r}})}function HL(e){if(typeof e=="string")return jm(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=jm(o);return i===o?n:(t=!0,{...n,text:i})});return t?r:e}function zL(e,t){let r=Br(t,e);return e.map((n,o)=>{let i=r[o];if(i==null||!("content"in n))return n;let a=Oo(jn(i));return Eo(n.content).includes(a)?n:{...n,content:WL(n.content,a)}})}function WL(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 Vk={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 $p(e){return e<1e3?`${e}`:`${(e/1e3).toFixed(1)}k`}function VL(e,t,r){let[n]=e.trim().split(/\s+/),o=n===void 0||n===""?"status":n,i=Fi(r);switch(o){case"on":return i.enabled=!0,un(r),"dcp: on";case"off":return i.enabled=!1,un(r),"dcp: off; the full transcript is sent unchanged";case"blocks":{let a=Lr(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=up({runtime:i.enabled,config:mp(t)}),m=Lr(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} (${$p(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} (${$p(c)} chars)`,`messages tracked: ${Object.keys(i.messageIds.keyToRef).length}`,`refs allocated: ${i.messageIds.nextRef-1}`].join(`
120
+ `)}case"context":{let a=Lr(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} (${$p(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(x=>`b${x.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 x=p.find(I=>I.blockId===g);x&&(x.consumedBlockIds=x.consumedBlockIds.filter(I=>I!==c))}return un(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 un(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(Vk).join(", ")}`}}import{Type as Im}from"@netrodev/hxf-ai";import{defineTool as tT}from"@netrodev/hxf-coding-agent";import{promises as JL}from"node:dns";var YL=/^(127\.|10\.|192\.168\.|169\.254\.|0\.)/;function Ep(e){if(YL.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 Sp(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 Yk(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 Ep(o)||Sp(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 Ep(a)||Sp(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:Ep(t)||Sp(t)}var kp=8e4,Tp=8;function hm(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"}:Yk(r)?{ok:!1,reason:"refused private address"}:{ok:!0,url:t}}function Qk(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>kp?t.slice(0,kp):t}function QL(e){let t=[],r=/class="result__a"[^>]*href="([^"]+)"[^>]*>([\s\S]*?)<\/a>/gi,n;for(;(n=r.exec(e))&&t.length<Tp;){let o=n[1]??"",i=Qk(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=hm(a);!c.ok||!i||t.push({title:i,url:c.url.toString(),snippet:""})}return t}var Xk="HowToCode (https://howtofix.id)";async function Zk(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??Xk,accept:"text/html, application/json"};try{if(t.braveKey){let p=`https://api.search.brave.com/res/v1/web/search?q=${encodeURIComponent(r)}&count=${Tp}`,f=await n(p,{headers:{...i,accept:"application/json","x-subscription-token":t.braveKey},signal:AbortSignal.timeout(o)});return f.ok?{ok:!0,hits:XL(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:QL(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 XL(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=hm(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>=Tp)break}return r}var Jk=5,ZL=new Set([301,302,303,307,308]);async function eD(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=>Yk(i));return o!==void 0?{ok:!1,error:`refused ${e}: resolves to private address ${o}`}:{ok:!0,addresses:n}}async function eT(e,t={}){let r=hm(e);if(!r.ok)return{ok:!1,error:r.reason};let n=t.fetchFn??fetch,o=t.lookup??(c=>JL.lookup(c,{all:!0}).then(p=>p.map(f=>f.address))),i=AbortSignal.timeout(t.timeoutMs??2e4),a={"user-agent":t.userAgent??Xk,accept:"text/html, text/plain, application/json"},m;try{let{Agent:c}=await import("undici"),p=[],f=((g,x,I)=>{let h=p.map($=>({address:$,family:$.includes(":")?6:4}));x?.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<=Jk;g++){let x=hm(d.toString());if(!x.ok)return{ok:!1,error:`redirect refused: ${x.reason}`};let I=await eD(x.url.hostname,o);if(!I.ok)return{ok:!1,error:I.error};p=I.addresses;let h=await n(x.url,{headers:a,signal:i,redirect:"manual",dispatcher:m});if(ZL.has(h.status)){let A=h.headers.get("location");if(!A)return{ok:!1,error:`HTTP ${h.status} without a location`};try{d=new URL(A,x.url)}catch{return{ok:!1,error:"redirect location is not a URL"}}continue}if(!h.ok)return{ok:!1,error:`HTTP ${h.status}`};let $=h.headers.get("content-type")??"",S=await h.text(),_=/html/i.test($)?Qk(S):S.slice(0,kp);return{ok:!0,url:d.toString(),contentType:$,text:_}}return{ok:!1,error:`too many redirects (max ${Jk})`}}catch(c){return{ok:!1,error:c instanceof Error?c.message:String(c)}}finally{await m?.close()}}function tD(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 rT=tT({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:Im.Object({query:Im.String({description:"Search query"})}),async execute(e,t){let r=await Zk(t.query,{braveKey:process.env.BRAVE_API_KEY});return r.ok?{content:[{type:"text",text:tD(r.hits)}],details:{count:r.hits.length,provider:r.provider}}:{content:[{type:"text",text:r.error}],details:{error:r.error},isError:!0}}}),nT=tT({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:Im.Object({url:Im.String({description:"http(s) URL"})}),async execute(e,t){let r=await eT(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 rD}from"node:child_process";import{existsSync as bm,readFileSync as sT}from"node:fs";import{delimiter as aT,isAbsolute as mT,join as $m}from"node:path";import{fileURLToPath as nD,pathToFileURL as Dr}from"node:url";function oT(e){let t=JSON.stringify(e);return`Content-Length: ${Buffer.byteLength(t,"utf8")}\r
125
+ \r
126
+ ${t}`}var oD=32*1024*1024;function iD(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>oD)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 Cp=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=iD(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=oT({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(oT({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:Dr(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:Dr(t).toString()},position:{line:r,character:n}}))?.contents?.value}async definition(t,r,n){let o=await this.request("textDocument/definition",{textDocument:{uri:Dr(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:Dr(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:Dr(t).toString()}});return Array.isArray(r)?r:[]}diagnostics(t,r=2e3){let n=Dr(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=Dr(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(Dr(t).toString())}notifyChange(t,r,n){let o=Dr(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)}}},sD=[{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 uT(e){return sD.find(t=>t.match(e))}var jr=new Map;async function cT(e,t){let r=jr.get(e.command);if(r)return await r.ready,r.client;let n=rD(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 Cp({stdin:o,stdout:i,root:t});n.on("error",()=>{let c=jr.get(e.command);c?.child===n&&jr.delete(e.command),c?.client.dispose()}),n.on("exit",()=>{jr.get(e.command)?.child===n&&jr.delete(e.command),a.dispose()});let m=a.initialize().catch(c=>{throw jr.delete(e.command),n.kill(),c});return jr.set(e.command,{client:a,child:n,ready:m}),await m,a}function aD(){for(let[e,t]of jr)jr.delete(e),t.client.dispose(),t.child.kill()}process.on("exit",aD);async function fve(e,t,r={}){let n=uT(e);if(!n)return{diagnostics:[],unavailable:"no language server configured for this file type"};if(!(n.command.includes("/")?bm(n.command):(process.env.PATH??"").split(aT).some(i=>bm($m(i,n.command)))))return{diagnostics:[],unavailable:`${n.command} is not on PATH`};try{let i=mT(e)?e:$m(t,e),a=await cT(n,t);return a.notifyChange(i,sT(i,"utf8"),n.languageId),{diagnostics:(await a.diagnostics(i,r.waitMs??1500)).map(c=>`${c.range.start.line+1}:${c.range.start.character+1} ${pT[c.severity??3]??"info"} ${c.message}`)}}catch(i){return{diagnostics:[],unavailable:i instanceof Error?i.message:String(i)}}}var pT={1:"error",2:"warning",3:"info",4:"hint"};function iT(e){let t=e.uri;try{t=nD(e.uri)}catch{}let r=e.range?.start;return r?`${t}:${r.line+1}:${r.character+1}`:t}function fT(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(...fT(n.children,t+1))}return r}async function dT(e){try{let t=uT(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("/")?bm(t.command):(process.env.PATH??"").split(aT).some(p=>bm($m(p,t.command)))))return{ok:!1,error:`${t.command} is not on PATH. Install it to use lsp on ${e.file}.`};let o=mT(e.file)?e.file:$m(e.root,e.file),i=sT(o,"utf8"),a=await cT(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:iT(p),count:1}:{ok:!0,text:"no definition found",count:0}}case"references":{let f=(await a.references(o,m,c)).map(iT);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=fT(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} ${pT[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 mD}from"@netrodev/hxf-ai";import{defineTool as uD}from"@netrodev/hxf-coding-agent";var lT=uD({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:M.Object({action:mD(["diagnostics","definition","references","hover","symbols"],{description:"Which language-server query to run"}),file:M.String({description:"File to query, relative to the project root"}),line:M.Optional(M.Number({description:"1-based line (definition, references, hover)"})),symbol:M.Optional(M.String({description:"Substring to locate on that line when column is omitted"}))}),async execute(e,t,r,n,o){let i=await dT({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 _D}from"@netrodev/hxf-coding-agent";import{API as cD}from"typescript/unstable/async";import{SyntaxKind as jt,visitEachChild as gT}from"typescript/unstable/ast";var xT=new Set([jt.FunctionDeclaration,jt.FunctionExpression,jt.ArrowFunction,jt.MethodDeclaration,jt.Constructor,jt.GetAccessor,jt.SetAccessor]);function Co(e){return xT.has(e)}var pD=new Set([jt.AmpersandAmpersandToken,jt.BarBarToken,jt.QuestionQuestionToken]);function Em(e){if(e.kind!==jt.BinaryExpression)return!1;let t=ze(e,"operatorToken");return t!==void 0&&pD.has(t.kind)}function ze(e,t){let r=e[t];if(r&&typeof r=="object"&&typeof r.kind=="number")return r}function Li(e,t){let r=e[t];return Array.isArray(r)?r:[]}function yT(e,t){return Li(e,"modifiers").some(r=>r.kind===t)}function To(e){if(!e)return;let t=e.text;return typeof t=="string"?t:void 0}function fD(e,t){return e.getLineAndCharacterOfPosition(t).line+1}function wp(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 Sm(e,t){t(e),gT(e,r=>(Sm(r,t),r))}function Di(e,t){t(e),gT(e,r=>(Co(r.kind)||Di(r,t),r))}var dD=xT;function lD(e){let t=To(ze(e,"name"));if(t)return t;let r=ze(e,"parent");for(;r&&!dD.has(r.kind);){if(r.kind===jt.VariableDeclaration||r.kind===jt.PropertyAssignment){let n=To(ze(r,"name"));if(n)return n}r=ze(r,"parent")}return"<anonymous>"}function gD(e){let t=[];return Sm(e,r=>{if(!Co(r.kind))return;let n=wp(e,r);t.push({name:lD(r),node:r,startLine:n.startLine,endLine:n.endLine})}),t}async function hT(e){let t=new Map;if(e.length===0)return t;let r=new cD({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=fD(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:gD(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 Tr,visitEachChild as IT}from"typescript/unstable/ast";var xD=new Set([Tr.IfStatement,Tr.SwitchStatement,Tr.ForStatement,Tr.ForInStatement,Tr.ForOfStatement,Tr.WhileStatement,Tr.DoStatement,Tr.CatchClause]);function bT(e){let t=0,r=(o,i)=>{if(!Co(o.kind)){if(o.kind===Tr.IfStatement){n(o,i,!1);return}if(xD.has(o.kind)){t+=1+i,IT(o,a=>(r(a,i+1),a));return}Em(o)&&(t+=1),IT(o,a=>(r(a,i),a))}},n=(o,i,a)=>{a||(t+=1+i);let m=ze(o,"expression");m&&r(m,i);let c=ze(o,"thenStatement");c&&r(c,i+1);let p=ze(o,"alternate");p&&(t+=1,p.kind===Tr.IfStatement?n(p,i,!0):r(p,i+1))};return r(e,0),t}import{SyntaxKind as Nr}from"typescript/unstable/ast";var yD=new Set([Nr.IfStatement,Nr.ConditionalExpression,Nr.WhileStatement,Nr.DoStatement,Nr.ForStatement,Nr.ForInStatement,Nr.ForOfStatement,Nr.CatchClause,Nr.CaseClause]);function $T(e){let t=1;return Di(e,r=>{(yD.has(r.kind)||Em(r))&&(t+=1)}),t}import{SyntaxKind as ne}from"typescript/unstable/ast";var hD=new Set([ne.BinaryExpression,ne.PrefixUnaryExpression,ne.PostfixUnaryExpression,ne.ConditionalExpression,ne.CallExpression,ne.NewExpression,ne.PropertyAccessExpression,ne.ElementAccessExpression,ne.AwaitExpression,ne.YieldExpression,ne.SpreadElement,ne.IfStatement,ne.WhileStatement,ne.DoStatement,ne.ForStatement,ne.ForInStatement,ne.ForOfStatement,ne.SwitchStatement,ne.ReturnStatement,ne.ThrowStatement,ne.TryStatement,ne.BreakStatement,ne.ContinueStatement]),ID=new Set([ne.StringLiteral,ne.NumericLiteral,ne.BigIntLiteral,ne.RegularExpressionLiteral,ne.NoSubstitutionTemplateLiteral]);function Rp(e,t){e.set(t,(e.get(t)??0)+1)}function ET(e){let t=new Map,r=new Map;Di(e,i=>{if(hD.has(i.kind)){let m=ze(i,"operatorToken");Rp(t,ne[i.kind]+(m?`:${ne[m.kind]}`:""));return}let a=To(i);a!==void 0&&(i.kind===ne.Identifier||i.kind===ne.PrivateIdentifier?Rp(r,`id:${a}`):ID.has(i.kind)&&Rp(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 ST(e){return e.endLine-e.startLine+1}function kT(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 rr,visitEachChild as bD}from"typescript/unstable/ast";var $D=new Set([rr.IfStatement,rr.SwitchStatement,rr.WhileStatement,rr.DoStatement,rr.ForStatement,rr.ForInStatement,rr.ForOfStatement,rr.TryStatement,rr.CatchClause]);function TT(e){let t=0,r=(n,o)=>{if(Co(n.kind))return;let i=o;if($D.has(n.kind)&&(i=o+1,i>t&&(t=i)),n.kind===rr.IfStatement){let a=ze(n,"expression");a&&r(a,i);let m=ze(n,"thenStatement");m&&r(m,i);let c=ze(n,"alternate");c&&r(c,c.kind===rr.IfStatement?o:i);return}bD(n,a=>(r(a,i),a))};return r(e,0),t}import{spawnSync as ED}from"node:child_process";import{mkdirSync as qve,readdirSync as SD,readFileSync as kD,statSync as TD,writeFileSync as _ve}from"node:fs";import{extname as Op,join as MT,relative as vT,resolve as CD}from"node:path";import{SyntaxKind as km}from"typescript/unstable/ast";var CT={"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 wT(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 wD=["ok","warn","error"],Lp=["cyclomatic","cognitive","nesting","length","halstead","mi","parameters","booleanParameters"];var qr={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 FT(){let e={cyclomatic:{...qr.cyclomatic},cognitive:{...qr.cognitive},nesting:{...qr.nesting},length:{...qr.length},halstead:{...qr.halstead},mi:{...qr.mi},fileLines:{...qr.fileLines},exports:{...qr.exports},parameters:{...qr.parameters}};return{ignore:[],thresholds:e,ci:{failBelow:65,mode:"advisory"}}}var RD=["cyclomatic","cognitive","nesting","length","halstead","mi","fileLines","exports","parameters"];function Pp(e){return typeof e=="number"&&Number.isFinite(e)}function Dp(e){let t=FT(),r;try{r=JSON.parse(kD(MT(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 RD){let a=o[i];if(typeof a!="object"||a===null)continue;let m=a;Pp(m.warn)&&(t.thresholds[i].warn=m.warn),Pp(m.error)&&(t.thresholds[i].error=m.error)}}if(typeof n.ci=="object"&&n.ci!==null){let o=n.ci;Pp(o.failBelow)&&(t.ci.failBelow=o.failBelow),(o.mode==="advisory"||o.mode==="blocking")&&(t.ci.mode=o.mode)}return t}function LT(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=Dp(e).enabled;return n!==void 0?{enabled:n,source:"config"}:t!==void 0?{enabled:t,source:"runtime"}:{enabled:!0,source:"default"}}function cn(e,t){return e>t.error?2:e>t.warn?1:0}function DT(e,t){return e<t.error?2:e<t.warn?1:0}function PD(e){let t=[];for(let r of Li(e.node,"parameters"))ze(r,"type")?.kind===km.BooleanKeyword&&t.push(To(ze(r,"name"))??"<pattern>");return t}function AD(e,t,r,n){let o=n.thresholds,i=ze(e.node,"body")??e.node,a={cyclomatic:$T(i),cognitive:bT(i),nesting:TT(i),length:ST(e),halstead:ET(i),mi:0};a.mi=kT(a.halstead,a.cyclomatic,a.length);let m=PD(e),c=Li(e.node,"parameters").length,p={cyclomatic:{value:a.cyclomatic,rank:cn(a.cyclomatic,o.cyclomatic)},cognitive:{value:a.cognitive,rank:cn(a.cognitive,o.cognitive)},nesting:{value:a.nesting,rank:cn(a.nesting,o.nesting)},length:{value:a.length,rank:cn(a.length,o.length)},halstead:{value:a.halstead,rank:cn(a.halstead,o.halstead)},mi:{value:a.mi,rank:DT(a.mi,o.mi)},parameters:{value:c,rank:cn(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=wp(t,e.node),g=0;for(let x of Lp)p[x].rank>g&&(g=p[x].rank);return{path:r,name:e.name,startLine:d.startLine,endLine:d.endLine,startColumn:d.startColumn,endColumn:d.endColumn,metrics:p,booleanParameterNames:m,smells:wT(a,f),worstRank:g}}function OD(e){let t=0;return Sm(e,r=>{if(r.kind===km.ExportDeclaration){let n=ze(r,"exportClause"),o=n?Li(n,"elements"):[];t+=o.length>0?o.length:1;return}if(r.kind===km.ExportAssignment){t+=1;return}yT(r,km.ExportKeyword)&&(t+=1)}),t}function MD(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 RT={value:0,rank:0};function PT(e,t){return{path:e,ok:!1,error:t,lines:0,metrics:{lines:RT,exports:RT,mi:{value:100,rank:0}},functions:[]}}function Ap(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 jT(e,t=FT()){let r=await hT(e),n=new Map,o=[],i=t.thresholds;for(let a of e){let m=r.get(a);if(!m){let $=PT(a,"internal: file missing from the parse result");n.set(a,$),o.push({path:a,metric:"parse error",detail:$.error??"",rank:2,line:1,endLine:1,startColumn:1,endColumn:1});continue}if(!m.ok){let $=PT(a,m.error);n.set(a,$),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($=>AD($,c,a,t)),f=MD(c.text),d=OD(c),g=p.reduce(($,S)=>$+S.metrics.length.value,0),x=g===0?100:Math.round(p.reduce(($,S)=>$+S.metrics.mi.value*S.metrics.length.value,0)/g*10)/10,I={path:a,ok:!0,lines:f,metrics:{lines:{value:f,rank:cn(f,i.fileLines)},exports:{value:d,rank:cn(d,i.exports)},mi:{value:x,rank:DT(x,i.mi)}},functions:p};n.set(a,I);let h={line:1,endLine:Math.max(f,1),startColumn:1,endColumn:1};Ap(o,I,void 0,h,"file lines",I.metrics.lines,i.fileLines.warn),Ap(o,I,void 0,h,"exports",I.metrics.exports,i.exports.warn);for(let $ of p){let S={line:$.startLine,endLine:$.endLine,startColumn:$.startColumn,endColumn:$.endColumn};for(let _ of Lp)Ap(o,I,$,S,_,$.metrics[_],NT(_,i));for(let _ of $.smells)o.push({path:a,metric:"smell",detail:`${_.label}: ${_.reason}`,rank:1,line:$.startLine,endLine:$.endLine,startColumn:$.startColumn,endColumn:$.endColumn,function:$.name})}}return{files:n,findings:o}}function jp(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 Np(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:jp(e)}}var vD=["ok","\u26A0","\u2717"],FD=[["cyclomatic","cyclomatic"],["cognitive","cognitive"],["nesting","nesting"],["length","length"],["halstead","halstead"],["mi","MI"],["parameters","parameters"],["booleanParameters","boolean params"]];function NT(e,t){return e==="mi"?t.mi.warn:e==="booleanParameters"?t.parameters.warn:t[e].warn}function Mp(e,t,r,n){return`${e}${t.padEnd(15)} ${r.value} (limit ${n}) ${wD[r.rank]}`}function LD(e,t){let r=[` ${e.name.padEnd(30)} L${e.startLine}-${e.endLine}`];for(let[n,o]of FD){let i=e.metrics[n];if(i.rank!==0){if(n==="booleanParameters"){r.push(` ${o.padEnd(15)} ${e.booleanParameterNames.join(", ")} warn`);continue}r.push(Mp(" ",o,i,NT(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 ${CT[n.id]??n.label}`)}return r}function AT(e){let t=e.smells.length;for(let r of Lp)e.metrics[r].rank>0&&(t+=1);return t}function DD(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=AT(i)-AT(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 qT(e,t,r={}){let n=Np(e),o=r.top&&r.top>0?DD(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} ${vD[p.metrics.mi.rank]}`),p.metrics.lines.rank>0&&m.push(Mp(" ","file lines",p.metrics.lines,t.thresholds.fileLines.warn)),p.metrics.exports.rank>0&&m.push(Mp(" ","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(...LD(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 vp=new Set([".ts",".tsx",".mts",".cts"]),jD=new Set(["node_modules","dist","coverage"]);function Fp(e,t,r){for(let n of SD(e,{withFileTypes:!0})){let o=MT(e,n.name);if(n.isDirectory()){if(n.name.startsWith(".")||jD.has(n.name))continue;Fp(o,t,r);continue}n.isFile()&&vp.has(Op(n.name))&&r.push(vT(t,o))}}function OT(e,t){let r=ED("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 ND(e,t){let r=OT(e,["diff","--name-only","--diff-filter=ACMR",t]),n=OT(e,["ls-files","--others","--exclude-standard"]);return[...r,...n]}function qD(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 _T(e,t,r=[]){let n;if(t.changes)n=ND(e,t.base??"HEAD");else if(t.target){let i=CD(e,t.target),a=TD(i,{throwIfNoEntry:!1});if(!a)throw new Error(`no such path: ${t.target}`);if(a.isDirectory())n=[],Fp(i,e,n);else{if(!vp.has(Op(i)))throw new Error(`not a TypeScript source file: ${t.target}`);n=[vT(e,i)]}}else n=[],Fp(e,e,n);let o=new Set;for(let i of n)vp.has(Op(i))&&(r.some(a=>qD(i,a))||o.add(i));return[...o].sort()}var UT=6e3,BT=_D({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:M.Object({path:M.Optional(M.String({description:"One file or directory, relative to the project root. Omit to scan the changed set."})),changes:M.Optional(M.Boolean({description:"Scan only files changed against the base ref. Default true when path is omitted."})),base:M.Optional(M.String({description:"Git ref for `changes`. Defaults to HEAD."})),top:M.Optional(M.Number({description:"Only report the N worst functions."}))}),async execute(e,t,r,n,o){let i=o.cwd??process.cwd(),a=LT(i);if(!a.enabled)return{content:[{type:"text",text:`quality metrics are off (source: ${a.source})`}],details:{off:!0}};let m=Dp(i),c=t.changes??t.path===void 0,p=_T(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 jT(p,m),d=Np(f),g=qT(f,m,{top:t.top});return{content:[{type:"text",text:g.length>UT?`${g.slice(0,UT)}
135
+ \u2026 (truncated; run the quality script for the full report)`:g}],details:{files:d.files,functions:d.functions,findings:d.findings,score:jp(f)}}}});import{availableParallelism as UD}from"node:os";var BD=4;function GD(){let e=cf(Ve).agents;return e!==void 0?e:Math.max(1,Math.min(BD,UD()-2))}var qp=0,GT=[];async function Tm(){for(;qp>=GD();)await new Promise(t=>GT.push(t));qp+=1;let e=!1;return()=>{e||(e=!0,qp-=1,GT.shift()?.())}}function KT(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 KD=["deepseek","qwen","claude","gpt-5","gpt-4","gemini","glm","mimo","kimi","llama"],HD=/(image|embedding|embed|whisper|tts|audio|video|rerank|moderation|dall-e|stable-diffusion|sora)/i;function zD(e){let t=r=>{if(HD.test(r))return 100;let n=KD.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 xFe(e,t=[]){if(e.length===0)return;let r=e.filter(i=>t.includes(i.provider)),n=r.length>0?r:e,o=zD(n.map(i=>i.id))[0];return n.find(i=>i.id===o)??n[0]}import{mkdirSync as WD,readdirSync as VD,readFileSync as JD,unlinkSync as YD}from"node:fs";import{join as Up}from"node:path";import{createAgentSession as QD,DefaultResourceLoader as XD,SessionManager as ZD}from"@netrodev/hxf-coding-agent";var _p=["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."],ej=`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.`,pn=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.",..._p].join(`
154
+ `),effort:"low"}],["architect",{name:"architect",description:"designs an implementation plan",tools:["read","grep","find","ls","context","web_search","web_fetch","lsp"],prompt:ej,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.",..._p].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.",..._p].join(`
156
+ `),effort:"medium"}]]),FFe=new Set(pn.keys());function tj(e){return e>=1e3?`${(e/1e3).toFixed(1)}k`:String(e)}function rj(e){return e<6e4?`${(e/1e3).toFixed(1)}s`:`${Math.floor(e/6e4)}m ${(e%6e4/1e3).toFixed(1)}s`}function LFe(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(tj(e.tokens)),e.startedAt&&e.endedAt&&r.push(rj(e.endedAt-e.startedAt)),`## ${e.agent}#${e.id} ${t}${r.length>0?` (${r.join(" \xB7 ")})`:""}`}var Rt=[],nj=3,HT=8,DFe=6,Cm=12;function wm(e){WD(Dn,{recursive:!0}),sr(Up(Dn,`${e.id}.json`),JSON.stringify({...e,session:void 0},null,1))}function Bp(){let e;try{e=VD(Dn)}catch{return}for(let t of e)if(t.endsWith(".json"))try{let r=JSON.parse(JD(Up(Dn,t),"utf8"));if(r.status!=="parked"||Rt.some(n=>n.id===r.id))continue;Rt.push({...r,mail:r.mail??[]})}catch{}if(Rt.length>Cm){let t=Rt.splice(0,Rt.length-Cm);for(let r of t){let n=r.session;r.session=void 0,n&&n.dispose();try{YD(Up(Dn,`${r.id}.json`))}catch{}}}}function jFe(){if(Bp(),Rt.length===0)return"no agents";let e=Rt.map(t=>`${t.id} ${t.agent} ${t.status}${t.model?` model=${t.model}`:""}${t.background?" background":""} requests=${t.requests} ${t.task}`);return wo&&e.unshift("background work in flight"),e.join(`
157
+ `)}function NFe(e){Bp();let t=Rt.find(r=>r.id===e);return t?`${t.agent}#${t.id} ${t.status}
158
+ ${t.result??t.task}`:`no agent ${e}`}async function Rm(e){let t=pn.get(e.agent);if(!t)throw new Error(`unknown agent ${e.agent}`);let r=e.worktree||e.cwd||process.cwd(),n=new XD({cwd:r,agentDir:Ve,appendSystemPrompt:[t.prompt],additionalSkillPaths:sf(r),extensionFactories:[uf({interactive:!1}),Ik()]});await n.reload();let{session:o}=await QD({cwd:r,agentDir:Ve,sessionManager:ZD.inMemory(r),resourceLoader:n,tools:t.tools,customTools:[sk,rk,rT,nT,lT,BT,ZS],thinkingLevel:e.effort}),i=oj(e,t);if(i){let a=await o.modelRuntime.getAvailable(),m=KT(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 qFe(e,t){Bp();let r=Rt.find(o=>o.id===e);if(!r)return`no agent ${e}`;let n=r.session??await Rm(r);if(r.session=n,r.status==="running"||n.isStreaming)return r.mail.push(t),wm(r),`queued for ${e}`;if(r.requests>=HT)return`${e} is out of budget (${r.requests} requests)`;r.status="running";try{await n.prompt(t),r.requests+=1,r.result=Mo(n.getLastAssistantText()??"")||r.result,r.status="parked"}catch(o){r.result=o instanceof Error?o.message:String(o),r.status="error"}return wm(r),`${e} ${r.status}`}function oj(e,t){for(let r of[e.model,t.model,e.parentModel]){let n=r?.trim();if(n)return n}}function zT(e){if(!(!e?.provider||!e.id))return`${e.provider}/${e.id}`}async function _Fe(e){let t=pn.get(e.agent);if(!t)throw new Error(`unknown agent ${e.agent}. known: ${[...pn.keys()].join(", ")}`);if(Rt.length>=Cm)throw new Error(`${Cm} agents is the limit (${Rt.length} live or parked). Finish with the existing ones, or clear them with /agents, before spawning more.`);let r={id:`${Date.now().toString(36)}-${Rt.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 Rt.push(r),wm(r),r}async function ij(e,t){if(!pn.get(e.agent))return;let n=e.session??await Rm(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<HT;)await n.followUp(e.mail.splice(0).join(`
164
+ `)),e.requests+=1;if(t?.aborted)throw new Error("aborted");let i=Mo(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(),wm(e);try{WT?.(e)}catch{}}}var WT;function UFe(e){WT=e}var wo;function BFe(){wo||(wo=sj().catch(()=>{}).finally(()=>{wo=void 0}))}async function sj(e){wo&&await wo.catch(()=>{});let t=()=>Rt.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 Tm();try{await ij(n,e)}finally{o()}}};if(await Promise.all(Array.from({length:nj},r)),e?.aborted)throw new Error("aborted")}import{execFile as aj}from"node:child_process";import{cp as mj,readdir as uj,stat as VT}from"node:fs/promises";import{promisify as cj}from"node:util";import{tmpdir as pj}from"node:os";import{join as Pm}from"node:path";var JT=cj(aj);async function Ht(e,t){try{let{stdout:r}=await JT("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 fj(e){return(await Ht(e,["rev-parse","--is-inside-work-tree"])).output==="true"}async function JFe(e){return(await Ht(e,["status","--porcelain"])).output.length>0}async function YFe(e,t){let r=await Ht(e,["add","-A"]);if(!r.ok)return r;let n=await Ht(e,["commit","-m",t]);return n.ok?{ok:!0,output:(await Ht(e,["log","-1","--oneline"])).output||n.output}:n}async function QFe(e){let t=await Ht(e,["reset","--soft","HEAD~1"]);return t.ok?{ok:!0,output:(await Ht(e,["log","-1","--oneline"])).output||"reset to the previous commit"}:t}async function XFe(e){let t=(await Ht(e,["diff"])).output,r=(await Ht(e,["diff","--cached"])).output;return[t,r].filter(Boolean).join(`
165
+ `)}function ZFe(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 dj=["node_modules","vendor","target",".venv","venv","__pycache__",".pnpm-store","dist","build"],YT=1024*1024*1024;async function QT(e){let t=0,r;try{r=await uj(e,{withFileTypes:!0})}catch{return 0}for(let n of r){let o=Pm(e,n.name);if(n.isDirectory())t+=await QT(o);else if(n.isFile())try{t+=(await VT(o)).size}catch{}if(t>YT)return t}return t}async function lj(e,t){let r=[];for(let n of dj){let o=Pm(e,n),i=Pm(t,n);try{if(!(await VT(o)).isDirectory())continue}catch{continue}if(await QT(o)>YT){r.push(n);continue}await gj(o,i)||r.push(n)}return r}async function gj(e,t){if(process.platform!=="win32")try{return await JT("cp",["-a",e,t],{maxBuffer:8*1024*1024}),!0}catch{}try{return await mj(e,t,{recursive:!0,force:!0,errorOnExist:!1,dereference:!1}),!0}catch{return!1}}async function XT(e,t){if(!await fj(e))return null;let r=t.replace(/[^A-Za-z0-9._-]/g,"-").slice(0,40)||"agent",n=Pm(pj(),`howtocode-wt-${process.pid}-${Date.now()}-${r}`);if(!(await Ht(e,["worktree","add","--detach",n,"HEAD"])).ok)return null;let i=await lj(e,n);return{path:n,skipped:i,async remove(){await Ht(e,["worktree","remove","--force",n]),await Ht(e,["worktree","prune"])}}}import{detectCapabilities as xj,getTerminalColorMode as yj,parseColor as _r,styleText as ZT}from"@netrodev/hxf-tui";function hj(){let e=process.env.NO_COLOR;if(e!==void 0&&e!=="")return"256color";try{return yj(xj())}catch{return"256color"}}var eC=hj();function Ij(){let e=process.env.NO_COLOR;return e!==void 0&&e!==""}var qe={text:_r("#e6e6e6"),mute:_r("#8b8b8b"),dim:_r("#5c5c5c"),user:_r("#d0d0d0"),accent:_r("#c4b5fd"),tool:_r("#6ee7b7"),bad:_r("#f0a8a4"),warn:_r("#e6b15a"),line:_r("#3a3a3a")};function bj(e,t){if(Ij()){let{bold:r,dim:n,italic:o,underline:i,strikethrough:a}=t;return!r&&!n&&!o&&!i&&!a?e:ZT(e,{bold:r,dim:n,italic:o,underline:i,strikethrough:a},eC)}return ZT(e,t,eC)}function mt(e,t,r){return bj(e,{...r,fg:t})}var r1e={heading:e=>mt(e,qe.text,{bold:!0}),link:e=>mt(e,qe.accent,{underline:!0}),linkUrl:e=>mt(e,qe.mute),code:e=>mt(e,qe.text),codeBlock:e=>mt(e,qe.text),codeBlockBorder:e=>mt(e,qe.line),quote:e=>mt(e,qe.mute,{italic:!0}),quoteBorder:e=>mt(e,qe.line),hr:e=>mt(e,qe.line),listBullet:e=>mt(e,qe.mute),bold:e=>mt(e,qe.text,{bold:!0}),italic:e=>mt(e,qe.text,{italic:!0}),strikethrough:e=>mt(e,qe.mute,{strikethrough:!0}),underline:e=>mt(e,qe.text,{underline:!0})};import{truncateToWidth as Ni,visibleWidth as nr}from"@netrodev/hxf-tui";var tC={text:qe.text,muted:qe.mute,dim:qe.dim,accent:qe.accent,success:qe.tool,error:qe.bad,border:qe.line},oe=(e,t,r=!1)=>r?mt(t,tC[e],{bold:!0}):mt(t,tC[e]),$j=25,Ej=15e5,nC=420;function Po(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 s1e(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 Hp(e){return e>=1e6?`${(e/1e6).toFixed(1)}M`:e>=1e3?`${(e/1e3).toFixed(1)}k`:String(e)}var ji=(e,t,r)=>Math.max(t,Math.min(r,e)),Ro=(e,t)=>nr(e)>t?Ni(e,Math.max(0,t),"\u2026"):e;function Am(e,t,r="left"){if(t<=0)return"";let n=nr(e);if(n>t)return Ni(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=nr(t);if(o>=r)return Ni(t,r);let i=r-o-n;if(i<=0)return Am(t,r,"right");let a=nr(e)>i?Ni(e,i):e,m=" ".repeat(r-nr(a)-o);return a+m+t}function Gp(e,t,r){let n=Ro(e,Math.max(0,r-2)),o=Math.max(1,r-1-nr(n)),i=oe("border","\u250C\u2500 ")+oe("accent",n)+oe("border",` ${"\u2500".repeat(o)}\u2510`),a=oe("border",`\u2514${"\u2500".repeat(r+2)}\u2518`),m=oe("border","\u2502"),c=t.map(p=>`${m} ${Am(p,r)} ${m}`);return[i,...c,a]}function Sj(e,t,r,n){let o=n?.gap??1,i=n?.leftWidth??ji(Math.round(r*.38),28,44),a=r-i-o,m=Math.max(e.rows.length,t.rows.length),c=g=>{let x=[...g];for(;x.length<m;)x.push("");return x},p=Gp(e.title,c(e.rows),i-4),f=Gp(t.title,c(t.rows),a-4),d=" ".repeat(o);return p.map((g,x)=>g+d+(f[x]??Am("",a)))}function oC(e,t,r){switch(e){case"running":return oe(t||r?"accent":"muted","\u25CF");case"failed":return oe("error","\u2717");default:return oe("success","\u2713")}}function iC(e,t,r,n=Date.now(),o=0){return t?n-o<nC?oe("success","\u2713",!0):oe("success","\u2713"):oe(r?"accent":"dim",String(e))}var rC="Workflow";function Wp(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||rC;r.includes(i)||r.push(i)}return r.map((o,i)=>{let a=e.steps.filter(I=>(I.phase||rC)===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 $=h.endedAt??t;return Math.max(I,$-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,x=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:x,anchor:f}})}function Vp(e){return e.steps.reduce((t,r)=>t+r.outputTokens,0)}function kj(e){return e.steps.reduce((t,r)=>t+(r.toolCalls??0),0)}function sC(e,t=Date.now()){return Math.max(0,(e.endedAt??t)-e.startedAt)}function Tj(e){return e.steps.length>$j||Vp(e)>Ej}function Cj(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 aC(e,t=Date.now()){let r=Wp(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(`${Hp(Vp(e))} tok`),a.push(Po(sC(e,t))),i>0&&a.push(`${i} failed`);let c=a.join(" \xB7 ");return Tj(e)?`large workflow \xB7 ${c}`:c}var mC=16,wj=12,Rj=18,Pj=72,Aj=24;function uC(e,t){if(e.status==="running"&&e.outputTokens===0)return[`idle ${Po(t-e.startedAt)}`,"idle"];let r=Hp(e.outputTokens),n=e.toolCalls??0,o=Po((e.endedAt??t)-e.startedAt);return[`${r} tok \xB7 ${n} tools \xB7 ${o}`,`${r} tok \xB7 ${n} tools`,`${r} tok`]}var Oj=e=>e.status==="running"&&e.outputTokens===0;function Kp(e,t,r){if(e.length<=r)return{slice:e,start:0,more:0};let n=Math.max(1,r-1),o=ji(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 Mj(e,t,r,n,o){let i=`${e.done}/${e.agents.length}`,a=r?oe("accent","\u276F"):" ",m=iC(t+1,e.allDone,r,o,e.finishedAt),c=Math.max(0,n-4-nr(i)),p=nr(e.title)>c?Ni(e.title,c,"\u2026"):e.title,f=e.allDone&&o-e.finishedAt<nC,d=oe(f&&!r?"success":r?"accent":"text",p),g=`${a}${m} ${d}`,x=oe(r?"accent":"muted",i);return zp(g,x,n,1)}function vj(e,t,r,n,o,i){let a=t?oe("accent","\u276F"):" ",m=oC(e.status,t,r),c=oe(t?"accent":"text",Am(e.label,n)),p=`${a}${m} ${c}`,f=Math.max(0,o-nr(p)-1),d=uC(e,i).find(x=>nr(x)<=f)??"",g=oe(t?"accent":Oj(e)?"dim":"muted",d);return zp(p,g,o,1)}function Fj(e,t,r,n){let o=[];return e.forEach((i,a)=>{let c=`${iC(a+1,i.allDone,a===r,n,i.finishedAt)} ${oe(a===r?"accent":"text",i.title)} ${oe("muted",`${i.done}/${i.agents.length}`)}`;o.push(Ro(c,t));let{slice:p,more:f}=Kp(i.agents,0,mC);p.forEach((d,g)=>{let x=oC(d.status,!1,g===i.anchor),I=uC(d,n)[0]??"";o.push(Ro(` ${x} ${oe("text",d.label)} ${oe("muted",I)}`,t))}),f>0&&o.push(Ro(` ${oe("dim",`\u2026+${f} more`)}`,t))}),o}function Lj(e,t,r){let n=r?.now??Date.now(),o=Wp(e,n),i=e.steps,a=i.filter(lt=>lt.status!=="running").length,m=i.filter(lt=>lt.status==="failed").length,c=[`${a}/${i.length} agents`,`${Hp(Vp(e))} tok`,`${kj(e)} tools`,Po(sC(e,n)),...m>0?[`${m} failed`]:[]].join(" \xB7 "),p=[zp(oe("accent",e.name,!0),oe("muted",c),t,2),...e.description?[oe("muted",Ro(e.description,t))]:[]],f=r?.footer?[oe("muted",Ro(r.footerText??Dj(),t))]:[];if(o.length===0)return[...p,...Gp("Phases",["(no agents yet)"],Math.max(0,t-4)),...f];let d=ji(r?.selectedPhase??Cj(o),0,Math.max(0,o.length-1)),g=ji(Math.round(t*.38),28,44),x=t-g-1-4;if(t<Pj||x<Aj)return[...p,...Fj(o,t,d,n),...f];let I=o[d],{slice:h,start:$,more:S}=Kp(o,d,wj),_=h.map((lt,ir)=>Mj(lt,$+ir,$+ir===d,g-4,n));S>0&&_.push(oe("dim",`\u2026+${S} more`));let A=r?.filter?r.filter(I.agents):I.agents,Xe=A.length?ji(Math.max(...A.map(lt=>nr(lt.label))),6,Rj):6,{slice:rt,more:ce}=Kp(A,0,r?.agentWindow??mC),V=rt.map((lt,ir)=>vj(lt,!1,ir===I.anchor,Xe,x,n));ce>0&&V.push(oe("dim",`\u2026+${ce} more`));let or=Sj({title:"Phases",rows:_},{title:`${I.title} \xB7 ${A.length} agents${r?.filterLabel??""}`,rows:V},t,{leftWidth:g,gap:1});return[...p,...or,...f]}function a1e(e,t=[],r=96,n,o){let i=Lj(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=Wp(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(` ${oe("muted",f)} ${oe("text",p.content)}`)}c.detail&&m.push(` ${oe("dim",c.detail)}`)}return m.length===0?i:[...i.slice(0,-1),...m,i[i.length-1]]}function Dj(){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 Kj}from"node:fs";import{basename as Hj}from"node:path";import{StringEnum as zj}from"@netrodev/hxf-ai";import{defineTool as Wj}from"@netrodev/hxf-coding-agent";var Ln=e=>typeof e=="object"&&e!==null&&!Array.isArray(e);function cC(e){return e===null?"null":Array.isArray(e)?"array":Number.isInteger(e)?"integer":typeof e}function jj(e,t){let r=cC(e);return t==="number"?r==="number"||r==="integer":t==="integer"?r==="integer":r===t}function Nj(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(!Ln(r)&&!Array.isArray(r))return;r=r[o]}return Ln(r)?r:void 0}function fn(e,t,r,n,o){if(!Ln(t))return;if(t.$ref!==void 0){let a=Nj(r,t.$ref);a&&fn(e,a,r,n,o);return}if(Array.isArray(t.allOf))for(let a of t.allOf)fn(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 fn(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=>jj(e,m))){o.push({path:n,message:`expected ${a.join(" or ")}, got ${cC(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(", ")}`}),Ln(e)){let a=Ln(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&&fn(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(Ln(t.additionalProperties))for(let[m,c]of Object.entries(e))m in a||fn(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&&fn(m,a[c],r,`${n}[${c}]`,o)}):e.forEach((m,c)=>fn(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 pC(e,t){if(!Ln(t))return[];let r=[];return fn(e,t,t,"",r),r}function fC(e){return e.map(t=>`- ${t.path||"(root)"}: ${t.message}`).join(`
168
+ `)}function dC(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 qj=1e3,_j=4096,lC=100,gC=300*1e3;async function Uj(e,t=lC,r=gC){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 We=class extends Error{constructor(t){super(t),this.name="WorkflowError"}};function Bj(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 xC(e){let t=e.lifetimeCap??qj,r=e.fanoutCap??_j,n=e.concurrency?Bj(e.concurrency):null,o=async()=>{let S=await Tm();if(!n)return S;let _=await n();return()=>{_(),S()}},i=0,a=0,m=0,c="",p=S=>e.onEvent?.(S),f=new Map,d=()=>e.onProgress?.([...f.values()]),g=async(S,_)=>{let A=_??{},Xe=typeof A.label=="string"?A.label:`agent-${i+1}`,rt=typeof A.phase=="string"?A.phase:c,ce=typeof A.agentType=="string"?A.agentType:"task",V=typeof A.effort=="string"?A.effort:void 0,or=typeof A.model=="string"?A.model:void 0,lt=typeof A.isolation=="string"?A.isolation:void 0,ir=A.schema;if(e.budgetTotal!=null&&a+m>=e.budgetTotal)throw new We(`budget exhausted: spent ${a+m} of ${e.budgetTotal} output tokens`);if(i>=t)throw new We(`lifetime cap reached: ${t} agent calls in one run`);i++;let tf=i;if(e.isPaused?.()&&!await Uj(e,lC,gC))return null;let rf=e.budgetTotal==null?0:Math.max(0,e.budgetTotal-a-m);m+=rf;let PC=await o();try{if(e.signal?.aborted)return null;p({kind:"agent_start",label:Xe,phase:rt,ordinal:i}),f.set(tf,{label:Xe,phase:rt,agentType:ce,status:"running",outputTokens:0,...or?{model:or}:{},startedAt:Date.now()}),d();let Ao=(dn,Ur,qt)=>{let zt=f.get(tf);zt&&(zt.status=dn,zt.outputTokens=Ur.outputTokens,zt.endedAt=Date.now(),Ur.toolCalls!==void 0&&(zt.toolCalls=Ur.toolCalls),Ur.model!==void 0&&(zt.model=Ur.model),qt&&(zt.detail=qt)),p({kind:"agent_end",label:Xe,ok:dn==="ok",outputTokens:Ur.outputTokens}),d()},nf=ir===void 0?1:2;for(let dn=0;dn<nf;dn++){let Ur=dn===0?String(S):void 0,qt=await I(Ur??Gj(String(S),x),{label:Xe,phase:rt,agentType:ce,effort:V,model:or,isolation:lt});if(qt===null)return Ao("failed",{text:"",outputTokens:0}),null;if(a+=qt.outputTokens,ir===void 0)return Ao("ok",qt,Jp(qt.text)),qt.text;let zt=dC(qt.text),of=zt===void 0?[{path:"",message:"reply was not JSON"}]:pC(zt,ir);if(of.length===0)return Ao("ok",qt,Jp(qt.text)),zt;if(x=fC(of),dn===nf-1)return Ao("failed",qt,`schema: ${Jp(x)}`),null}return null}finally{m=Math.max(0,m-rf),PC()}},x="",I=async(S,_)=>{try{return await e.invoke({prompt:S,..._})}catch{return null}};return{agent:(S,_)=>g(S,_),parallel:async S=>{if(S.length>r)throw new We(`fan-out cap exceeded: ${S.length} items (max ${r})`);return await Promise.all(S.map(async A=>{try{return await A()}catch{return null}}))},pipeline:async(S,..._)=>{if(S.length>r)throw new We(`fan-out cap exceeded: ${S.length} items (max ${r})`);return await Promise.all(S.map(async(Xe,rt)=>{let ce=Xe;for(let V of _)try{ce=await V(ce,Xe,rt)}catch{return null}return ce}))},phase:S=>{c=String(S),p({kind:"phase",title:c})},log:S=>p({kind:"log",message:String(S)}),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 Gj(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 Jp(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 Yp="workflow",yC=null;function S1e(e){yC=e}var Vj=600*1e3;function Jj(e){let t=e.replace(/^(?:\s+|\/\/[^\n]*\n|\/\*[\s\S]*?\*\/)*/,""),r=/^export\s+const\s+meta\s*=\s*/.exec(t);if(!r)throw new We("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 x=o;x<t.length;x++){let I=t[x];if(a){I==="\\"?x++:I===a&&(a=null);continue}if(I==='"'||I==="'"||I==="`")a=I;else if(I==="{"||I==="[")i++;else if((I==="}"||I==="]")&&(i--,i===0)){m=x+1;break}}if(m===-1)throw new We("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 We("a workflow body must not contain import or export declarations");if(/\bimport\s*\(/.test(p))throw new We("a workflow body must not use dynamic import()");let f;try{f=new Function(`"use strict"; return (${c});`)()}catch(x){throw new We(`meta must be a literal object: ${x instanceof Error?x.message:String(x)}`)}if(typeof f!="object"||f===null)throw new We("meta must be an object");let d=f;if(typeof d.name!="string"||!d.name.trim())throw new We("meta.name is required");if(typeof d.description!="string"||!d.description.trim())throw new We("meta.description is required");let g=Array.isArray(d.phases)?d.phases.filter(x=>typeof x=="object"&&x!==null).map(x=>({title:String(x.title??""),...typeof x.detail=="string"?{detail:x.detail}:{}})).filter(x=>x.title):void 0;return{meta:{name:d.name,description:d.description,...typeof d.whenToUse=="string"?{whenToUse:d.whenToUse}:{},...g?{phases:g}:{}},body:p}}function Yj(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 We(`workflow did not compile: ${o instanceof Error?o.message:String(o)}`)}return n}function Qj(e){return Mo(e.getLastAssistantText()??"")}function Xj(e){return async({prompt:t,agentType:r,effort:n,model:o,isolation:i})=>{let a=pn.get(r)??pn.get("task");if(!a)throw new We(`no agent named ${r}`);let m=i==="worktree"?await XT(process.cwd(),r):null,c=await Rm({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=Zj(c)??o;return{text:Qj(c),outputTokens:p.tokens.output,toolCalls:p.toolCalls,...f?{model:f}:{}}}finally{c.dispose(),await m?.remove()}}}function Zj(e){return e.model?.id??e.model?.name}var eN=M.Object({code:M.Optional(M.String({description:"The workflow script source"})),path:M.Optional(M.String({description:"Path to a workflow script, instead of code"})),agent:M.Optional(zj(["scout","task","reviewer"],{description:"Default agent profile for calls"})),budget:M.Optional(M.Number({description:"Output-token ceiling for the whole run"}))});function k1e(e){let t=()=>e??yC;return Wj({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:eN,executionMode:"sequential",async execute(r,n,o,i,a){let m=n.path?Kj(n.path,"utf8"):n.code??"";if(!m.trim())throw new We("provide code or path");let{meta:c,body:p}=Jj(m);if(n.path){let ce=Hj(n.path).replace(/\.(js|mjs|cjs|ts)$/,"");if(ce!==c.name)throw new We(`meta.name "${c.name}" must match the script filename "${ce}"`)}let f=Yj(p),d=Date.now(),g=[],x=0,I=0,h=(ce,V)=>({name:c.name,...c.description?{description:c.description}:{},ok:ce,agents:I,outputTokens:x,startedAt:d,phases:c.phases??[],steps:g,...V?{error:V}:{}}),$=(ce,V)=>{a.ui.setStatus(Yp,V?void 0:aC(ce)),i?.({content:[],details:h(!1)})},S=ce=>{I=ce.length,x=ce.reduce((V,or)=>V+or.outputTokens,0),g.splice(0,g.length,...ce.map(V=>({label:V.label,phase:V.phase,agent:V.agentType,status:V.status,outputTokens:V.outputTokens,startedAt:V.startedAt,...V.toolCalls!==void 0?{toolCalls:V.toolCalls}:{},...V.model?{model:V.model}:{},...V.endedAt?{endedAt:V.endedAt}:{},...V.detail?{detail:V.detail}:{},...V.tasks?{tasks:V.tasks}:{}}))),$({name:c.name,...c.description?{description:c.description}:{},phases:c.phases??[],steps:g,startedAt:d},!1)},_=Xj(zT(a?.model)),A=xC({invoke:n.agent?tN(_,n.agent):_,budgetTotal:n.budget??null,onProgress:S,...o?{signal:o}:{},...t()?.isPaused?{isPaused:t().isPaused}:{}}),Xe=new AbortController,rt=setTimeout(()=>Xe.abort(),Vj);o&&o.addEventListener("abort",()=>Xe.abort(),{once:!0}),t()?.onStop?.(()=>Xe.abort());try{let ce=await Promise.race([f(A.agent,A.parallel,A.pipeline,A.phase,A.log,A.args,A.budget),new Promise((or,lt)=>Xe.signal.addEventListener("abort",()=>lt(new We("workflow timed out or was aborted"))))]),V=Date.now();return a.ui.setStatus(Yp,void 0),{content:[{type:"text",text:`${c.name}: ${I} agent call(s), ${x} output tokens in ${Po(V-d)}
180
+
181
+ ${rN(ce)}`}],details:{...h(!0),endedAt:V}}}catch(ce){let V=ce instanceof Error?ce.message:String(ce);return a.ui.setStatus(Yp,void 0),{content:[{type:"text",text:`${c.name} failed after ${I} agent call(s): ${V}`}],details:{...h(!1,V),endedAt:Date.now()},isError:!0}}finally{clearTimeout(rt),t()?.onStop?.(null)}}})}function tN(e,t){return r=>e({...r,agentType:t})}function rN(e){if(typeof e=="string")return e;try{return JSON.stringify(e,null,2)}catch{return String(e)}}import{existsSync as hC,readFileSync as IC}from"node:fs";var _i=null,qi=null;function bC(){try{return JSON.parse(IC(new URL("../../package.json",import.meta.url),"utf8")).version??"0.0.0"}catch{return"0.0.0"}}function A1e(){return af(Ve,bC())}async function O1e(){if(_i)return _i;if(qi)return qi;qi=(async()=>{let{tokenPath:e}=qm(Ve);if(!hC(e))throw new Error("Browser relay is not installed. Run /browser-relay install and load the extension in Chrome first.");let t=IC(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 mf({token:t,port:n,productVersion:bC()});return _i=o,o})();try{return await qi}finally{qi=null}}async function M1e(){let{extensionDir:e,tokenPath:t}=qm(Ve);return{running:_i!==null,state:_i?.state()??null,tokenConfigured:hC(t),extensionDir:e}}import{execFile as nN,execFileSync as Ui}from"node:child_process";import{promisify as oN}from"node:util";import{createHash as kC}from"node:crypto";import{copyFileSync as iN,existsSync as Om,mkdirSync as Mm,readFileSync as Zp,readdirSync as sN,rmSync as aN,statSync as Qp}from"node:fs";import{dirname as TC,join as Pt,resolve as vm}from"node:path";var Xp=Pt(Ve,"rewind"),Bi="refs/howtocode",$C="refs/howtofix",EC=100,CC=30,wC="project.json",RC="checkpoints.json",SC=!1;function mN(e){let t=vm(e);for(;;){if(Om(Pt(t,".git")))return!0;let r=TC(t);if(r===t)return!1;t=r}}var uN=oN(nN);async function Nt(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 uN("git",t,{cwd:e.root,env:r,encoding:"utf8",maxBuffer:8*1024*1024});return n.trim()}function cN(e){return kC("sha1").update(e).digest("hex").slice(0,16)}function pN(e){let t={...process.env,GIT_DIR:e.gitDir,GIT_WORK_TREE:e.root};try{let r=Ui("git",["for-each-ref","--format=%(refname)",`${$C}/`],{env:t,encoding:"utf8",stdio:["ignore","pipe","ignore"]}).trim();for(let n of r.split(`
182
+ `).filter(Boolean)){let o=`${Bi}/${n.slice($C.length+1)}`;try{let i=Ui("git",["rev-parse",n],{env:t,encoding:"utf8",stdio:["ignore","pipe","ignore"]}).trim();Ui("git",["update-ref",o,i],{env:t,stdio:"ignore"}),Ui("git",["update-ref","-d",n],{env:t,stdio:"ignore"})}catch{}}}catch{}}function U1e(e){let t=vm(e).replace(/\/+$/,"")||"/",r=Pt(Xp,cN(t)),n=Pt(r,"git"),o={root:t,gitDir:n,metaFile:Pt(r,RC),disabled:!1};return!Om(Pt(n,"HEAD"))&&!mN(t)?(o.disabled=!0,o):(Mm(r,{recursive:!0}),Om(Pt(n,"HEAD"))||(Mm(n,{recursive:!0}),Ui("git",["init","--quiet","--initial-branch=howtocode"],{env:{...process.env,GIT_DIR:n},stdio:["ignore","ignore","pipe"]})),fN(t,n),pN(o),dN(r,t),SC||(SC=!0,gN({keep:r})),o)}function fN(e,t){let r=Pt(e,".git","info","exclude");try{if(!Qp(r).isFile())return;Mm(Pt(t,"info"),{recursive:!0}),iN(r,Pt(t,"info","exclude"))}catch{}}function dN(e,t){let r=Pt(e,wC),n=`${JSON.stringify({version:1,root:t})}
183
+ `;try{if(Zp(r,"utf8")===n)return}catch{}try{sr(r,n)}catch{}}function Fm(e){try{let t=JSON.parse(Zp(e.metaFile,"utf8"));if(t?.version===1&&t.sessions)return t}catch{}return{version:1,sessions:{}}}function ef(e,t){Mm(TC(e.metaFile),{recursive:!0}),sr(e.metaFile,`${JSON.stringify(t,null,1)}
184
+ `)}function lN(e,t){return e.disabled?[]:[...Fm(e).sessions[t]??[]].sort((r,n)=>r.at-n.at)}async function B1e(e,t,r){if(e.disabled)return null;let n;try{await Nt(e,["add","-A","--ignore-errors","--"]),n=await Nt(e,["write-tree"])}catch{return null}let i=lN(e,t).find(g=>g.tree===n),a=Date.now(),m=`${a.toString(36)}-${kC("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(`
185
+ `);c=await Nt(e,["commit-tree",n,"-m",g]),await Nt(e,["update-ref",`${Bi}/${m}`,c])}let p={id:m,tree:n,commit:c,prompt:r,at:a},f=Fm(e),d=[...f.sessions[t]??[],p];for(let g of d.slice(0,Math.max(0,d.length-EC)))try{await Nt(e,["update-ref","-d",`${Bi}/${g.id}`])}catch{}return f.sessions[t]=d.slice(-EC),ef(e,f),p}async function G1e(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 Nt(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 Nt(e,["clean","-fd"]);for(let o of n.split(`
186
+ `)){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 K1e(e,t){if(e.disabled)return[];try{await Nt(e,["add","-A","--ignore-errors","--"]);let r=await Nt(e,["write-tree"]);return r===t.tree?[]:(await Nt(e,["diff-tree","-r","--name-status","--no-commit-id",t.tree,r])).split(`
187
+ `).filter(Boolean).map(o=>{let[i,...a]=o.split(" ");return`${i?.[0]??"?"} ${a.at(-1)??""}`})}catch{return[]}}async function H1e(e,t={}){let r={droppedSessions:0,droppedRefs:0};if(e.disabled)return r;let n=(t.now??Date.now())-CC*24*60*60*1e3,o=Fm(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 Nt(e,["update-ref","-d",`${Bi}/${p.id}`]),r.droppedRefs+=1}catch{}}if(!i)return r;ef(e,o);try{await Nt(e,["gc","--quiet","--prune=now"])}catch{}return r}function gN(e={}){let t={removedDirs:0,failed:[]},r;try{r=sN(Xp,{withFileTypes:!0})}catch{return t}let n=(e.now??Date.now())-CC*24*60*60*1e3,o=e.keep?vm(e.keep):void 0;for(let i of r){if(!i.isDirectory())continue;let a=Pt(Xp,i.name);if(vm(a)!==o)try{(xN(a)||yN(a)<n)&&(aN(a,{recursive:!0,force:!0}),t.removedDirs+=1)}catch{t.failed.push(i.name)}}return t}function xN(e){try{let t=JSON.parse(Zp(Pt(e,wC),"utf8"));return typeof t?.root!="string"||t.root.length===0?!1:!Om(t.root)}catch{return!1}}function yN(e){try{return Qp(Pt(e,RC)).mtimeMs}catch{return Qp(e).mtimeMs}}async function z1e(e,t){if(e.disabled)return;let r=Fm(e);for(let n of r.sessions[t]??[])try{await Nt(e,["update-ref","-d",`${Bi}/${n.id}`])}catch{}delete r.sessions[t],ef(e,r)}export{Eo as a,fm as b,b1 as c,xPe as d,yPe as e,hPe as f,IPe as g,kPe as h,TPe as i,v1 as j,PPe as k,APe as l,OPe as m,GPe as n,KPe as o,HPe as p,zPe as q,WPe as r,ZS as s,M as t,rk as u,$Oe as v,sk as w,ak as x,COe as y,sL as z,wOe as A,ROe as B,POe as C,AOe as D,aL as E,OOe as F,mL as G,uL as H,MOe as I,qOe as J,_Oe as K,UOe as L,BOe as M,GOe as N,KOe as O,rp as P,HOe as Q,zOe as R,WOe as S,VOe as T,Ik as U,TL as V,Fi as W,AL as X,_L as Y,UL as Z,BL as _,GL as $,VL as aa,rT as ba,nT as ca,aD as da,fve as ea,lT as fa,BT as ga,BD as ha,GD as ia,KT as ja,zD as ka,xFe as la,pn as ma,FFe as na,LFe as oa,Rt as pa,DFe as qa,jFe as ra,NFe as sa,qFe as ta,zT as ua,_Fe as va,UFe as wa,BFe as xa,sj as ya,fj as za,JFe as Aa,YFe as Ba,QFe as Ca,XFe as Da,ZFe as Ea,XT as Fa,eC as Ga,qe as Ha,bj as Ia,mt as Ja,r1e as Ka,nC as La,Po as Ma,s1e as Na,Wp as Oa,a1e as Pa,S1e as Qa,k1e as Ra,A1e as Sa,O1e as Ta,M1e as Ua,CC as Va,U1e as Wa,lN as Xa,B1e as Ya,G1e as Za,K1e as _a,H1e as $a,z1e as ab};