howtocode 0.7.69 → 0.7.71
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/{chunk-KKQCOMDH.js → chunk-5AYXLMSC.js} +2 -2
- package/dist/{chunk-ZEBSTTKL.js → chunk-6RTTDISU.js} +1 -1
- package/dist/chunk-7HVQT3IC.js +201 -0
- package/dist/{chunk-DXMLXM3S.js → chunk-CU4IJVIZ.js} +1 -1
- package/dist/{chunk-SKLMU4IE.js → chunk-D5TQNROK.js} +1 -1
- package/dist/{chunk-DK3DYJTA.js → chunk-EF3Z3FAO.js} +1 -1
- package/dist/{chunk-ADGPAPXH.js → chunk-F5OVNAST.js} +1 -1
- package/dist/{chunk-IQGALTAR.js → chunk-H23J4FSF.js} +1 -1
- package/dist/{chunk-W7C4PWUR.js → chunk-SY75TNLH.js} +1 -1
- package/dist/{chunk-PMWAHAZV.js → chunk-VCDC3RAJ.js} +1 -1
- package/dist/{chunk-W34I6VMP.js → chunk-VSVEFNSH.js} +1 -1
- package/dist/{chunk-VZZPQZDI.js → chunk-YUS7EX6B.js} +1 -1
- package/dist/cli-auth.js +1 -1
- package/dist/main-app.js +4 -4
- package/package.json +2 -2
- package/dist/chunk-GNV6G3JW.js +0 -201
|
@@ -0,0 +1,201 @@
|
|
|
1
|
+
import{b as df}from"./chunk-27TRKD65.js";import{t as ff}from"./chunk-ZJL4OEXX.js";import{H as tt,K as pf,L as Un,a as Ji}from"./chunk-5FIFNXLT.js";import{a as fr}from"./chunk-UTYFLLSM.js";import{a as Gm,b as Bn,c as Gn,d as Km,e as Hm,f as Do,g as zm,h as Vr,j as jo}from"./chunk-MVVEYKN6.js";import{a as Dt}from"./chunk-WOT6VMZA.js";import{spawn as w1}from"node:child_process";import{existsSync as C1,readFileSync as R1}from"node:fs";import{join as P1}from"node:path";var H={};Dt(H,{Match:()=>_w});function _w(e,t){return t[e.length]?.(...e)??(()=>{throw Error("Invalid Arguments")})()}var De={};Dt(De,{Get:()=>ns,Reset:()=>DC,Set:()=>jC});var s={};Dt(s,{CodePointCount:()=>tC,Counted:()=>mC,Entries:()=>pC,EntriesRegExp:()=>cC,Every:()=>oC,EveryAll:()=>iC,GraphemeCount:()=>eC,HasPropertyKey:()=>uC,IsArray:()=>qo,IsBigInt:()=>No,IsBoolean:()=>If,IsClassInstance:()=>Zw,IsConstructor:()=>Ww,IsDeepEqual:()=>Jm,IsEqual:()=>Z,IsFunction:()=>bf,IsGreaterEqualThan:()=>Ef,IsGreaterThan:()=>Yw,IsInteger:()=>Wm,IsLessEqualThan:()=>$f,IsLessThan:()=>Qw,IsMaxLength:()=>rC,IsMinLength:()=>nC,IsMultipleOf:()=>Xw,IsNull:()=>Zi,IsNumber:()=>es,IsObject:()=>_o,IsObjectNotArray:()=>Vw,IsString:()=>ts,IsSymbol:()=>Jw,IsUndefined:()=>Vm,IsUnsafePropertyKey:()=>kf,IsValueLike:()=>Sf,Keys:()=>Xi,ShiftLeft:()=>rs,Some:()=>sC,SomeAll:()=>aC,Symbols:()=>fC,Values:()=>dC});function Kn(e,t,r){return e>=t&&e<=r}function Uw(e){return e===8205}function lf(e){return Kn(e,127462,127487)}function Bw(e){return Kn(e,65024,65039)}function Gw(e){return Kn(e,768,879)||Kn(e,6832,6911)||Kn(e,7616,7679)||Kn(e,65056,65071)}function Yi(e){return e>65535?2:1}function gf(e,t){for(;t<e.length;){let r=e.codePointAt(t);if(Gw(r)||Bw(r))t+=Yi(r);else break}return t}function Kw(e,t){let r=e.codePointAt(t),n=t+Yi(r);for(n=gf(e,n);n<e.length-1&&Uw(e.codePointAt(n));){let o=e.codePointAt(n+1);n+=1+Yi(o),n=gf(e,n)}return lf(r)&&n<e.length&&lf(e.codePointAt(n))&&(n+=Yi(e.codePointAt(n))),n}function yf(e){let t=0,r=0;for(;r<e.length;)r=Kw(e,r),t++;return t}function Qi(e){let t=0,r=0,n=0;for(;r<e.length;){let o=e.charCodeAt(r++)>>10;t+=+((n<<8|o)!==13879),n=o}return t}function xf(e,t){return e.length<=t||e.length<=t<<1&&Qi(e)<=t}function hf(e,t){return e.length>=t<<1||e.length>=t&&Qi(e)>=t}function qo(e){return Array.isArray(e)}function No(e){return Z(typeof e,"bigint")}function If(e){return Z(typeof e,"boolean")}function Ww(e){if(Vm(e)||!bf(e))return!1;let t=Function.prototype.toString.call(e);return!!(/^class\s/.test(t)||/\[native code\]/.test(t))}function bf(e){return Z(typeof e,"function")}function Wm(e){return Number.isInteger(e)}function Zi(e){return Z(e,null)}function es(e){return Number.isFinite(e)}function Vw(e){return _o(e)&&!qo(e)}function _o(e){return Z(typeof e,"object")&&!Zi(e)}function ts(e){return Z(typeof e,"string")}function Jw(e){return Z(typeof e,"symbol")}function Vm(e){return Z(e,void 0)}function Z(e,t){return e===t}function Yw(e,t){return e>t}function Qw(e,t){return e<t}function $f(e,t){return e<=t}function Ef(e,t){return e>=t}function Xw(e,t){if(No(e)||No(t))return BigInt(e)%BigInt(t)===0n;let r=1e-10;if(!es(e)||Wm(e)&&1/t%1===0)return!0;let n=e%t;return Math.min(Math.abs(n),Math.abs(n-t),Math.abs(n+t))<r}function Zw(e){if(!_o(e))return!1;let t=globalThis.Object.getPrototypeOf(e);return Zi(t)?!1:Z(typeof t.constructor,"function")&&!(Z(t.constructor,globalThis.Object)||Z(t.constructor.name,"Object"))}function Sf(e){return No(e)||If(e)||Zi(e)||es(e)||ts(e)||Vm(e)}function eC(e){return yf(e)}function tC(e){return Qi(e)}function rC(e,t){return xf(e,t)}function nC(e,t){return hf(e,t)}function oC(e,t,r){return e.every((n,o)=>o<t||r(n,o))}function iC(e,t,r){let n=!0;return e.forEach((o,i)=>{i>=t&&!r(o,i)&&(n=!1)}),n}function sC(e,t){return e.some((r,n)=>t(r,n))}function aC(e,t){let r=!1;return e.forEach((n,o)=>{t(n,o)&&(r=!0)}),r}function mC(e,t){return e.reduce((r,n,o)=>t(n,o)?++r:r,0)}function rs(e,t,r){return Z(e.length,0)?r():t(e[0],e.slice(1))}function kf(e){return Z(e,"__proto__")||Z(e,"constructor")||Z(e,"prototype")}function uC(e,t){return kf(t)?Object.prototype.hasOwnProperty.call(e,t):t in e}function cC(e){return Xi(e).map(t=>[new RegExp(`^${t}$`),e[t]])}function pC(e){return Object.entries(e)}function Xi(e){return Object.getOwnPropertyNames(e)}function fC(e){return Object.getOwnPropertySymbols(e)}function dC(e){return Object.values(e)}function lC(e,t){if(!_o(t))return!1;let r=Xi(e);return Z(r.length,Xi(t).length)&&r.every(n=>Jm(e[n],t[n]))}function gC(e,t){return qo(t)&&Z(e.length,t.length)&&e.every((r,n)=>Jm(e[n],t[n]))}function Jm(e,t){return qo(e)?gC(e,t):_o(e)?lC(e,t):Z(e,t)}var Ue={};Dt(Ue,{IsBigInt64Array:()=>PC,IsBigUint64Array:()=>AC,IsBoolean:()=>yC,IsDate:()=>MC,IsFloat32Array:()=>CC,IsFloat64Array:()=>RC,IsInt16Array:()=>SC,IsInt32Array:()=>TC,IsInt8Array:()=>bC,IsMap:()=>FC,IsNumber:()=>xC,IsRegExp:()=>OC,IsSet:()=>vC,IsString:()=>hC,IsTypeArray:()=>IC,IsUint16Array:()=>kC,IsUint32Array:()=>wC,IsUint8Array:()=>$C,IsUint8ClampedArray:()=>EC});function yC(e){return e instanceof Boolean}function xC(e){return e instanceof Number}function hC(e){return e instanceof String}function IC(e){return globalThis.ArrayBuffer.isView(e)}function bC(e){return e instanceof globalThis.Int8Array}function $C(e){return e instanceof globalThis.Uint8Array}function EC(e){return e instanceof globalThis.Uint8ClampedArray}function SC(e){return e instanceof globalThis.Int16Array}function kC(e){return e instanceof globalThis.Uint16Array}function TC(e){return e instanceof globalThis.Int32Array}function wC(e){return e instanceof globalThis.Uint32Array}function CC(e){return e instanceof globalThis.Float32Array}function RC(e){return e instanceof globalThis.Float64Array}function PC(e){return e instanceof globalThis.BigInt64Array}function AC(e){return e instanceof globalThis.BigUint64Array}function OC(e){return e instanceof globalThis.RegExp}function MC(e){return e instanceof globalThis.Date}function vC(e){return e instanceof globalThis.Set}function FC(e){return e instanceof globalThis.Map}var Tf=s;var er={immutableTypes:!1,maxErrors:8,maxParseErrors:1,maxInstantiationCount:128,useAcceleration:!0,exactOptionalPropertyTypes:!1,enumerableKind:!1,correctiveParse:!1,unionPrioritySort:!0};function DC(){er.immutableTypes=!1,er.maxErrors=8,er.maxParseErrors=1,er.maxInstantiationCount=128,er.useAcceleration=!0,er.exactOptionalPropertyTypes=!1,er.enumerableKind=!1,er.correctiveParse=!1,er.unionPrioritySort=!0}function jC(e){for(let t of s.Keys(e)){let r=e[t];r!==void 0&&Object.defineProperty(er,t,{value:r})}}function ns(){return er}function os(e){return s.HasPropertyKey(e,"~refine")&&s.IsArray(e["~refine"])&&s.Every(e["~refine"],0,t=>s.IsObject(t)&&s.HasPropertyKey(t,"check")&&s.HasPropertyKey(t,"error")&&s.IsFunction(t.check)&&s.IsFunction(t.error))}function $t(e){return s.IsObject(e)&&!s.IsArray(e)}function In(e){return s.IsBoolean(e)}function N(e){return $t(e)||In(e)}function is(e){return s.HasPropertyKey(e,"additionalItems")&&N(e.additionalItems)}function Wt(e){return s.HasPropertyKey(e,"additionalProperties")&&N(e.additionalProperties)}function ss(e){return s.HasPropertyKey(e,"allOf")&&s.IsArray(e.allOf)&&e.allOf.every(t=>N(t))}function wf(e){return s.HasPropertyKey(e,"$anchor")&&s.IsString(e.$anchor)}function as(e){return s.HasPropertyKey(e,"anyOf")&&s.IsArray(e.anyOf)&&e.anyOf.every(t=>N(t))}function Ym(e){return s.HasPropertyKey(e,"const")}function Jr(e){return s.HasPropertyKey(e,"contains")&&N(e.contains)}function wt(e){return s.HasPropertyKey(e,"default")}function Qm(e){return s.HasPropertyKey(e,"dependencies")&&s.IsObject(e.dependencies)&&Object.values(e.dependencies).every(t=>N(t)||s.IsArray(t)&&t.every(r=>s.IsString(r)))}function Xm(e){return s.HasPropertyKey(e,"dependentRequired")&&s.IsObject(e.dependentRequired)&&Object.values(e.dependentRequired).every(t=>s.IsArray(t)&&t.every(r=>s.IsString(r)))}function ms(e){return s.HasPropertyKey(e,"dependentSchemas")&&s.IsObject(e.dependentSchemas)&&Object.values(e.dependentSchemas).every(t=>N(t))}function Yr(e){return s.HasPropertyKey(e,"$dynamicAnchor")&&s.IsString(e.$dynamicAnchor)}function us(e){return s.HasPropertyKey(e,"$dynamicRef")&&s.IsString(e.$dynamicRef)}function cs(e){return s.HasPropertyKey(e,"else")&&N(e.else)}function Zm(e){return s.HasPropertyKey(e,"enum")&&s.IsArray(e.enum)}function eu(e){return s.HasPropertyKey(e,"exclusiveMaximum")&&(s.IsNumber(e.exclusiveMaximum)||s.IsBigInt(e.exclusiveMaximum))}function Mr(e){return s.HasPropertyKey(e,"exclusiveMinimum")&&(s.IsNumber(e.exclusiveMinimum)||s.IsBigInt(e.exclusiveMinimum))}function Uo(e){return s.HasPropertyKey(e,"format")&&s.IsString(e.format)}function gt(e){return s.HasPropertyKey(e,"$id")&&s.IsString(e.$id)}function ps(e){return s.HasPropertyKey(e,"if")&&N(e.if)}function bn(e){return s.HasPropertyKey(e,"items")&&(N(e.items)||s.IsArray(e.items)&&e.items.every(t=>N(t)))}function fs(e){return bn(e)&&s.IsArray(e.items)}function tu(e){return s.HasPropertyKey(e,"maximum")&&(s.IsNumber(e.maximum)||s.IsBigInt(e.maximum))}function ru(e){return s.HasPropertyKey(e,"maxContains")&&s.IsNumber(e.maxContains)}function Bo(e){return s.HasPropertyKey(e,"maxItems")&&s.IsNumber(e.maxItems)}function nu(e){return s.HasPropertyKey(e,"maxLength")&&s.IsNumber(e.maxLength)}function ou(e){return s.HasPropertyKey(e,"maxProperties")&&s.IsNumber(e.maxProperties)}function vr(e){return s.HasPropertyKey(e,"minimum")&&(s.IsNumber(e.minimum)||s.IsBigInt(e.minimum))}function $n(e){return s.HasPropertyKey(e,"minContains")&&s.IsNumber(e.minContains)}function En(e){return s.HasPropertyKey(e,"minItems")&&s.IsNumber(e.minItems)}function Go(e){return s.HasPropertyKey(e,"minLength")&&s.IsNumber(e.minLength)}function Ko(e){return s.HasPropertyKey(e,"minProperties")&&s.IsNumber(e.minProperties)}function iu(e){return s.HasPropertyKey(e,"multipleOf")&&(s.IsNumber(e.multipleOf)||s.IsBigInt(e.multipleOf))}function ds(e){return s.HasPropertyKey(e,"not")&&N(e.not)}function ls(e){return s.HasPropertyKey(e,"oneOf")&&s.IsArray(e.oneOf)&&e.oneOf.every(t=>N(t))}function Ho(e){return s.HasPropertyKey(e,"pattern")&&(s.IsString(e.pattern)||e.pattern instanceof RegExp)}function Hn(e){return s.HasPropertyKey(e,"patternProperties")&&s.IsObject(e.patternProperties)&&Object.values(e.patternProperties).every(t=>N(t))}function Sn(e){return s.HasPropertyKey(e,"prefixItems")&&s.IsArray(e.prefixItems)&&e.prefixItems.every(t=>N(t))}function zn(e){return s.HasPropertyKey(e,"properties")&&s.IsObject(e.properties)&&Object.values(e.properties).every(t=>N(t))}function gs(e){return s.HasPropertyKey(e,"propertyNames")&&(s.IsObject(e.propertyNames)||N(e.propertyNames))}function NC(e){return s.HasPropertyKey(e,"$recursiveAnchor")&&s.IsBoolean(e.$recursiveAnchor)}function zo(e){return NC(e)&&s.IsEqual(e.$recursiveAnchor,!0)}function ys(e){return s.HasPropertyKey(e,"$recursiveRef")&&s.IsString(e.$recursiveRef)}function xs(e){return s.HasPropertyKey(e,"$ref")&&s.IsString(e.$ref)}function kn(e){return s.HasPropertyKey(e,"required")&&s.IsArray(e.required)&&e.required.every(t=>s.IsString(t))}function hs(e){return s.HasPropertyKey(e,"then")&&N(e.then)}function su(e){return s.HasPropertyKey(e,"type")&&(s.IsString(e.type)||s.IsArray(e.type)&&e.type.every(t=>s.IsString(t)))}function Qr(e){return s.HasPropertyKey(e,"uniqueItems")&&s.IsBoolean(e.uniqueItems)}function Wo(e){return s.HasPropertyKey(e,"unevaluatedItems")&&N(e.unevaluatedItems)}function Vo(e){return s.HasPropertyKey(e,"unevaluatedProperties")&&N(e.unevaluatedProperties)}var yt=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}},it=class extends yt{constructor(){super(),this.errors=[]}AtCapacity(){return this.errors.length>=De.Get().maxErrors}AddError(t,r,n,o){return this.AddErrorObject({keyword:t,schemaPath:r,instancePath:n,params:o})}AddErrors(t){return t.forEach(r=>this.AddErrorObject(r)),!1}GetErrors(){return this.errors}AddErrorObject(t){return this.AtCapacity()||this.errors.push(t),!1}};function Cf(e,t,r,n){return s.Every(r["~refine"],0,(o,i)=>o.check(n))}function Rf(e,t,r,n,o,i){return s.EveryAll(o["~refine"],0,(a,m)=>a.check(i)||t.AddError("~refine",r,n,{index:m,message:a.error(i)}))}var Jo="urn:typebox:root";function Fr(e,t){return URL.canParse(e,t)?new URL(e,t):s.IsEqual(t,Jo)?new URL(`${t}:${e}`):new URL(`${t.slice(0,t.lastIndexOf(":"))}:${e}`)}function Vn(e,t){let r=$t(t)&>(t)?Fr(t.$id,Jo).href:Jo;return{context:e,schema:t,lexicalSchema:t,lexicalBase:r,resourceBase:r,referenceBase:r,ids:[],useResourceBaseForReference:!0,recursiveAnchor:void 0,dynamicAnchors:[],resourceEntries:new Map,pendingResource:!0,enteredResource:!1}}function au(e,t,r=!0){if(In(t))return e;if(Array.isArray(t))return t.reduce((o,i)=>au(o,i,!1),e);if(!$t(t)||!r&>(t))return e;let n=!r&&Yr(t)?[...e,t]:e;return Object.keys(t).reduce((o,i)=>au(o,t[i],!1),n)}function Yo(e,t){return e.resourceEntries.get(t)}function Pf(e,t){return e.enteredResource||Yo(e,t)!==void 0}function qC(e){return!/^[A-Za-z][A-Za-z0-9+.-]*:/.test(e.$id)}function _C(e,t){return gt(t)?[...e.ids,t]:e.ids}function UC(e,t){return e.recursiveAnchor??(zo(t)?t:void 0)}function BC(e,t){let r=gt(t)?au(e.dynamicAnchors,t):e.dynamicAnchors;return Yr(t)?[...r,t]:r}function GC(e,t){return gt(t)?!1:e.pendingResource}function Af(e,t){let r=Yo(e,t);return r?r.base:gt(t)?Fr(t.$id,e.lexicalBase).href:e.lexicalBase}function Of(e,t){let r=Yo(e,t);return r?r.base:gt(t)&&e.pendingResource?Fr(t.$id,e.resourceBase).href:e.resourceBase}function Mf(e,t){return gt(t)?!qC(t):e.useResourceBaseForReference}function KC(e,t){let r=Pf(e,t),n=Mf(e,t);return r||n?Of(e,t):Af(e,t)}function HC(e,t){let r=Yo(e,t);return r?r.root:gt(t)?t:e.lexicalSchema}function zC(e,t){return $t(t)&&(gt(t)||Yr(t)||s.IsUndefined(e.recursiveAnchor)&&zo(t)||!s.IsUndefined(Yo(e,t)))}function Jn(e,t){return zC(e,t)?{...e,ids:_C(e,t),dynamicAnchors:BC(e,t),recursiveAnchor:UC(e,t),pendingResource:GC(e,t),lexicalBase:Af(e,t),resourceBase:Of(e,t),useResourceBaseForReference:Mf(e,t),referenceBase:KC(e,t),lexicalSchema:HC(e,t),enteredResource:Pf(e,t)}:e}function vf(e){return bn(e)&&s.IsArray(e.items)}function Ff(e,t,r,n){return vf(r)?s.Every(n,0,(i,a)=>s.IsLessThan(a,r.items.length)||jt(e,t,r.additionalItems,i)&&t.AddIndex(a)):!0}function Lf(e,t,r,n,o,i){return vf(o)?s.Every(i,0,(m,c)=>{let p=`${r}/additionalItems`,f=`${n}/${c}`;return s.IsLessThan(c,o.items.length)||Nt(e,t,p,f,o.additionalItems,m)&&t.AddIndex(c)}):!0}function Ct(e){return e.replace(/~/g,"~0").replace(/\//g,"~1")}function Xr(e){return new RegExp(e,"u")}function WC(e){return`^${e.replace(/[.*+?^${}()|[\]\\]/g,"\\$&")}$`}function Df(e){let t=[];return Hn(e)&&t.push(...s.Keys(e.patternProperties)),zn(e)&&t.push(...s.Keys(e.properties).map(WC)),s.IsEqual(t.length,0)?"(?!)":`(${t.join("|")})`}function jf(e,t,r,n){let o=Xr(Df(r));return s.Every(s.Keys(n),0,(a,m)=>o.test(a)||jt(e,t,r.additionalProperties,n[a])&&t.AddKey(a))}function Nf(e,t,r,n,o,i){let a=Xr(Df(o)),m=[];return s.EveryAll(s.Keys(i),0,(p,f)=>{let d=`${r}/additionalProperties`,g=`${n}/${Ct(p)}`,y=a.test(p)||Nt(e,t,d,g,o.additionalProperties,i[p])&&t.AddKey(p);return y||m.push(p),y})||t.AddError("additionalProperties",r,n,{additionalProperties:m})}function qf(e,t,r,n){let o=r.allOf.reduce((i,a)=>{let m=new yt;return ee(e,m,a,n)?[...i,m]:i},[]);return s.IsEqual(o.length,r.allOf.length)&&t.Merge(o)}function _f(e,t,r,n,o,i){let a=[],m=o.allOf.reduce((p,f,d)=>{let g=`${r}/allOf/${d}`,y=new it,I=pe(e,y,g,n,f,i);return I||a.push(y),I?[...p,y]:p},[]),c=s.IsEqual(m.length,o.allOf.length)&&t.Merge(m);return c||a.forEach(p=>t.AddErrors(p.GetErrors())),c}function Uf(e,t,r,n){let o=r.anyOf.reduce((i,a)=>{let m=new yt;return ee(e,m,a,n)?[...i,m]:i},[]);return s.IsGreaterThan(o.length,0)&&t.Merge(o)}function Bf(e,t,r,n,o,i){let a=[],m=o.anyOf.reduce((p,f,d)=>{let g=new it,y=`${r}/anyOf/${d}`,I=pe(e,g,y,n,f,i);return I||a.push(g),I?[...p,g]:p},[]),c=s.IsGreaterThan(m.length,0)&&t.Merge(m);return c||a.forEach(p=>t.AddErrors(p.GetErrors())),c||t.AddError("anyOf",r,n,{})}function cu(e,t,r,n){return r}function Gf(e,t,r,n,o,i){return cu(e,t,o,i)||t.AddError("boolean",r,n,{})}function pu(e,t,r,n){return s.IsValueLike(r.const)?s.IsEqual(n,r.const):s.IsDeepEqual(n,r.const)}function Kf(e,t,r,n,o,i){return pu(e,t,o,i)||t.AddError("const",r,n,{allowedValue:o.const})}function VC(e){return!($n(e)&&s.IsEqual(e.minContains,0))}function fu(e,t,r,n){return VC(r)?!s.IsEqual(n.length,0)&&s.SomeAll(n,(o,i)=>ee(e,t,r.contains,o)&&t.AddIndex(i)):!0}function Hf(e,t,r,n,o,i){return fu(e,t,o,i)||t.AddError("contains",r,n,{minContains:1})}function zf(e,t,r,n){let o=s.IsEqual(s.Keys(n).length,0),i=s.Every(s.Entries(r.dependencies),0,([a,m])=>!s.HasPropertyKey(n,a)||(s.IsArray(m)?m.every(c=>s.HasPropertyKey(n,c)):ee(e,t,m,n)));return o||i}function Wf(e,t,r,n,o,i){let a=s.IsEqual(s.Keys(i).length,0),m=s.EveryAll(s.Entries(o.dependencies),0,([c,p])=>{let f=`${r}/dependencies/${Ct(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})):pe(e,t,f,n,p,i))});return a||m}function Vf(e,t,r,n){let o=s.IsEqual(s.Keys(n).length,0),i=s.Every(s.Entries(r.dependentRequired),0,([a,m])=>!s.HasPropertyKey(n,a)||m.every(c=>s.HasPropertyKey(n,c)));return o||i}function Jf(e,t,r,n,o,i){let a=s.IsEqual(s.Keys(i).length,0),m=s.EveryAll(s.Entries(o.dependentRequired),0,([c,p])=>!s.HasPropertyKey(i,c)||s.EveryAll(p,0,f=>s.HasPropertyKey(i,f)||t.AddError("dependentRequired",r,n,{property:c,dependencies:p})));return a||m}function Yf(e,t,r,n){let o=s.IsEqual(s.Keys(n).length,0),i=s.Every(s.Entries(r.dependentSchemas),0,([a,m])=>!s.HasPropertyKey(n,a)||ee(e,t,m,n));return o||i}function Qf(e,t,r,n,o,i){let a=s.IsEqual(s.Keys(i).length,0),m=s.EveryAll(s.Entries(o.dependentSchemas),0,([c,p])=>{let f=`${r}/dependentSchemas/${Ct(c)}`;return!s.HasPropertyKey(i,c)||pe(e,t,f,n,p,i)});return a||m}var Vt={};Dt(Vt,{DynamicRef:()=>TR,RecursiveRef:()=>ER,Ref:()=>bR});var lr={};Dt(lr,{Delete:()=>XC,Get:()=>YC,Has:()=>JC,Indices:()=>Xo,Set:()=>QC});function Zf(e){throw Error(e)}function Xf(){Zf("Pointer contains unsafe property key")}function du(){Zf("Cannot set value")}function Xo(e){let t=e.split("/").map(r=>r.replace(/~1/g,"/").replace(/~0/g,"~"));return t[0]===""?t.slice(1):t}function JC(e,t){let r=e;for(let n of Xo(t)){if(!s.IsObject(r)||!s.HasPropertyKey(r,n))return!1;r=r[n]}return!0}function YC(e,t){let r=e;for(let n of Xo(t)){if(!s.IsObject(r)||s.IsUnsafePropertyKey(n))return;r=r[n]}return r}function ed(e,t,r){let n=e;for(let o of t)s.IsUnsafePropertyKey(o)&&Xf(),n=s.IsObject(n)?n[o]:void 0;return s.IsUnsafePropertyKey(r)&&Xf(),s.IsObject(n)||du(),n}function QC(e,t,r){let n=Xo(t),o=n.pop();return s.IsUndefined(o)&&du(),ed(e,n,o)[o]=r,e}function XC(e,t){let r=Xo(t),n=r.pop();s.IsUndefined(n)&&du();let o=ed(e,r,n);return s.IsArray(o)&&/^(0|[1-9]\d*)$/.test(n)?o.splice(Number(n),1):delete o[n],e}function yu(e,t){return $t(e)&>(e)?Fr(e.$id,t.href):t}function xu(e){return Fr(e,Jo)}function lu(e){return e.href.split("#")[0]}function ZC(e,t,r){return gu(e,xu(t),r)}function eR(e,t){return t.$ref.startsWith("#")||e.enteredResource?e.lexicalSchema:e.schema}function tR(e){return e.startsWith("#/")}function td(e,t){if(s.IsObject(e)&&Yr(e)&&s.IsEqual(e.$dynamicAnchor,t))return e;if(s.IsObject(e))for(let r of s.Keys(e)){let n=td(e[r],t);if(n)return n}}function gu(e,t,r){if(s.IsEqual(e,r))return t.href;let n=yu(e,t);if(s.IsArray(e))for(let o of e){let i=gu(o,n,r);if(!s.IsUndefined(i))return i}else if(s.IsObject(e))for(let o of s.Keys(e)){let i=gu(e[o],n,r);if(!s.IsUndefined(i))return i}}function rd(e,t){if(t.href.endsWith("#"))return e;if(!t.hash.startsWith("#"))return;let r=decodeURIComponent(t.hash.slice(1));if(r.startsWith("/"))return lr.Get(e,r)}function rR(e,t,r){if(!gt(e))return;if(s.IsEqual(e.$id,r.hash))return e;let n=new URL(r.href,t.href);if(s.IsEqual(t.pathname,n.pathname))return r.hash.startsWith("#")?rd(e,r):e}function nR(e,t,r){if(!wf(e))return;let n=new URL(`#${e.$anchor}`,t.href),o=new URL(r.href,t.href);return s.IsEqual(n.href,o.href)?e:void 0}function oR(e,t,r){if(!Yr(e))return;let n=new URL(`#${e.$dynamicAnchor}`,t.href),o=new URL(r.href,t.href);return s.IsEqual(n.href,o.href)?e:void 0}function iR(e,t,r){if($t(e))return rR(e,t,r)??nR(e,t,r)??oR(e,t,r)??rd(e,r)}function sR(e,t,r){if(s.IsArray(e))return e.reduce((n,o)=>{let i=Is(o,t,r);return s.IsUndefined(i)?n:i},void 0)}function aR(e,t,r){if(s.IsObject(e))return s.Keys(e).reduce((n,o)=>{if(s.IsEqual(o,"const")||s.IsEqual(o,"enum"))return n;let i=Is(e[o],t,r);return s.IsUndefined(i)?n:i},void 0)}function Is(e,t,r){let n=yu(e,t);return iR(e,n,r)??sR(e,n,r)??aR(e,n,r)}function mR(e,t,r,n){let o=bs(e,t,r,n);return $t(o)&>(o)?o:void 0}function uR(e,t,r){if(!t.$ref.startsWith("#")||!$t(e.schema)||s.HasPropertyKey(e.schema,"$schema"))return;let n=ZC(e.lexicalSchema,e.referenceBase,r);if(!(s.IsUndefined(n)||s.IsEqual(n,e.referenceBase)))return{target:r,base:n,root:e.lexicalSchema}}function cR(e,t,r){let n=e.context[t];if($t(n))return{target:r,base:t,root:n}}function pR(e,t,r,n,o){let i=o?cR(e,n,r):void 0;return s.IsUndefined(i)?uR(e,t,r):i}function fR(e,t,r){if(gt(r))return;let n=mR(e.context,e.schema,e.referenceBase,t);if(!(!n||e.ids.includes(n)))return{resource:n}}function dR(e,t){return s.HasPropertyKey(e,t)?e[t]:void 0}function lR(e,t,r){return Is(e,t,r)}function gR(e,t,r){let n=lu(r);if(!s.HasPropertyKey(e,n)||s.IsEqual(n,lu(t)))return;let o=e[n],i=yu(o,new URL(n));return s.IsEqual(r.hash,"")?o:Is(o,i,r)}function bs(e,t,r,n){let o=xu(r),i=Fr(n,o.href);return dR(e,n)??lR(t,o,i)??gR(e,o,i)}function yR(e,t){if(!t)return e;let r=new Map(e.resourceEntries);return r.set(t.target,{base:t.base,root:t.root}),{...e,resourceEntries:r}}function xR(e,t){return t?Jn(e,t.resource):e}function nd(e,t,r,n){let o=yR({...e,pendingResource:t},r);return xR(o,n)}function hR(e,t,r){let n=lu(Fr(t.$ref,e.referenceBase)),o=!s.IsEqual(n,e.resourceBase),i=pR(e,t,r,n,o),a=o?fR(e,n,r):void 0;return{schema:r,stack:nd(e,!0,i,a)}}function IR(e,t){return{schema:t,stack:nd(e,!s.IsUndefined(t))}}function bR(e,t){let r=bs(e.context,eR(e,t),e.referenceBase,t.$ref);return $t(r)?hR(e,t,r):IR(e,r)}function $R(e){return $t(e.lexicalSchema)&&zo(e.lexicalSchema)}function ER(e,t){let r=$R(e)?e.recursiveAnchor:e.lexicalSchema;return bs(e.context,r,e.lexicalBase,t.$recursiveRef)}function od(e,t){return Fr(t.$dynamicRef,xu(e.lexicalBase).href).hash}function id(e,t){return e.dynamicAnchors.find(r=>s.IsEqual(r.$dynamicAnchor,t))??td(e.schema,t)}function SR(e,t,r){if(!$t(r)||!Yr(r))return r;let n=od(e,t);return tR(n)?r:id(e,r.$dynamicAnchor)}function kR(e,t){let r=od(e,t);return id(e,decodeURIComponent(r.slice(1)))}function TR(e,t){let r=t.$dynamicRef.startsWith("#")?e.lexicalSchema:e.schema,n=bs(e.context,r,e.lexicalBase,t.$dynamicRef);return s.IsUndefined(n)?kR(e,t):SR(e,t,n)}function sd(e,t,r,n){let o=Vt.DynamicRef(e,r)??!1,i=o?{...e,pendingResource:!0}:e;return N(o)&&ee(i,t,o,n)}function ad(e,t,r,n,o,i){let a=Vt.DynamicRef(e,o)??!1,m=a?{...e,pendingResource:!0}:e;return N(a)&&pe(m,t,r,n,a,i)}function bu(e,t,r,n){return s.Some(r.enum,o=>s.IsValueLike(o)?s.IsEqual(n,o):s.IsDeepEqual(n,o))}function md(e,t,r,n,o,i){return bu(e,t,o,i)||t.AddError("enum",r,n,{allowedValues:o.enum})}function $u(e,t,r,n){return s.IsLessThan(n,r.exclusiveMaximum)}function ud(e,t,r,n,o,i){return $u(e,t,o,i)||t.AddError("exclusiveMaximum",r,n,{comparison:"<",limit:o.exclusiveMaximum})}function Eu(e,t,r,n){return s.IsGreaterThan(n,r.exclusiveMinimum)}function cd(e,t,r,n,o,i){return Eu(e,t,o,i)||t.AddError("exclusiveMinimum",r,n,{comparison:">",limit:o.exclusiveMinimum})}var ri={};Dt(ri,{Clear:()=>jd,Entries:()=>l0,Get:()=>x0,Has:()=>y0,IsDate:()=>Qn,IsDateTime:()=>$s,IsDuration:()=>Es,IsEmail:()=>Ss,IsHostname:()=>Os,IsIPv4:()=>Fs,IsIPv6:()=>Ls,IsIdnEmail:()=>Ms,IsIdnHostname:()=>vs,IsIri:()=>js,IsIriReference:()=>Ds,IsJsonPointer:()=>qs,IsJsonPointerUriFragment:()=>Ns,IsRegex:()=>_s,IsRelativeJsonPointer:()=>Us,IsTime:()=>Xn,IsUri:()=>Ks,IsUriReference:()=>Bs,IsUriTemplate:()=>Gs,IsUrl:()=>Hs,IsUuid:()=>zs,Reset:()=>Nd,Set:()=>g0,Test:()=>h0});var wR=[0,31,28,31,30,31,30,31,31,30,31,30,31],CR=/^(\d\d\d\d)-(\d\d)-(\d\d)$/;function RR(e){return e%4===0&&(e%100!==0||e%400===0)}function Qn(e){let t=CR.exec(e);if(!t)return!1;let r=+t[1],n=+t[2],o=+t[3];return n>=1&&n<=12&&o>=1&&o<=(n===2&&RR(r)?29:wR[n])}var PR=/^(\d\d):(\d\d):(\d\d)(?:\.\d+)?(?:([Zz])|([+-])(\d\d):(\d\d))?$/;function Xn(e,t=!0){let r=PR.exec(e);if(!r||t&&!r[4]&&!r[5])return!1;let n=+r[1],o=+r[2],i=+r[3];if(n>23||o>59||i>60)return!1;if(r[5]){let f=+r[6],d=+r[7];if(f>23||d>59)return!1}if(i<60)return!0;let a=r[5]==="-"?-1:1,m=+(r[6]||0),c=+(r[7]||0);return((n*60+o-a*(m*60+c))%1440+1440)%1440===1439}var AR=/^(?:\[!?(?:(?!\.{1,2}[/\]])[A-Za-z._][A-Za-z._0-9+-]{0,13}(?:\/(?!\.{1,2}[/\]])[A-Za-z._][A-Za-z._0-9+-]{0,13})*|[+-](?:[01][0-9]|2[0-3]):[0-5][0-9])\](?:\[!?[a-z_][a-z_0-9-]*=[A-Za-z0-9]+(?:-[A-Za-z0-9]+)*\])*|(?:\[!?[a-z_][a-z_0-9-]*=[A-Za-z0-9]+(?:-[A-Za-z0-9]+)*\])*)$/;function $s(e){let t=e.indexOf("["),r=t===-1?e:e.slice(0,t);if(t!==-1&&!AR.test(e.slice(t)))return!1;let n=r.split(/T/i);return n.length===2&&Qn(n[0])&&Xn(n[1])}var OR=/^P((\d+Y(\d+M(\d+D)?)?|\d+M(\d+D)?|\d+D)(T(\d+H(\d+M(\d+S)?)?|\d+M(\d+S)?|\d+S))?|T(\d+H(\d+M(\d+S)?)?|\d+M(\d+S)?|\d+S)|\d+W)$/;function Es(e){return OR.test(e)}var MR=/^(?:[a-z0-9!#$%&'*+/=?^_`{|}~-]+(?:\.[a-z0-9!#$%&'*+/=?^_`{|}~-]+)*|"(?:[^"\\]|\\[\x20-\x7e])*")@(?:[a-z0-9](?:[a-z0-9-]{0,61}[a-z0-9])?(?:\.[a-z0-9](?:[a-z0-9-]{0,61}[a-z0-9])?)*|\[(?:IPv6:[a-f0-9:]+|(?:25[0-5]|2[0-4][0-9]|1[0-9]{2}|[1-9]?[0-9])(?:\.(?:25[0-5]|2[0-4][0-9]|1[0-9]{2}|[1-9]?[0-9])){3})\])$/i;function Ss(e){return MR.test(e)}var pd=/^(?!-).*(?<!-)$/,fd=/^(?!..--)/,dd=/^[a-zA-Z0-9-]*$/,pG=new RegExp("^\\p{ASCII}*$","u"),Zn=/[^\p{ASCII}]/u;var vR=/[0-9]/,ld=/[\u{0660}-\u{0669}]/u,FR=/[\u{06f0}-\u{06f9}]/u,LR=/[\u{002e}\u{002c}\u{003a}\u{002f}]/u,DR=/[\u{002d}\u{002b}]/u,Su=new RegExp("\\p{Mn}","u"),jR=new RegExp("\\p{Mc}","u"),fG=new RegExp("\\p{Me}","u"),gd=/[\p{Mn}\p{Mc}\p{Me}]/u,ku=new RegExp("\\p{L}","u"),NR=new RegExp("\\p{Nd}","u"),yd=new RegExp("\\p{Script=Greek}","u"),ks=new RegExp("\\p{Script=Hebrew}","u"),xd=/[\p{Script=Hiragana}\p{Script=Katakana}\p{Script=Han}]/u,hd=/[\p{Script=Arabic}\p{Script=Syriac}\p{Script=Thaana}\p{Script=Mandaic}]/u,Tu=/[\u{094d}\u{09cd}\u{0a4d}\u{0acd}\u{0b4d}\u{0bcd}\u{0c4d}\u{0ccd}\u{0d3b}\u{0d3c}\u{0d4d}\u{0dca}\u{1b44}\u{1baa}\u{1bab}\u{a9c0}\u{11046}\u{1107f}\u{110b9}\u{11133}\u{11134}\u{111c0}\u{11235}\u{1134d}\u{11442}\u{114c2}\u{115bf}\u{1163f}\u{116b6}\u{11c3f}\u{11d44}\u{11d45}]/u,Id=/[\u{0640}\u{07fa}\u{302e}\u{302f}\u{3031}\u{3032}\u{3033}\u{3034}\u{3035}\u{303b}]/u,qR=/[\u{00b7}\u{0375}\u{05f3}\u{05f4}\u{200c}\u{200d}\u{30fb}]/u,_R=/[\u{00df}\u{03c2}\u{06fd}\u{06fe}\u{0f0b}\u{3007}]/u,bd=new RegExp([vR,FR].map(e=>e.source).join("|"),"u"),$d=new RegExp([ku,DR,LR,NR,Su,jR,qR,_R].map(e=>e.source).join("|"),"u");function Ed(e){return pd.test(e)&&fd.test(e)&&dd.test(e)}var rr=36,ei=1,ti=26,BR=38,GR=700,kd=72,Td=128;function wu(){throw null}function Ts(e){return e.toLowerCase().startsWith("xn--")}function wd(e,t,r){e=r?Math.floor(e/GR):e>>1,e+=Math.floor(e/t);let n=0;for(;e>(rr-ei)*ti>>1;)e=Math.floor(e/(rr-ei)),n+=rr;return n+Math.floor((rr-ei+1)*e/(e+BR))}function ws(e){let t=[],r=Td,n=0,o=kd,i=e.lastIndexOf("-");if(i>0)for(let m=0;m<i;m++){let c=e.charCodeAt(m);c>=128&&wu(),t.push(c)}let a=i<0?0:i+1;for(;a<e.length;){let m=n,c=1,p=rr;for(;;){a>=e.length&&wu();let d=e.charCodeAt(a++),g;d>=97&&d<=122?g=d-97:d>=48&&d<=57?g=d-48+26:wu(),n+=g*c;let y=p<=o?ei:p>=o+ti?ti:p-o;if(g<y)break;c*=rr-y,p+=rr}let f=t.length+1;o=wd(n-m,f,m===0),r+=Math.floor(n/f),n%=f,t.splice(n,0,r),n++}return String.fromCodePoint(...t)}function Sd(e){return e<26?String.fromCharCode(e+97):String.fromCharCode(e-26+48)}var KR=new RegExp(Zn.source,"gu");function Cd(e){let t=e.replace(KR,""),r=t.length,n=r>0?[t,"-"]:[],o=Array.from(e,p=>p.codePointAt(0)),i=Td,a=0,m=kd,c=r;for(;c<o.length;){let p=1/0;for(let f of o)f>=i&&f<p&&(p=f);a+=(p-i)*(c+1),i=p;for(let f of o)if(f<i&&a++,f===i){let d=a;for(let g=rr;;g+=rr){let y=g<=m?ei:g>=m+ti?ti:g-m;if(d<y)break;let I=y+(d-y)%(rr-y);n.push(Sd(I)),d=Math.floor((d-y)/(rr-y))}n.push(Sd(d)),m=wd(a,c+1,c===r),a=0,c++}a++,i++}return n.join("")}var HR=/^(?:R|AL|AN|EN|ES|CS|ET|ON|BN|NSM)$/,Rd=/^(?:L|EN|ES|CS|ET|ON|BN|NSM)$/,zR=/^(?:R|AL|AN)$/;function Pd(e){if(Ts(e))try{return Cs(ws(e.slice(4).toLowerCase()))}catch{return!1}return Cs(e)}function Ad(e){let t=String.fromCodePoint(e);return bd.test(t)?"EN":ld.test(t)?"AN":Su.test(t)?"NSM":ks.test(t)?"R":hd.test(t)?"AL":ku.test(t)?"L":"ON"}function Cs(e){for(let t of e)if(zR.test(Ad(t.codePointAt(0))))return!0;return!1}function Rs(e){let t=!1,r=Rd,n=!1,o=!1,i=!0;for(let a of e){let m=Ad(a.codePointAt(0));if(i){if(m!=="L"&&m!=="R"&&m!=="AL")return!1;t=m==="R"||m==="AL",r=t?HR:Rd,i=!1}if(!r.test(m))return!1;m==="EN"?n=!0:m==="AN"&&(o=!0)}return!(t&&n&&o)}function WR(e){return Zn.test(e)&&Cd(e).length+4>63}function VR(e){return e[0]==="-"||e[e.length-1]==="-"?!0:e.slice(2).join("").startsWith("--")}function Ps(e){if(WR(e)||Cs(e)&&!Rs(e))return!1;let t=[...e],r=t.map(i=>i.codePointAt(0)),n=r.length;if(VR(t)||gd.test(t[0]))return!1;let o=!1;for(let i=0;i<n;i++){let a=r[i],m=t[i];if(Id.test(m)||!$d.test(m))return!1;xd.test(m)&&(o=!0);let c=r[i-1],p=r[i+1];switch(a){case 183:if(c!==108||p!==108)return!1;break;case 885:if(!p||!yd.test(t[i+1]))return!1;break;case 1523:case 1524:if(!c||!ks.test(t[i-1]))return!1;break;case 8204:if(!c||c<128&&!Tu.test(t[i-1]))return!1;break;case 8205:if(!c||!Tu.test(t[i-1]))return!1;break;case 12539:break}}return!(e.includes("\u30FB")&&!o)}function As(e){if(!Ts(e))return!1;try{let t=e.slice(4).toLowerCase();if(t.lastIndexOf("-")===0)return!1;let r=ws(t);return Zn.test(r)?Ps(r):!1}catch{return!1}}function JR(e){return e.length>0&&e.length<=63}function YR(e){return JR(e)&&(As(e)||Ed(e))}function Fd(e){return e.length===0||e.length>253||e.charCodeAt(e.length-1)===46?!1:e.split(".").every(t=>YR(t))}function QR(e){return e.length>0&&e.length<=63}function XR(e){return QR(e)&&(As(e)||Ps(e))}function ZR(e){return e.replace(/[\uff01-\uff5e]/g,t=>String.fromCharCode(t.charCodeAt(0)-65248)).normalize("NFC").replace(/[\u00ad\u034f\u180b-\u180d\u200b\ufe00-\ufe0f\u{e0100}-\u{e01ef}]/gu,"").replace(/[\u002E\u3002\uFF0E\uFF61]/g,".")}function Ld(e){if(e.length===0||e.includes(" "))return!1;let t=ZR(e);if(t.length>253)return!1;let r=t.split("."),n=r.some(o=>Pd(o));return r.every(o=>XR(o)&&(!n||Rs(o)))}function Os(e){return Fd(e)}var e0=/^(?:[A-Za-z0-9!#$%&'*+\/=?^_`{|}~\u{0080}-\u{10FFFF}-]+(?:\.[A-Za-z0-9!#$%&'*+\/=?^_`{|}~\u{0080}-\u{10FFFF}-]+)*|"(?:[^"\\]|\\.)*")@[\p{L}\p{N}](?:[\p{L}\p{N}-]{0,62})(?<!-)(?:\.[\p{L}\p{N}](?:[\p{L}\p{N}-]{0,62})(?<!-))*$/iu;function Ms(e){return e0.test(e.normalize("NFC"))}function vs(e){return Ld(e)}var t0=/^(?:(?:25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)\.){3}(?:25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)$/;function Fs(e){return t0.test(e)}var r0=/^(?:(?:(?:[0-9a-f]{1,4}:){6}|::(?:[0-9a-f]{1,4}:){5}|(?:[0-9a-f]{1,4})?::(?:[0-9a-f]{1,4}:){4}|(?:(?:[0-9a-f]{1,4}:)?[0-9a-f]{1,4})?::(?:[0-9a-f]{1,4}:){3}|(?:(?:[0-9a-f]{1,4}:){0,2}[0-9a-f]{1,4})?::(?:[0-9a-f]{1,4}:){2}|(?:(?:[0-9a-f]{1,4}:){0,3}[0-9a-f]{1,4})?::[0-9a-f]{1,4}:|(?:(?:[0-9a-f]{1,4}:){0,4}[0-9a-f]{1,4})?::)(?:[0-9a-f]{1,4}:[0-9a-f]{1,4}|(?:(?:25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)\.){3}(?:25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d))|(?:(?:[0-9a-f]{1,4}:){0,5}[0-9a-f]{1,4})?::[0-9a-f]{1,4}|(?:(?:[0-9a-f]{1,4}:){0,6}[0-9a-f]{1,4})?::)$/i;function Ls(e){return r0.test(e)}var n0=/[\x00-\x20\x7F\\]|%(?![0-9a-fA-F]{2})/,o0=/^[a-zA-Z][a-zA-Z0-9+\-.]*\/\//;function Ds(e){return!n0.test(e)&&!o0.test(e)&&URL.canParse(e,"http://example.com")}var i0=/[\x00-\x20<>\^`{|}\\]/,s0=/%(?![0-9a-fA-F]{2})/;function js(e){return i0.test(e)||s0.test(e)?!1:URL.canParse(e)}var a0=/^#(?:\/(?:[a-z0-9_\-.!$&'()*+,;:=@]|%[0-9a-f]{2}|~0|~1)*)*$/i;function Ns(e){return a0.test(e)}var m0=/^(?:\/(?:[^~/]|~0|~1)*)*$/;function qs(e){return m0.test(e)}function _s(e){try{return new RegExp(e,"u"),!0}catch{return!1}}var u0=/^(?:0|[1-9][0-9]*)(?:#|(?:\/(?:[^~/]|~0|~1)*)*)$/;function Us(e){return u0.test(e)}var c0=/^(?:[a-z][a-z0-9+\-.]*:(?:\/\/(?:(?:[-a-z0-9._~!$&'()*+,;=:]|%[0-9a-f]{2})*@)?(?:\[(?:(?:(?:[\da-f]{1,4}:){6}(?:[\da-f]{1,4}:[\da-f]{1,4}|(?:(?:25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)\.){3}(?:25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d))|::(?:[\da-f]{1,4}:){5}(?:[\da-f]{1,4}:[\da-f]{1,4}|(?:(?:25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)\.){3}(?:25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d))|(?:[\da-f]{1,4})?::(?:[\da-f]{1,4}:){4}(?:[\da-f]{1,4}:[\da-f]{1,4}|(?:(?:25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)\.){3}(?:25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d))|(?:(?:[\da-f]{1,4}:){0,1}[\da-f]{1,4})?::(?:[\da-f]{1,4}:){3}(?:[\da-f]{1,4}:[\da-f]{1,4}|(?:(?:25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)\.){3}(?:25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d))|(?:(?:[\da-f]{1,4}:){0,2}[\da-f]{1,4})?::(?:[\da-f]{1,4}:){2}(?:[\da-f]{1,4}:[\da-f]{1,4}|(?:(?:25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)\.){3}(?:25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d))|(?:(?:[\da-f]{1,4}:){0,3}[\da-f]{1,4})?::[\da-f]{1,4}:(?:[\da-f]{1,4}:[\da-f]{1,4}|(?:(?:25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)\.){3}(?:25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d))|(?:(?:[\da-f]{1,4}:){0,4}[\da-f]{1,4})?::(?:[\da-f]{1,4}:[\da-f]{1,4}|(?:(?:25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)\.){3}(?:25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d))|(?:(?:[\da-f]{1,4}:){0,5}[\da-f]{1,4})?::[\da-f]{1,4}|(?:(?:[\da-f]{1,4}:){0,6}[\da-f]{1,4})?::)|v[0-9a-f]+\.[-a-z0-9._~!$&'()*+,;=:]+)\]|(?:(?:25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)\.){3}(?:25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)|(?:[-a-z0-9._~!$&'()*+,;=]|%[0-9a-f]{2})*)(?::\d*)?(?:\/(?:[-a-z0-9._~!$&'()*+,;=:@]|%[0-9a-f]{2})*)*|\/(?:(?:[-a-z0-9._~!$&'()*+,;=:@]|%[0-9a-f]{2})+(?:\/(?:[-a-z0-9._~!$&'()*+,;=:@]|%[0-9a-f]{2})*)*)?|(?:[-a-z0-9._~!$&'()*+,;=:@]|%[0-9a-f]{2})+(?:\/(?:[-a-z0-9._~!$&'()*+,;=:@]|%[0-9a-f]{2})*)*)?|(?:\/\/(?:(?:[-a-z0-9._~!$&'()*+,;=:]|%[0-9a-f]{2})*@)?(?:\[(?:(?:(?:[\da-f]{1,4}:){6}(?:[\da-f]{1,4}:[\da-f]{1,4}|(?:(?:25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)\.){3}(?:25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d))|::(?:[\da-f]{1,4}:){5}(?:[\da-f]{1,4}:[\da-f]{1,4}|(?:(?:25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)\.){3}(?:25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d))|(?:[\da-f]{1,4})?::(?:[\da-f]{1,4}:){4}(?:[\da-f]{1,4}:[\da-f]{1,4}|(?:(?:25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)\.){3}(?:25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d))|(?:(?:[\da-f]{1,4}:){0,1}[\da-f]{1,4})?::(?:[\da-f]{1,4}:){3}(?:[\da-f]{1,4}:[\da-f]{1,4}|(?:(?:25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)\.){3}(?:25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d))|(?:(?:[\da-f]{1,4}:){0,2}[\da-f]{1,4})?::(?:[\da-f]{1,4}:){2}(?:[\da-f]{1,4}:[\da-f]{1,4}|(?:(?:25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)\.){3}(?:25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d))|(?:(?:[\da-f]{1,4}:){0,3}[\da-f]{1,4})?::[\da-f]{1,4}:(?:[\da-f]{1,4}:[\da-f]{1,4}|(?:(?:25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)\.){3}(?:25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d))|(?:(?:[\da-f]{1,4}:){0,4}[\da-f]{1,4})?::(?:[\da-f]{1,4}:[\da-f]{1,4}|(?:(?:25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)\.){3}(?:25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d))|(?:(?:[\da-f]{1,4}:){0,5}[\da-f]{1,4})?::[\da-f]{1,4}|(?:(?:[\da-f]{1,4}:){0,6}[\da-f]{1,4})?::)|v[0-9a-f]+\.[-a-z0-9._~!$&'()*+,;=:]+)\]|(?:(?:25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)\.){3}(?:25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)|(?:[-a-z0-9._~!$&'()*+,;=]|%[0-9a-f]{2})*)(?::\d*)?(?:\/(?:[-a-z0-9._~!$&'()*+,;=:@]|%[0-9a-f]{2})*)*|\/(?:(?:[-a-z0-9._~!$&'()*+,;=:@]|%[0-9a-f]{2})+(?:\/(?:[-a-z0-9._~!$&'()*+,;=:@]|%[0-9a-f]{2})*)*)?|(?:[-a-z0-9._~!$&'()*+,;=@]|%[0-9a-f]{2})+(?:\/(?:[-a-z0-9._~!$&'()*+,;=:@]|%[0-9a-f]{2})*)*)?)(?:\?(?:[-a-z0-9._~!$&'()*+,;=:@/?]|%[0-9a-f]{2})*)?(?:#(?:[-a-z0-9._~!$&'()*+,;=:@/?]|%[0-9a-f]{2})*)?$/i;function Bs(e){return c0.test(e)}var p0=/^(?:(?:[^\x00-\x20"<>%\\^`{|}\x7f]|%[0-9a-f]{2})|\{[+#./;?&=,!@|]?(?:[a-z0-9_]|%[0-9a-f]{2})+(?:\.(?:[a-z0-9_]|%[0-9a-f]{2})+)*(?::[1-9]\d{0,3}|\*)?(?:,(?:[a-z0-9_]|%[0-9a-f]{2})+(?:\.(?:[a-z0-9_]|%[0-9a-f]{2})+)*(?::[1-9]\d{0,3}|\*)?)*\})*$/i;function Gs(e){return p0.test(e)}var f0=/^[a-z][a-z0-9+\-.]*:(?:\/\/(?:(?:[-a-z0-9._~!$&'()*+,;=:]|%[0-9a-f]{2})*@)?(?:\[(?:(?:(?:[\da-f]{1,4}:){6}(?:[\da-f]{1,4}:[\da-f]{1,4}|(?:(?:25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)\.){3}(?:25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d))|::(?:[\da-f]{1,4}:){5}(?:[\da-f]{1,4}:[\da-f]{1,4}|(?:(?:25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)\.){3}(?:25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d))|(?:[\da-f]{1,4})?::(?:[\da-f]{1,4}:){4}(?:[\da-f]{1,4}:[\da-f]{1,4}|(?:(?:25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)\.){3}(?:25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d))|(?:(?:[\da-f]{1,4}:){0,1}[\da-f]{1,4})?::(?:[\da-f]{1,4}:){3}(?:[\da-f]{1,4}:[\da-f]{1,4}|(?:(?:25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)\.){3}(?:25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d))|(?:(?:[\da-f]{1,4}:){0,2}[\da-f]{1,4})?::(?:[\da-f]{1,4}:){2}(?:[\da-f]{1,4}:[\da-f]{1,4}|(?:(?:25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)\.){3}(?:25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d))|(?:(?:[\da-f]{1,4}:){0,3}[\da-f]{1,4})?::[\da-f]{1,4}:(?:[\da-f]{1,4}:[\da-f]{1,4}|(?:(?:25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)\.){3}(?:25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d))|(?:(?:[\da-f]{1,4}:){0,4}[\da-f]{1,4})?::(?:[\da-f]{1,4}:[\da-f]{1,4}|(?:(?:25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)\.){3}(?:25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d))|(?:(?:[\da-f]{1,4}:){0,5}[\da-f]{1,4})?::[\da-f]{1,4}|(?:(?:[\da-f]{1,4}:){0,6}[\da-f]{1,4})?::)|v[0-9a-f]+\.[-a-z0-9._~!$&'()*+,;=:]+)\]|(?:(?:25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)\.){3}(?:25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)|(?:[-a-z0-9._~!$&'()*+,;=]|%[0-9a-f]{2})*)(?::\d*)?(?:\/(?:[-a-z0-9._~!$&'()*+,;=:@]|%[0-9a-f]{2})*)*|\/(?:(?:[-a-z0-9._~!$&'()*+,;=:@]|%[0-9a-f]{2})+(?:\/(?:[-a-z0-9._~!$&'()*+,;=:@]|%[0-9a-f]{2})*)*)?|(?:[-a-z0-9._~!$&'()*+,;=:@]|%[0-9a-f]{2})+(?:\/(?:[-a-z0-9._~!$&'()*+,;=:@]|%[0-9a-f]{2})*)*)?(?:\?(?:[-a-z0-9._~!$&'()*+,;=:@/?]|%[0-9a-f]{2})*)?(?:#(?:[-a-z0-9._~!$&'()*+,;=:@/?]|%[0-9a-f]{2})*)?$/i;function Ks(e){return f0.test(e)}function Hs(e){return URL.canParse(e)}var d0=/^[0-9a-f]{8}-(?:[0-9a-f]{4}-){3}[0-9a-f]{12}$/i;function zs(e){return d0.test(e)}var ge=new Map;function jd(){ge.clear()}function l0(){return[...ge.entries()]}function g0(e,t){ge.set(e,t)}function y0(e){return ge.has(e)}function x0(e){return ge.get(e)}function h0(e,t){return ge.get(e)?.(t)??!0}function Nd(){jd(),ge.set("date-time",$s),ge.set("date",Qn),ge.set("duration",Es),ge.set("email",Ss),ge.set("hostname",Os),ge.set("idn-email",Ms),ge.set("idn-hostname",vs),ge.set("ipv4",Fs),ge.set("ipv6",Ls),ge.set("iri-reference",Ds),ge.set("iri",js),ge.set("json-pointer-uri-fragment",Ns),ge.set("json-pointer",qs),ge.set("regex",_s),ge.set("relative-json-pointer",Us),ge.set("time",Xn),ge.set("uri-reference",Bs),ge.set("uri-template",Gs),ge.set("uri",Ks),ge.set("url",Hs),ge.set("uuid",zs)}Nd();function Ru(e,t,r,n){return ri.Test(r.format,n)}function qd(e,t,r,n,o,i){return Ru(e,t,o,i)||t.AddError("format",r,n,{format:o.format})}function _d(e,t,r,n){let o=hs(r)?r.then:!0,i=cs(r)?r.else:!0;return ee(e,t,r.if,n)?ee(e,t,o,n):ee(e,t,i,n)}function Ud(e,t,r,n,o,i){let a=hs(o)?o.then:!0,m=cs(o)?o.else:!0,c=new it,p=pe(e,c,`${r}/if`,n,o.if,i)?pe(e,c,`${r}/then`,n,a,i)||t.AddError("if",r,n,{failingKeyword:"then"}):pe(e,t,`${r}/else`,n,m,i)||t.AddError("if",r,n,{failingKeyword:"else"});return p&&t.Merge([c]),p}function I0(e,t,r,n){return s.Every(r.items,0,(o,i)=>s.IsLessEqualThan(n.length,i)||jt(e,t,o,n[i])&&t.AddIndex(i))}function b0(e,t,r,n,o,i){return s.EveryAll(o.items,0,(a,m)=>{let c=`${r}/items/${m}`,p=`${n}/${m}`;return s.IsLessEqualThan(i.length,m)||Nt(e,t,c,p,a,i[m])&&t.AddIndex(m)})}function $0(e,t,r,n){let o=Sn(r)?r.prefixItems.length:0;return s.Every(n,o,(i,a)=>jt(e,t,r.items,i)&&t.AddIndex(a))}function E0(e,t,r,n,o,i){let a=Sn(o)?o.prefixItems.length:0;return s.EveryAll(i,a,(m,c)=>{let p=`${r}/items`,f=`${n}/${c}`;return Nt(e,t,p,f,o.items,m)&&t.AddIndex(c)})}function Bd(e,t,r,n){return fs(r)?I0(e,t,r,n):$0(e,t,r,n)}function Gd(e,t,r,n,o,i){return fs(o)?b0(e,t,r,n,o,i):E0(e,t,r,n,o,i)}function S0(e){return Jr(e)}function Pu(e,t,r,n){if(!S0(r))return!0;let o=s.Counted(n,i=>ee(e,t,r.contains,i));return s.IsLessEqualThan(o,r.maxContains)}function Kd(e,t,r,n,o,i){let a=$n(o)?o.minContains:1;return Pu(e,t,o,i)||t.AddError("contains",r,n,{minContains:a,maxContains:o.maxContains})}function Au(e,t,r,n){return s.IsLessEqualThan(n,r.maximum)}function Hd(e,t,r,n,o,i){return Au(e,t,o,i)||t.AddError("maximum",r,n,{comparison:"<=",limit:o.maximum})}function Ou(e,t,r,n){return s.IsLessEqualThan(n.length,r.maxItems)}function zd(e,t,r,n,o,i){return Ou(e,t,o,i)||t.AddError("maxItems",r,n,{limit:o.maxItems})}function Mu(e,t,r,n){return s.IsMaxLength(n,r.maxLength)}function Wd(e,t,r,n,o,i){return Mu(e,t,o,i)||t.AddError("maxLength",r,n,{limit:o.maxLength})}function vu(e,t,r,n){return s.IsLessEqualThan(s.Keys(n).length,r.maxProperties)}function Vd(e,t,r,n,o,i){return vu(e,t,o,i)||t.AddError("maxProperties",r,n,{limit:o.maxProperties})}function k0(e){return Jr(e)}function Fu(e,t,r,n){if(!k0(r))return!0;let o=s.Counted(n,(i,a)=>ee(e,t,r.contains,i)&&t.AddIndex(a));return s.IsGreaterEqualThan(o,r.minContains)}function Jd(e,t,r,n,o,i){return Fu(e,t,o,i)||t.AddError("contains",r,n,{minContains:o.minContains})}function Lu(e,t,r,n){return s.IsGreaterEqualThan(n,r.minimum)}function Yd(e,t,r,n,o,i){return Lu(e,t,o,i)||t.AddError("minimum",r,n,{comparison:">=",limit:o.minimum})}function Du(e,t,r,n){return s.IsGreaterEqualThan(n.length,r.minItems)}function Qd(e,t,r,n,o,i){return Du(e,t,o,i)||t.AddError("minItems",r,n,{limit:o.minItems})}function ju(e,t,r,n){return s.IsMinLength(n,r.minLength)}function Xd(e,t,r,n,o,i){return ju(e,t,o,i)||t.AddError("minLength",r,n,{limit:o.minLength})}function Nu(e,t,r,n){return s.IsGreaterEqualThan(s.Keys(n).length,r.minProperties)}function Zd(e,t,r,n,o,i){return Nu(e,t,o,i)||t.AddError("minProperties",r,n,{limit:o.minProperties})}function qu(e,t,r,n){return s.IsMultipleOf(n,r.multipleOf)}function el(e,t,r,n,o,i){return qu(e,t,o,i)||t.AddError("multipleOf",r,n,{multipleOf:o.multipleOf})}function _u(e,t,r,n){let o=new yt;return!ee(e,o,r.not,n)&&t.Merge([o])}function tl(e,t,r,n,o,i){return _u(e,t,o,i)||t.AddError("not",r,n,{})}function rl(e,t,r,n){let o=r.oneOf.reduce((i,a)=>{let m=new yt;return ee(e,m,a,n)?[...i,m]:i},[]);return s.IsEqual(o.length,1)&&t.Merge(o)}function nl(e,t,r,n,o,i){let a=[],m=[],c=o.oneOf.reduce((f,d,g)=>{let y=new it,I=`${r}/oneOf/${g}`,h=pe(e,y,I,n,d,i);return h&&m.push(g),h||a.push(y),h?[...f,y]:f},[]),p=s.IsEqual(c.length,1)&&t.Merge(c);return!p&&s.IsEqual(m.length,0)&&a.forEach(f=>t.AddErrors(f.GetErrors())),p||t.AddError("oneOf",r,n,{passingSchemas:m})}function Uu(e,t,r,n){return(s.IsString(r.pattern)?Xr(r.pattern):r.pattern).test(n)}function ol(e,t,r,n,o,i){return Uu(e,t,o,i)||t.AddError("pattern",r,n,{pattern:o.pattern})}function il(e,t,r,n){return s.Every(s.Entries(r.patternProperties),0,([o,i])=>{let a=Xr(o);return s.Every(s.Entries(n),0,([m,c])=>!a.test(m)||jt(e,t,i,c)&&t.AddKey(m))})}function sl(e,t,r,n,o,i){return s.EveryAll(s.Entries(o.patternProperties),0,([a,m])=>{let c=`${r}/patternProperties/${Ct(a)}`,p=Xr(a);return s.EveryAll(s.Entries(i),0,([f,d])=>{let g=`${n}/${Ct(f)}`;return!p.test(f)||Nt(e,t,c,g,m,d)&&t.AddKey(f)})})}function al(e,t,r,n){return s.IsEqual(n.length,0)||s.Every(r.prefixItems,0,(o,i)=>s.IsLessEqualThan(n.length,i)||jt(e,t,o,n[i])&&t.AddIndex(i))}function ml(e,t,r,n,o,i){return s.IsEqual(i.length,0)||s.EveryAll(o.prefixItems,0,(a,m)=>{let c=`${r}/prefixItems/${m}`,p=`${n}/${m}`;return s.IsLessEqualThan(i.length,m)||Nt(e,t,c,p,a,i[m])&&t.AddIndex(m)})}function Bu(e,t){return e.includes(t)||De.Get().exactOptionalPropertyTypes}function Gu(e,t){return s.IsUndefined(e[t])}function ul(e,t,r,n){let o=kn(r)?r.required:[];return s.Every(s.Entries(r.properties),0,([a,m])=>{let c=!s.HasPropertyKey(n,a)||jt(e,t,m,n[a])&&t.AddKey(a);return Bu(o,a)?c:Gu(n,a)||c})}function cl(e,t,r,n,o,i){let a=kn(o)?o.required:[];return s.EveryAll(s.Entries(o.properties),0,([c,p])=>{let f=`${r}/properties/${Ct(c)}`,d=`${n}/${Ct(c)}`,g=()=>!s.HasPropertyKey(i,c)||Nt(e,t,f,d,p,i[c])&&t.AddKey(c);return Bu(a,c)?g():Gu(i,c)||g()})}function pl(e,t,r,n){return s.Every(s.Keys(n),0,(o,i)=>ee(e,t,r.propertyNames,o))}function fl(e,t,r,n,o,i){let a=[];return s.EveryAll(s.Keys(i),0,(c,p)=>{let f=`${n}/${Ct(c)}`,d=`${r}/propertyNames`,g=pe(e,t,d,f,o.propertyNames,c);return g||a.push(c),g})||t.AddError("propertyNames",r,n,{propertyNames:a})}function dl(e,t,r,n){let o=Vt.RecursiveRef(e,r)??!1,i=o?{...e,pendingResource:!0}:e;return N(o)&&ee(i,t,o,n)}function ll(e,t,r,n,o,i){let a=Vt.RecursiveRef(e,o)??!1,m=a?{...e,pendingResource:!0}:e;return N(a)&&pe(m,t,r,n,a,i)}function gl(e,t,r,n){let o=Vt.Ref(e,r),i=o.schema??!1,a=new yt,m=N(i)&&ee(o.stack,a,i,n);return m&&t.Merge([a]),m}function yl(e,t,r,n,o,i){let a=Vt.Ref(e,o),m=a.schema??!1,c=new it,p=N(m)&&pe(a.stack,c,r,n,m,i);return p&&t.Merge([c]),p||t.AddErrors(c.GetErrors()),p}function xl(e,t,r,n){return s.Every(r.required,0,o=>s.HasPropertyKey(n,o))}function hl(e,t,r,n,o,i){let a=[];return s.EveryAll(o.required,0,c=>{let p=s.HasPropertyKey(i,c);return p||a.push(c),p})||t.AddError("required",r,n,{requiredProperties:a})}function Ku(e,t,r,n,o){return s.IsEqual(r,"object")?s.IsObjectNotArray(o):s.IsEqual(r,"array")?s.IsArray(o):s.IsEqual(r,"boolean")?s.IsBoolean(o):s.IsEqual(r,"integer")?s.IsInteger(o):s.IsEqual(r,"number")?s.IsNumber(o):s.IsEqual(r,"null")?s.IsNull(o):s.IsEqual(r,"string")?s.IsString(o):s.IsEqual(r,"bigint")?s.IsBigInt(o):s.IsEqual(r,"constructor")?s.IsConstructor(o):s.IsEqual(r,"function")?s.IsFunction(o):s.IsEqual(r,"symbol")?s.IsSymbol(o):s.IsEqual(r,"undefined")?s.IsUndefined(o):s.IsEqual(r,"void")?s.IsUndefined(o):!0}function Il(e,t,r,n,o){return s.Some(r,i=>Ku(e,t,i,n,o))}function bl(e,t,r,n){return s.IsArray(r.type)?Il(e,t,r.type,r,n):Ku(e,t,r.type,r,n)}function $l(e,t,r,n,o,i){return(s.IsArray(o.type)?Il(e,t,o.type,o,i):Ku(e,t,o.type,o,i))||t.AddError("type",r,n,{type:o.type})}function El(e,t,r,n){let o=t.GetIndices();return s.Every(n,0,(i,a)=>(o.has(a)||ee(e,t,r.unevaluatedItems,i))&&t.AddIndex(a))}function Sl(e,t,r,n,o,i){let a=t.GetIndices(),m=[];return s.EveryAll(i,0,(p,f)=>{let d=new it,g=(a.has(f)||pe(e,d,r,n,o.unevaluatedItems,p))&&t.AddIndex(f);return g||m.push(f),g})||t.AddError("unevaluatedItems",r,n,{unevaluatedItems:m})}function kl(e,t,r,n){let o=t.GetKeys();return s.Every(s.Entries(n),0,([i,a])=>o.has(i)||ee(e,t,r.unevaluatedProperties,a)&&t.AddKey(i))}function Tl(e,t,r,n,o,i){let a=t.GetKeys(),m=[];return s.EveryAll(s.Entries(i),0,([p,f])=>{let d=new it,g=a.has(p)||pe(e,d,r,n,o.unevaluatedProperties,f)&&t.AddKey(p);return g||m.push(p),g})||t.AddError("unevaluatedProperties",r,n,{unevaluatedProperties:m})}var Lr={};Dt(Lr,{Hash:()=>Ol,HashCode:()=>q0});function Se(){throw new Error("Unreachable")}function T0(e){let t=new Set,r=e;for(;r&&r!==Object.prototype;){for(let n of Reflect.ownKeys(r))n!=="constructor"&&typeof n!="symbol"&&t.add(n);r=Object.getPrototypeOf(r)}return[...t]}function w0(e){return typeof e=="number"}var Pt={Array:0,BigInt:1,Boolean:2,Date:3,Constructor:4,Function:5,Null:6,Number:7,Object:8,RegExp:9,String:10,Symbol:11,TypeArray:12,Undefined:13},Vs=8997,ni=33826,Js=40164,Ys=52210,Rl=new Float64Array(1),Pl=new DataView(Rl.buffer),Al=new Uint8Array(Rl.buffer);function Ve(e){let t=Vs^e,r=t*435,n=ni*435+(r>>>16),o=Js*435+(n>>>16)+(t<<8),i=Ys*435+(o>>>16)+(ni<<8);Vs=r&65535,ni=n&65535,Js=o&65535,Ys=i&65535}function C0(e){Ve(Pt.Array);for(let t of e)Zr(t)}function R0(e){Ve(Pt.BigInt),Pl.setBigInt64(0,e);for(let t of Al)Ve(t)}function wl(e){Ve(Pt.Boolean),Ve(e?1:0)}function P0(e){Ve(Pt.Constructor),Zr(e.toString())}function A0(e){Ve(Pt.Date),Zr(e.getTime())}function O0(e){Ve(Pt.Function),Zr(e.toString())}function M0(e){Ve(Pt.Null)}function Cl(e){Ve(Pt.Number),Pl.setFloat64(0,e,!0);for(let t of Al)Ve(t)}function v0(e){Ve(Pt.Object);for(let t of T0(e).sort())Zr(t),Zr(e[t])}function F0(e){Ve(Pt.RegExp),Hu(e.toString())}var L0=new TextEncoder;function Hu(e){Ve(Pt.String);for(let t=0;t<e.length;t++){let r=e.charCodeAt(t);if(r>127){for(let n of L0.encode(e.slice(t)))Ve(n);return}Ve(r)}}function D0(e){Ve(Pt.Symbol),Zr(e.toString())}function j0(e){Ve(Pt.TypeArray);let t=new Uint8Array(e.buffer);for(let r=0;r<t.length;r++)Ve(t[r])}function N0(e){return Ve(Pt.Undefined)}function Zr(e){return Ue.IsTypeArray(e)?j0(e):Ue.IsDate(e)?A0(e):Ue.IsRegExp(e)?F0(e):Ue.IsBoolean(e)?wl(e.valueOf()):Ue.IsString(e)?Hu(e.valueOf()):Ue.IsNumber(e)?Cl(e.valueOf()):w0(e)?Cl(e):s.IsArray(e)?C0(e):s.IsBoolean(e)?wl(e):s.IsBigInt(e)?R0(e):s.IsConstructor(e)?P0(e):s.IsNull(e)?M0(e):s.IsObject(e)?v0(e):s.IsString(e)?Hu(e):s.IsSymbol(e)?D0(e):s.IsUndefined(e)?N0(e):s.IsFunction(e)?O0(e):Se()}function Ws(e){return e.toString(16).padStart(4,"0")}function q0(e){return BigInt(`0x${Ol(e)}`)}function Ol(e){return Vs=8997,ni=33826,Js=40164,Ys=52210,Zr(e),`${Ws(Ys)}${Ws(Js)}${Ws(ni)}${Ws(Vs)}`}function Ml(e){return!s.IsEqual(e.uniqueItems,!1)}function vl(e,t,r,n){if(!Ml(r))return!0;let o=new Set(n.map(Lr.Hash)).size,i=n.length;return s.IsEqual(o,i)}function Fl(e,t,r,n,o,i){if(!Ml(o))return!0;let a=new Set,m=i.reduce((p,f,d)=>{let g=Lr.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 jt(e,t,r,n){return t.Push()&&ee(e,t,r,n)&&t.Pop()}function ee(e,t,r,n){let o=Jn(e,r);return In(r)?cu(o,t,r,n):(!su(r)||bl(o,t,r,n))&&(!(s.IsObject(n)&&!s.IsArray(n))||(!kn(r)||xl(o,t,r,n))&&(!Wt(r)||jf(o,t,r,n))&&(!Qm(r)||zf(o,t,r,n))&&(!Xm(r)||Vf(o,t,r,n))&&(!ms(r)||Yf(o,t,r,n))&&(!Hn(r)||il(o,t,r,n))&&(!zn(r)||ul(o,t,r,n))&&(!gs(r)||pl(o,t,r,n))&&(!Ko(r)||Nu(o,t,r,n))&&(!ou(r)||vu(o,t,r,n)))&&(!s.IsArray(n)||(!is(r)||Ff(o,t,r,n))&&(!Jr(r)||fu(o,t,r,n))&&(!bn(r)||Bd(o,t,r,n))&&(!$n(r)||Fu(o,t,r,n))&&(!ru(r)||Pu(o,t,r,n))&&(!En(r)||Du(o,t,r,n))&&(!Bo(r)||Ou(o,t,r,n))&&(!Sn(r)||al(o,t,r,n))&&(!Qr(r)||vl(o,t,r,n)))&&(!s.IsString(n)||(!Go(r)||ju(o,t,r,n))&&(!nu(r)||Mu(o,t,r,n))&&(!Uo(r)||Ru(o,t,r,n))&&(!Ho(r)||Uu(o,t,r,n)))&&(!(s.IsNumber(n)||s.IsBigInt(n))||(!Mr(r)||Eu(o,t,r,n))&&(!eu(r)||$u(o,t,r,n))&&(!vr(r)||Lu(o,t,r,n))&&(!tu(r)||Au(o,t,r,n))&&(!iu(r)||qu(o,t,r,n)))&&(!xs(r)||gl(o,t,r,n))&&(!ys(r)||dl(o,t,r,n))&&(!us(r)||sd(o,t,r,n))&&(!Ym(r)||pu(o,t,r,n))&&(!Zm(r)||bu(o,t,r,n))&&(!ps(r)||_d(o,t,r,n))&&(!ds(r)||_u(o,t,r,n))&&(!ss(r)||qf(o,t,r,n))&&(!as(r)||Uf(o,t,r,n))&&(!ls(r)||rl(o,t,r,n))&&(!Wo(r)||!s.IsArray(n)||El(o,t,r,n))&&(!Vo(r)||!s.IsObject(n)||kl(o,t,r,n))&&(!os(r)||Cf(o,t,r,n))}function Nt(e,t,r,n,o,i){return t.Push()&&pe(e,t,r,n,o,i)&&t.Pop()}function pe(e,t,r,n,o,i){if(t.AtCapacity())return!1;let a=Jn(e,o);return In(o)?Gf(a,t,r,n,o,i):!!(+(!su(o)||$l(a,t,r,n,o,i))&+(!(s.IsObject(i)&&!s.IsArray(i))||!!(+(!kn(o)||hl(a,t,r,n,o,i))&+(!Wt(o)||Nf(a,t,r,n,o,i))&+(!Qm(o)||Wf(a,t,r,n,o,i))&+(!Xm(o)||Jf(a,t,r,n,o,i))&+(!ms(o)||Qf(a,t,r,n,o,i))&+(!Hn(o)||sl(a,t,r,n,o,i))&+(!zn(o)||cl(a,t,r,n,o,i))&+(!gs(o)||fl(a,t,r,n,o,i))&+(!Ko(o)||Zd(a,t,r,n,o,i))&+(!ou(o)||Vd(a,t,r,n,o,i))))&+(!s.IsArray(i)||!!(+(!is(o)||Lf(a,t,r,n,o,i))&+(!Jr(o)||Hf(a,t,r,n,o,i))&+(!bn(o)||Gd(a,t,r,n,o,i))&+(!$n(o)||Jd(a,t,r,n,o,i))&+(!ru(o)||Kd(a,t,r,n,o,i))&+(!En(o)||Qd(a,t,r,n,o,i))&+(!Bo(o)||zd(a,t,r,n,o,i))&+(!Sn(o)||ml(a,t,r,n,o,i))&+(!Qr(o)||Fl(a,t,r,n,o,i))))&+(!s.IsString(i)||!!(+(!Go(o)||Xd(a,t,r,n,o,i))&+(!nu(o)||Wd(a,t,r,n,o,i))&+(!Uo(o)||qd(a,t,r,n,o,i))&+(!Ho(o)||ol(a,t,r,n,o,i))))&+(!(s.IsNumber(i)||s.IsBigInt(i))||!!(+(!Mr(o)||cd(a,t,r,n,o,i))&+(!eu(o)||ud(a,t,r,n,o,i))&+(!vr(o)||Yd(a,t,r,n,o,i))&+(!tu(o)||Hd(a,t,r,n,o,i))&+(!iu(o)||el(a,t,r,n,o,i))))&+(!xs(o)||yl(a,t,r,n,o,i))&+(!ys(o)||ll(a,t,r,n,o,i))&+(!us(o)||ad(a,t,r,n,o,i))&+(!Ym(o)||Kf(a,t,r,n,o,i))&+(!Zm(o)||md(a,t,r,n,o,i))&+(!ps(o)||Ud(a,t,r,n,o,i))&+(!ds(o)||tl(a,t,r,n,o,i))&+(!ss(o)||_f(a,t,r,n,o,i))&+(!as(o)||Bf(a,t,r,n,o,i))&+(!ls(o)||nl(a,t,r,n,o,i))&+(!Wo(o)||!s.IsArray(i)||Sl(a,t,r,n,o,i))&+(!Vo(o)||!s.IsObject(i)||Tl(a,t,r,n,o,i)))&&(!os(o)||Rf(a,t,r,n,o,i))}function Dl(e){switch(e.keyword){case"additionalProperties":return"must not have additional properties";case"anyOf":return"must match a schema in anyOf";case"boolean":return"schema is false";case"const":return"must be equal to constant";case"contains":return"must contain at least 1 valid item";case"dependencies":return`must have properties ${e.params.dependencies.join(", ")} when property ${e.params.property} is present`;case"dependentRequired":return`must have properties ${e.params.dependencies.join(", ")} when property ${e.params.property} is present`;case"enum":return"must be equal to one of the allowed values";case"exclusiveMaximum":return`must be ${e.params.comparison} ${e.params.limit}`;case"exclusiveMinimum":return`must be ${e.params.comparison} ${e.params.limit}`;case"format":return`must match format "${e.params.format}"`;case"if":return`must match "${e.params.failingKeyword}" schema`;case"maxItems":return`must not have more than ${e.params.limit} items`;case"maxLength":return`must not have more than ${e.params.limit} characters`;case"maxProperties":return`must not have more than ${e.params.limit} properties`;case"maximum":return`must be ${e.params.comparison} ${e.params.limit}`;case"minItems":return`must not have fewer than ${e.params.limit} items`;case"minLength":return`must not have fewer than ${e.params.limit} characters`;case"minProperties":return`must not have fewer than ${e.params.limit} properties`;case"minimum":return`must be ${e.params.comparison} ${e.params.limit}`;case"multipleOf":return`must be multiple of ${e.params.multipleOf}`;case"not":return"must not be valid";case"oneOf":return"must match exactly one schema in oneOf";case"pattern":return`must match pattern "${e.params.pattern}"`;case"propertyNames":return`property names ${e.params.propertyNames.join(", ")} are invalid`;case"required":return`must have required properties ${e.params.requiredProperties.join(", ")}`;case"type":return typeof e.params.type=="string"?`must be ${e.params.type}`:`must be either ${e.params.type.join(" or ")}`;case"unevaluatedItems":return"must not have unevaluated items";case"unevaluatedProperties":return"must not have unevaluated properties";case"uniqueItems":return"must not have duplicate items";case"~refine":return e.params.message;default:return"an unknown validation error occurred"}}var _0=Dl;function jl(){return _0}var l={};Dt(l,{Assign:()=>B0,Clone:()=>G0,Create:()=>H0,Discard:()=>z0,Metrics:()=>nr,Update:()=>Y0});var nr={assign:0,create:0,clone:0,discard:0,update:0};function qt(e){return[...s.Keys(e),...s.Symbols(e)]}function Nl(e,t){if(!t.has(e)){t.add(e);for(let r of qt(e)){let n=Object.getOwnPropertyDescriptor(e,r);!n||!("value"in n)||s.IsObject(n.value)&&Nl(n.value,t)}Object.freeze(e)}}function en(e){return De.Get().immutableTypes&&Nl(e,new WeakSet),e}function B0(e,t){nr.assign+=1;let r={},n=qt(t),o=qt(e);for(let i of o)n.includes(i)||Object.defineProperty(r,i,Object.getOwnPropertyDescriptor(e,i));for(let i of n)Object.defineProperty(r,i,Object.getOwnPropertyDescriptor(t,i));return en(r)}function G0(e){nr.clone+=1;let t={};for(let r of qt(e)){if(s.IsUnsafePropertyKey(r))continue;let n=Object.getOwnPropertyDescriptor(e,r);s.IsEqual(n.enumerable,!0)?t[r]=n.value:Object.defineProperty(t,r,n)}return t}function ql(e,t){return{...e,...t}}function K0(e,t){for(let r of Object.keys(t))Object.defineProperty(e,r,{configurable:!0,writable:!0,enumerable:!1,value:t[r]});return e}function H0(e,t,r={}){nr.create+=1;let n=ql(t,r),o=De.Get().enumerableKind?ql(n,e):K0(n,e);return en(o)}function z0(e,t){nr.discard+=1;let r={};for(let n of qt(e)){if(t.includes(n))continue;let o=Object.getOwnPropertyDescriptor(e,n);Object.defineProperty(r,n,o)}return en(r)}function W0(e,t,r,n){for(let o of qt(e)){if(s.IsUnsafePropertyKey(o)||t.includes(o)||r.includes(o))continue;let i=Object.getOwnPropertyDescriptor(e,o);Object.defineProperty(n,o,i)}}function V0(e,t,r){let n=De.Get().enumerableKind;for(let o of t)s.IsUnsafePropertyKey(o)||Object.defineProperty(r,o,{configurable:!0,writable:!0,enumerable:n,value:e[o]})}function J0(e,t,r){for(let n of t)s.IsUnsafePropertyKey(n)||Object.defineProperty(r,n,{configurable:!0,enumerable:!0,writable:!0,value:e[n]})}function Y0(e,t,r){nr.update+=1;let n={},o=qt(t),i=qt(r);return W0(e,o,i,n),V0(t,o,n),J0(r,i,n),en(n)}function Qs(...e){let[t,r,n]=H.Match(e,{3:(f,d,g)=>[f,d,g],2:(f,d)=>[{},f,d]}),o=Vn(t,r),i=new it,a=pe(o,i,"#","",r,n),m=i.GetErrors(),c=jl(),p=m.map(f=>({...f,message:c(f)}));return[a,p]}var Ul=0;function Xs(){let e=ns();Ul=e.maxErrors,e.maxErrors=e.maxParseErrors}function Zs(){let e=ns();e.maxErrors=Ul}function Wu(...e){let[t,r,n]=H.Match(e,{3:(a,m,c)=>[a,m,c],2:(a,m)=>[{},a,m]}),o=Vn(t,r),i=new yt;return ee(o,i,r,n)}function W(...e){let[t,r,n]=H.Match(e,{3:(o,i,a)=>[o,i,a],2:(o,i)=>[{},o,i]});return Wu(t,r,n)}function or(...e){let[t,r,n]=H.Match(e,{3:(a,m,c)=>[a,m,c],2:(a,m)=>[{},a,m]}),[o,i]=Qs(t,r,n);return i}var Dr=class extends Error{constructor(t,r,n){super(t),Object.defineProperty(this,"cause",{value:{source:t,errors:n,value:r},writable:!1,configurable:!1,enumerable:!1})}};function ea(...e){let[t,r,n]=H.Match(e,{3:(i,a,m)=>[i,a,m],2:(i,a)=>[{},i,a]});if(!W(t,r,n))throw new Dr("Assert",n,or(t,r,n))}function C(e,t){return s.IsObject(e)&&s.HasPropertyKey(e,"~kind")&&s.IsEqual(e["~kind"],t)}function xe(e){return s.IsObject(e)}function P(e,t,r){return l.Create({"~kind":"Deferred"},{type:"deferred",action:e,parameters:t,options:r},{})}function tn(e){return C(e,"Deferred")}function gr(e,t){return l.Update(e,{"~readonly":!0},t)}function Bl(e,t,r,n){let o=$(e,t,r);return gr(o,n)}function yr(e,t){return l.Update(e,{"~optional":!0},t)}function Gl(e,t,r,n){let o=$(e,t,r);return yr(o,n)}function Et(e,t){return l.Create({"~kind":"Array"},{type:"array",items:e},t)}function Y(e){return C(e,"Array")}function eo(e){return l.Discard(e,["~kind","type","items"])}function xr(e,t,r={}){return l.Create({"~kind":"Constructor"},{type:"constructor",parameters:e,instanceType:t},r)}function ke(e){return C(e,"Constructor")}function Kl(e){return l.Discard(e,["~kind","type","parameters","instanceType"])}function hr(e,t,r={}){return l.Create({"~kind":"Function"},{type:"function",parameters:e,returnType:t},r)}function Te(e){return C(e,"Function")}function Hl(e){return l.Discard(e,["~kind","type","parameters","returnType"])}function ze(e,t){return l.Create({"~kind":"Ref"},{$ref:e},t)}function ne(e){return C(e,"Ref")}function rn(e,t){return l.Create({"~kind":"Generic"},{type:"generic",parameters:e,expression:t})}function to(e){return C(e,"Generic")}function ro(e){return l.Create({"~kind":"Any"},{},e)}function $e(e){return C(e,"Any")}var zl="(?!)";function se(e){return l.Create({"~kind":"Never"},{not:{}},e)}function St(e){return C(e,"Never")}function Ir(e,t={}){return P("AddOptional",[e],t)}function ta(e,t={}){return yr(e,t)}function Wl(e){return ta(e)}function je(e){return xe(e)&&s.HasPropertyKey(e,"~optional")}function Vl(e){return s.Keys(e).filter(t=>!je(e[t]))}function ra(e){return s.Keys(e)}function na(e){return s.Values(e)}function L(e,t={}){let r=Vl(e),n=r.length>0?{required:r}:{};return l.Create({"~kind":"Object"},{type:"object",...n,properties:e},t)}function v(e){return C(e,"Object")}function Jl(e){return l.Discard(e,["~kind","type","properties","required"])}function Be(e){return l.Create({"~kind":"Unknown"},{},e)}function Ne(e){return C(e,"Unknown")}function br(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 ue(e){return C(e,"Cyclic")}function Yl(e){return l.Update(e,{"~unsafe":null},{})}function oa(e){return s.IsObjectNotArray(e)&&s.HasPropertyKey(e,"~unsafe")&&s.IsNull(e["~unsafe"])}function oi(...e){let[t,r]=H.Match(e,{2:(n,o)=>[n,o,o],1:n=>[n,Be(),Be()]});return l.Create({"~kind":"Infer"},{type:"infer",name:t,extends:r},{})}function qe(e){return C(e,"Infer")}function wn(e,t,r,n={}){return l.Create({"~kind":"Dependent"},{if:e,then:t,else:r},n)}function we(e){return C(e,"Dependent")}function Ql(e){return l.Discard(e,["~kind","if","then","else"])}function Xl(e){return s.IsObjectNotArray(e)}function Zl(e){return s.Keys(e).filter(r=>isNaN(r)).reduce((r,n)=>[...r,e[n]],[])}function eg(e){return s.IsString(e)||s.IsNumber(e)}function tg(e,t){let r=Xl(e)?Zl(e):e;return l.Create({"~kind":"Enum"},{enum:r},t)}function Ce(e){return C(e,"Enum")}function ut(e,t={}){return l.Create({"~kind":"Intersect"},{allOf:e},t)}function F(e){return C(e,"Intersect")}function rg(e){return l.Discard(e,["~kind","allOf"])}var ii=class{constructor(t,r){this.type=t,this.decode=r}Encode(t){let r=this.type,n=xt(r)?a=>this.decode(r["~codec"].decode(a)):this.decode,o=xt(r)?a=>r["~codec"].encode(t(a)):t,i={decode:n,encode:o};return l.Update(this.type,{"~codec":i},{})}},si=class{constructor(t){this.type=t}Decode(t){return new ii(this.type,t)}};function ia(e){return new si(e)}function ng(e,t){return ia(e).Decode(t).Encode(()=>{throw Error("Encode not implemented")})}function og(e,t){return ia(e).Decode(()=>{throw Error("Decode not implemented")}).Encode(t)}function xt(e){return xe(e)&&s.HasPropertyKey(e,"~codec")&&s.IsObject(e["~codec"])&&s.HasPropertyKey(e["~codec"],"encode")&&s.HasPropertyKey(e["~codec"],"decode")}function ig(e){return no(e)}function Cn(e){return xe(e)&&s.HasPropertyKey(e,"~immutable")}function $r(e,t={}){return P("AddReadonly",[e],t)}function sa(e,t={}){return gr(e,t)}function sg(e){return sa(e)}function jr(e){return xe(e)&&s.HasPropertyKey(e,"~readonly")}function Z0(e,t){let r=ai(e)?[...e["~refine"],t]:[t];return l.Update(e,{"~refine":r},{})}function ag(...e){let[t,r,n]=H.Match(e,{3:(o,i,a)=>[o,i,a],2:(o,i)=>[o,i,()=>"Refine Error"]});return Z0(t,{check:r,error:n})}function eP(e){return s.IsObjectNotArray(e)&&s.HasPropertyKey(e,"check")&&s.HasPropertyKey(e,"error")&&s.IsFunction(e.check)&&s.IsFunction(e.error)}function ai(e){return xe(e)&&s.HasPropertyKey(e,"~refine")&&s.IsArray(e["~refine"])&&s.Every(e["~refine"],0,t=>eP(t))}var mg="-?(?:0|[1-9][0-9]*)n";function mi(e){return l.Create({"~kind":"BigInt"},{type:"bigint"},e)}function At(e){return C(e,"BigInt")}function aa(e){return l.Create({"~kind":"Boolean"},{type:"boolean"},e)}function ht(e){return C(e,"Boolean")}function ui(e){return l.Create({"~kind":"Identifier"},{name:e})}function ug(e){return C(e,"Identifier")}var ma="-?(?:0|[1-9][0-9]*)";function Rn(e){return l.Create({"~kind":"Integer"},{type:"integer"},e)}function Je(e){return C(e,"Integer")}var Vu=class extends Error{constructor(t){super("Invalid Literal value"),Object.defineProperty(this,"cause",{value:{value:t},writable:!1,configurable:!1,enumerable:!1})}};function tP(e){return s.IsBigInt(e)?"bigint":s.IsBoolean(e)?"boolean":s.IsNumber(e)?"number":s.IsString(e)?"string":(()=>{throw new Vu(e)})()}function z(e,t){return l.Create({"~kind":"Literal"},{type:tP(e),const:e},t)}function ua(e){return s.IsBigInt(e)||s.IsBoolean(e)||s.IsNumber(e)||s.IsString(e)}function cg(e){return V(e)&&s.IsBigInt(e.const)}function pg(e){return V(e)&&s.IsBoolean(e.const)}function ca(e){return V(e)&&s.IsNumber(e.const)}function pa(e){return V(e)&&s.IsString(e.const)}function V(e){return C(e,"Literal")}function oo(e){return l.Create({"~kind":"Null"},{type:"null"},e)}function Er(e){return C(e,"Null")}var fa="-?(?:0|[1-9][0-9]*)(?:\\.[0-9]+)?";function Ot(e){return l.Create({"~kind":"Number"},{type:"number"},e)}function he(e){return C(e,"Number")}function io(e){return l.Create({"~kind":"Symbol"},{type:"symbol"},e)}function Sr(e){return C(e,"Symbol")}function Pn(...e){let[t,r,n]=H.Match(e,{3:(o,i,a)=>[o,i,a],2:(o,i)=>[o,i,i],1:o=>[o,Be(),Be()]});return l.Create({"~kind":"Parameter"},{name:t,extends:r,equals:n},{})}function fg(e){return C(e,"Parameter")}var da=".*";function st(e){return l.Create({"~kind":"String"},{type:"string"},e)}function Ge(e){return C(e,"String")}function q(e,t={}){return l.Create({"~kind":"Union"},{anyOf:e},t)}function E(e){return C(e,"Union")}function dg(e){return l.Discard(e,["~kind","anyOf"])}function ci(e){let t=lg(e);return s.IsEqual(t.length,2)?t[0]:[]}function rP(e){return!0}function gg(e){return s.ShiftLeft(e,(t,r)=>nP(t)?gg(r):!1,()=>!0)}function yg(e){return s.IsEqual(e.length,0)?!1:gg(e)}function nP(e){return E(e)?yg(e.anyOf):V(e)?rP(e.const):!1}function la(e){return yg(e)}function ga(e){return l.Create({"~kind":"TemplateLiteral"},{type:"string",pattern:e},{})}function xg(e,t,r=[]){return s.ShiftLeft(e,(n,o)=>xg(o,t,[...r,`${n}${t}`]),()=>r)}function oP(e,t){return s.IsEqual(e.length,0)?[`${t}`]:xg(e,t)}function hg(e,t,r=[]){return s.ShiftLeft(t,(n,o)=>hg(e,o,[...r,...Ig(e,n)]),()=>r)}function Ig(e,t){return E(t)?hg(e,t.anyOf):V(t)?oP(e,t.const):Se()}function bg(e,t){return s.ShiftLeft(t,(r,n)=>bg(Ig(e,r),n),()=>e)}function iP(e){return e.map(t=>z(t))}function sP(e){let t=bg([],e),r=iP(t);return q(r)}function aP(e){return s.IsEqual(e.length,0)?Se():s.IsEqual(e.length,1)&&V(e[0])?e[0]:sP(e)}function Ju(e){let t=ci(e);return s.IsEqual(t.length,0)?st():la(t)?aP(t):ga(e)}function so(e){let t=Ju(e);return ce(t)?st():t}function kt(e,t){let r="object",n={[e]:t};return l.Create({"~kind":"Record"},{type:r,patternProperties:n})}function $g(e){return kt(ir,e)}function Eg(e){return L({true:e,false:e})}function Re(e,t={}){let[r,n,o]=[e,e.length,!1];return l.Create({"~kind":"Tuple"},{type:"array",additionalItems:o,items:r,minItems:n},t)}function G(e){return C(e,"Tuple")}function Sg(e){return l.Discard(e,["~kind","type","items","minItems","additionalItems"])}function Yu(e){return e.reduceRight((r,n,o)=>({[o]:n,...r}),{})}function kg(e){let t=Yu(e.items);return L(t)}function mP(e){return l.Discard(e,["~optional"])}function An(e,t){return l.Update(mP(e),{},t)}function Tg(e,t,r,n){let o=$(e,t,r);return An(o,n)}function uP(e){return l.Discard(e,["~readonly"])}function ao(e,t){return l.Update(uP(e),{},t)}function wg(e,t,r,n){let o=$(e,t,r);return ao(o,n)}function ya(e,t){let r=jr(e)&&jr(t),n=je(e)&&je(t),o=Pe([e,t]),i=ao(An(o,{}),{});return r&&n?gr(yr(i,{}),{}):r?gr(i,{}):n?yr(i,{}):i}function Cg(e,t){let r=jr(e)||jr(t),n=je(e)||je(t),o=ao(An(e,{}),{}),i=ao(An(t,{}),{}),a=Tt([o,i]);return r&&n?gr(yr(a,{}),{}):r?gr(a,{}):n?yr(a,{}):a}function cP(e,t,r){return r in e?r in t?ya(e[r],t[r]):e[r]:r in t?t[r]:se()}function pP(e,t){return[...new Set([...s.Keys(e),...s.Keys(t)])].reduce((o,i)=>({...o,[i]:cP(e,t,i)}),{})}function Rg(e){return v(e)?e.properties:G(e)?Yu(e.items):{}}function Pg(e,t){let r=Rg(e),n=Rg(t),o=pP(r,n);return L(o)}function fP(e,t){let r=mo(e,t);return s.IsEqual(r,fi)?e:s.IsEqual(r,di)||s.IsEqual(r,pi)?t:se()}function Ag(e){return v(e)||G(e)}function dP(e,t){let r=Ag(e),n=Ag(t);return r&&n?Pg(e,t):r&&!n?e:!r&&n?t:fP(e,t)}function Og(e,t){return St(e)||$e(e)?e:Ne(e)||St(t)||$e(t)?t:Ne(t)?e:dP(e,t)}function lP(e,t){return E(e)||E(t)}function gP(e,t){let r=Jt(e),n=Jt(t);return lP(r,n)?Pe([r,n]):Og(r,n)}function Mg(e,t,r=[]){return s.ShiftLeft(t,(n,o)=>Mg(e,o,[...r,gP(n,e)]),()=>s.IsEqual(r.length,0)?[e]:r)}function vg(e,t,r=[]){return s.ShiftLeft(e,(n,o)=>vg(o,t,[...r,...li([n],t)]),()=>r)}function li(e,t=[]){return s.ShiftLeft(e,(r,n)=>E(r)?li(n,vg(r.anyOf,t)):li(n,Mg(r,t)),()=>t)}function yP(e,t){let r=at({},e,t);return j.IsExtendsTrueLike(r)?[]:[e]}function Fg(e,t,r=[]){return s.ShiftLeft(e,(n,o)=>Fg(o,t,[...r,...yP(n,t)]),()=>r)}function xa(e,t){let r=Jt(e),n=E(r)?r.anyOf:[r],o=Fg(n,t);return Tt(o)}function sr(e,t,r){let n=Pe([e,t]),o=xa(r,e);return Tt([n,o])}function It(e,t=[]){return s.ShiftLeft(e,(r,n)=>It(n,[...t,z(r)]),()=>Tt(t))}function Pe(e){let t=li(e),r=Qu(t);return Tt(r)}function ct(e){let t=so(e);return Jt(t)}function Tt(e){let t=Qu(e);return nn(t)}function Jt(e){return we(e)?sr(e.if,e.then,e.else):Ce(e)?It(e.enum):F(e)?Pe(e.allOf):ce(e)?ct(e.pattern):E(e)?Tt(e.anyOf):e}function nn(e){return s.IsEqual(e.length,1)?e[0]:s.IsEqual(e.length,0)?se():q(e)}function Lg(e,t){let r=It(e);return on(r,t)}function Dg(e,t){return kt(sn,t)}function jg(e,t){let r=Pe(e);return on(r,t)}function Ng(e,t){return s.IsString(e)||s.IsNumber(e)?L({[e]:t}):s.IsEqual(e,!1)?L({false:t}):s.IsEqual(e,!0)?L({true:t}):L({})}function qg(e,t){return kt(uo,t)}function _g(e,t){return s.HasPropertyKey(e,"pattern")&&(s.IsString(e.pattern)||e.pattern instanceof RegExp)?kt(e.pattern.toString(),t):kt(ir,t)}function Ug(e,t){let r=ci(e);return la(r)?on(ct(e),t):kt(e,t)}function xP(e){return E(e)?an(e.anyOf):[e]}function an(e,t=[]){return s.ShiftLeft(e,(r,n)=>an(n,[...t,...xP(r)]),()=>t)}function hP(e){return e.some(t=>Ge(t)||he(t)||Je(t))}function IP(e,t){return s.IsEqual(hP(e),!0)?kt(ir,t):void 0}function bP(e,t){return e.reduce((r,n)=>V(n)&&(s.IsString(n.const)||s.IsNumber(n.const))?{...r,[n.const]:t}:r,{})}function $P(e,t){let r=bP(e,t);return L(r)}function Bg(e,t){let r=an(e),n=IP(r,t);return xe(n)?n:$P(r,t)}function on(e,t){return $e(e)?$g(t):ht(e)?Eg(t):Ce(e)?Lg(e.enum,t):Je(e)?Dg(e,t):F(e)?jg(e.allOf,t):V(e)?Ng(e.const,t):he(e)?qg(e,t):E(e)?Bg(e.anyOf,t):Ge(e)?_g(e,t):ce(e)?Ug(e.pattern,t):L({})}function Xu(e,t,r){return K([e])?l.Update(on(e,t),{},r):ha(e,t,r)}function Gg(e,t,r,n,o){let i=$(e,t,r),a=$(e,t,n);return Xu(i,a,o)}var sn=`^${ma}$`,uo=`^${fa}$`,ir=`^${da}$`;function ha(e,t,r={}){return P("Record",[e,t],r)}function co(e,t,r={}){return Xu(e,t,r)}function Kg(e,t){return kt(e,t)}function Ia(e){return s.IsEqual(e,ir)?st():s.IsEqual(e,sn)?Rn():s.IsEqual(e,uo)?Ot():Ju(e)}function _e(e){return s.Keys(e.patternProperties)[0]}function po(e){let t=_e(e);return Ia(t)}function fe(e){return e.patternProperties[_e(e)]}function ie(e){return C(e,"Record")}function On(e){return l.Create({"~kind":"Rest"},{type:"rest",items:e},{})}function mn(e){return C(e,"Rest")}function ba(e){return l.Create({"~kind":"This"},{$ref:"#"},e)}function $a(e){return C(e,"This")}function fo(e){return l.Create({"~kind":"Undefined"},{type:"undefined"},e)}function Yt(e){return C(e,"Undefined")}function Ea(e){return l.Create({"~kind":"Void"},{type:"void"},e)}function Mt(e){return C(e,"Void")}function SP(e,t){return s.IsEqual(e,"Array")?Et(t[0]):s.IsEqual(e,"Capitalize")?ka(t[0]):s.IsEqual(e,"ConstructorParameters")?Pa(t[0]):s.IsEqual(e,"Evaluate")?Wx(t[0]):s.IsEqual(e,"Exclude")?Aa(t[0],t[1]):s.IsEqual(e,"Extract")?Oa(t[0],t[1]):s.IsEqual(e,"Index")?hi(t[0],t[1]):s.IsEqual(e,"InstanceType")?Ma(t[0]):s.IsEqual(e,"Lowercase")?Ta(t[0]):s.IsEqual(e,"NonNullable")?va(t[0]):s.IsEqual(e,"Omit")?Fa(t[0],t[1]):s.IsEqual(e,"Parameters")?La(t[0]):s.IsEqual(e,"Partial")?Da(t[0]):s.IsEqual(e,"Pick")?ja(t[0],t[1]):s.IsEqual(e,"Readonly")?Na(t[0]):s.IsEqual(e,"KeyOf")?Ii(t[0]):s.IsEqual(e,"Record")?ha(t[0],t[1]):s.IsEqual(e,"Required")?qa(t[0]):s.IsEqual(e,"ReturnType")?_a(t[0]):s.IsEqual(e,"Uncapitalize")?wa(t[0]):s.IsEqual(e,"Uppercase")?Ca(t[0]):xi(ze(e),t)}function Mn(){throw Error("Unreachable")}function Jg(e,t=[]){return s.ShiftLeft(e,(r,n)=>Jg(n,[...t,r[1]]),()=>t)}function Nr(e){return s.IsEqual(e.length,3)?[e[0],...Jg(e[1])]:[]}function Yg(e){return Pn(e[0],e[2],e[4])}function Qg(e){return Pn(e[0],e[2],e[2])}function Xg(e){return Pn(e[0],Be(),e[2])}function Zg(e){return Pn(e,Be(),Be())}function ey(e){return Nr(e)}function ty(e){return e[1]}function ry(e){return Nr(e)}function ny(e){return e[1]}function oy(e){return SP(e[0],e[1])}function iy(e){return null}function sy(e){return st()}function ay(e){return Ot()}function my(e){return aa()}function uy(e){return fo()}function cy(e){return oo()}function py(e){return Rn()}function fy(e){return mi()}function dy(e){return Be()}function ly(e){return ro()}function gy(e){return L({})}function yy(e){return se()}function xy(e){return io()}function hy(e){return Ea()}function Iy(e){return ba()}function by(e){return z(BigInt(e))}function $y(e){return z(s.IsEqual(e,"true"))}function Ey(e){return z(parseFloat(e))}function Sy(e){return z(e)}function ky(e){return e[1]}function Ty(e){return z(e)}function wy(e){return s.IsEqual(e.length,3)?[e[0],e[1],...e[2]]:[e[0]]}function Cy(e){return e[1]}function Ry(e){return Sa(e)}function Py(e){return s.IsEqual(e.length,6)?wn(e[1],e[3],e[5]):wn(e[1],e[3],Be())}function Ay(e){return e.length>0}function Oy(e){return e.reduce((t,r)=>s.IsEqual(r.length,3)?[...t,[r[1]]]:[...t,[]],[])}function My(e){return s.IsEqual(e.length,6)?[e[1],e[3],e[5]]:[]}function vy(e){return s.IsArray(e)&&s.IsEqual(e.length,3)?e[1]:e}function Fy(e){return s.IsEqual(e.length,2)?e[1]:[]}function Hg(e,t){return t.reduce((r,n)=>{let o=n;return s.IsEqual(o.length,1)?hi(r,o[0]):s.IsEqual(o.length,0)?Et(r):Mn()},e)}function zg(e,t){return s.IsEqual(t.length,3)?Ra(e,t[0],t[1],t[2]):e}function kP(e,t){return s.IsArray(t)&&s.IsEqual(t.length,0)?e:Ua(e,t)}function Ly(e){let[t,r,n,o,i]=e;return kP(zg(t?Ii(Hg(r,n)):Hg(r,n),o),i)}function Zu(e,t){return s.IsEqual(t.length,3)?(()=>{let[r,n,o]=t,i=Zu(n,o);if(s.IsEqual(r,"&"))return F(i)?ut([e,...i.allOf]):ut([e,i]);if(s.IsEqual(r,"|"))return E(i)?q([e,...i.anyOf]):q([e,i]);Mn()})():e}function Dy(e){let[t,r]=e;return Zu(t,r)}function jy(e){let[t,r]=e;return Zu(t,r)}function Ny(e){return Hx(e[1])}function qy(e){return e[1]}function _y(e){return rn(e[0],e[2])}function Uy(e){return s.IsEqual(e.length,4)?oi(e[1],e[3]):s.IsEqual(e.length,2)?oi(e[1],Be()):Mn()}function By(e){return`${e}`}function Gy(e){return Je(e[3])?sn:he(e[3])?uo:Sr(e[3])?ir:Ge(e[3])?ir:Mn()}function Ky(e){return e.length>0}function Hy(e){return e.length>0}function zy(e){let[t,r,n,o,i]=e;return{[r]:t&&n?$r(Ir(i)):t&&!n?$r(i):!t&&n?Ir(i):i}}function Wy(e){return Nr(e)}function Vy(e){return e.reduce((t,r)=>s.HasPropertyKey(r,sn)||s.HasPropertyKey(r,uo)||s.HasPropertyKey(r,ir)?[t[0],l.Assign(t[1],r)]:[l.Assign(t[0],r),t[1]],[{},{}])}function Jy(e){return Vy(e[1])}function Yy(e){let[t,r]=e,n=s.IsEqual(s.Keys(r).length,0)?{}:{patternProperties:r};return L(t,n)}function Qy(e){return s.IsEqual(e.length,5)?$r(Ir(e[4])):s.IsEqual(e.length,3)?e[2]:s.IsEqual(e.length,4)?s.IsEqual(e[2],"readonly")?$r(e[3]):Ir(e[3]):Mn()}function Xy(e){if(!s.IsArray(e)||!s.IsEqual(e.length,3))return e;let[t,r,n]=e;return t&&n?$r(Ir(r)):t&&!n?$r(r):!t&&n?Ir(r):r}function Zy(e){return s.IsEqual(e.length,2)?On(e[1]):s.IsEqual(e.length,1)?e[0]:Mn()}function ex(e){return Nr(e)}function tx(e){return Re(e[1])}function rx(e){return $r(Ir(e[4]))}function nx(e){return $r(e[3])}function ox(e){return Ir(e[3])}function ix(e){return e[2]}function sx(e){return s.IsEqual(e.length,2)?On(e[1]):s.IsEqual(e.length,1)?e[0]:Mn()}function ax(e){return Nr(e)}function mx(e){return hr(e[1],e[4])}function ux(e){return xr(e[2],e[5])}function Wg(e,t){return s.IsEqual(e,"remove")?zx(t):s.IsEqual(e,"add")?$r(t):t}function cx(e){return s.IsEqual(e.length,2)&&s.IsEqual(e[0],"-")?"remove":s.IsEqual(e.length,2)&&s.IsEqual(e[0],"+")||s.IsEqual(e.length,1)?"add":"none"}function Vg(e,t){return s.IsEqual(e,"remove")?Kx(t):s.IsEqual(e,"add")?Ir(t):t}function px(e){return s.IsEqual(e.length,2)&&s.IsEqual(e[0],"-")?"remove":s.IsEqual(e.length,2)&&s.IsEqual(e[0],"+")||s.IsEqual(e.length,1)?"add":"none"}function fx(e){return s.IsEqual(e.length,2)?[e[1]]:[]}function dx(e){return s.IsArray(e[6])&&s.IsEqual(e[6].length,1)?gi(ui(e[3]),e[5],e[6][0],Wg(e[1],Vg(e[8],e[10]))):gi(ui(e[3]),e[5],ze(e[3]),Wg(e[1],Vg(e[8],e[10])))}function lx(e){return ze(e)}function gx(e){return BigInt(e)}function yx(e){return parseFloat(e)}function xx(e){return s.IsEqual(e,"true")}function hx(e){return null}function Ix(e){return{[e[0]]:e[2]}}function bx(e){return Nr(e)}function TP(e){return e.reduce((t,r)=>l.Assign(t,r),{})}function $x(e){return TP(e[1])}function Ex(e){return Nr(e)}function Sx(e){return e[1]}function kx(e){return mi()}function Tx(e){return st()}function wx(e){return Ot()}function Cx(e){return Rn()}function Rx(e){return se()}function Px(e){return z(e)}function Ax(e){return q(e[1])}function Ox(e){return e.length===3?[...e[0],...e[2]]:e.length===1?[...e[0]]:[]}function Mx(e){return[e[0],...e[1]]}function vx(e){return e[1]}function Fx(e){return Nr(e)}function Lx(e){return s.IsEqual(e.length,2)?e[1]:[]}function Dx(e){let t=e[2],r=e[3],[n,o]=e[4],i=s.IsEqual(s.Keys(o).length,0)?{}:{patternProperties:o};return{[e[1]]:rn(t,yi(r,n,i))}}function jx(e){let t=e[2],[r,n]=e[3],o=s.IsEqual(s.Keys(n).length,0)?{}:{patternProperties:n};return{[e[1]]:yi(t,r,o)}}function Nx(e){return{[e[1]]:rn(e[2],e[4])}}function qx(e){return{[e[1]]:e[3]}}function _x(e){return null}function Ux(e){return Nr(e)}function Bx(e){return e[1]}function Gx(e){let[t,r]=[e[0],e[1]];return Vx(l.Assign(t,Vy(r)[0]))}function bi(e){return Z(e.length,2)}function Q(e,t,r){return bi(e)?t(e[0],e[1]):r()}function RP(e,t){return Z(t.indexOf(e),0)?[e,t.slice(e.length)]:[]}function Ee(e,t){for(let r=0;r<e.length;r++){let n=RP(e[r],t);if(bi(n))return n}return[]}function ec(e,t){return Array.from({length:t-e+1},(r,n)=>String.fromCharCode(e+n))}var Jx=[...ec(97,122),...ec(65,90)],tc="0",rc=ec(49,57),lo=[tc,...rc],Yx=" ",go=`
|
|
2
|
+
`;var un="_",Ba=".",Qx="$",Ga="-";var Xx="//",Zx="/*",AP="*/";function eh(e){let t=e.indexOf(AP);return Z(t,-1)?"":e.slice(t+2)}function th(e){let t=e.indexOf(go);return Z(t,-1)?"":e.slice(t)}function OP(e){return e.replace(/^[ \t\r\f\v]+/,"")}function Ka(e){let t=OP(e);return t.startsWith(Zx)?Ka(eh(t.slice(2))):t.startsWith(Xx)?Ka(th(t.slice(2))):t}function rt(e){let t=e.trimStart();return t.startsWith(Zx)?rt(eh(t.slice(2))):t.startsWith(Xx)?rt(th(t.slice(2))):t}function Ha(e,t){return Q(Ee([e],t),(r,n)=>[r,n],()=>["",t])}function MP(e,t){return e.includes(t)}function yo(e,t,r,n=""){return Q(Ee(e,r),(o,i)=>MP(t,o)?yo(e,t,i,n):yo(e,t,i,`${n}${o}`),()=>[n,r])}function vP(e){return Ee(rc,e)}var FP=[...lo,un];function LP(e){return yo(FP,[un],e)}function DP(e){return Q(Ee([tc],e),(t,r)=>[t,r],()=>Q(vP(e),(t,r)=>Q(LP(r),(n,o)=>[`${t}${n}`,o],()=>[]),()=>[]))}function za(e){return DP(rt(e))}function jP(e){return Ha(Ga,e)}function NP(e){return Q(jP(e),(t,r)=>Q(za(r),(n,o)=>[`${t}${n}`,o],()=>[]),()=>[])}function rh(e){return NP(rt(e))}function qP(e){return Q(rh(e),(t,r)=>Q(Ee(["n"],r),(n,o)=>[`${t}`,o],()=>[]),()=>[])}function nc(e){return qP(e)}function oc(e,t){return Ee([e],t)}function x(e,t){return Z(e,"")?["",t]:e.startsWith(go)?oc(e,Ka(t)):e.startsWith(Yx)?oc(e,t):oc(e,rt(t))}var nh=[...Jx,un,Qx];function _P(e){return Ee(nh,e)}var UP=[...nh,...lo];function oh(e,t=""){return Q(Ee(UP,e),(r,n)=>oh(n,`${t}${r}`),()=>[t,e])}function BP(e){return Q(_P(e),(t,r)=>Q(oh(r),(n,o)=>[`${t}${n}`,o],()=>[]),()=>[])}function Ae(e){return BP(rt(e))}var GP=[...lo,un];function KP(e){return bi(Ee([Ba],e))}function ih(e){return Q(yo(GP,[un],e),(t,r)=>Z(t,"")?[]:[t,r],()=>[])}function HP(e){return Q(Ee([Ba],e),(t,r)=>Q(ih(r),(n,o)=>[`0${t}${n}`,o],()=>[]),()=>[])}function zP(e){return Q(za(e),(t,r)=>Q(Ee([Ba],r),(n,o)=>Q(ih(o),(i,a)=>[`${t}${n}${i}`,a],()=>[`${t}`,o]),()=>[`${t}`,r]),()=>[])}function WP(e){return KP(e)?HP(e):zP(e)}function sh(e){return WP(rt(e))}function VP(e){return Ha(Ga,e)}function JP(e){return Q(VP(e),(t,r)=>Q(sh(r),(n,o)=>[`${t}${n}`,o],()=>[]),()=>[])}function Wa(e){return JP(rt(e))}function YP(e){return Z(e,"")?[]:[e.slice(0,1),e.slice(1)]}function ah(e,t){return rs(e,(r,n)=>t.startsWith(r)?!0:ah(n,t),()=>!1)}function cn(e,t,r=""){return Q(YP(t),(n,o)=>ah(e,t)?[r,t]:cn(e,o,`${r}${n}`),()=>[])}function QP(e,t,r){return Q(Ee([e],r),(n,o)=>Q(cn([t],o),(i,a)=>Q(Ee([t],a),(m,c)=>[`${i}`,c],()=>[]),()=>[]),()=>[])}function XP(e,t,r){return Q(Ee([e],r),(n,o)=>Q(cn([go,t],o),(i,a)=>Q(Ee([t],a),(m,c)=>[`${i}`,c],()=>[]),()=>[]),()=>[])}function mh(e,t,r,n){return r?QP(e,t,rt(n)):XP(e,t,rt(n))}function ZP(e,t){return Ee(e,t)}function eA(e,t){return mh(e,e,!1,t)}function tA(e,t){return Q(ZP(e,t),(r,n)=>eA(r,`${r}${n}`),()=>[])}function Va(e,t){return tA(e,rt(t))}function uh(e,t){return Q(cn(e,t),(r,n)=>Z(r,"")?[]:[r,n],()=>[])}var u=(e,t,r=()=>[])=>e.length===2?t(e):r(),nA=e=>u(u(Ae(e),([t,r])=>u(x("extends",r),([n,o])=>u(te(o),([i,a])=>u(x("=",a),([m,c])=>u(te(c),([p,f])=>[[t,n,i,m,p],f]))))),([t,r])=>[Yg(t),r]),oA=e=>u(u(Ae(e),([t,r])=>u(x("extends",r),([n,o])=>u(te(o),([i,a])=>[[t,n,i],a]))),([t,r])=>[Qg(t),r]),iA=e=>u(u(Ae(e),([t,r])=>u(x("=",r),([n,o])=>u(te(o),([i,a])=>[[t,n,i],a]))),([t,r])=>[Xg(t),r]),sA=e=>u(Ae(e),([t,r])=>[Zg(t),r]),fh=e=>u(u(nA(e),([t,r])=>[t,r],()=>u(oA(e),([t,r])=>[t,r],()=>u(iA(e),([t,r])=>[t,r],()=>u(sA(e),([t,r])=>[t,r],()=>[])))),([t,r])=>[t,r]),dh=(e,t=[])=>u(u(x(",",e),([r,n])=>u(fh(n),([o,i])=>[[r,o],i])),([r,n])=>dh(n,[...t,r]),()=>[t,e]),aA=e=>u(u(u(fh(e),([t,r])=>u(dh(r),([n,o])=>u(u(x(",",o),([i,a])=>[[i],a],()=>[[],o]),([i,a])=>[[t,n,i],a]))),([t,r])=>[t,r],()=>u([[],e],([t,r])=>[t,r],()=>[])),([t,r])=>[ey(t),r]),ac=e=>u(u(x("<",e),([t,r])=>u(aA(r),([n,o])=>u(x(">",o),([i,a])=>[[t,n,i],a]))),([t,r])=>[ty(t),r]),lh=(e,t=[])=>u(u(x(",",e),([r,n])=>u(te(n),([o,i])=>[[r,o],i])),([r,n])=>lh(n,[...t,r]),()=>[t,e]),mA=e=>u(u(u(te(e),([t,r])=>u(lh(r),([n,o])=>u(u(x(",",o),([i,a])=>[[i],a],()=>[[],o]),([i,a])=>[[t,n,i],a]))),([t,r])=>[t,r],()=>u([[],e],([t,r])=>[t,r],()=>[])),([t,r])=>[ry(t),r]),uA=e=>u(u(x("<",e),([t,r])=>u(mA(r),([n,o])=>u(x(">",o),([i,a])=>[[t,n,i],a]))),([t,r])=>[ny(t),r]),cA=e=>u(u(Ae(e),([t,r])=>u(uA(r),([n,o])=>[[t,n],o])),([t,r])=>[oy(t),r]),gh=e=>u(u(u(x(";",e),([t,r])=>[[t],r]),([t,r])=>[t,r],()=>u([[],e],([t,r])=>[t,r],()=>[])),([t,r])=>[iy(t),r]),yh=e=>u(x("string",e),([t,r])=>[sy(t),r]),xh=e=>u(x("number",e),([t,r])=>[ay(t),r]),pA=e=>u(x("boolean",e),([t,r])=>[my(t),r]),fA=e=>u(x("undefined",e),([t,r])=>[uy(t),r]),dA=e=>u(x("null",e),([t,r])=>[cy(t),r]),hh=e=>u(x("integer",e),([t,r])=>[py(t),r]),lA=e=>u(x("bigint",e),([t,r])=>[fy(t),r]),gA=e=>u(x("unknown",e),([t,r])=>[dy(t),r]),yA=e=>u(x("any",e),([t,r])=>[ly(t),r]),xA=e=>u(x("object",e),([t,r])=>[gy(t),r]),hA=e=>u(x("never",e),([t,r])=>[yy(t),r]),Ih=e=>u(x("symbol",e),([t,r])=>[xy(t),r]),IA=e=>u(x("void",e),([t,r])=>[hy(t),r]),bA=e=>u(x("this",e),([t,r])=>[Iy(t),r]),$A=e=>u(u(x("${",e),([t,r])=>u(te(r),([n,o])=>u(x("}",o),([i,a])=>[[t,n,i],a]))),([t,r])=>[ky(t),r]),ic=e=>u(cn(["${","`"],e),([t,r])=>[Ty(t),r]),bh=e=>u(u(u(ic(e),([t,r])=>u($A(r),([n,o])=>u(bh(o),([i,a])=>[[t,n,i],a]))),([t,r])=>[t,r],()=>u(u(ic(e),([t,r])=>[[t],r]),([t,r])=>[t,r],()=>u(u(ic(e),([t,r])=>[[t],r]),([t,r])=>[t,r],()=>[]))),([t,r])=>[wy(t),r]),mc=e=>u(u(x("`",e),([t,r])=>u(bh(r),([n,o])=>u(x("`",o),([i,a])=>[[t,n,i],a]))),([t,r])=>[Cy(t),r]),EA=e=>u(mc(e),([t,r])=>[Ry(t),r]),SA=e=>u(u(u(x("if",e),([t,r])=>u(te(r),([n,o])=>u(x("then",o),([i,a])=>u(te(a),([m,c])=>u(x("else",c),([p,f])=>u(te(f),([d,g])=>[[t,n,i,m,p,d],g])))))),([t,r])=>[t,r],()=>u(u(x("if",e),([t,r])=>u(te(r),([n,o])=>u(x("then",o),([i,a])=>u(te(a),([m,c])=>[[t,n,i,m],c])))),([t,r])=>[t,r],()=>[])),([t,r])=>[Py(t),r]),kA=e=>u(nc(e),([t,r])=>[by(t),r]),TA=e=>u(u(x("true",e),([t,r])=>[t,r],()=>u(x("false",e),([t,r])=>[t,r],()=>[])),([t,r])=>[$y(t),r]),wA=e=>u(Wa(e),([t,r])=>[Ey(t),r]),CA=e=>u(Va(["'",'"'],e),([t,r])=>[Sy(t),r]),RA=e=>u(u(u(x("keyof",e),([t,r])=>[[t],r]),([t,r])=>[t,r],()=>u([[],e],([t,r])=>[t,r],()=>[])),([t,r])=>[Ay(t),r]),$h=(e,t=[])=>u(u(u(x("[",e),([r,n])=>u(te(n),([o,i])=>u(x("]",i),([a,m])=>[[r,o,a],m]))),([r,n])=>[r,n],()=>u(u(x("[",e),([r,n])=>u(x("]",n),([o,i])=>[[r,o],i])),([r,n])=>[r,n],()=>[])),([r,n])=>$h(n,[...t,r]),()=>[t,e]),PA=e=>u($h(e),([t,r])=>[Oy(t),r]),AA=e=>u(u(u(x("extends",e),([t,r])=>u(te(r),([n,o])=>u(x("?",o),([i,a])=>u(te(a),([m,c])=>u(x(":",c),([p,f])=>u(te(f),([d,g])=>[[t,n,i,m,p,d],g])))))),([t,r])=>[t,r],()=>u([[],e],([t,r])=>[t,r],()=>[])),([t,r])=>[My(t),r]),OA=e=>u(u(u(x("(",e),([t,r])=>u(te(r),([n,o])=>u(x(")",o),([i,a])=>[[t,n,i],a]))),([t,r])=>[t,r],()=>u(yh(e),([t,r])=>[t,r],()=>u(xh(e),([t,r])=>[t,r],()=>u(pA(e),([t,r])=>[t,r],()=>u(fA(e),([t,r])=>[t,r],()=>u(dA(e),([t,r])=>[t,r],()=>u(hh(e),([t,r])=>[t,r],()=>u(lA(e),([t,r])=>[t,r],()=>u(gA(e),([t,r])=>[t,r],()=>u(yA(e),([t,r])=>[t,r],()=>u(xA(e),([t,r])=>[t,r],()=>u(hA(e),([t,r])=>[t,r],()=>u(Ih(e),([t,r])=>[t,r],()=>u(IA(e),([t,r])=>[t,r],()=>u(bA(e),([t,r])=>[t,r],()=>u(kA(e),([t,r])=>[t,r],()=>u(TA(e),([t,r])=>[t,r],()=>u(wA(e),([t,r])=>[t,r],()=>u(CA(e),([t,r])=>[t,r],()=>u(EA(e),([t,r])=>[t,r],()=>u(SA(e),([t,r])=>[t,r],()=>u(BA(e),([t,r])=>[t,r],()=>u(HA(e),([t,r])=>[t,r],()=>u(QA(e),([t,r])=>[t,r],()=>u(YA(e),([t,r])=>[t,r],()=>u(tO(e),([t,r])=>[t,r],()=>u(cA(e),([t,r])=>[t,r],()=>u(rO(e),([t,r])=>[t,r],()=>[])))))))))))))))))))))))))))),([t,r])=>[vy(t),r]),MA=e=>u(u(u(x("with",e),([t,r])=>u(Nh(r),([n,o])=>[[t,n],o])),([t,r])=>[t,r],()=>u([[],e],([t,r])=>[t,r],()=>[])),([t,r])=>[Fy(t),r]),Eh=e=>u(u(RA(e),([t,r])=>u(OA(r),([n,o])=>u(PA(o),([i,a])=>u(AA(a),([m,c])=>u(MA(c),([p,f])=>[[t,n,i,m,p],f]))))),([t,r])=>[Ly(t),r]),Sh=e=>u(u(u(x("&",e),([t,r])=>u(Eh(r),([n,o])=>u(Sh(o),([i,a])=>[[t,n,i],a]))),([t,r])=>[t,r],()=>u([[],e],([t,r])=>[t,r],()=>[])),([t,r])=>[t,r]),kh=e=>u(u(Eh(e),([t,r])=>u(Sh(r),([n,o])=>[[t,n],o])),([t,r])=>[Dy(t),r]),Th=e=>u(u(u(x("|",e),([t,r])=>u(kh(r),([n,o])=>u(Th(o),([i,a])=>[[t,n,i],a]))),([t,r])=>[t,r],()=>u([[],e],([t,r])=>[t,r],()=>[])),([t,r])=>[t,r]),Ja=e=>u(u(kh(e),([t,r])=>u(Th(r),([n,o])=>[[t,n],o])),([t,r])=>[jy(t),r]),vA=e=>u(u(x("readonly",e),([t,r])=>u(Ja(r),([n,o])=>[[t,n],o])),([t,r])=>[Ny(t),r]),FA=e=>u(u(x("|",e),([t,r])=>u(Ja(r),([n,o])=>[[t,n],o])),([t,r])=>[qy(t),r]),LA=e=>u(u(ac(e),([t,r])=>u(x("=",r),([n,o])=>u(te(o),([i,a])=>[[t,n,i],a]))),([t,r])=>[_y(t),r]),DA=e=>u(u(u(x("infer",e),([t,r])=>u(Ae(r),([n,o])=>u(x("extends",o),([i,a])=>u(Ja(a),([m,c])=>[[t,n,i,m],c])))),([t,r])=>[t,r],()=>u(u(x("infer",e),([t,r])=>u(Ae(r),([n,o])=>[[t,n],o])),([t,r])=>[t,r],()=>[])),([t,r])=>[Uy(t),r]),te=e=>u(u(DA(e),([t,r])=>[t,r],()=>u(FA(e),([t,r])=>[t,r],()=>u(vA(e),([t,r])=>[t,r],()=>u(Ja(e),([t,r])=>[t,r],()=>[])))),([t,r])=>[t,r]),jA=e=>u(Wa(e),([t,r])=>[By(t),r]),NA=e=>u(Ae(e),([t,r])=>[t,r]),qA=e=>u(Va(["'",'"'],e),([t,r])=>[t,r]),_A=e=>u(u(x("[",e),([t,r])=>u(Ae(r),([n,o])=>u(x(":",o),([i,a])=>u(u(hh(a),([m,c])=>[m,c],()=>u(xh(a),([m,c])=>[m,c],()=>u(yh(a),([m,c])=>[m,c],()=>u(Ih(a),([m,c])=>[m,c],()=>[])))),([m,c])=>u(x("]",c),([p,f])=>[[t,n,i,m,p],f]))))),([t,r])=>[Gy(t),r]),wh=e=>u(u(jA(e),([t,r])=>[t,r],()=>u(NA(e),([t,r])=>[t,r],()=>u(qA(e),([t,r])=>[t,r],()=>u(_A(e),([t,r])=>[t,r],()=>[])))),([t,r])=>[t,r]),Ch=e=>u(u(u(x("readonly",e),([t,r])=>[[t],r]),([t,r])=>[t,r],()=>u([[],e],([t,r])=>[t,r],()=>[])),([t,r])=>[Ky(t),r]),Rh=e=>u(u(u(x("?",e),([t,r])=>[[t],r]),([t,r])=>[t,r],()=>u([[],e],([t,r])=>[t,r],()=>[])),([t,r])=>[Hy(t),r]),Ph=e=>u(u(Ch(e),([t,r])=>u(wh(r),([n,o])=>u(Rh(o),([i,a])=>u(x(":",a),([m,c])=>u(te(c),([p,f])=>[[t,n,i,m,p],f]))))),([t,r])=>[zy(t),r]),Ya=e=>u(u(u(x(",",e),([t,r])=>u(x(`
|
|
3
|
+
`,r),([n,o])=>[[t,n],o])),([t,r])=>[t,r],()=>u(u(x(";",e),([t,r])=>u(x(`
|
|
4
|
+
`,r),([n,o])=>[[t,n],o])),([t,r])=>[t,r],()=>u(u(x(",",e),([t,r])=>[[t],r]),([t,r])=>[t,r],()=>u(u(x(";",e),([t,r])=>[[t],r]),([t,r])=>[t,r],()=>u(u(x(`
|
|
5
|
+
`,e),([t,r])=>[[t],r]),([t,r])=>[t,r],()=>[]))))),([t,r])=>[t,r]),Ah=(e,t=[])=>u(u(Ya(e),([r,n])=>u(Ph(n),([o,i])=>[[r,o],i])),([r,n])=>Ah(n,[...t,r]),()=>[t,e]),UA=e=>u(u(u(Ph(e),([t,r])=>u(Ah(r),([n,o])=>u(u(Ya(o),([i,a])=>[[i],a],()=>[[],o]),([i,a])=>[[t,n,i],a]))),([t,r])=>[t,r],()=>u([[],e],([t,r])=>[t,r],()=>[])),([t,r])=>[Wy(t),r]),uc=e=>u(u(x("{",e),([t,r])=>u(UA(r),([n,o])=>u(x("}",o),([i,a])=>[[t,n,i],a]))),([t,r])=>[Jy(t),r]),BA=e=>u(uc(e),([t,r])=>[Yy(t),r]),GA=e=>u(u(u(Ae(e),([t,r])=>u(x("?",r),([n,o])=>u(x(":",o),([i,a])=>u(x("readonly",a),([m,c])=>u(te(c),([p,f])=>[[t,n,i,m,p],f]))))),([t,r])=>[t,r],()=>u(u(Ae(e),([t,r])=>u(x(":",r),([n,o])=>u(x("readonly",o),([i,a])=>u(te(a),([m,c])=>[[t,n,i,m],c])))),([t,r])=>[t,r],()=>u(u(Ae(e),([t,r])=>u(x("?",r),([n,o])=>u(x(":",o),([i,a])=>u(te(a),([m,c])=>[[t,n,i,m],c])))),([t,r])=>[t,r],()=>u(u(Ae(e),([t,r])=>u(x(":",r),([n,o])=>u(te(o),([i,a])=>[[t,n,i],a]))),([t,r])=>[t,r],()=>[])))),([t,r])=>[Qy(t),r]),ch=e=>u(u(GA(e),([t,r])=>[t,r],()=>u(u(Ch(e),([t,r])=>u(te(r),([n,o])=>u(Rh(o),([i,a])=>[[t,n,i],a]))),([t,r])=>[t,r],()=>[])),([t,r])=>[Xy(t),r]),Oh=e=>u(u(u(x("...",e),([t,r])=>u(ch(r),([n,o])=>[[t,n],o])),([t,r])=>[t,r],()=>u(u(ch(e),([t,r])=>[[t],r]),([t,r])=>[t,r],()=>[])),([t,r])=>[Zy(t),r]),Mh=(e,t=[])=>u(u(x(",",e),([r,n])=>u(Oh(n),([o,i])=>[[r,o],i])),([r,n])=>Mh(n,[...t,r]),()=>[t,e]),KA=e=>u(u(u(Oh(e),([t,r])=>u(Mh(r),([n,o])=>u(u(x(",",o),([i,a])=>[[i],a],()=>[[],o]),([i,a])=>[[t,n,i],a]))),([t,r])=>[t,r],()=>u([[],e],([t,r])=>[t,r],()=>[])),([t,r])=>[ex(t),r]),HA=e=>u(u(x("[",e),([t,r])=>u(KA(r),([n,o])=>u(x("]",o),([i,a])=>[[t,n,i],a]))),([t,r])=>[tx(t),r]),zA=e=>u(u(Ae(e),([t,r])=>u(x("?",r),([n,o])=>u(x(":",o),([i,a])=>u(x("readonly",a),([m,c])=>u(te(c),([p,f])=>[[t,n,i,m,p],f]))))),([t,r])=>[rx(t),r]),WA=e=>u(u(Ae(e),([t,r])=>u(x(":",r),([n,o])=>u(x("readonly",o),([i,a])=>u(te(a),([m,c])=>[[t,n,i,m],c])))),([t,r])=>[nx(t),r]),VA=e=>u(u(Ae(e),([t,r])=>u(x("?",r),([n,o])=>u(x(":",o),([i,a])=>u(te(a),([m,c])=>[[t,n,i,m],c])))),([t,r])=>[ox(t),r]),JA=e=>u(u(Ae(e),([t,r])=>u(x(":",r),([n,o])=>u(te(o),([i,a])=>[[t,n,i],a]))),([t,r])=>[ix(t),r]),ph=e=>u(u(zA(e),([t,r])=>[t,r],()=>u(WA(e),([t,r])=>[t,r],()=>u(VA(e),([t,r])=>[t,r],()=>u(JA(e),([t,r])=>[t,r],()=>[])))),([t,r])=>[t,r]),vh=e=>u(u(u(x("...",e),([t,r])=>u(ph(r),([n,o])=>[[t,n],o])),([t,r])=>[t,r],()=>u(u(ph(e),([t,r])=>[[t],r]),([t,r])=>[t,r],()=>[])),([t,r])=>[sx(t),r]),Fh=(e,t=[])=>u(u(x(",",e),([r,n])=>u(vh(n),([o,i])=>[[r,o],i])),([r,n])=>Fh(n,[...t,r]),()=>[t,e]),Lh=e=>u(u(u(vh(e),([t,r])=>u(Fh(r),([n,o])=>u(u(x(",",o),([i,a])=>[[i],a],()=>[[],o]),([i,a])=>[[t,n,i],a]))),([t,r])=>[t,r],()=>u([[],e],([t,r])=>[t,r],()=>[])),([t,r])=>[ax(t),r]),YA=e=>u(u(x("(",e),([t,r])=>u(Lh(r),([n,o])=>u(x(")",o),([i,a])=>u(x("=>",a),([m,c])=>u(te(c),([p,f])=>[[t,n,i,m,p],f]))))),([t,r])=>[mx(t),r]),QA=e=>u(u(x("new",e),([t,r])=>u(x("(",r),([n,o])=>u(Lh(o),([i,a])=>u(x(")",a),([m,c])=>u(x("=>",c),([p,f])=>u(te(f),([d,g])=>[[t,n,i,m,p,d],g])))))),([t,r])=>[ux(t),r]),XA=e=>u(u(u(x("+",e),([t,r])=>u(x("readonly",r),([n,o])=>[[t,n],o])),([t,r])=>[t,r],()=>u(u(x("-",e),([t,r])=>u(x("readonly",r),([n,o])=>[[t,n],o])),([t,r])=>[t,r],()=>u(u(x("readonly",e),([t,r])=>[[t],r]),([t,r])=>[t,r],()=>u([[],e],([t,r])=>[t,r],()=>[])))),([t,r])=>[cx(t),r]),ZA=e=>u(u(u(x("+",e),([t,r])=>u(x("?",r),([n,o])=>[[t,n],o])),([t,r])=>[t,r],()=>u(u(x("-",e),([t,r])=>u(x("?",r),([n,o])=>[[t,n],o])),([t,r])=>[t,r],()=>u(u(x("?",e),([t,r])=>[[t],r]),([t,r])=>[t,r],()=>u([[],e],([t,r])=>[t,r],()=>[])))),([t,r])=>[px(t),r]),eO=e=>u(u(u(x("as",e),([t,r])=>u(te(r),([n,o])=>[[t,n],o])),([t,r])=>[t,r],()=>u([[],e],([t,r])=>[t,r],()=>[])),([t,r])=>[fx(t),r]),tO=e=>u(u(x("{",e),([t,r])=>u(XA(r),([n,o])=>u(x("[",o),([i,a])=>u(Ae(a),([m,c])=>u(x("in",c),([p,f])=>u(te(f),([d,g])=>u(eO(g),([y,I])=>u(x("]",I),([h,b])=>u(ZA(b),([k,_])=>u(x(":",_),([A,Fe])=>u(te(Fe),([We,S])=>u(gh(S),([w,O])=>u(x("}",O),([R,J])=>[[t,n,i,m,p,d,y,h,k,A,We,w,R],J]))))))))))))),([t,r])=>[dx(t),r]),rO=e=>u(Ae(e),([t,r])=>[lx(t),r]),nO=e=>u(nc(e),([t,r])=>[gx(t),r]),oO=e=>u(Wa(e),([t,r])=>[yx(t),r]),iO=e=>u(u(x("true",e),([t,r])=>[t,r],()=>u(x("false",e),([t,r])=>[t,r],()=>[])),([t,r])=>[xx(t),r]),sO=e=>u(Va(['"',"'"],e),([t,r])=>[t,r]),aO=e=>u(x("null",e),([t,r])=>[hx(t),r]),mO=e=>u(x("undefined",e),([t,r])=>[void 0,r]),Dh=e=>u(u(wh(e),([t,r])=>u(x(":",r),([n,o])=>u(cc(o),([i,a])=>[[t,n,i],a]))),([t,r])=>[Ix(t),r]),jh=(e,t=[])=>u(u(Ya(e),([r,n])=>u(Dh(n),([o,i])=>[[r,o],i])),([r,n])=>jh(n,[...t,r]),()=>[t,e]),uO=e=>u(u(u(Dh(e),([t,r])=>u(jh(r),([n,o])=>u(u(Ya(o),([i,a])=>[[i],a],()=>[[],o]),([i,a])=>[[t,n,i],a]))),([t,r])=>[t,r],()=>u([[],e],([t,r])=>[t,r],()=>[])),([t,r])=>[bx(t),r]),Nh=e=>u(u(x("{",e),([t,r])=>u(uO(r),([n,o])=>u(x("}",o),([i,a])=>[[t,n,i],a]))),([t,r])=>[$x(t),r]),qh=(e,t=[])=>u(u(x(",",e),([r,n])=>u(cc(n),([o,i])=>[[r,o],i])),([r,n])=>qh(n,[...t,r]),()=>[t,e]),cO=e=>u(u(u(cc(e),([t,r])=>u(qh(r),([n,o])=>u(u(x(",",o),([i,a])=>[[i],a],()=>[[],o]),([i,a])=>[[t,n,i],a]))),([t,r])=>[t,r],()=>u([[],e],([t,r])=>[t,r],()=>[])),([t,r])=>[Ex(t),r]),pO=e=>u(u(x("[",e),([t,r])=>u(cO(r),([n,o])=>u(x("]",o),([i,a])=>[[t,n,i],a]))),([t,r])=>[Sx(t),r]),cc=e=>u(u(nO(e),([t,r])=>[t,r],()=>u(oO(e),([t,r])=>[t,r],()=>u(iO(e),([t,r])=>[t,r],()=>u(sO(e),([t,r])=>[t,r],()=>u(aO(e),([t,r])=>[t,r],()=>u(mO(e),([t,r])=>[t,r],()=>u(Nh(e),([t,r])=>[t,r],()=>u(pO(e),([t,r])=>[t,r],()=>[])))))))),([t,r])=>[t,r]),fO=e=>u(x("-?(?:0|[1-9][0-9]*)n",e),([t,r])=>[kx(t),r]),dO=e=>u(x(".*",e),([t,r])=>[Tx(t),r]),lO=e=>u(x("-?(?:0|[1-9][0-9]*)(?:\\.[0-9]+)?",e),([t,r])=>[wx(t),r]),gO=e=>u(x("-?(?:0|[1-9][0-9]*)",e),([t,r])=>[Cx(t),r]),yO=e=>u(x("(?!)",e),([t,r])=>[Rx(t),r]),xO=e=>u(uh(["-?(?:0|[1-9][0-9]*)n",".*","-?(?:0|[1-9][0-9]*)(?:\\.[0-9]+)?","-?(?:0|[1-9][0-9]*)","(?!)","(",")","$","|"],e),([t,r])=>[Px(t),r]),hO=e=>u(u(fO(e),([t,r])=>[t,r],()=>u(dO(e),([t,r])=>[t,r],()=>u(lO(e),([t,r])=>[t,r],()=>u(gO(e),([t,r])=>[t,r],()=>u(yO(e),([t,r])=>[t,r],()=>u(IO(e),([t,r])=>[t,r],()=>u(xO(e),([t,r])=>[t,r],()=>[]))))))),([t,r])=>[t,r]),IO=e=>u(u(x("(",e),([t,r])=>u(pc(r),([n,o])=>u(x(")",o),([i,a])=>[[t,n,i],a]))),([t,r])=>[Ax(t),r]),_h=e=>u(u(u(sc(e),([t,r])=>u(x("|",r),([n,o])=>u(_h(o),([i,a])=>[[t,n,i],a]))),([t,r])=>[t,r],()=>u(u(sc(e),([t,r])=>[[t],r]),([t,r])=>[t,r],()=>u([[],e],([t,r])=>[t,r],()=>[]))),([t,r])=>[Ox(t),r]),sc=e=>u(u(hO(e),([t,r])=>u(pc(r),([n,o])=>[[t,n],o])),([t,r])=>[Mx(t),r]),pc=e=>u(u(_h(e),([t,r])=>[t,r],()=>u(sc(e),([t,r])=>[t,r],()=>[])),([t,r])=>[t,r]),lg=e=>u(u(x("^",e),([t,r])=>u(pc(r),([n,o])=>u(x("$",o),([i,a])=>[[t,n,i],a]))),([t,r])=>[vx(t),r]),Uh=(e,t=[])=>u(u(x(",",e),([r,n])=>u(te(n),([o,i])=>[[r,o],i])),([r,n])=>Uh(n,[...t,r]),()=>[t,e]),bO=e=>u(u(u(te(e),([t,r])=>u(Uh(r),([n,o])=>u(u(x(",",o),([i,a])=>[[i],a],()=>[[],o]),([i,a])=>[[t,n,i],a]))),([t,r])=>[t,r],()=>u([[],e],([t,r])=>[t,r],()=>[])),([t,r])=>[Fx(t),r]),Bh=e=>u(u(u(x("extends",e),([t,r])=>u(bO(r),([n,o])=>[[t,n],o])),([t,r])=>[t,r],()=>u([[],e],([t,r])=>[t,r],()=>[])),([t,r])=>[Lx(t),r]),$O=e=>u(u(x("interface",e),([t,r])=>u(Ae(r),([n,o])=>u(ac(o),([i,a])=>u(Bh(a),([m,c])=>u(uc(c),([p,f])=>[[t,n,i,m,p],f]))))),([t,r])=>[Dx(t),r]),EO=e=>u(u(x("interface",e),([t,r])=>u(Ae(r),([n,o])=>u(Bh(o),([i,a])=>u(uc(a),([m,c])=>[[t,n,i,m],c])))),([t,r])=>[jx(t),r]),SO=e=>u(u(x("type",e),([t,r])=>u(Ae(r),([n,o])=>u(ac(o),([i,a])=>u(x("=",a),([m,c])=>u(te(c),([p,f])=>[[t,n,i,m,p],f]))))),([t,r])=>[Nx(t),r]),kO=e=>u(u(x("type",e),([t,r])=>u(Ae(r),([n,o])=>u(x("=",o),([i,a])=>u(te(a),([m,c])=>[[t,n,i,m],c])))),([t,r])=>[qx(t),r]),TO=e=>u(u(u(x("export",e),([t,r])=>[[t],r]),([t,r])=>[t,r],()=>u([[],e],([t,r])=>[t,r],()=>[])),([t,r])=>[_x(t),r]),Gh=e=>u(u(u(x(";",e),([t,r])=>u(x(`
|
|
6
|
+
`,r),([n,o])=>[[t,n],o])),([t,r])=>[t,r],()=>u(u(x(";",e),([t,r])=>[[t],r]),([t,r])=>[t,r],()=>u(u(x(`
|
|
7
|
+
`,e),([t,r])=>[[t],r]),([t,r])=>[t,r],()=>[]))),([t,r])=>[t,r]),Kh=(e,t=[])=>u(u(Gh(e),([r,n])=>u(fc(n),([o,i])=>[[r,o],i])),([r,n])=>Kh(n,[...t,r]),()=>[t,e]),wO=e=>u(u(u(fc(e),([t,r])=>u(Kh(r),([n,o])=>u(u(Gh(o),([i,a])=>[[i],a],()=>[[],o]),([i,a])=>[[t,n,i],a]))),([t,r])=>[t,r],()=>u([[],e],([t,r])=>[t,r],()=>[])),([t,r])=>[Ux(t),r]),fc=e=>u(u(TO(e),([t,r])=>u(u($O(r),([n,o])=>[n,o],()=>u(EO(r),([n,o])=>[n,o],()=>u(SO(r),([n,o])=>[n,o],()=>u(kO(r),([n,o])=>[n,o],()=>[])))),([n,o])=>u(gh(o),([i,a])=>[[t,n,i],a]))),([t,r])=>[Bx(t),r]),CO=e=>u(u(fc(e),([t,r])=>u(wO(r),([n,o])=>[[t,n],o])),([t,r])=>[Gx(t),r]),Hh=e=>u(u(CO(e),([t,r])=>[t,r],()=>u(LA(e),([t,r])=>[t,r],()=>u(te(e),([t,r])=>[t,r],()=>[]))),([t,r])=>[t,r]);function zh(e){let t=mc(`\`${e}\``);return s.IsEqual(t.length,2)?t[0]:Se()}function PO(e){return e.join("|")}function AO(e){return e.slice(1,e.length-1)}function OO(e,t,r){return pn(t,`${r}${e}`)}function MO(e,t){return pn(e,`${t}${mg}`)}function vO(e,t){return pn(e,`${t}${ma}`)}function FO(e,t){return pn(e,`${t}${fa}`)}function LO(e,t){return $i(q([z("false"),z("true")]),e,t)}function DO(e,t){return pn(e,`${t}${da}`)}function jO(e,t,r){return pn(t,`${r}${AO(e)}`)}function NO(e,t,r){let n=Ei(e,{});return $i(n,t,r)}function qO(e,t,r){let n=It(e);return $i(n,t,r)}function Wh(e,t,r,n=[]){return s.ShiftLeft(e,(o,i)=>Wh(i,t,r,[...n,$i(o,[],"")]),()=>pn(t,`${r}(${PO(n)})`))}function $i(e,t,r){return Ce(e)?qO(e.enum,t,r):Je(e)?vO(t,r):V(e)?OO(e.const,t,r):At(e)?MO(t,r):ht(e)?LO(t,r):he(e)?FO(t,r):Ge(e)?DO(t,r):ce(e)?jO(e.pattern,t,r):Jh(e)?NO(e.parameters[0],t,r):E(e)?Wh(e.anyOf,t,r):zl}function pn(e,t){return s.ShiftLeft(e,(r,n)=>$i(r,n,t),()=>t)}function _O(e){return`^${pn(e,"")}$`}function Vh(e){let t=_O(e);return ga(t)}function Ei(e,t){return K(e)?l.Update(Vh(e),{},t):Sa(e,t)}function Yh(e,t,r,n){let o=_t(e,t,r);return Ei(o,n)}function Sa(e,t={}){return P("TemplateLiteral",[e],t)}function Jh(e){return xe(e)&&s.HasPropertyKey(e,"action")&&s.IsEqual(e.action,"TemplateLiteral")}function Qh(e){return Ei(e,{})}function UO(e){let t=zh(e);return Qh(t)}function Xh(e,t={}){let r=s.IsString(e)?UO(e):Qh(e);return l.Update(r,{},t)}function ce(e){return C(e,"TemplateLiteral")}var j={};Dt(j,{ExtendsFalse:()=>B,ExtendsTrue:()=>T,ExtendsUnion:()=>dc,IsExtendsFalse:()=>BO,IsExtendsTrue:()=>eI,IsExtendsTrueLike:()=>kr,IsExtendsUnion:()=>Zh,Match:()=>Oe});function dc(e){return l.Create({"~kind":"ExtendsUnion"},{inferred:e})}function Zh(e){return s.IsObject(e)&&s.HasPropertyKey(e,"~kind")&&s.HasPropertyKey(e,"inferred")&&s.IsEqual(e["~kind"],"ExtendsUnion")&&s.IsObject(e.inferred)}function T(e){return l.Create({"~kind":"ExtendsTrue"},{inferred:e})}function eI(e){return s.IsObject(e)&&s.HasPropertyKey(e,"~kind")&&s.HasPropertyKey(e,"inferred")&&s.IsEqual(e["~kind"],"ExtendsTrue")&&s.IsObject(e.inferred)}function B(){return l.Create({"~kind":"ExtendsFalse"},{})}function BO(e){return s.IsObject(e)&&s.HasPropertyKey(e,"~kind")&&s.IsEqual(e["~kind"],"ExtendsFalse")}function kr(e){return Zh(e)||eI(e)}function Oe(e,t,r){return kr(e)?t(e.inferred):r()}function GO(e,t,r,n){return Oe(X(e,r,n),o=>T(l.Assign(l.Assign(e,o),{[t]:r})),()=>B())}function KO(e,t){return T(e)}function HO(e,t,r,n,o){return Oe(X(e,t,r),i=>Oe(X(i,t,n),a=>T(a),()=>B()),()=>Oe(X(e,t,o),i=>T(i),()=>B()))}function zO(e,t,r){let n=It(r);return X(e,t,n)}function tI(e,t,r){return s.ShiftLeft(r,(n,o)=>Oe(X(e,t,n),i=>tI(i,t,o),()=>B()),()=>T(e))}function WO(e,t,r){let n=ct(r);return X(e,t,n)}function rI(e,t,r){return s.ShiftLeft(r,(n,o)=>Oe(X(e,t,n),i=>T(i),()=>rI(e,t,o)),()=>B())}function oe(e,t,r){return $e(r)?KO(e,t):we(r)?HO(e,t,r.if,r.then,r.else):Ce(r)?zO(e,t,r.enum):qe(r)?GO(e,r.name,t,r.extends):F(r)?tI(e,t,r.allOf):ce(r)?WO(e,t,r.pattern):E(r)?rI(e,t,r.anyOf):Ne(r)?T(e):B()}function nI(e,t,r){return qe(r)?oe(e,t,r):$e(r)?T(e):Ne(r)?T(e):dc(e)}function VO(e,t){let r=Cn(e),n=Cn(t);return r&&n||!r&&n?!0:!(r&&!n)}function oI(e,t,r,n){return Y(n)?VO(t,n)?X(e,r,n.items):B():oe(e,t,n)}function iI(e,t,r){return At(r)?T(e):oe(e,t,r)}function sI(e,t,r){return ht(r)?T(e):oe(e,t,r)}function JO(e,t,r,n,o){let i=qe(n)?t:n,a=qe(n)?n:t,m=je(t),c=je(n);return!m&&c?B():Oe(X(e,i,a),p=>Si(p,r,o),()=>B())}function YO(e,t,r,n){return s.ShiftLeft(n,(o,i)=>JO(e,t,r,o,i),()=>je(t)?T(e):B())}function QO(e,t,r){return s.ShiftLeft(t,(n,o)=>YO(e,n,o,r),()=>T(e))}function Si(e,t,r){return QO(e,t,r)}function Qa(e,t,r){return Mt(r)?T(e):X(e,t,r)}function aI(e,t,r,n){return $e(n)?T(e):Ne(n)?T(e):ke(n)?Oe(Si(e,t,n.parameters),o=>Qa(o,r,n.instanceType),()=>B()):B()}function mI(e,t,r,n,o){return Oe(X(e,t,o),()=>X(e,r,o),()=>X(e,n,o))}function uI(e,t,r){let n=It(t);return X(e,n,r)}function cI(e,t,r,n){return $e(n)?T(e):Ne(n)?T(e):Te(n)?Oe(Si(e,t,n.parameters),o=>Qa(o,r,n.returnType),()=>B()):B()}function pI(e,t,r){return Je(r)?T(e):he(r)?T(e):oe(e,t,r)}function fI(e,t,r){let n=Pe(t);return X(e,n,r)}function Xa(e,t,r){return t===r?T(e):B()}function XO(e,t,r){return V(r)?Xa(e,t,r.const):At(r)?T(e):oe(e,z(t),r)}function ZO(e,t,r){return V(r)?Xa(e,t,r.const):ht(r)?T(e):oe(e,z(t),r)}function eM(e,t,r){return V(r)?Xa(e,t,r.const):he(r)?T(e):oe(e,z(t),r)}function tM(e,t,r){return V(r)?Xa(e,t,r.const):Ge(r)?T(e):oe(e,z(t),r)}function dI(e,t,r){return s.IsBigInt(t.const)?XO(e,t.const,r):s.IsBoolean(t.const)?ZO(e,t.const,r):s.IsNumber(t.const)?eM(e,t.const,r):s.IsString(t.const)?tM(e,t.const,r):Se()}function lI(e,t,r){return qe(r)?oe(e,t,r):T(e)}function gI(e,t,r){return Er(r)?T(e):oe(e,t,r)}function yI(e,t,r){return he(r)?T(e):oe(e,t,r)}function rM(e,t,r){return je(t)?je(r)?T(e):B():T(e)}function nM(e,t,r){return qe(r)&&St(r.extends)?B():Oe(X(e,t,r),n=>rM(n,t,r),()=>B())}function oM(e,t){return e.reduce((r,n)=>n in t?kr(t[n])?{...r,...t[n].inferred}:Se():Se(),{})}function iM(e,t,r){let n={};for(let a of s.Keys(r))n[a]=a in t?nM({},t[a],r[a]):je(r[a])?qe(r[a])?T(l.Assign(e,{[r[a].name]:r[a].extends})):T(e):B();let o=s.Values(n).every(a=>kr(a)),i=o?oM(s.Keys(n),n):{};return o?T(i):B()}function sM(e,t,r){let n=iM(e,t,r);return kr(n)?T(l.Assign(e,n.inferred)):B()}function aM(e,t,r){return sM(e,t,r)}function mM(e,t){return s.Keys(t).reduce((r,n)=>({...r,[n]:s.HasPropertyKey(e,n)?E(r[n])?q([...r[n].anyOf,t[n]]):q([e[n],t[n]]):t[n]}),e)}function xI(e,t,r,n){return s.ShiftLeft(t,(o,i)=>Oe(X({},e[o],r),a=>xI(e,i,r,mM(n,a)),()=>B()),()=>T(n))}function uM(e,t,r,n){let o=s.Keys(t);return xI(t,o,n,e)}function hI(e,t,r){return ie(r)?uM(e,t,_e(r),fe(r)):v(r)?aM(e,t,r.properties):oe(e,L(t),r)}function cM(e,t){return s.IsEqual(s.Keys(t).length,0)?T(e):B()}function pM(e,t,r,n,o){return X(e,r,o)}function II(e,t,r,n){return ie(n)?pM(e,Ia(t),r,Ia(_e(n)),fe(n)):v(n)?cM(e,n.properties):$e(n)?T(e):Ne(n)?T(e):B()}function bI(e,t,r){return Ge(r)?T(e):oe(e,t,r)}function $I(e,t,r){return Sr(r)?T(e):oe(e,t,r)}function EI(e,t,r){let n=ct(t);return X(e,n,r)}function lc(e,t){return l.Create({"~kind":"Inferrable"},{name:e,type:t},{})}function ki(e){return s.IsObject(e)&&s.HasPropertyKey(e,"~kind")&&s.HasPropertyKey(e,"name")&&s.HasPropertyKey(e,"type")&&s.IsEqual(e["~kind"],"Inferrable")&&s.IsString(e.name)&&s.IsObject(e.type)}function gc(e){return mn(e)?qe(e.items)?Y(e.items.extends)?lc(e.items.name,e.items.extends.items):Ne(e.items.extends)?lc(e.items.name,e.items.extends):void 0:Se():void 0}function Za(e){return qe(e)?lc(e.name,e.extends):void 0}function SI(e,t){let r=[];for(let n of e){if(!kr(X({},n,t)))return;r.push(n)}return r}function kI(e,t,r,n){let o=SI(r,n);return s.IsArray(o)?T(l.Assign(e,{[t]:Re(o)})):B()}function em(e,t,r,n){let o=SI(r,n);return s.IsArray(o)?T(l.Assign(e,{[t]:q(o)})):B()}function fM(e){return[...e].reverse()}function yc(e,t){return t?fM(e):e}function dM(e){let t=e.length>0?e[0]:void 0,r=xe(t)?gc(t):void 0;return xe(r)}function lM(e,t,r,n,o,i){return Oe(X(e,r,o),a=>TI(a,t,n,i),()=>B())}function gM(e,t,r,n,o){let i=gc(n);return ki(i)?kI(e,i.name,yc(r,t),i.type):s.ShiftLeft(r,(a,m)=>lM(e,t,a,m,n,o),()=>B())}function yM(e,t,r,n){return s.ShiftLeft(n,(o,i)=>gM(e,t,r,o,i),()=>s.IsEqual(r.length,0)?T(e):B())}function TI(e,t,r,n){return yM(e,t,r,n)}function xM(e,t,r){let n=fn(e,le([],[]),r),o=dM(n);return TI(e,o,yc(t,o),yc(n,o))}function hM(e,t,r){for(let n of t){let o=X(e,n,r);if(!kr(o))return o;e=o.inferred}return T(e)}function IM(e,t,r){let n=Za(r);return ki(n)?em(e,n.name,t,n.type):hM(e,t,r)}function wI(e,t,r){let n=fn(e,le([],[]),t);return G(r)?xM(e,n,r.items):Y(r)?IM(e,n,r.items):oe(e,Re(n),r)}function CI(e,t,r){return Mt(r)?T(e):Yt(r)?T(e):oe(e,t,r)}function RI(e,t,r){return s.ShiftLeft(r,(n,o)=>Oe(X(e,t,n),i=>T(i),()=>RI(e,t,o)),()=>B())}function xc(e,t,r){return s.ShiftLeft(t,(n,o)=>Oe(RI(e,n,r),i=>xc(i,o,r),()=>B()),()=>T(e))}function PI(e,t,r){let n=Za(r);return ki(n)?em(e,n.name,t,n.type):E(r)?xc(e,t,r.anyOf):xc(e,t,[r])}function AI(e,t,r){return qe(r)?oe(e,t,r):$e(r)?T(e):Ne(r)?T(e):B()}function OI(e,t,r){return Mt(r)?T(e):oe(e,t,r)}function X(e,t,r){return $e(t)?nI(e,t,r):Y(t)?oI(e,t,t.items,r):At(t)?iI(e,t,r):ht(t)?sI(e,t,r):ke(t)?aI(e,t.parameters,t.instanceType,r):we(t)?mI(e,t.if,t.then,t.else,r):Ce(t)?uI(e,t.enum,r):Te(t)?cI(e,t.parameters,t.returnType,r):Je(t)?pI(e,t,r):F(t)?fI(e,t.allOf,r):V(t)?dI(e,t,r):St(t)?lI(e,t,r):Er(t)?gI(e,t,r):he(t)?yI(e,t,r):v(t)?hI(e,t.properties,r):ie(t)?II(e,_e(t),fe(t),r):Ge(t)?bI(e,t,r):Sr(t)?$I(e,t,r):ce(t)?EI(e,t.pattern,r):G(t)?wI(e,t.items,r):Yt(t)?CI(e,t,r):E(t)?PI(e,t.anyOf,r):Ne(t)?AI(e,t,r):Mt(t)?OI(e,t,r):B()}function bM(e,t){return Pe([...e,L(t)])}function hc(e,t,r){return K(e)?l.Update(bM(e,t),{},r):yi(e,t,r)}function MI(e,t,r,n,o){let i=_t(e,t,r),a=Ti(e,t,n);return hc(i,a,o)}function yi(e,t,r={}){return P("Interface",[e,t],r)}function xo(e){return xe(e)&&s.HasPropertyKey(e,"action")&&s.IsEqual(e.action,"Interface")}function vI(e,t,r={}){return hc(e,t,r)}function $M(e,t,r){return e.includes(r)?!0:wi([...e,r],t,t[r])}function FI(e,t,r){let n=na(r);return vn(e,t,n)}function vn(e,t,r){return s.ShiftLeft(r,(n,o)=>wi(e,t,n)?!0:vn(e,t,o),()=>!1)}function wi(e,t,r){return ne(r)?$M(e,t,r.$ref):Y(r)?wi(e,t,r.items):ke(r)?vn(e,t,[...r.parameters,r.instanceType]):Te(r)?vn(e,t,[...r.parameters,r.returnType]):xo(r)?FI(e,t,r.parameters[1]):F(r)?vn(e,t,r.allOf):v(r)?FI(e,t,r.properties):E(r)?vn(e,t,r.anyOf):G(r)?vn(e,t,r.items):ie(r)?wi(e,t,fe(r)):!1}function LI(e,t,r){return wi(e,t,r)}function EM(e,t){return t.reduce((r,n)=>LI([n],e,e[n])?[...r,n]:r,[])}function DI(e){let t=ra(e);return EM(e,t)}function SM(e,t,r){return r.includes(t)?r:t in e?Ci(e,e[t],[...r,t]):Se()}function jI(e,t,r){let n=na(t);return ho(e,n,r)}function ho(e,t,r){return t.reduce((n,o)=>Ci(e,o,n),r)}function Ci(e,t,r){return ne(t)?SM(e,t.$ref,r):Y(t)?Ci(e,t.items,r):ke(t)?ho(e,[...t.parameters,t.instanceType],r):Te(t)?ho(e,[...t.parameters,t.returnType],r):xo(t)?jI(e,t.parameters[1],r):F(t)?ho(e,t.allOf,r):v(t)?jI(e,t.properties,r):E(t)?ho(e,t.anyOf,r):G(t)?ho(e,t.items,r):ie(t)?Ci(e,fe(t),r):r}function NI(e,t,r){return Ci(e,r,[t])}function kM(e){return ro()}function TM(e){return s.Keys(e).reduce((t,r)=>({...t,[r]:Fn(e[r])}),{})}function Ri(e){return e.reduce((t,r)=>[...t,Fn(r)],[])}function Fn(e){return ne(e)?kM(e.$ref):Y(e)?Et(Fn(e.items),eo(e)):ke(e)?xr(Ri(e.parameters),Fn(e.instanceType)):Te(e)?hr(Ri(e.parameters),Fn(e.returnType)):F(e)?ut(Ri(e.allOf)):v(e)?L(TM(e.properties)):ie(e)?co(po(e),Fn(fe(e))):E(e)?q(Ri(e.anyOf)):G(e)?Re(Ri(e.items)):e}function wM(e,t){return t in e?Fn(e[t]):Be()}function qI(e){return wM(e.$defs,e.$ref)}function CM(e,t,r){let n=_t(e,le([],[]),t),o=Ti({},le([],[]),r);return Pe([...n,L(o)])}function RM(e,t){return s.Keys(e).filter(n=>t.includes(n)).reduce((n,o)=>{let i=e[o],a=xo(i)?CM(e,i.parameters[0],i.parameters[1]):i;return{...n,[o]:a}},{})}function _I(e,t,r){let n=NI(e,t,r),o=RM(e,n);return br(o,t)}function UI(e,t){return t in e?ne(e[t])?UI(e,e[t].$ref):e[t]:se()}function Tr(e,t){return UI(e,t)}function BI(e){return ue(e)?qI(e):oa(e)?Be():e}function at(e,t,r){let n=BI(t),o=BI(r);return X(e,n,o)}var pi=0,Pi=1,fi=2,di=3;function mo(e,t){let r=[at({},e,t),at({},t,e)];return j.IsExtendsTrueLike(r[0])&&j.IsExtendsTrueLike(r[1])?pi:j.IsExtendsTrueLike(r[0])&&j.IsExtendsFalse(r[1])?fi:j.IsExtendsFalse(r[0])&&j.IsExtendsTrueLike(r[1])?di:Pi}function Ic(e,t,r=[],n=t){return s.ShiftLeft(t,(o,i)=>{let a=mo(e,o);return s.IsEqual(a,fi)||s.IsEqual(a,pi)?n:s.IsEqual(a,Pi)?Ic(e,i,[...r,o],n):Ic(e,i,r,n)},()=>[...r,e])}function PM(e,t,r){let n=Jt(e);return $e(n)?[n]:Ne(n)?[n]:St(n)?tm(t,r):v(n)?tm(t,[...r,n]):tm(t,Ic(n,r))}function tm(e,t=[]){return s.ShiftLeft(e,(r,n)=>PM(r,n,t),()=>t)}function Qu(e){let t=tm(e);return an(t)}function bc(e,t){return l.Update(Jt(e),{},t)}function GI(e,t,r,n){let o=$(e,t,r);return bc(o,n)}function Ai(e,t=[]){return tn(e)&&s.IsEqual(e.action,"Conditional")?ne(e.parameters[0])?Ai(e.parameters[2],Ai(e.parameters[3],[...t,e.parameters[0].$ref])):Ai(e.parameters[2],Ai(e.parameters[3],t)):tn(e)&&s.IsEqual(e.action,"Mapped")&&tn(e.parameters[1])&&s.IsEqual(e.parameters[1].action,"KeyOf")&&ne(e.parameters[1].parameters[0])?[...t,e.parameters[1].parameters[0].$ref]:t}function AM(e,t){return e.reduce((r,n)=>[...r,t.includes(n.name)],[])}function zI(e,t,r=[]){return s.ShiftLeft(e,(n,o)=>s.ShiftLeft(t,(i,a)=>zI(o,a,[...r,[i,n]]),()=>r),()=>r)}function OM(e){return ce(e)?ct(e.pattern):Ce(e)?It(e.enum):e}function MM(e){let t=OM(e);return E(t)?[...t.anyOf]:[t]}function vM(e,t){return e.reduce((r,n)=>[...r,[...n,t]],[])}function KI(e,t){return t.reduce((r,n)=>[...r,...vM(e,n)],[])}function HI(e){return e.reduce((t,r)=>s.IsEqual(r[0],!0)?KI(t,MM(r[1])):KI(t,[r[1]]),[[]])}function WI(e,t,r){let n=Ai(r),o=AM(e,n),i=zI(t,o);return tn(r)&&s.IsEqual(r.action,"Conditional")||tn(r)&&s.IsEqual(r.action,"Mapped")?HI(i):[t]}function FM(){return["(not-resolvable)",se()]}function LM(){return["(not-generic)",se()]}function DM(e,t,r){return[e,rn(t,r)]}function jM(e,t,r){return t in e?VI(e,t,e[t],r):FM()}function VI(e,t,r,n){return to(r)?DM(t,r.parameters,r.expression):ne(r)?jM(e,r.$ref,n):LM()}function JI(e,t,r){return VI(e,"(anonymous)",t,r)}function NM(e,t,r){if(qe(t)||Io(t)||j.IsExtendsTrueLike(at({},t,r)))return;let n={parameter:e,expect:r,actual:t};throw new Error(`Argument for parameter ${e} does not satisfy constraint`,{cause:n})}function YI(e,t,r,n,o){let i=$(e,t,o);return NM(r,i,n),l.Assign(e,{[r]:i})}function qM(e,t,r,n,o){let i=$(e,t,r.extends),a=$(e,t,r.equals);return s.ShiftLeft(o,(m,c)=>$c(YI(e,t,r.name,i,m),t,n,c),()=>$c(YI(e,t,r.name,i,a),t,n,[]))}function $c(e,t,r,n){return s.ShiftLeft(r,(o,i)=>qM(e,t,o,i,n),()=>e)}function QI(e,t,r,n){return $c(e,t,r,n)}var Ec=0,Sc=0;function _M(){if(!s.IsLessThan(Sc,De.Get().maxInstantiationCount))throw Error("Type instantiation is excessively deep and possibly infinite")}function UM(){_M(),Sc++,Ec++}function BM(){Ec--,s.IsEqual(Ec,0)&&(Sc=0)}function GM(e){return s.IsGreaterThan(e.callstack.length,0)?e.callstack[e.callstack.length-1]:""}function KM(e,t){return s.IsEqual(GM(e),t)}function HM(e,t,r,n,o,i){UM();try{let a=QI(e,t,n,i),m=$(a,le([...t.callstack,r.$ref],t.visited),o);return $(a,le([],[]),m)}finally{BM()}}function zM(e,t,r,n,o,i){return i.reduce((a,m)=>{let c=HM(e,t,r,n,o,m);return[...a,c]},[])}function WM(e,t,r,n,o,i){let a=WI(n,i,o),m=zM(e,t,r,n,o,a);return s.IsEqual(m.length,1)?m[0]:Tt(m)}function rm(e,t,r,n){let o=_t(e,t,n),i=JI(e,r,n),a=i[0],m=i[1];return to(m)?KM(t,a)?xi(ze(a),o):WM(e,t,ze(a),m.parameters,m.expression,o):xi(r,o)}function xi(e,t){return l.Create({"~kind":"Call"},{type:"call",target:e,arguments:t},{})}function XI(e,t){return rm({},le([],[]),e,t)}function Io(e){return C(e,"Call")}function VM(e){return l.Discard(e,["~immutable"])}function ZI(e,t){return l.Update(VM(e),{},t)}function eb(e,t,r,n){let o=$(e,t,r);return ZI(o,n)}function tb(e,t){return e(t)}function rb(e,t){return s.IsString(t)?z(tb(e,t)):z(t)}function nb(e,t){let r=ct(t);return qr(e,r)}function ob(e,t){let r=t.map(n=>qr(e,n));return q(r)}function qr(e,t){return V(t)?rb(e,t.const):ce(t)?nb(e,t.pattern):E(t)?ob(e,t.anyOf):t}function ka(e,t={}){return P("Capitalize",[e],t)}function ib(e,t={}){return kc(e,t)}function Ta(e,t={}){return P("Lowercase",[e],t)}function sb(e,t={}){return Tc(e,t)}function wa(e,t={}){return P("Uncapitalize",[e],t)}function ab(e,t={}){return wc(e,t)}function Ca(e,t={}){return P("Uppercase",[e],t)}function mb(e,t={}){return Cc(e,t)}var JM=e=>e[0].toUpperCase()+e.slice(1),YM=e=>e.toLowerCase(),QM=e=>e[0].toLowerCase()+e.slice(1),XM=e=>e.toUpperCase();function kc(e,t){return K([e])?l.Update(qr(JM,e),{},t):ka(e,t)}function Tc(e,t){return K([e])?l.Update(qr(YM,e),{},t):Ta(e,t)}function wc(e,t){return K([e])?l.Update(qr(QM,e),{},t):wa(e,t)}function Cc(e,t){return K([e])?l.Update(qr(XM,e),{},t):Ca(e,t)}function ub(e,t,r,n){let o=$(e,t,r);return kc(o,n)}function cb(e,t,r,n){let o=$(e,t,r);return Tc(o,n)}function pb(e,t,r,n){let o=$(e,t,r);return wc(o,n)}function fb(e,t,r,n){let o=$(e,t,r);return Cc(o,n)}function Ra(e,t,r,n,o={}){return P("Conditional",[e,t,r,n],o)}function db(e,t,r,n,o={}){return Rc({},le([],[]),e,t,r,n,o)}function ZM(e,t,r,n,o,i){let a=at(e,r,n);return j.IsExtendsUnion(a)?q([$(a.inferred,t,o),$(e,t,i)]):j.IsExtendsTrue(a)?$(a.inferred,t,o):$(e,t,i)}function Rc(e,t,r,n,o,i,a){return K([r,n])?l.Update(ZM(e,t,r,n,o,i),{},a):Ra(r,n,o,i,a)}function lb(e,t,r,n,o,i,a){let m=$(e,t,r),c=$(e,t,n);return Rc(e,t,m,c,o,i,a)}function Pa(e,t={}){return P("ConstructorParameters",[e],t)}function gb(e,t={}){return Pc(e,t)}function ev(e){let t=ke(e)?e.parameters:[],r=fn({},le([],[]),t);return Re(r)}function Pc(e,t){return K([e])?l.Update(ev(e),{},t):Pa(e,t)}function yb(e,t,r,n){let o=$(e,t,r);return Pc(o,n)}function Aa(e,t,r={}){return P("Exclude",[e,t],r)}function xb(e,t,r={}){return Oi(e,t,r)}function Oi(e,t,r){return K([e,t])?l.Update(xa(e,t),{},r):Aa(e,t,r)}function hb(e,t,r,n,o){let i=$(e,t,r),a=$(e,t,n);return Oi(i,a,o)}function Oa(e,t,r={}){return P("Extract",[e,t],r)}function Ib(e,t,r={}){return Ac(e,t,r)}function tv(e,t){let r=at({},e,t);return j.IsExtendsTrueLike(r)?[e]:[]}function bb(e,t,r=[]){return s.ShiftLeft(e,(n,o)=>bb(o,t,[...r,...tv(n,t)]),()=>r)}function $b(e,t){let r=Jt(e),n=E(r)?r.anyOf:[r],o=bb(n,t);return Tt(o)}function Ac(e,t,r){return K([e,t])?l.Update($b(e,t),{},r):Oa(e,t,r)}function Eb(e,t,r,n,o){let i=$(e,t,r),a=$(e,t,n);return Ac(i,a,o)}function rv(e){return e.reduce((t,r)=>ua(r)?[...t,z(r)]:t,[])}function bo(e){let t=rv(e);return q(t)}function hi(e,t,r={}){return P("Index",[e,t],r)}function Sb(e,t,r={}){let n=s.IsArray(t)?bo(t):t;return Oc(e,n,r)}function kb(e,t){let r=Tr(e,t);return Ut(r)}function Tb(e,t,r){let n=sr(e,t,r);return Ut(n)}function nv(e,t){let r=s.Keys(e).filter(f=>!s.HasPropertyKey(t,f)),n=s.Keys(t).filter(f=>!s.HasPropertyKey(e,f)),o=s.Keys(e).filter(f=>s.HasPropertyKey(t,f)),i=r.reduce((f,d)=>({...f,[d]:e[d]}),{}),a=n.reduce((f,d)=>({...f,[d]:t[d]}),{}),m=o.reduce((f,d)=>({...f,[d]:ya(e[d],t[d])}),{}),c=l.Assign(i,a);return l.Assign(c,m)}function wb(e){return e.reduce((t,r)=>nv(t,Ut(r)),{})}function Cb(e){let t=kg(Re(e));return Ut(t)}function ov(e,t){return s.Keys(e).filter(o=>o in t).reduce((o,i)=>({...o,[i]:Cg(e[i],t[i])}),{})}function Rb(e,t){return s.ShiftLeft(e,(r,n)=>Rb(n,ov(t,Ut(r))),()=>t)}function Pb(e){return s.ShiftLeft(e,(t,r)=>Rb(r,Ut(t)),()=>Se())}function Ut(e){return ue(e)?kb(e.$defs,e.$ref):we(e)?Tb(e.if,e.then,e.else):F(e)?wb(e.allOf):E(e)?Pb(e.anyOf):G(e)?Cb(e.items):v(e)?e.properties:{}}function $o(e){let t=Ut(e);return L(t)}var iv=new RegExp("^(?:0|[1-9][0-9]*)$");function Eo(e){let t=`${e}`;return iv.test(t)?parseInt(t):e}function sv(e){return z(Eo(e))}function Ab(e){return e.map(t=>Ob(t))}function Ob(e){return F(e)?ut(Ab(e.allOf)):E(e)?q(Ab(e.anyOf)):V(e)?sv(e.const):e}function Mb(e,t){let r=Ob(t),n=at({},r,Ot());return j.IsExtendsTrueLike(n)?e:V(t)&&s.IsEqual(t.const,"length")?Ot():se()}function vb(e,t){let r=Tr(e,t);return vt(r)}function Fb(e,t,r){let n=sr(e,t,r);return vt(n)}function Lb(e){let t=It(e);return vt(t)}function Db(e){let t=Pe(e);return vt(t)}function jb(e){return[`${e}`]}function Nb(e){let t=ct(e);return vt(t)}function qb(e){return e.reduce((t,r)=>[...t,...vt(r)],[])}function vt(e){return ue(e)?vb(e.$defs,e.$ref):we(e)?Fb(e.if,e.then,e.else):Ce(e)?Lb(e.enum):F(e)?Db(e.allOf):V(e)?jb(e.const):ce(e)?Nb(e.pattern):E(e)?qb(e.anyOf):[]}function So(e){return vt(e)}function Mi(e,t){return t.map(r=>vi(e,r))}function vi(e,t){return Y(t)?Et(vi(e,t.items)):ke(t)?xr(Mi(e,t.parameters),vi(e,t.instanceType)):Te(t)?hr(Mi(e,t.parameters),vi(e,t.returnType)):G(t)?Re(Mi(e,t.items)):E(t)?q(Mi(e,t.anyOf)):F(t)?ut(Mi(e,t.allOf)):$a(t)?L(e):t}function _b(e,t){return vi(e,t)}function av(e,t){let r=t in e?e[t]:se();return _b(e,r)}function Ub(e,t){return t.reduce((r,n)=>[...r,av(e,n)],[])}function mv(e,t){let r=So(t),n=Ub(e,r);return Tt(n)}var uv=new RegExp(sn);function cv(e){return e.filter(r=>uv.test(r))}function pv(e){let t=ra(e),r=cv(t),n=Ub(e,r);return Tt(n)}function Bb(e,t){return he(t)?pv(e):mv(e,t)}function fv(e){return z(Eo(e))}function Gb(e){return e.map(t=>Mc(t))}function Mc(e){return F(e)?ut(Gb(e.allOf)):E(e)?q(Gb(e.anyOf)):V(e)?fv(e.const):e}function dv(e,t){return e.reduceRight((r,n,o)=>{let i=at({},z(o),t);return j.IsExtendsTrueLike(i)?[n,...r]:r},[])}function lv(e,t){let r=Mc(t),n=dv(e,r);return nn(n)}function gv(e){return nn(e)}function Kb(e,t){return V(t)&&s.IsEqual(t.const,"length")?z(e.length):he(t)||Je(t)?gv(e):lv(e,t)}function Hb(e,t){return Y(e)?Mb(e.items,t):v(e)?Bb(e.properties,t):G(e)?Kb(e.items,t):se()}function yv(e){return ue(e)||we(e)||F(e)||E(e)?$o(e):e}function Oc(e,t,r){return K([e,t])?l.Update(Hb(yv(e),t),{},r):hi(e,t,r)}function zb(e,t,r,n,o){let i=$(e,t,r),a=$(e,t,n);return Oc(i,a,o)}function Ma(e,t={}){return P("InstanceType",[e],t)}function Wb(e,t={}){return vc(e,t)}function xv(e){return ke(e)?e.instanceType:se()}function vc(e,t){return K([e])?l.Update(xv(e),{},t):Ma(e,t)}function Vb(e,t,r,n={}){let o=$(e,t,r);return vc(o,n)}function Ii(e,t={}){return P("KeyOf",[e],t)}function Jb(e,t={}){return Fc(e,t)}function Yb(){return q([Ot(),st(),io()])}function Qb(e){return Ot()}function hv(e){return e.reduce((r,n)=>ua(n)?[...r,z(Eo(n))]:Se(),[])}function Xb(e){let t=s.Keys(e),r=hv(t);return nn(r)}function Zb(e){return po(e)}function e$(e){let t=e.map((r,n)=>z(n));return nn(t)}function t$(e){return $e(e)?Yb():Y(e)?Qb(e.items):v(e)?Xb(e.properties):ie(e)?Zb(e):G(e)?e$(e.items):se()}function Iv(e){return ue(e)||we(e)||F(e)||E(e)?$o(e):e}function Fc(e,t){return K([e])?l.Update(t$(Iv(e)),{},t):Ii(e,t)}function r$(e,t,r,n){let o=$(e,t,r);return Fc(o,n)}function gi(e,t,r,n,o={}){return P("Mapped",[e,t,r,n],o)}function n$(e,t,r,n,o={}){return Lc({},le([],[]),e,t,r,n,o)}function bv(e){let t=ct(e);return nm(t)}function $v(e){return e.reduce((t,r)=>[...t,...nm(r)],[])}function Ev(e){let t=It(e);return nm(t)}function Sv(e){return s.IsNumber(e)?[z(`${e}`)]:[z(e)]}function nm(e){return Ce(e)?Ev(e.enum):V(e)?Sv(e.const):ce(e)?bv(e.pattern):E(e)?$v(e.anyOf):[e]}function o$(e){return nm(e)}function kv(e){return ce(e)?ct(e.pattern):e}function Tv(e,t,r,n,o,i){let a=l.Assign(e,{[r.name]:n}),m=$(a,t,o),c=kv(m),p=$(a,t,i);return ca(c)||pa(c)?{[c.const]:p}:{}}function wv(e,t,r,n,o,i){return n.reduce((a,m)=>[...a,Tv(e,t,r,m,o,i)],[])}function Cv(e){return e.reduce((t,r)=>[...t,L(r)],[])}function i$(e,t,r,n,o,i){let a=o$(n),m=wv(e,t,r,a,o,i),c=Cv(m);return Pe(c)}function Lc(e,t,r,n,o,i,a){return K([n])?l.Update(i$(e,t,r,n,o,i),{},a):gi(r,n,o,i,a)}function s$(e,t,r,n,o,i,a){let m=$(e,t,n);return Lc(e,t,r,m,o,i,a)}function Rv(e,t,r){let n=l.Assign(e,t);return s.Keys(t).filter(i=>r.includes(i)).reduce((i,a)=>({...i,[a]:_I(n,a,t[a])}),{})}function Pv(e,t,r){let n=l.Assign(e,t);return s.Keys(t).filter(i=>!r.includes(i)).reduce((i,a)=>({...i,[a]:$(n,le([],[]),t[a])}),{})}function Av(e,t,r){let n=DI(t),o=Rv(e,t,n),i=Pv(e,t,n),a={...o,...i};return l.Update(a,{},r)}function om(e,t,r,n){return Av(e,r,n)}function va(e,t={}){return P("NonNullable",[e],t)}function a$(e,t={}){return Dc(e,t)}function Ov(e){let t=q([oo(),fo()]);return Oi(e,t,{})}function Dc(e,t){return K([e])?l.Update(Ov(e),{},t):va(e,t)}function m$(e,t,r,n){let o=$(e,t,r);return Dc(o,n)}function Fa(e,t,r={}){return P("Omit",[e,t],r)}function u$(e,t,r={}){let n=s.IsArray(t)?bo(t):t;return jc(e,n,r)}function im(e){let t=$o(e);return v(t)?t.properties:Se()}function Mv(e,t){return s.Keys(e).reduce((n,o)=>t.includes(o)?n:{...n,[o]:e[o]},{})}function c$(e,t){let r=im(e),n=So(t),o=Mv(r,n);return L(o)}function jc(e,t,r){return K([e,t])?l.Update(c$(e,t),{},r):Fa(e,t,r)}function p$(e,t,r,n,o){let i=$(e,t,r),a=$(e,t,n);return jc(i,a,o)}function La(e,t={}){return P("Parameters",[e],t)}function f$(e,t={}){return Nc(e,t)}function vv(e){let t=Te(e)?e.parameters:[],r=fn({},le([],[]),t);return Re(r)}function Nc(e,t){return K([e])?l.Update(vv(e),{},t):La(e,t)}function d$(e,t,r,n){let o=$(e,t,r);return Nc(o,n)}function Da(e,t={}){return P("Partial",[e],t)}function l$(e,t={}){return qc(e,t)}function g$(e,t){let r=Tr(e,t),n=wr(r);return br(l.Assign(e,{[t]:n}),t)}function y$(e,t,r){let n=sr(e,t,r);return wr(n)}function x$(e){let t=Pe(e);return wr(t)}function h$(e){let t=e.map(r=>wr(r));return q(t)}function I$(e){let t=s.Keys(e).reduce((n,o)=>({...n,[o]:ta(e[o])}),{});return L(t)}function wr(e){return ue(e)?g$(e.$defs,e.$ref):we(e)?y$(e.if,e.then,e.else):F(e)?x$(e.allOf):E(e)?h$(e.anyOf):v(e)?I$(e.properties):L({})}function qc(e,t){return K([e])?l.Update(wr(e),{},t):Da(e,t)}function b$(e,t,r,n){let o=$(e,t,r);return qc(o,n)}function ja(e,t,r={}){return P("Pick",[e,t],r)}function $$(e,t,r={}){let n=s.IsArray(t)?bo(t):t;return _c(e,n,r)}function Fv(e,t){return s.Keys(e).reduce((n,o)=>t.includes(o)?l.Assign(n,{[o]:e[o]}):n,{})}function E$(e,t){let r=im(e),n=So(t),o=Fv(r,n);return L(o)}function _c(e,t,r){return K([e,t])?l.Update(E$(e,t),{},r):ja(e,t,r)}function S$(e,t,r,n,o){let i=$(e,t,r),a=$(e,t,n);return _c(i,a,o)}function Na(e,t={}){return P("ReadonlyObject",[e],t)}function Uc(e,t={}){return Bc(e,t)}var k$=Uc;function T$(e){return no(Et(e))}function w$(e,t){let r=Tr(e,t),n=Cr(r);return br(l.Assign(e,{[t]:n}),t)}function C$(e,t,r){let n=sr(e,t,r);return Cr(n)}function R$(e){let t=Pe(e);return Cr(t)}function P$(e){let t=s.Keys(e).reduce((n,o)=>({...n,[o]:sa(e[o])}),{});return L(t)}function A$(e){return no(Re(e))}function O$(e){let t=e.map(r=>Cr(r));return q(t)}function Cr(e){return Y(e)?T$(e.items):ue(e)?w$(e.$defs,e.$ref):we(e)?C$(e.if,e.then,e.else):F(e)?R$(e.allOf):v(e)?P$(e.properties):G(e)?A$(e.items):E(e)?O$(e.anyOf):e}function Bc(e,t){return K([e])?l.Update(Cr(e),{},t):Na(e)}function M$(e,t,r,n){let o=$(e,t,r);return Bc(o,n)}function v$(e,t,r,n){return t.visited.includes(n)?r:n in e?$(e,le(t.callstack,[...t.visited,n]),e[n]):r}function F$(e,t){let r=Tr(e,t),n=Rr(r);return br(l.Assign(e,{[t]:n}),t)}function L$(e,t,r){let n=sr(e,t,r);return Rr(n)}function D$(e){let t=Pe(e);return Rr(t)}function j$(e){let t=e.map(r=>Rr(r));return q(t)}function Kx(e,t={}){return P("RemoveOptional",[e],t)}function N$(e,t={}){return An(e,t)}function q$(e){let t=s.Keys(e).reduce((n,o)=>({...n,[o]:N$(e[o])}),{});return L(t)}function Rr(e){return ue(e)?F$(e.$defs,e.$ref):we(e)?L$(e.if,e.then,e.else):F(e)?D$(e.allOf):E(e)?j$(e.anyOf):v(e)?q$(e.properties):L({})}function qa(e,t={}){return P("Required",[e],t)}function _$(e,t={}){return Gc(e,t)}function Gc(e,t){return K([e])?l.Update(Rr(e),{},t):qa(e,t)}function U$(e,t,r,n){let o=$(e,t,r);return Gc(o,n)}function _a(e,t={}){return P("ReturnType",[e],t)}function B$(e,t={}){return Kc(e,t)}function Lv(e){return Te(e)?e.returnType:se()}function Kc(e,t){return K([e])?l.Update(Lv(e),{},t):_a(e,t)}function G$(e,t,r,n={}){let o=$(e,t,r);return Kc(o,n)}function Ua(e,t){return P("With",[e,t],{})}function sm(e,t){return Hc(e,t)}function Hc(e,t){return K([e])?l.Update(e,{},t):Ua(e,t)}function K$(e,t,r,n){let o=$(e,t,r);return Hc(o,n)}function Dv(e){return mn(e)?G(e.items)?zc(e.items.items):qe(e.items)?[e]:ne(e.items)?[e]:[se()]:[e]}function zc(e){return e.reduce((r,n)=>[...r,...Dv(n)],[])}function le(e,t){return{callstack:e,visited:t}}function K(e){return s.ShiftLeft(e,(t,r)=>ne(t)?!1:K(r),()=>!0)}function Ti(e,t,r){return s.Keys(r).reduce((n,o)=>({...n,[o]:$(e,t,r[o])}),{})}function fn(e,t,r){let n=_t(e,t,r);return zc(n)}function _t(e,t,r){return r.map(n=>$(e,t,n))}function jv(e,t){let r=je(e)?yr(t,{}):t,n=jr(e)?gr(r,{}):r;return Cn(e)?Fi(n,{}):n}function Nv(e,t,r,n,o){return s.IsEqual(r,"AddImmutable")?H$(e,t,n[0],o):s.IsEqual(r,"RemoveImmutable")?eb(e,t,n[0],o):s.IsEqual(r,"AddReadonly")?Bl(e,t,n[0],o):s.IsEqual(r,"RemoveReadonly")?wg(e,t,n[0],o):s.IsEqual(r,"AddOptional")?Gl(e,t,n[0],o):s.IsEqual(r,"RemoveOptional")?Tg(e,t,n[0],o):s.IsEqual(r,"Capitalize")?ub(e,t,n[0],o):s.IsEqual(r,"Conditional")?lb(e,t,n[0],n[1],n[2],n[3],o):s.IsEqual(r,"ConstructorParameters")?yb(e,t,n[0],o):s.IsEqual(r,"Evaluate")?GI(e,t,n[0],o):s.IsEqual(r,"Exclude")?hb(e,t,n[0],n[1],o):s.IsEqual(r,"Extract")?Eb(e,t,n[0],n[1],o):s.IsEqual(r,"Index")?zb(e,t,n[0],n[1],o):s.IsEqual(r,"InstanceType")?Vb(e,t,n[0],o):s.IsEqual(r,"Interface")?MI(e,t,n[0],n[1],o):s.IsEqual(r,"KeyOf")?r$(e,t,n[0],o):s.IsEqual(r,"Lowercase")?cb(e,t,n[0],o):s.IsEqual(r,"Mapped")?s$(e,t,n[0],n[1],n[2],n[3],o):s.IsEqual(r,"Module")?om(e,t,n[0],o):s.IsEqual(r,"NonNullable")?m$(e,t,n[0],o):s.IsEqual(r,"Pick")?S$(e,t,n[0],n[1],o):s.IsEqual(r,"Parameters")?d$(e,t,n[0],o):s.IsEqual(r,"Partial")?b$(e,t,n[0],o):s.IsEqual(r,"Omit")?p$(e,t,n[0],n[1],o):s.IsEqual(r,"ReadonlyObject")?M$(e,t,n[0],o):s.IsEqual(r,"Record")?Gg(e,t,n[0],n[1],o):s.IsEqual(r,"Required")?U$(e,t,n[0],o):s.IsEqual(r,"ReturnType")?G$(e,t,n[0],o):s.IsEqual(r,"TemplateLiteral")?Yh(e,t,n[0],o):s.IsEqual(r,"Uncapitalize")?pb(e,t,n[0],o):s.IsEqual(r,"Uppercase")?fb(e,t,n[0],o):s.IsEqual(r,"With")?K$(e,t,n[0],n[1]):P(r,n,o)}function qv(e,t,r){let n=ne(r)?v$(e,t,r,r.$ref):Y(r)?Et($(e,t,r.items),eo(r)):Io(r)?rm(e,t,r.target,r.arguments):ke(r)?xr(_t(e,t,r.parameters),$(e,t,r.instanceType),Kl(r)):Te(r)?hr(_t(e,t,r.parameters),$(e,t,r.returnType),Hl(r)):we(r)?wn($(e,t,r.if),$(e,t,r.then),$(e,t,r.else),Ql(r)):F(r)?ut(_t(e,t,r.allOf),rg(r)):v(r)?L(Ti(e,t,r.properties),Jl(r)):ie(r)?Kg(_e(r),$(e,t,fe(r))):mn(r)?On($(e,t,r.items)):G(r)?Re(fn(e,t,r.items),Sg(r)):E(r)?q(_t(e,t,r.anyOf),dg(r)):r;return jv(r,n)}function $(e,t,r){return tn(r)?Nv(e,t,r.action,r.parameters,r.options):qv(e,t,r)}function Bt(e,t){return $(e,le([],[]),t)}function Fi(e,t){return l.Update(e,{"~immutable":!0},t)}function H$(e,t,r,n){let o=$(e,t,r);return Fi(o,n)}function Hx(e,t={}){return P("AddImmutable",[e],t)}function no(e,t={}){return Fi(e,t)}function zx(e,t={}){return P("RemoveReadonly",[e],t)}function Wx(e,t={}){return P("Evaluate",[e],t)}function Ye(e,t={}){return bc(e,t)}function Vx(e,t={}){return P("Module",[e],t)}function z$(e,t={}){return om({},le([],[]),e,t)}function _v(e,t){let r=mo(e,t);return s.IsEqual(r,di)||s.IsEqual(r,Pi)?1:0}function W$(e,t,r=[]){return s.ShiftLeft(t,(n,o)=>s.IsEqual(_v(e,n),1)?W$(e,o,[...r,n]):[...r,e,...t],()=>[...r,e])}function V$(e,t=[]){return s.ShiftLeft(e,(r,n)=>V$(n,W$(r,t)),()=>t)}function J$(e){return V$(e)}function Y$(...e){let[t,r,n]=H.Match(e,{2:(a,m)=>s.IsString(a)?[{},a,m]:[a,m,{}],3:(a,m,c)=>[a,m,c],1:a=>[{},a,{}]}),o=Hh(r),i=s.IsArray(o)&&s.IsEqual(o.length,2)?$(t,le([],[]),o[0]):se();return l.Update(i,{},n)}function Q$(e,t,r){return s.IsArray(r)?r.map(n=>Qe(e,t.items,n)):r}function X$(e,t,r){return Qe({...e,...t.$defs},ze(t.$ref),r)}function Uv(e,t){let r=s.HasPropertyKey(t,"unevaluatedProperties")?{additionalProperties:t.unevaluatedProperties}:{},n=Bt(e,t),o=Ye(n);return v(o)?sm(o,r):o}function Z$(e,t,r){let n=Uv(e,t);return Qe(e,n,r)}function am(e){return s.HasPropertyKey(e,"additionalProperties")?e.additionalProperties:void 0}function eE(e,t,r){if(!s.IsObject(r)||s.IsArray(r))return r;let n=am(t);for(let o of s.Keys(r)){if(s.HasPropertyKey(t.properties,o)&&xe(t.properties[o])){r[o]=Qe(e,t.properties[o],r[o]);continue}if(s.IsBoolean(n)&&s.IsEqual(n,!0)||xe(n)&&W(e,n,r[o])){r[o]=Qe(e,n,r[o]);continue}delete r[o]}return r}function tE(e,t,r){if(!s.IsObject(r))return r;let n=am(t),[o,i]=[new RegExp(_e(t)),fe(t)];for(let a of s.Keys(r)){if(o.test(a)){r[a]=Qe(e,i,r[a]);continue}if(s.IsBoolean(n)&&s.IsEqual(n,!0)||xe(n)&&W(e,n,r[a])){r[a]=Qe(e,n,r[a]);continue}delete r[a]}return r}function rE(e,t,r){return s.HasPropertyKey(e,t.$ref)?Qe(e,e[t.$ref],r):r}function nE(e,t,r){if(!s.IsArray(r))return r;let n=Math.min(r.length,t.items.length);for(let o=0;o<n;o++)r[o]=Qe(e,t.items[o],r[o]);return s.IsGreaterThan(r.length,n)?r.slice(0,n):r}function Bv(e){return s.HasPropertyKey(e,"~kind")||s.HasPropertyKey(e,"~unsafe")}function Gv(e){let t={};for(let r of s.Keys(e)){if(s.IsUnsafePropertyKey(r))continue;let n=Object.getOwnPropertyDescriptor(e,r);n.value=Dn(n.value),s.IsEqual(n.enumerable,!0)?t[r]=n.value:Object.defineProperty(t,r,n)}return t}function Kv(e){let t={};for(let r of s.Keys(e))s.IsUnsafePropertyKey(r)||(t[r]=Dn(e[r]));for(let r of s.Symbols(e))t[r]=Dn(e[r]);return t}function Hv(e){return s.IsClassInstance(e)?e:Bv(e)?Gv(e):Kv(e)}function zv(e){return e.map(t=>Dn(t))}function Wv(e){return e.slice()}function Vv(e){return new RegExp(e.source,e.flags)}function Jv(e){return new Map(Dn([...e.entries()]))}function Yv(e){return new Set(Dn([...e.values()]))}function Dn(e){return Ue.IsTypeArray(e)?Wv(e):Ue.IsRegExp(e)?Vv(e):Ue.IsMap(e)?Jv(e):Ue.IsSet(e)?Yv(e):s.IsArray(e)?zv(e):s.IsObject(e)?Hv(e):e}function oE(e){return Dn(e)}function de(e){return oE(e)}function iE(e,t,r){for(let n of t.anyOf){let o=Qe(e,n,de(r));if(W(e,n,o))return o}return r}function Qe(e,t,r){return Y(t)?Q$(e,t,r):ue(t)?X$(e,t,r):F(t)?Z$(e,t,r):v(t)?eE(e,t,r):ie(t)?tE(e,t,r):ne(t)?rE(e,t,r):G(t)?nE(e,t,r):E(t)?iE(e,t,r):r}function Qv(e,t){return l.Assign(e,t)}function Xv(e){let t={};for(let r of Tf.Keys(e))t[r]=Li(e[r]);return t}function Zv(e){return st({pattern:_e(e)})}function eF(e){return Wc(J$(e))}function Wc(e){return e.map(t=>Li(t))}function Li(e){let t=Y(e)?Et(Li(e.items),eo(e)):F(e)?ut(Wc(e.allOf)):E(e)?q(eF(e.anyOf)):v(e)?L(Xv(e.properties)):ie(e)?co(Zv(e),Li(fe(e))):G(e)?Re(Wc(e.items)):e;return Qv(e,t)}function ko(e){return Li(e)}function ar(...e){let[t,r,n]=H.Match(e,{3:(i,a,m)=>[i,a,m],2:(i,a)=>[{},i,a]}),o=De.Get().unionPrioritySort?ko(r):r;return Qe(t,o,n)}var re={};Dt(re,{Fail:()=>jn,IsOk:()=>Vc,Ok:()=>M,TryArray:()=>tF,TryBigInt:()=>Jc,TryBoolean:()=>dF,TryNull:()=>hF,TryNumber:()=>EF,TryString:()=>SF,TryUndefined:()=>RF});function Vc(e){return s.IsObject(e)&&s.HasPropertyKey(e,"value")}function M(e){return{value:e}}function jn(){}function tF(e){return s.IsArray(e)?M(e):M([e])}function rF(e){return s.IsEqual(e,!0)?M(BigInt(1)):M(BigInt(0))}var nF=/^-?(0|[1-9]\d*)n$/,oF=/^-?(0|[1-9]\d*)\.\d+$/,iF=/^-?(0|[1-9]\d*)$/;function sF(e){return nF.test(e)}function aF(e){return oF.test(e)}function mF(e){return iF.test(e)}function uF(e){let t=e.toLowerCase();return sF(e)?M(BigInt(e.slice(0,e.length-1))):aF(e)?M(BigInt(e.split(".")[0])):mF(e)?M(BigInt(e)):s.IsEqual(t,"false")?M(BigInt(0)):s.IsEqual(t,"true")?M(BigInt(1)):void 0}function Jc(e){return s.IsBigInt(e)?M(e):s.IsBoolean(e)?rF(e):s.IsNumber(e)?M(BigInt(Math.trunc(e))):s.IsNull(e)?M(BigInt(0)):s.IsString(e)?uF(e):s.IsUndefined(e)?M(BigInt(0)):void 0}function cF(e){return s.IsEqual(e,BigInt(0))?M(!1):s.IsEqual(e,BigInt(1))?M(!0):void 0}function pF(e){return s.IsEqual(e,0)?M(!1):s.IsEqual(e,1)?M(!0):void 0}function fF(e){return s.IsEqual(e.toLowerCase(),"false")?M(!1):s.IsEqual(e.toLowerCase(),"true")?M(!0):s.IsEqual(e,"0")?M(!1):s.IsEqual(e,"1")?M(!0):void 0}function dF(e){return s.IsBigInt(e)?cF(e):s.IsBoolean(e)?M(e):s.IsNumber(e)?pF(e):s.IsNull(e)?M(!1):s.IsString(e)?fF(e):s.IsUndefined(e)?M(!1):void 0}function lF(e){return s.IsEqual(e,BigInt(0))?M(null):void 0}function gF(e){return s.IsEqual(e,!1)?M(null):void 0}function yF(e){return s.IsEqual(e,0)?M(null):void 0}function xF(e){let t=e.toLowerCase();return s.IsEqual(t,"undefined")||s.IsEqual(t,"null")||s.IsEqual(e,"")||s.IsEqual(e,"0")?M(null):void 0}function hF(e){return s.IsBigInt(e)?lF(e):s.IsBoolean(e)?gF(e):s.IsNumber(e)?yF(e):s.IsNull(e)?M(null):s.IsString(e)?xF(e):s.IsUndefined(e)?M(null):void 0}var sE=BigInt(Number.MAX_SAFE_INTEGER),aE=BigInt(Number.MIN_SAFE_INTEGER);function IF(e){return e<=sE&&e>=aE?M(Number(e)):void 0}function bF(e){return M(e?1:0)}function $F(e){let t=+e;if(s.IsNumber(t))return M(t);let r=e.toLowerCase();if(s.IsEqual(r,"false"))return M(0);if(s.IsEqual(r,"true"))return M(1);let n=Jc(e);return Vc(n)?n.value<=sE&&n.value>=aE?M(Number(n.value)):void 0:void 0}function EF(e){return s.IsBigInt(e)?IF(e):s.IsBoolean(e)?bF(e):s.IsNumber(e)?M(e):s.IsNull(e)?M(0):s.IsString(e)?$F(e):s.IsUndefined(e)?M(0):void 0}function SF(e){return s.IsBigInt(e)?M(e.toString()):s.IsBoolean(e)?M(e.toString()):s.IsNumber(e)?M(e.toString()):s.IsNull(e)?M("null"):s.IsString(e)?M(e):s.IsUndefined(e)?M(""):void 0}function kF(e){return s.IsEqual(e,BigInt(0))?M(void 0):void 0}function TF(e){return s.IsEqual(e,!1)?M(void 0):void 0}function wF(e){return s.IsEqual(e,0)?M(void 0):void 0}function CF(e){let t=e.toLowerCase();return s.IsEqual(t,"undefined")||s.IsEqual(t,"null")||s.IsEqual(e,"")||s.IsEqual(e,"0")?M(void 0):void 0}function RF(e){return s.IsBigInt(e)?kF(e):s.IsBoolean(e)?TF(e):s.IsNumber(e)?wF(e):s.IsNull(e)?M(void 0):s.IsString(e)?CF(e):s.IsUndefined(e)?M(e):void 0}function mE(e,t,r){return re.TryArray(r).value.map(o=>Me(e,t.items,o))}function uE(e,t,r){let n=re.TryBigInt(r);return re.IsOk(n)?n.value:r}function cE(e,t,r){let n=re.TryBoolean(r);return re.IsOk(n)?n.value:r}function pE(e,t,r){return Me({...e,...t.$defs},ze(t.$ref),r)}function fE(e,t,r){return Me(e,Ye(t),r)}function dE(e,t,r){let n=re.TryNumber(r);return re.IsOk(n)?Math.trunc(n.value):r}function lE(e,t,r){let n=Bt(e,t),o=Ye(n);return Me(e,o,r)}function PF(e,t,r){let n=re.TryBigInt(r);return re.IsOk(n)&&s.IsEqual(t.const,n.value)?n.value:r}function AF(e,t,r){let n=re.TryBoolean(r);return re.IsOk(n)&&s.IsEqual(t.const,n.value)?n.value:r}function OF(e,t,r){let n=re.TryNumber(r);return re.IsOk(n)&&s.IsEqual(t.const,n.value)?n.value:r}function MF(e,t,r){let n=re.TryString(r);return re.IsOk(n)&&s.IsEqual(t.const,n.value)?n.value:r}function gE(e,t,r){return s.IsEqual(t.const,r)?r:cg(t)?PF(e,t,r):pg(t)?AF(e,t,r):ca(t)?OF(e,t,r):pa(t)?MF(e,t,r):Se()}function yE(e,t,r){let n=re.TryNull(r);return re.IsOk(n)?n.value:r}function xE(e,t,r){let n=re.TryNumber(r);return re.IsOk(n)?n.value:r}function mm(e,t,r,n){let o=s.Keys(n);for(let[i,a]of t)for(let m of o)i.test(m)||(n[m]=Me(e,r,n[m]));return n}function Di(e,t,r){return je(e)&&s.IsUndefined(r[t])}function vF(e,t,r){let n=s.EntriesRegExp(t.properties),o=s.Keys(r);for(let[i,a]of n)for(let m of o)!i.test(m)||Di(a,m,r)||(r[m]=Me(e,a,r[m]));return s.HasPropertyKey(t,"additionalProperties")&&s.IsObject(t.additionalProperties)?mm(e,n,t.additionalProperties,r):r}function hE(e,t,r){return s.IsObjectNotArray(r)?vF(e,t,r):r}function FF(e,t,r){let n=s.EntriesRegExp(t.patternProperties),o=s.Keys(r);for(let[i,a]of n)for(let m of o)i.test(m)&&(r[m]=Me(e,a,r[m]));return s.HasPropertyKey(t,"additionalProperties")&&s.IsObject(t.additionalProperties)?mm(e,n,t.additionalProperties,r):r}function IE(e,t,r){return s.IsObjectNotArray(r)?FF(e,t,r):r}function bE(e,t,r){return s.HasPropertyKey(e,t.$ref)?Me(e,e[t.$ref],r):r}function $E(e,t,r){let n=re.TryString(r);return re.IsOk(n)?n.value:r}function EE(e,t,r){return Me(e,Ye(t),r)}function SE(e,t,r){if(!s.IsArray(r))return r;for(let n=0;n<Math.min(t.items.length,r.length);n++)r[n]=Me(e,t.items[n],r[n]);return r}function kE(e,t,r){let n=re.TryUndefined(r);return re.IsOk(n)?n.value:r}function TE(e,t,r){if(t.anyOf.some(a=>W(e,a,r)))return r;let i=t.anyOf.map(a=>Me(e,a,de(r))).find(a=>W(e,t,a));return s.IsUndefined(i)?r:i}function wE(e,t,r){let n=re.TryUndefined(r);return re.IsOk(n)?void 0:r}function Me(e,t,r){return Y(t)?mE(e,t,r):At(t)?uE(e,t,r):ht(t)?cE(e,t,r):ue(t)?pE(e,t,r):Ce(t)?fE(e,t,r):Je(t)?dE(e,t,r):F(t)?lE(e,t,r):V(t)?gE(e,t,r):Er(t)?yE(e,t,r):he(t)?xE(e,t,r):v(t)?hE(e,t,r):ie(t)?IE(e,t,r):ne(t)?bE(e,t,r):Ge(t)?$E(e,t,r):ce(t)?EE(e,t,r):G(t)?SE(e,t,r):Yt(t)?kE(e,t,r):E(t)?TE(e,t,r):Mt(t)?wE(e,t,r):r}function Pr(...e){let[t,r,n]=H.Match(e,{3:(o,i,a)=>[o,i,a],2:(o,i)=>[{},o,i]});return Me(t,r,n)}function CE(e,t,r){if(!s.IsArray(r))return r;for(let n=0;n<r.length;n++)r[n]=Xe(e,t.items,r[n]);return r}function RE(e,t,r){return Xe({...e,...t.$defs},ze(t.$ref),r)}function PE(e,t){return s.IsUndefined(t)?s.IsFunction(e.default)?e.default():de(e.default):t}function AE(e,t,r){let n=Bt(e,t),o=Ye(n);return Xe(e,o,r)}function OE(e,t,r){if(!s.IsObject(r))return r;let n=s.Keys(t.properties);for(let o of n){let i=Xe(e,t.properties[o],r[o]);s.IsUndefined(i)&&(je(t.properties[o])||!s.HasPropertyKey(t.properties[o],"default"))||(r[o]=i)}if(!Wt(t)||s.IsBoolean(t.additionalProperties))return r;for(let o of s.Keys(r))n.includes(o)||(r[o]=Xe(e,t.additionalProperties,r[o]));return r}function ME(e,t,r){if(!s.IsObject(r))return r;let[n,o]=[new RegExp(_e(t)),fe(t)];for(let i of s.Keys(r))n.test(i)&&wt(o)&&(r[i]=Xe(e,o,r[i]));if(!Wt(t))return r;for(let i of s.Keys(r))n.test(i)||(r[i]=Xe(e,t.additionalProperties,r[i]));return r}function vE(e,t,r){return s.HasPropertyKey(e,t.$ref)?Xe(e,e[t.$ref],r):r}function FE(e,t,r){if(!s.IsArray(r))return r;let[n,o]=[t.items,Math.max(t.items.length,r.length)];for(let i=0;i<o;i++)i<n.length&&(r[i]=Xe(e,n[i],r[i]));return r}function LE(e,t,r){for(let n of t.anyOf){let o=Xe(e,n,de(r));if(W(e,n,o))return o}return r}function Xe(e,t,r){let n=wt(t)?PE(t,r):r;return Y(t)?CE(e,t,n):ue(t)?RE(e,t,n):F(t)?AE(e,t,n):v(t)?OE(e,t,n):ie(t)?ME(e,t,n):ne(t)?vE(e,t,n):G(t)?FE(e,t,n):E(t)?LE(e,t,n):n}function dn(...e){let[t,r,n]=H.Match(e,{3:(o,i,a)=>[o,i,a],2:(o,i)=>[{},o,i]});return Xe(t,r,n)}function To(e){return(...t)=>{let[r,n,o]=H.Match(t,{3:(i,a,m)=>[i,a,m],2:(i,a)=>[{},i,a]});return e.reduce((i,a)=>a(r,n,i),o)}}function LF(e,t,r){return t["~codec"].decode(r)}function DF(e,t,r){return t["~codec"].encode(r)}function ye(e,t,r,n){return xt(r)?s.IsEqual(e,"Decode")?LF(t,r,n):DF(t,r,n):n}function jF(e,t,r,n){if(!s.IsArray(n))return n;for(let o=0;o<n.length;o++)n[o]=Ie(e,t,r.items,n[o]);return ye(e,t,r,n)}function NF(e,t,r,n){let o=ye(e,t,r,n);if(!s.IsArray(o))return o;for(let i=0;i<o.length;i++)o[i]=Ie(e,t,r.items,o[i]);return o}function DE(e,t,r,n){return s.IsEqual(e,"Decode")?jF(e,t,r,n):NF(e,t,r,n)}function jE(e,t,r,n){return n=Ie(e,{...t,...r.$defs},ze(r.$ref),n),ye(e,t,r,n)}function NE(e){return e.reduce((t,r)=>({...t,...r}),{})}function qE(e,t){for(let r of t)if(!s.IsDeepEqual(e,r))return r;return e}function qF(e,t,r,n){if(s.IsEqual(r.allOf.length,0))return ye(e,t,r,n);let o=r.allOf.map(m=>Ie(e,t,m,ar(m,de(n)))),a=o.every(m=>s.IsObject(m))?NE(o):qE(n,o);return ye(e,t,r,a)}function _F(e,t,r,n){if(s.IsEqual(r.allOf.length,0))return ye(e,t,r,n);let o=ye(e,t,r,n),i=r.allOf.map(m=>Ie(e,t,m,ar(m,de(o))));return i.every(m=>s.IsObject(m))?NE(i):qE(o,i)}function _E(e,t,r,n){return s.IsEqual(e,"Decode")?qF(e,t,r,n):_F(e,t,r,n)}function UF(e,t,r,n){if(!s.IsObjectNotArray(n))return n;for(let o of s.Keys(r.properties))!s.HasPropertyKey(n,o)||Di(r.properties[o],o,n)||(n[o]=Ie(e,t,r.properties[o],n[o]));return ye(e,t,r,n)}function BF(e,t,r,n){let o=ye(e,t,r,n);if(!s.IsObjectNotArray(o))return o;for(let i of s.Keys(r.properties))!s.HasPropertyKey(o,i)||Di(r.properties[i],i,o)||(o[i]=Ie(e,t,r.properties[i],o[i]));return o}function UE(e,t,r,n){return s.IsEqual(e,"Decode")?UF(e,t,r,n):BF(e,t,r,n)}function GF(e,t,r,n){if(!s.IsObjectNotArray(n))return n;let o=new RegExp(_e(r));for(let i of s.Keys(n))o.test(i)&&(n[i]=Ie(e,t,fe(r),n[i]));return ye(e,t,r,n)}function KF(e,t,r,n){let o=ye(e,t,r,n);if(!s.IsObjectNotArray(o))return o;let i=new RegExp(_e(r));for(let a of s.Keys(o))i.test(a)&&(o[a]=Ie(e,t,fe(r),o[a]));return o}function BE(e,t,r,n){return s.IsEqual(e,"Decode")?GF(e,t,r,n):KF(e,t,r,n)}function GE(e,t,r,n){return s.HasPropertyKey(t,r.$ref)?Ie(e,t,t[r.$ref],n):n}function KE(e,t,r,n){return s.IsEqual(e,"Decode")?ye(e,t,r,GE(e,t,r,n)):GE(e,t,r,ye(e,t,r,n))}function HF(e,t,r,n){if(!s.IsArray(n))return n;for(let o=0;o<Math.min(r.items.length,n.length);o++)n[o]=Ie(e,t,r.items[o],n[o]);return ye(e,t,r,n)}function zF(e,t,r,n){let o=ye(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]=Ie(e,t,r.items[i],o[i]);return o}function HE(e,t,r,n){return s.IsEqual(e,"Decode")?HF(e,t,r,n):zF(e,t,r,n)}function WF(e,t,r,n){for(let o of r.anyOf){if(!W(t,o,n))continue;let i=Ie(e,t,o,n);return ye(e,t,r,i)}return n}function VF(e,t,r,n){let o=ye(e,t,r,n);for(let i of r.anyOf){let a=Ie(e,t,i,de(o));if(W(t,i,a))return a}return o}function zE(e,t,r,n){return s.IsEqual(e,"Decode")?WF(e,t,r,n):VF(e,t,r,n)}function Ie(e,t,r,n){return Y(r)?DE(e,t,r,n):ue(r)?jE(e,t,r,n):F(r)?_E(e,t,r,n):v(r)?UE(e,t,r,n):ie(r)?BE(e,t,r,n):ne(r)?KE(e,t,r,n):G(r)?HE(e,t,r,n):E(r)?zE(e,t,r,n):ye(e,t,r,n)}var Yc=class extends Dr{constructor(t,r){super("Decode",t,r)}};function JF(e,t,r){if(!W(e,t,r))throw new Yc(r,or(e,t,r));return r}function YF(e,t,r){let n=De.Get().unionPrioritySort?ko(t):t;return Ie("Decode",e,n,r)}var QF=To([(e,t,r)=>de(r),(e,t,r)=>dn(e,t,r),(e,t,r)=>Pr(e,t,r),(e,t,r)=>ar(e,t,r),(e,t,r)=>JF(e,t,r),(e,t,r)=>YF(e,t,r)]);function WE(...e){let[t,r,n]=H.Match(e,{3:(o,i,a)=>[o,i,a],2:(o,i)=>[{},o,i]});return QF(t,r,n)}var Qc=class extends Dr{constructor(t,r){super("Encode",t,r)}};function XF(e,t,r){if(!W(e,t,r))throw new Qc(r,or(e,t,r));return r}function ZF(e,t,r){let n=De.Get().unionPrioritySort?ko(t):t;return Ie("Encode",e,n,r)}var e1=To([(e,t,r)=>de(r),(e,t,r)=>ZF(e,t,r),(e,t,r)=>dn(e,t,r),(e,t,r)=>Pr(e,t,r),(e,t,r)=>ar(e,t,r),(e,t,r)=>XF(e,t,r)]);function VE(...e){let[t,r,n]=H.Match(e,{3:(o,i,a)=>[o,i,a],2:(o,i)=>[{},o,i]});return e1(t,r,n)}function t1(e,t){return xt(t)||ln(e,t.items)}function r1(e,t){return xt(t)||JE({...e,...t.$defs},ze(t.$ref))}function n1(e,t){return xt(t)||t.allOf.some(r=>ln(e,r))}function o1(e,t){return xt(t)||s.Keys(t.properties).some(r=>ln(e,t.properties[r]))}function i1(e,t){return xt(t)||ln(e,fe(t))}function JE(e,t){return Xc.has(t.$ref)?!1:(Xc.add(t.$ref),xt(t)||s.HasPropertyKey(e,t.$ref)&&ln(e,e[t.$ref]))}function s1(e,t){return xt(t)||t.items.some(r=>ln(e,r))}function a1(e,t){return xt(t)||t.anyOf.some(r=>ln(e,r))}function ln(e,t){return Y(t)?t1(e,t):ue(t)?r1(e,t):F(t)?n1(e,t):v(t)?o1(e,t):ie(t)?i1(e,t):ne(t)?JE(e,t):G(t)?s1(e,t):E(t)?a1(e,t):xt(t)}var Xc=new Set;function YE(...e){let[t,r]=H.Match(e,{2:(n,o)=>[n,o],1:n=>[{},n]});return Xc.clear(),ln(t,r)}var Qt=class extends Error{constructor(t,r){super(r),this.type=t}};function QE(e,t){return s.IsFunction(t.default)?t.default(t):s.IsObject(t.default)?de(t.default):t.default}function XE(e,t){if(Qr(t)&&!wt(t))throw new Qt(t,"Arrays with uniqueItems constraints must specify a default annotation");let r=En(t)?t.minItems:0;return Array.from({length:r},()=>ve(e,t.items))}function ZE(e,t){return Mr(t)?BigInt(t.exclusiveMinimum)+BigInt(1):vr(t)?BigInt(t.minimum):BigInt(0)}function eS(e,t){return!1}function tS(e,t){let r=ve(e,t.instanceType);return class{constructor(){Object.assign(this,r)}}}function rS(e,t){return ve({...e,...t.$defs},ze(t.$ref))}function nS(e,t){return ve(e,Ye(t))}function oS(e,t){let r=ve(e,t.returnType);return()=>r}function iS(e,t){return Mr(t)&&s.IsNumber(t.exclusiveMinimum)?t.exclusiveMinimum+1:vr(t)?t.minimum:0}function sS(e,t){let r=Bt(e,t),n=Ye(r);return ve(e,n)}function aS(e,t){return t.const}function mS(e,t){throw new Qt(t,"Cannot create TNever types")}function uS(e,t){return null}function cS(e,t){return Mr(t)&&s.IsNumber(t.exclusiveMinimum)?t.exclusiveMinimum+1:vr(t)?t.minimum:0}function pS(e,t){return(s.IsUndefined(t.required)?[]:t.required).reduce((n,o)=>({...n,[o]:ve(e,t.properties[o])}),{})}function fS(e,t){if(Ko(t)&&!wt(t))throw new Qt(t,"Record with the minProperties constraint must have a default annotation");return{}}function dS(e,t){return s.HasPropertyKey(e,t.$ref)?ve(e,e[t.$ref]):(()=>{throw new Qt(t,"Unable to deref Ref")})()}function lS(e,t){if((Ho(t)||Uo(t))&&!wt(t))throw Error("Strings with format or pattern constraints must specify default");let n=Go(t)?t.minLength:0;return"".padEnd(n)}function gS(e,t){return Symbol()}function yS(e,t){let r=so(t.pattern);if(Ge(r))throw new Qt(t,"Unable to create TemplateLiteral due to infinite type expansion");return ve(e,r)}function xS(e,t){return Array.from({length:t.minItems},(r,n)=>ve(e,t.items[n]))}function hS(e,t){if(s.IsEqual(t.anyOf.length,0))throw Error("Unable to create Union with no variants");return ve(e,t.anyOf[0])}function ve(e,t){return wt(t)?QE(e,t):Y(t)?XE(e,t):At(t)?ZE(e,t):ht(t)?eS(e,t):ke(t)?tS(e,t):ue(t)?rS(e,t):Ce(t)?nS(e,t):Te(t)?oS(e,t):Je(t)?iS(e,t):F(t)?sS(e,t):V(t)?aS(e,t):St(t)?mS(e,t):Er(t)?uS(e,t):he(t)?cS(e,t):v(t)?pS(e,t):ie(t)?fS(e,t):ne(t)?dS(e,t):Ge(t)?lS(e,t):Sr(t)?gS(e,t):ce(t)?yS(e,t):G(t)?xS(e,t):Yt(t)?void 0:E(t)?hS(e,t):Mt(t)?void 0:void 0}function nt(...e){let[t,r]=H.Match(e,{2:(n,o)=>[n,o],1:n=>[{},n]});return ve(t,r)}function um(e,t){return s.IsDeepEqual(e,t)}function cm(e){return Lr.Hash(e)}var pm=class extends Dr{constructor(t,r){super("Parse",t,r)}};function m1(e,t,r){Xs();let n=or(e,t,r);if(Zs(),!W(e,t,r))throw new pm(r,n);return r}var u1=To([(e,t,r)=>de(r),(e,t,r)=>dn(e,t,r),(e,t,r)=>Pr(e,t,r),(e,t,r)=>ar(e,t,r),(e,t,r)=>m1(e,t,r)]);function IS(...e){let[t,r,n]=H.Match(e,{3:(a,m,c)=>[a,m,c],2:(a,m)=>[{},a,m]});if(W(t,r,n))return n;if(De.Get().correctiveParse)return u1(t,r,n);Xs();let i=or(t,r,n);throw Zs(),new pm(n,i)}function fm(e,t){return{type:"update",path:e,value:t}}function $S(e,t){return{type:"insert",path:e,value:t}}function ES(e){return{type:"delete",path:e}}function bS(e){if(!(s.IsObject(e)&&s.IsEqual(s.Symbols(e).length,0)))throw new Error("Cannot create diffs for objects with symbols keys")}function*c1(e,t,r){if(!s.IsObject(r)||s.IsArray(r))return yield fm(e,r);bS(t),bS(r);let n=s.Keys(t),o=s.Keys(r);for(let i of o)s.HasPropertyKey(t,i)||s.IsUnsafePropertyKey(i)||(yield $S(`${e}/${i}`,r[i]));for(let i of n)s.HasPropertyKey(r,i)&&(s.IsUnsafePropertyKey(i)||um(t,r)||(yield*dm(`${e}/${i}`,t[i],r[i])));for(let i of n)s.HasPropertyKey(r,i)||s.IsUnsafePropertyKey(i)||(yield ES(`${e}/${i}`))}function*p1(e,t,r){if(!s.IsArray(r))return yield fm(e,r);for(let n=0;n<Math.min(t.length,r.length);n++)yield*dm(`${e}/${n}`,t[n],r[n]);for(let n=0;n<r.length;n++)n<t.length||(yield $S(`${e}/${n}`,r[n]));for(let n=t.length-1;n>=0;n--)n<r.length||(yield ES(`${e}/${n}`))}function*f1(e,t,r){let n=globalThis.Object.getPrototypeOf(t).constructor.name,o=globalThis.Object.getPrototypeOf(r).constructor.name;if(Ue.IsTypeArray(r)&&s.IsEqual(t.length,r.length)&&s.IsEqual(n,o))for(let a=0;a<Math.min(t.length,r.length);a++)yield*dm(`${e}/${a}`,t[a],r[a]);else return yield fm(e,r)}function*d1(e,t,r){t!==r&&(yield fm(e,r))}function*dm(e,t,r){return Ue.IsTypeArray(t)?yield*f1(e,t,r):s.IsArray(t)?yield*p1(e,t,r):s.IsObject(t)?yield*c1(e,t,r):yield*d1(e,t,r)}function SS(e,t){return[...dm("",e,t)]}var l1=L({type:z("insert"),path:st(),value:Be()}),g1=Object({type:z("update"),path:st(),value:Be()}),y1=L({type:z("delete"),path:st()}),gRe=q([l1,g1,y1]);function x1(e){return e.length>0&&e[0].path===""&&e[0].type==="update"}function h1(e){return e.length===0}function kS(e,t){if(x1(t))return de(t[0].value);if(h1(t))return de(e);let r=de(e);for(let n of t)switch(n.type){case"insert":{lr.Set(r,n.path,n.value);break}case"update":{lr.Set(r,n.path,n.value);break}case"delete":{lr.Delete(r,n.path);break}}return r}var _r=class extends Error{constructor(t,r,n,o){super(o),this.context=t,this.type=r,this.value=n}};function I1(e){let[t,r]=[new Set,[]];for(let n of e){let o=cm(n);t.has(o)||(t.add(o),r.push(n))}return r}function TS(e,t,r){if(W(e,t,r))return r;let n=s.IsArray(r)?r:nt(e,t),o=En(t)&&n.length<t.minItems?[...n,...Array.from({length:t.minItems-n.length},()=>nt(e,t))]:n,a=(Bo(t)&&o.length>t.maxItems?o.slice(0,t.maxItems):o).map(c=>Ke(e,t.items,c));if(!Qr(t)||Qr(t)&&!s.IsEqual(t.uniqueItems,!0))return a;let m=I1(a);if(!W(e,t,m))throw new _r(e,t,r,"Failed to repair Array due to uniqueItems constraint");return m}function wS(e,t,r){return Ke(e,Ye(t),r)}function CS(e,t,r){let n=Bt(e,t),o=Ye(n);return Ke(e,o,r)}function RS(e,t,r){if(W(e,t,r))return r;if(!s.IsObjectNotArray(r))return nt(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?Ke(e,m,r[a]):nt(e,m));let i=s.Keys(t.properties);if(Wt(t)&&s.IsObject(t.additionalProperties))for(let a of s.Keys(r))i.includes(a)||(o[a]=Ke(e,t.additionalProperties,r[a]));return o}function PS(e,t,r){if(W(e,t,r))return r;if(s.IsNull(r)||!s.IsObject(r)||s.IsArray(r))return nt(e,t);let n=new RegExp(_e(t)),o=fe(t),i=new Set,a={};for(let[m,c]of s.Entries(r))n.test(m)&&(a[m]=Ke(e,o,c),i.add(m));if(Wt(t))for(let m of s.Keys(r))i.has(m)||(a[m]=Ke(e,t.additionalProperties,r[m]));return a}function AS(e,t,r){return s.HasPropertyKey(e,t.$ref)?Ke(e,e[t.$ref],r):(()=>{throw new _r(e,t,r,"Unable to de-reference target type")})()}function OS(e,t,r){let n=so(t.pattern);return Ke(e,n,r)}function MS(e,t,r){return W(e,t,r)?r:s.IsArray(r)?t.items.map((n,o)=>Ke(e,n,r[o])):nt(e,t)}function vS(e,t,r){return ne(t)?s.HasPropertyKey(e,t.$ref)?vS(e,e[t.$ref],r):(()=>{throw new Error("Unable to Deref target")})():t}function b1(e,t,r){if(!(v(t)&&s.IsObject(r)))return 0;let n=s.Keys(r);return s.Entries(t.properties).reduce((i,[a,m])=>{let c=V(m)&&s.IsEqual(m.const,r[a])?100:0,p=W(e,m,r[a])?10:0,f=n.includes(a)?1:0;return i+(c+p+f)},0)}function FS(e,t,r){let n=t.anyOf.map(a=>vS(e,a,r)),[o,i]=[n[0],0];for(let a of n){let m=b1(e,a,r);m>i&&(o=a,i=m)}return o}function $1(e,t,r){let n=q(an(t.anyOf)),o=FS(e,n,r);return Ke(e,o,r)}function LS(e,t,r){return W(e,t,r)?de(r):wt(t)?nt(e,t):$1(e,t,r)}function DS(e,t,r){if(W(e,t,r))return r;let n=Pr(e,t,r);return W(e,t,n)?n:nt(e,t)}function E1(e,t,r){if(Ue.IsDate(r)||Ue.IsMap(r)||Ue.IsSet(r)||Ue.IsTypeArray(r)||s.IsConstructor(r)||s.IsFunction(r))throw new _r(e,t,r,"Value is not repairable")}function S1(e,t,r){if(ke(t)||Te(t)||St(t))throw new _r(e,t,r,"Type is not repairable")}function k1(e,t,r){return s.IsUndefined(r)&&!Yt(t)?nt(e,t):r}function T1(e,t,r){return ai(t)?W(e,t,r)?r:nt(e,t):r}function Ke(e,t,r){E1(e,t,r),S1(e,t,r);let n=k1(e,t,r),o=Y(t)?TS(e,t,n):Ce(t)?wS(e,t,n):F(t)?CS(e,t,n):v(t)?RS(e,t,n):ie(t)?PS(e,t,n):ne(t)?AS(e,t,n):ce(t)?OS(e,t,n):G(t)?MS(e,t,n):E(t)?LS(e,t,n):DS(e,t,n);return T1(e,t,o)}function jS(...e){let[t,r,n]=H.Match(e,{3:(i,a,m)=>[i,a,m],2:(i,a)=>[{},i,a]}),o=Ke(t,r,n);return ea(t,r,o),o}var wo={};Dt(wo,{Assert:()=>ea,Check:()=>W,Clean:()=>ar,Clone:()=>de,Convert:()=>Pr,Create:()=>nt,Decode:()=>WE,Default:()=>dn,Diff:()=>SS,Encode:()=>VE,Equal:()=>um,Errors:()=>or,HasCodec:()=>YE,Hash:()=>cm,Parse:()=>IS,Patch:()=>kS,Pointer:()=>lr,Repair:()=>jS});var A1=P1(tt,"hooks.json"),NS=64*1024,US=30,qS=["PreToolUse","PostToolUse","UserPromptSubmit","SessionStart","Stop","PreCompact","SessionEnd"];function NPe(e,t){if(t===null||typeof t!="object"||Array.isArray(t))return"the rewrite is not a JSON object";if(!(e===null||typeof e!="object"))try{if(wo.Check(e,t))return;let r=[...wo.Errors(e,t)][0];if(!r)return"the rewrite does not match the tool's schema";let n="instancePath"in r?String(r.instancePath):"";return`the rewrite does not match the tool's schema${n&&n!=="/"?` at \`${n}\``:""}: ${r.message}`}catch(r){return`the tool's schema could not be checked: ${r instanceof Error?r.message:String(r)}`}}function qPe(e=A1){let t=[],r={hooks:{}};try{if(!C1(e))return{config:r,diagnostics:t};let n=R1(e,"utf8");if(Buffer.byteLength(n,"utf8")>NS)return t.push({source:e,message:`skipped: larger than ${NS} bytes`}),{config:r,diagnostics:t};let o=JSON.parse(n),i=O1(o);for(let a of i.diagnostics)t.push({source:e,message:a});return{config:i.config,diagnostics:t}}catch(n){return t.push({source:e,message:`unreadable: ${n instanceof Error?n.message:String(n)}`}),{config:r,diagnostics:t}}}function O1(e){let t=[],r={hooks:{}};if(e===null||typeof e!="object"||Array.isArray(e))return{config:r,diagnostics:["expected a JSON object with a `hooks` key"]};let n=e.hooks;if(n===void 0)return{config:r,diagnostics:["no `hooks` key"]};if(n===null||typeof n!="object"||Array.isArray(n))return{config:r,diagnostics:["`hooks` must be an object keyed by event name"]};for(let[o,i]of Object.entries(n)){if(!qS.includes(o)){t.push(`unknown event \`${o}\` \u2014 supported: ${qS.join(", ")}`);continue}if(!Array.isArray(i)){t.push(`\`${o}\` must be an array of matchers`);continue}let a=[];for(let m of i){let c=M1(m,o,t);c&&a.push(c)}a.length&&(r.hooks[o]=a)}return{config:r,diagnostics:t}}function M1(e,t,r){if(e===null||typeof e!="object"||Array.isArray(e)){r.push(`\`${t}\`: a matcher must be an object`);return}let n=e,o=Array.isArray(n.hooks)?n.hooks:void 0;if(!o){r.push(`\`${t}\`: a matcher needs a \`hooks\` array`);return}let i=[];for(let m of o){if(m===null||typeof m!="object")continue;let c=m,p=typeof c.type=="string"?c.type:"command";if(p!=="command"){r.push(`\`${t}\`: only \`type: "command"\` is supported, got \`${p}\``);continue}if(typeof c.command!="string"||!c.command.trim()){r.push(`\`${t}\`: a hook needs a non-empty \`command\``);continue}let f=typeof c.timeout=="number"&&Number.isFinite(c.timeout)&&c.timeout>0?c.timeout:void 0;i.push({type:"command",command:c.command,timeout:f,...c.async===!0?{async:!0}:{},...c.once===!0?{once:!0}:{}})}return i.length?{matcher:typeof n.matcher=="string"?n.matcher:void 0,hooks:i}:void 0}function v1(e,t,r){let n=e.hooks[t];return n?n.filter(o=>{let i=o.matcher?.trim();if(!i||i==="*")return!0;if(r===void 0)return!1;let a=r.toLowerCase();return i.split("|").map(m=>m.trim().toLowerCase()).filter(Boolean).includes(a)}):[]}function _S(e,t,r={cwd:process.cwd()}){let n=r.timeoutS??US;return new Promise(o=>{let i="",a="",m=!1,c=!1,p=w1(e,{cwd:r.cwd,shell:!0,stdio:["pipe","pipe","pipe"]});p.stdin?.on("error",()=>{}),p.stdout?.on("error",()=>{}),p.stderr?.on("error",()=>{});let f=setTimeout(()=>{m=!0,p.kill("SIGKILL")},n*1e3);p.stdout?.on("data",g=>{i+=g.toString("utf8")}),p.stderr?.on("data",g=>{a+=g.toString("utf8")});let d=g=>{c||(c=!0,clearTimeout(f),o({code:g,stdout:i,stderr:a,timedOut:m}))};p.on("error",g=>{a+=g.message,d(null)}),p.on("close",g=>d(g));try{p.stdin?.end(JSON.stringify(t))}catch{}})}function F1(e){let{code:t,stdout:r,stderr:n,timedOut:o}=e,i=n.trim();if(o)return{block:!1,error:`timed out after ${US}s and was killed`};let a=L1(r),m=a?.hookSpecificOutput,c=typeof m?.additionalContext=="string"?m.additionalContext:typeof a?.additionalContext=="string"?a.additionalContext:void 0,p=typeof m?.permissionDecision=="string"?m.permissionDecision:void 0,f=typeof m?.permissionDecisionReason=="string"?m.permissionDecisionReason:void 0,d=m?.updatedInput,g=d!==null&&typeof d=="object"&&!Array.isArray(d)?d:void 0;return p==="deny"||p==="block"?{block:!0,reason:f||i||"denied by a hook",context:c}:p==="allow"?{block:!1,context:c,updatedInput:g}:t===2?{block:!0,reason:i||"blocked by a hook",context:c}:t!==0?{block:!1,context:c,updatedInput:g,error:`exited ${t===null?"without a status":t}${i?`: ${i}`:""}`}:!a&&r.trim()?{block:!1,context:r.trim()}:{block:!1,context:c,updatedInput:g}}function L1(e){let t=e.trim();if(t.startsWith("{"))try{let r=JSON.parse(t);return r&&typeof r=="object"&&!Array.isArray(r)?r:void 0}catch{return}}var Zc=new Set;function _Pe(){Zc.clear()}async function UPe(e,t,r,n){let o=v1(e,t,r.tool_name);if(!o.length)return{outcome:{block:!1},ran:0};let i=[],a=0,m,c,p;for(let f of o)for(let d of f.hooks){if(d.once){let I=`${t}\0${d.command}`;if(Zc.has(I))continue;Zc.add(I)}if(a+=1,d.async){_S(d.command,r,{cwd:n.cwd,timeoutS:d.timeout}).catch(()=>{});continue}let g=await _S(d.command,r,{cwd:n.cwd,timeoutS:d.timeout}),y=F1(g);y.context&&i.push(y.context),y.error&&(c=y.error),y.updatedInput&&(p=y.updatedInput),y.block&&!m&&(m=y)}return m?{outcome:{block:!0,reason:m.reason,context:i.join(`
|
|
8
|
+
|
|
9
|
+
`)||void 0},ran:a}:{outcome:{block:!1,context:i.join(`
|
|
10
|
+
|
|
11
|
+
`)||void 0,error:c,updatedInput:p},ran:a}}import{existsSync as BS,readFileSync as D1}from"node:fs";function j1(e){return`${e}/.howtocode/mcp.json`}function ep(e,t){if(!BS(e))return{};try{let n=JSON.parse(D1(e,"utf8"))?.mcpServers;return!n||typeof n!="object"||Array.isArray(n)?{}:n}catch(r){return t.push(`${e}: ${r instanceof Error?r.message:String(r)}`),{}}}function zPe(e){let t=[];return ep(Ji(e??tt),t)}function WPe(e){let t=[],r=ep(Ji(e.agentDir??tt),t),n=j1(e.cwd),o=e.projectTrusted&&BS(n)?n:void 0,i=o?ep(o,t):{},a=Ji(e.agentDir??tt),m=new Map;for(let[c,p]of Object.entries(r))m.set(c,{name:c,config:p,source:a,scope:"global"});for(let[c,p]of Object.entries(i))m.set(c,{name:c,config:p,source:o,scope:"project"});return{servers:[...m.values()],errors:t,projectConfig:o}}import{mkdirSync as N1,readdirSync as q1,readFileSync as _1,renameSync as U1,unlinkSync as GS,writeFileSync as B1}from"node:fs";import{join as KS}from"node:path";var G1=180*1e3,QPe="presence";function HS(e,t){return KS(e.dir,`${t.replace(/[^A-Za-z0-9._-]/g,"_")}.json`)}function K1(e,t=Date.now()){let r;try{r=q1(e.dir)}catch{return[]}let n=[];for(let o of r){if(!o.endsWith(".json"))continue;let i=KS(e.dir,o),a;try{a=_1(i,"utf8")}catch{continue}let m;try{m=JSON.parse(a)}catch{tp(i);continue}if(typeof m?.id!="string"||typeof m?.cwd!="string"||typeof m?.at!="number"){tp(i);continue}if(t-m.at>=G1){tp(i);continue}n.push({id:m.id,cwd:m.cwd,host:typeof m.host=="string"?m.host:"",pid:typeof m.pid=="number"?m.pid:0,at:m.at,...typeof m.activity=="string"&&m.activity?{activity:m.activity}:{}})}return n.sort((o,i)=>i.at-o.at)}function XPe(e,t){N1(e.dir,{recursive:!0});let r=HS(e,t.id),n=`${r}.${process.pid}.tmp`;B1(n,JSON.stringify(t,null,2)),U1(n,r)}function ZPe(e,t){try{GS(HS(e,t))}catch{}}function zS(e,t,r,n=Date.now()){return K1(e,n).filter(o=>o.cwd===t&&o.id!==r)}function tp(e){try{GS(e)}catch{}}import{Type as ot}from"@netrodev/hxf-ai";import{defineTool as lm}from"@netrodev/hxf-coding-agent";import{relative as eL,join as tL}from"node:path";import{mkdirSync as rL,writeFileSync as nL}from"node:fs";import{existsSync as rAe,mkdirSync as H1,readFileSync as z1,renameSync as W1,writeFileSync as V1}from"node:fs";import{dirname as J1,isAbsolute as Y1,join as JS,relative as Q1,resolve as WS,sep as VS}from"node:path";var X1=1800*1e3,Z1=JS(".howtocode","claims.json");function YS(e){return JS(e,Z1)}function np(e,t){try{let r=z1(YS(e),"utf8"),n=JSON.parse(r);return(Array.isArray(n.claims)?[...n.claims]:[]).filter(i=>typeof i?.path=="string"&&typeof i?.holder=="string"&&typeof i?.at=="number"&&t-i.at<X1)}catch{return[]}}function QS(e,t){let r=YS(e);H1(J1(r),{recursive:!0});let n=`${r}.${process.pid}.tmp`;V1(n,JSON.stringify({version:1,claims:[...t]},null,2)),W1(n,r)}function XS(e,t){return Y1(t)?WS(t):WS(e,t)}function ZS(e,t){if(e===t)return!0;let r=n=>n.endsWith(VS)?n:n+VS;return e.startsWith(r(t))||t.startsWith(r(e))}function ek(e){let t=e.now??Date.now(),r=np(e.root,t),n=[],o=[],i=[];for(let a of e.paths){if(!a.trim())continue;let m=XS(e.root,a.trim()),c=r.find(p=>p.holder!==e.holder&&ZS(p.path,m));if(c){o.push({path:rp(e.root,m),by:c.holder,reason:c.reason||"no reason given"});continue}n.push(rp(e.root,m)),i.push({path:m,holder:e.holder,reason:e.reason,at:t})}if(i.length>0){let a=r.filter(m=>m.holder!==e.holder||!i.some(c=>c.path===m.path));QS(e.root,[...a,...i])}return{granted:n,conflicts:o}}function tk(e,t,r){let n=Date.now(),o=np(e,n),i=r?.length?r.map(c=>XS(e,c.trim())).filter(Boolean):void 0,a=[],m=[];for(let c of o){let p=c.holder===t,f=i===void 0||i.some(d=>ZS(c.path,d));p&&f?m.push(rp(e,c.path)):a.push(c)}return QS(e,a),m}function op(e,t=Date.now()){return np(e,t)}function rp(e,t){let r=Q1(e,t);return r&&!r.startsWith("..")?r:t}var ip;function pAe(e){ip=e}var fAe=lm({name:"think",label:"think",description:"Private scratchpad. The text is not shown to the user. Use it before a non-obvious step.",promptSnippet:"think: private notes, not shown to the user",parameters:ot.Object({thoughts:ot.String({description:"Private notes"})}),async execute(){return{content:[{type:"text",text:"noted"}],details:{recorded:!0}}}}),dAe=lm({name:"ask",label:"ask",description:"Ask the user one question and wait for a selected answer. Use this instead of guessing when a choice blocks the task.",promptSnippet:"ask: ask the user to pick one option",parameters:ot.Object({question:ot.String(),options:ot.Array(ot.String(),{minItems:2})}),async execute(e,t){if(!ip)return{content:[{type:"text",text:"cancelled"}],details:{answer:"cancelled"}};let r=await ip(t.question,t.options);return{content:[{type:"text",text:r}],details:{answer:r}}}}),ji;function lAe(e){ji=e}var gAe=lm({name:"sessions",label:"sessions",description:"See the other HowToCode sessions working in this workspace, what they hold, and what they are doing. Use it to find who is blocking a claim, or to tell another session to release a file. Send a message with message + to.",promptSnippet:"sessions: other CLI sessions, and who holds what",parameters:ot.Object({message:ot.Optional(ot.String({description:"Message text to leave for another session."})),to:ot.Optional(ot.String({description:"Session id to send the message to. Use `all` for every other session."}))}),async execute(e,t){let r=ji,n=r?.presenceDir?.();if(!r||!n)return{content:[{type:"text",text:"the session registry is unavailable here"}],details:{}};let o=r.selfId?.()??"",i=r.root(),a=zS({dir:n},i);if(t.message&&t.message.trim()){let c=t.to?.trim()||"all",p=a.filter(f=>f.id!==o&&(c==="all"||f.id===c));if(p.length===0)return{content:[{type:"text",text:"no other session in this workspace to message"}],details:{sent:0}};for(let f of p){let d=tL(n,`${f.id.replace(/[^A-Za-z0-9._-]/g,"_")}.inbox`);try{rL(n,{recursive:!0}),nL(d,`${JSON.stringify({from:o,at:Date.now(),text:t.message.trim()})}
|
|
12
|
+
`,{flag:"a"})}catch{}}return{content:[{type:"text",text:`left a message for ${p.map(f=>f.id).join(", ")}`}],details:{sent:p.length}}}if(a.length===0)return{content:[{type:"text",text:"no other session in this workspace"}],details:{sessions:[]}};let m=a.map(c=>{let p=c.id===o?"this session":c.id,f=op(i).filter(y=>y.holder===`session:${c.id}`),d=c.activity?` \u2014 ${c.activity}`:"",g=f.length>0?`
|
|
13
|
+
holds:
|
|
14
|
+
${f.map(y=>` ${nk(i,y.path)} \u2014 ${y.reason}`).join(`
|
|
15
|
+
`)}`:"";return` ${p} (pid ${c.pid}${c.id===o?"":`, seen ${Math.round((Date.now()-c.at)/1e3)}s ago`})${d}${g}`});return{content:[{type:"text",text:`sessions in ${i}:
|
|
16
|
+
${m.join(`
|
|
17
|
+
`)}`}],details:{sessions:a}}}});function oL(e){let t=[];if(e.granted.length>0&&t.push(`claimed: ${e.granted.join(", ")}`),e.conflicts.length>0){t.push(""),t.push("refused \u2014 another agent is working on these:");for(let r of e.conflicts)t.push(` ${r.path} \u2014 held by ${r.by}: ${r.reason}`);t.push(""),t.push("Wait for the holder to release it, or work on something else. Do not edit a refused path.")}return t.length===0&&t.push("nothing to claim"),{text:t.join(`
|
|
18
|
+
`),isError:e.conflicts.length>0}}var rk=lm({name:"claim",label:"claim",description:"Claim files or directories before editing them, so a parallel agent cannot overwrite your work. Refused paths are held by someone else \u2014 do not edit them. Pass no paths to list every claim in this workspace.",promptSnippet:"claim: reserve files before editing",parameters:ot.Object({paths:ot.Optional(ot.Array(ot.String(),{description:"Files or directories to claim. Omit to list the current claims."})),reason:ot.Optional(ot.String({description:"Why you are taking them, shown to a refused agent."})),release:ot.Optional(ot.Boolean({description:"Release these paths instead of claiming them. Omit paths to release everything you hold."}))}),async execute(e,t){if(!ji)return{content:[{type:"text",text:"claims are unavailable in this session"}],details:{},isError:!0};let r=ji.root(),n=ji.holder();if(t.release){let m=tk(r,n,t.paths);return{content:[{type:"text",text:m.length>0?`released: ${m.join(", ")}`:"you held nothing matching that"}],details:{released:m}}}if(!t.paths||t.paths.length===0){let m=op(r);return m.length===0?{content:[{type:"text",text:"no active claims in this workspace"}],details:{claims:[]}}:{content:[{type:"text",text:m.map(p=>`${p.holder===n?"(you) ":""}${nk(r,p.path)} \u2014 ${p.reason}`).join(`
|
|
19
|
+
`)}],details:{claims:m}}}let o=ek({root:r,holder:n,reason:t.reason??"no reason given",paths:t.paths}),{text:i,isError:a}=oL(o);return{content:[{type:"text",text:i}],isError:a,details:o}}});function nk(e,t){let r=eL(e,t);return r&&!r.startsWith("..")?r:t}import{StringEnum as iL}from"@netrodev/hxf-ai";import{defineTool as sL}from"@netrodev/hxf-coding-agent";var D={};Dt(D,{Any:()=>ro,Array:()=>Et,BigInt:()=>mi,Boolean:()=>aa,Call:()=>XI,Capitalize:()=>ib,Codec:()=>ia,Conditional:()=>db,Constructor:()=>xr,ConstructorParameters:()=>gb,Cyclic:()=>br,Decode:()=>ng,DecodeBuilder:()=>si,Dependent:()=>wn,Encode:()=>og,EncodeBuilder:()=>ii,Enum:()=>tg,Evaluate:()=>Ye,Exclude:()=>xb,Extends:()=>at,ExtendsResult:()=>j,Extract:()=>Ib,Function:()=>hr,Generic:()=>rn,Identifier:()=>ui,Immutable:()=>ig,Index:()=>Sb,Infer:()=>oi,InstanceType:()=>Wb,Instantiate:()=>Bt,Integer:()=>Rn,Interface:()=>vI,Intersect:()=>ut,IsAny:()=>$e,IsArray:()=>Y,IsBigInt:()=>At,IsBoolean:()=>ht,IsCall:()=>Io,IsCodec:()=>xt,IsConstructor:()=>ke,IsCyclic:()=>ue,IsDependent:()=>we,IsEnum:()=>Ce,IsEnumValue:()=>eg,IsFunction:()=>Te,IsGeneric:()=>to,IsIdentifier:()=>ug,IsImmutable:()=>Cn,IsInfer:()=>qe,IsInteger:()=>Je,IsIntersect:()=>F,IsKind:()=>C,IsLiteral:()=>V,IsNever:()=>St,IsNull:()=>Er,IsNumber:()=>he,IsObject:()=>v,IsOptional:()=>je,IsParameter:()=>fg,IsReadonly:()=>jr,IsRecord:()=>ie,IsRef:()=>ne,IsRefine:()=>ai,IsRest:()=>mn,IsSchema:()=>xe,IsString:()=>Ge,IsSymbol:()=>Sr,IsTemplateLiteral:()=>ce,IsThis:()=>$a,IsTuple:()=>G,IsUndefined:()=>Yt,IsUnion:()=>E,IsUnknown:()=>Ne,IsUnsafe:()=>oa,IsVoid:()=>Mt,KeyOf:()=>Jb,Literal:()=>z,Lowercase:()=>sb,Mapped:()=>n$,Module:()=>z$,Never:()=>se,NonNullable:()=>a$,Null:()=>oo,Number:()=>Ot,Object:()=>L,Omit:()=>u$,Optional:()=>Wl,Parameter:()=>Pn,Parameters:()=>f$,Partial:()=>l$,Pick:()=>$$,Readonly:()=>sg,ReadonlyObject:()=>Uc,ReadonlyType:()=>k$,Record:()=>co,RecordKey:()=>po,RecordPattern:()=>_e,RecordValue:()=>fe,Ref:()=>ze,Refine:()=>ag,Required:()=>_$,Rest:()=>On,ReturnType:()=>B$,Script:()=>Y$,String:()=>st,Symbol:()=>io,TemplateLiteral:()=>Xh,This:()=>ba,Tuple:()=>Re,Uncapitalize:()=>ab,Undefined:()=>fo,Union:()=>q,Unknown:()=>Be,Unsafe:()=>Yl,Uppercase:()=>mb,Void:()=>Ea,With:()=>sm});var aL={pending:"[ ]",in_progress:"[>]",completed:"[x]",dropped:"[-]"},mL=D.Object({op:iL(["init","start","done","drop","view"],{description:"init replaces the list; start/done/drop move one task; view reads it"}),items:D.Optional(D.Array(D.String(),{description:"Task labels for init. 5-10 words each, specific enough to execute without re-planning"})),task:D.Optional(D.String({description:"Exact label of the task to start, complete or drop"}))});function ok(e){if(e.length===0)return"Todo list is empty.";let t=e.filter(o=>o.status==="completed").length,r=e.map(o=>`${aL[o.status]} ${o.content}`),n=e.filter(o=>o.status==="pending"||o.status==="in_progress").length;return[`${t}/${e.length} done, ${n} open`,...r].join(`
|
|
20
|
+
`)}function uL(e,t,r,n){let o=e.map(i=>({...i}));switch(t){case"init":return!r||r.length===0?{todos:o,error:"init needs a non-empty items array"}:{todos:r.map(i=>({content:i,status:"pending"}))};case"view":return{todos:o};case"start":case"done":case"drop":{if(!n)return{todos:o,error:`${t} needs task`};let i=o.find(a=>a.content===n);if(!i)return{todos:o,error:`no task matches ${JSON.stringify(n)}`};if(t==="start"){for(let a of o)a.status==="in_progress"&&(a.status="pending");i.status="in_progress"}else i.status=t==="done"?"completed":"dropped";return{todos:o}}default:return{todos:o,error:`unknown op ${JSON.stringify(t)}`}}}function cL(e){let t=[];for(let r of e.sessionManager.getBranch()){if(r.type!=="message")continue;let n=r.message;if(n.role!=="toolResult"||n.toolName!=="todo")continue;let o=n.details;o?.todos&&(t=o.todos)}return t}var ik=sL({name:"todo",label:"todo",description:"Track the plan for this task. Use `init` once with the whole plan (investigation through verification), then `start`/`done` as you go. Keep the list current so progress stays visible; do not re-init unless the plan materially changes.",promptSnippet:"todo: record and advance the plan for the current task",parameters:mL,async execute(e,t,r,n,o){let i=cL(o),{todos:a,error:m}=uL(i,t.op,t.items,t.task),c={op:t.op,todos:a,...m?{error:m}:{}};return{content:[{type:"text",text:m?`Error: ${m}
|
|
21
|
+
${ok(a)}`:ok(a)}],details:c,...m?{isError:!0}:{}}}});import{StringEnum as pL}from"@netrodev/hxf-ai";import{defineTool as fL}from"@netrodev/hxf-coding-agent";var Ar=new Map,sk=2e3,ak=80;function GOe(){Ar.clear()}function mk(){return Ar.size===0?"":["<shared-notes>","Working notes recorded with the `context` tool. They survive compaction and are visible to every agent on this task.",...[...Ar].map(([t,r])=>`- ${t}: ${r}`),"</shared-notes>"].join(`
|
|
22
|
+
`)}function dL(e,t,r){if(e==="list")return Ar.size===0?{text:"No notes."}:{text:[...Ar].map(([n,o])=>`${n} = ${o}`).join(`
|
|
23
|
+
`)};if(!t)return{text:"Error: key is required",error:"key required"};if(t.length>ak)return{text:`Error: key longer than ${ak} characters`,error:"key too long"};if(e==="forget")return{text:Ar.delete(t)?`Removed ${t}`:`No note named ${t}`};if(e==="set"){if(!r)return{text:"Error: value is required for set",error:"value required"};let n=r.length>sk?`${r.slice(0,sk)}\u2026`:r;return Ar.set(t,n),{text:`Recorded ${t} (${Ar.size} note${Ar.size===1?"":"s"} held)`}}return{text:`Error: unknown op ${JSON.stringify(e)}`,error:"unknown op"}}var uk=fL({name:"context",label:"context",description:"Record a durable working note (a decision, a file's role, a fact you would otherwise re-derive). Notes survive context compaction and are visible to every agent on this task, including subagents. Use `set` to write, `list` to read, `forget` to remove.",promptSnippet:"context: durable notes shared with every agent on this task",parameters:D.Object({op:pL(["set","list","forget"],{description:"set writes a note, list reads all, forget removes one"}),key:D.Optional(D.String({description:"Short lookup key, e.g. 'auth-entrypoint'"})),value:D.Optional(D.String({description:"The fact to keep (for set)"}))}),async execute(e,t){let{text:r,error:n}=dL(t.op,t.key,t.value);return{content:[{type:"text",text:r}],details:{op:t.op,notes:Object.fromEntries(Ar)},...n?{isError:!0}:{}}}});import{StringEnum as lL}from"@netrodev/hxf-ai";import{defineTool as gL}from"@netrodev/hxf-coding-agent";var ck="howtocode.goal",VOe="howtocode.goal.continue",pk=400,gm=25,fk={active:"\u25CF",paused:"\u2016",done:"\u2713",cleared:"\u25CB"};function yL(e){if(!e||e.status==="cleared")return"No goal set.";let t=e.budget??gm,r=[`${fk[e.status]} ${e.status}`,`${e.used}/${t} continuations`];return e.note&&r.push(e.note),`${r.join(" \xB7 ")}
|
|
24
|
+
${e.text}`}function JOe(e){if(!e||e.status==="cleared"||e.status==="done")return"";let t=e.budget??gm,r=e.text.length>48?`${e.text.slice(0,47)}\u2026`:e.text;return`goal ${fk[e.status]} ${e.used}/${t} \xB7 ${r}`}function YOe(e){let t=["<goal>",e.text,`Status: ${e.status}.`];return e.status==="active"&&t.push("Work toward this goal until it is genuinely met. When it is, call the `goal` tool with",'op="complete" and a note naming the evidence; a command you ran or a file you checked.',"If you are blocked and cannot proceed, say so plainly instead of repeating an attempt."),t.push("</goal>"),t.join(`
|
|
25
|
+
`)}function QOe(e){return["[goal] The goal is still open and you stopped without closing it:",` ${e.text}`,"","Continue from where you left off. Do not repeat work you already did. If the goal is met,",'call the `goal` tool with op="complete" and a note naming the evidence. Do not call it',"complete to escape a hard problem: if you cannot make progress, state what is blocking you.",`Continuations used: ${e.used}/${e.budget??gm}.`].join(`
|
|
26
|
+
`)}var dk;function XOe(){return dk}function xL(e){dk=e}function ZOe(e){if(!e)return{action:"stop",reason:"no goal",close:!1};if(e.status==="done")return{action:"stop",reason:"goal complete",close:!1};if(e.status==="cleared")return{action:"stop",reason:"goal cleared",close:!1};if(e.status==="paused")return{action:"stop",reason:"goal paused",close:!1};let t=e.budget??gm;return e.used>=t?{action:"stop",reason:`budget exhausted (${t} continuations)`,close:!0}:{action:"continue"}}function hL(e,t,r,n,o){switch(t){case"view":return{goal:e};case"set":return r?.trim()?r.length>pk?{goal:e,error:`text longer than ${pk} characters`}:n!==void 0&&(!Number.isInteger(n)||n<1)?{goal:e,error:"budget must be a positive integer"}:{goal:{text:r.trim(),status:"active",used:0,...n===void 0?{}:{budget:n}}}:{goal:e,error:"set needs text"};case"pause":case"resume":case"complete":case"clear":return!e||e.status==="cleared"?{goal:e,error:"no goal to change"}:t==="resume"?e.status==="done"?{goal:e,error:"goal is complete; set a new one instead"}:{goal:{...e,status:"active",note:void 0}}:t==="pause"?{goal:{...e,status:"paused"}}:t==="clear"?{goal:{...e,status:"cleared"}}:o?.trim()?{goal:{...e,status:"done",note:o.trim()}}:{goal:e,error:"complete needs a note naming the evidence (a command you ran or a file you checked)"};default:return{goal:e,error:`unknown op ${JSON.stringify(t)}`}}}function IL(e){let t;for(let r of e.sessionManager.getBranch()){if(r.type==="custom"&&r.customType===ck){t=r.data;continue}if(r.type==="custom_message"&&r.customType===ck){t=r.details??t;continue}if(r.type!=="message")continue;let n=r.message;if(n.role!=="toolResult"||n.toolName!=="goal")continue;let o=n.details;o?.goal&&(t=o.goal)}return t}var bL=D.Object({op:lL(["set","view","pause","resume","complete","clear"],{description:"set starts a goal; complete closes it with evidence; pause/resume/clear manage it; view reads it"}),text:D.Optional(D.String({description:"The goal, in one sentence, as the user would state it (for set)"})),budget:D.Optional(D.Number({description:"Optional cap on automatic continuations before the run stops"})),note:D.Optional(D.String({description:"Evidence that the goal is met (required for complete)"}))}),eMe=gL({name:"goal",label:"goal",description:"Track the goal for this session. The goal is already shown in your context every request, so you rarely need `view`. Call `complete` only when the goal is genuinely met, and pass a note naming the evidence. When a goal is active the harness continues the run if you stop without closing it, so closing it is how you stop.",promptSnippet:"goal: the session's objective, and how to close it",parameters:bL,async execute(e,t,r,n,o){let i=IL(o),{goal:a,error:m}=hL(i,t.op,t.text,t.budget,t.note);xL(a);let c=yL(a);return{content:[{type:"text",text:m?`Error: ${m}
|
|
27
|
+
${c}`:c}],details:{op:t.op,goal:a},...m?{isError:!0}:{}}}});import{existsSync as mp,mkdirSync as lk,readFileSync as gk}from"node:fs";import{dirname as yk,join as xk}from"node:path";import{defineTool as hk}from"@netrodev/hxf-coding-agent";function ym(){return{state:"inactive",wasActive:!1}}function $L(e){return e?e.state==="pending"?{...e,state:"inactive"}:{...e}:ym()}function aMe(e){return e.state!=="inactive"?e:{...e,state:"pending"}}function EL(e){return e.state!=="pending"?e:{state:"active",wasActive:!0}}function SL(e){return e.state!=="inactive"?e:{state:"active",wasActive:!0}}function kL(e){return e.state!=="active"?e:{...e,state:"inactive"}}function mMe(e){return e.state==="inactive"?e:{...e,state:"inactive"}}function xm(e){return e.state==="active"}function TL(e,t){return e===t}function wL(e,t){return["<plan-mode>","Plan mode is active. Do not make any edits or writes to the system.",t?`A plan file exists at ${e}. Read it and refine it with the \`edit\` tool.`:`No plan is written yet. Write yours to ${e} with the \`write\` tool.`,"That file is the only path you may edit.","Explore first: read, search, and run read-only commands until the approach is clear.","End your turn with either `ask` to clarify a requirement, or `exit_plan_mode` to present","the plan for approval. Do not start implementing before the plan is approved.","</plan-mode>"].join(`
|
|
28
|
+
`)}function CL(e){return`Rejected: file edits are not allowed in plan mode. The only editable file is the plan file (${e}). Present the plan with exit_plan_mode first.`}var pt,ft=ym(),ap;function uMe(){return ft}function cMe(){return pt}function pMe(){return xm(ft)}function Ik(){if(!(!pt||!mp(pt)))try{let e=gk(pt,"utf8");return e.trim()?e:void 0}catch{return}}function bk(){return Ik()!==void 0}function fMe(){return ft.state==="inactive"?"":ft.state==="pending"?"plan pending":bk()?"plan \u25CF ready":"plan \u25CF planning"}function $k(){return ap?xk(ap,"plan_mode.json"):void 0}function RL(){let e=$k();if(e)try{lk(yk(e),{recursive:!0}),fr(e,JSON.stringify(ft))}catch{}}function PL(){let e=$k();if(!e||!mp(e))return ym();try{return $L(JSON.parse(gk(e,"utf8")))}catch{return ym()}}function AL(e){ap=e,pt=xk(e,"plan.md"),ft=PL()}function up(e){return ft=e,RL(),ft}function dMe(){return e=>{e.on("tool_call",async t=>{if(!xm(ft)||t.toolName!=="edit"&&t.toolName!=="write")return;let r=t.input?.path;if(typeof r=="string"&&!(!pt||TL(r,pt)))return{block:!0,reason:CL(pt)}})}}function lMe(){return e=>{e.on("session_start",async(t,r)=>{AL(r.sessionManager.getSessionDir())}),e.on("before_agent_start",async()=>{ft.state==="pending"&&up(EL(ft))}),e.on("context_with_system",async t=>{if(!xm(ft)||!pt)return;let r=t.messages[0];if(!r||r.role!=="system")return;let n=wL(pt,bk()),o=`${typeof r.content=="string"?r.content:""}
|
|
29
|
+
|
|
30
|
+
${n}`;return{messages:t.messages.map(a=>a===r?{...r,content:o}:a)}})}}var sp=2e4;function OL(){if(pt){try{lk(yk(pt),{recursive:!0}),mp(pt)||fr(pt,"")}catch{return}return pt}}var gMe=hk({name:"enter_plan_mode",label:"enter_plan_mode",description:"Enter plan mode to design an approach before writing code. Use it when a task has genuine ambiguity; several reasonable designs, or a restructuring where the wrong approach wastes significant effort. Do not use it for a clear fix, a rename, or a task that follows existing conventions. The user must approve entering.",promptSnippet:"enter_plan_mode: design first when the approach is genuinely ambiguous",parameters:D.Object({}),async execute(e,t,r,n,o){if(ft.state!=="inactive")return{content:[{type:"text",text:`Plan mode is already ${ft.state}.`}],details:{}};if(!o.hasUI)return{content:[{type:"text",text:"Plan mode needs an interactive session: there is no one to approve the plan. Proceed normally."}],details:{},isError:!0};if(!await o.ui.confirm("Enter plan mode?","The agent will explore and design an approach before editing anything."))return{content:[{type:"text",text:"The user declined plan mode. Proceed normally."}],details:{}};up(SL(ft));let a=OL();return{content:[{type:"text",text:["Plan mode is active. Edits are blocked except for the plan file.",a?`Write your plan to ${a}.`:"Write your plan to the session plan file."].join(`
|
|
31
|
+
`)}],details:{planFile:a}}}}),yMe=hk({name:"exit_plan_mode",label:"exit_plan_mode",description:"Present your plan for approval when you have finished planning. The plan is read from the plan file on disk, so write the file first. If the user asks for changes, stay in plan mode and revise it.",promptSnippet:"exit_plan_mode: present the written plan for approval",parameters:D.Object({}),executionMode:"sequential",async execute(e,t,r,n,o){if(!xm(ft))return{content:[{type:"text",text:"Plan mode is not active."}],details:{},isError:!0};let i=Ik();if(!i)return{content:[{type:"text",text:`No plan has been written yet. Write it to ${pt??"the plan file"} before exiting plan mode.`}],details:{},isError:!0};if(!o.hasUI)return{content:[{type:"text",text:"Plan approval needs an interactive session."}],details:{},isError:!0};let a=i.length>sp?`${i.slice(0,sp)}
|
|
32
|
+
\u2026 (${i.length-sp} more characters)`:i;return await o.ui.confirm("Approve this plan?",a)?(up(kL(ft)),{content:[{type:"text",text:"Plan approved. You may now implement it."}],details:{approved:!0,planFile:pt}}):{content:[{type:"text",text:"The user did not approve the plan. Stay in plan mode, revise the plan file with the feedback, and present it again."}],details:{approved:!1}}}});function Co(e){return typeof e=="string"?e:Array.isArray(e)?e.map(t=>{let r=t;return r.type==="text"&&typeof r.text=="string"?r.text:""}).join(`
|
|
33
|
+
`):e==null?"":String(e)}function hm(e,t){if(Array.isArray(e)){let r=e.map(o=>({...o})),n=r.filter(o=>o.type==="text");if(n.length>0){n[0].text=t;for(let o of n.slice(1))o.text="";return r}return[...r,{type:"text",text:t}]}return t}function Ek(){return e=>{e.on("context_with_system",async t=>{let r=mk();if(!r)return;let n=t.messages[0];if(!n||n.role!=="system")return;let o=`${Co(n.content)}
|
|
34
|
+
|
|
35
|
+
${r}`;return{messages:t.messages.map(a=>a===n?{...n,content:hm(n.content,o)}:a)}})}}import{Type as Nn}from"@netrodev/hxf-ai";import{defineTool as ML}from"@netrodev/hxf-coding-agent";var Ro="[Compressed conversation section]";function Ni(e){return Math.round(e.length/4)}function cp(e){let t=e.prune.messages.nextBlockId;return!Number.isInteger(t)||t<1?(e.prune.messages.nextBlockId=2,1):(e.prune.messages.nextBlockId=t+1,t)}function pp(e){let t=e.prune.messages.nextRunId;return!Number.isInteger(t)||t<1?(e.prune.messages.nextRunId=2,1):(e.prune.messages.nextRunId=t+1,t)}function fp(e,t,r="xml"){let n=Do(Gn(e,r),void 0,r),o=t.trim();return o.length===0?`${Ro}
|
|
36
|
+
${n}`:`${Ro}
|
|
37
|
+
${o}
|
|
38
|
+
|
|
39
|
+
${n}`}function Ur(e){return e.prune.messages.blocks.filter(t=>t.active).map(t=>({blockId:t.blockId,anchorIndex:t.anchorIndex,coveredIndices:t.coveredIndices,summary:t.summary}))}function dp(e,t,r,n,o,i,a){let m=e.prune.messages,c=[...new Set(a.filter(b=>Number.isInteger(b)&&b>0))],p=new Set;for(let b of m.blocks)if(b.active)for(let k of b.coveredIndices)p.add(k);let f=new Set(r.indices);for(let b of c){let k=m.blocks.find(_=>_.blockId===b);if(k)for(let _ of k.coveredIndices)f.add(_)}let d=[...f].sort((b,k)=>b-k),g=d.filter(b=>!p.has(b)),y=0;for(let b of g)y+=r.tokenByIndex.get(b)??0;let I={blockId:o,runId:t.runId,active:!0,deactivatedByUser:!1,mode:t.mode,topic:t.topic,startId:t.startId,endId:t.endId,anchorIndex:n,compressedTokens:y,summaryTokens:Ni(i),coveredIndices:d,consumedBlockIds:c,parentBlockIds:[],createdAt:Date.now(),summary:i};m.blocks.push(I);let h=Date.now();for(let b of c){let k=m.blocks.find(_=>_.blockId===b);!k||!k.active||(k.active=!1,k.deactivatedAt=h,k.deactivatedByBlockId=o,k.parentBlockIds.includes(o)||k.parentBlockIds.push(o))}return e.stats.totalCompressTokens+=y,{compressedTokens:y,coveredIndices:d,newlyCoveredIndices:g}}function kk(e,t="xml"){let r=[],n=t==="compact"?/@b([1-9]\d*)@/gi:/\(b(\d+)\)/gi,o;for(;(o=n.exec(e))!==null;){let i=Number.parseInt(o[1],10);Number.isInteger(i)&&r.push({raw:o[0],blockId:i,startIndex:o.index,endIndex:o.index+o[0].length})}return r}function Tk(e){if(typeof e.topic!="string"||e.topic.trim().length===0)throw new Error("topic is required and must be a non-empty string");if(!Array.isArray(e.content)||e.content.length===0)throw new Error("content is required and must be a non-empty array");for(let t=0;t<e.content.length;t++){let r=e.content[t],n=`content[${t}]`;if(typeof r?.startId!="string"||r.startId.trim().length===0)throw new Error(`${n}.startId is required and must be a non-empty string`);if(typeof r?.endId!="string"||r.endId.trim().length===0)throw new Error(`${n}.endId is required and must be a non-empty string`);if(typeof r?.summary!="string"||r.summary.trim().length===0)throw new Error(`${n}.summary is required and must be a non-empty string`)}}function lp(e,t,r,n){let o=new Set,i=new Map;for(let d of r)o.add(d.index),i.set(d.index,d.tokenCount??0);let a=Sk(e,o,t.startId,"startId",n),m=Sk(e,o,t.endId,"endId",n);if(a.index>m.index)throw new Error(`startId ${a.ref} appears after endId ${m.ref} in the conversation. Start must come before end.`);let c=[];for(let d of r)d.index>=a.index&&d.index<=m.index&&c.push(d.index);let p=new Set(c),f=e.prune.messages.blocks.filter(d=>d.active&&p.has(d.anchorIndex)).map(d=>d.blockId);return{startIdx:a.index,endIdx:m.index,indices:c,requiredBlockIds:f,tokenByIndex:i}}function Sk(e,t,r,n,o){let i=Km(r,o);if(i===null){let m=o==="compact"?"@4@":"mNNNN",c=o==="compact"?"@b1@":"bN";throw new Error(`${n} is invalid. Use an injected message ID (${m}) or block ID (${c}).`)}let a;if(i.kind==="message")a=i.index;else{let m=e.prune.messages.blocks.find(c=>c.blockId===i.blockId&&c.active);a=m?m.anchorIndex:-1}if(a<0||!t.has(a))throw new Error(`${n} ${i.ref} is not available in the current conversation context. Choose an injected ID visible in context.`);return{ref:i.ref,index:a}}function wk(e,t,r,n="xml"){let i=[...e.map((m,c)=>{let p={startId:m.startId.trim(),endId:m.endId.trim(),summary:m.summary};return{index:c,entry:p,selection:lp(t,p,r,n)}})].sort((m,c)=>m.selection.startIdx-c.selection.startIdx||m.selection.endIdx-c.selection.endIdx||m.index-c.index),a=[];for(let m=1;m<i.length;m++){let c=i[m-1],p=i[m];!c||!p||p.selection.startIdx>c.selection.endIdx||a.push(`content[${c.index}] (${c.entry.startId}..${c.entry.endId}) overlaps content[${p.index}] (${p.entry.startId}..${p.entry.endId}). Overlapping ranges cannot be compressed in the same batch.`)}if(a.length>0)throw new Error(a.length===1?a[0]:a.map(m=>`- ${m}`).join(`
|
|
40
|
+
`))}function Ck(e,t,r,n="xml"){let o=new Set(t.prune.messages.blocks.filter(i=>i.active).map(i=>i.blockId));return e.map((i,a)=>{let m={startId:i.startId.trim(),endId:i.endId.trim(),summary:i.summary},c=lp(t,m,r,n),p=new Set(c.requiredBlockIds),f=kk(m.summary,n),d=new Set,g=`content[${a}]`;for(let y of f){if(d.has(y.blockId))throw new Error(`${g}.summary duplicates placeholder ${y.raw}`);if(d.add(y.blockId),!p.has(y.blockId))throw new Error(o.has(y.blockId)?`${g}.summary references ${y.raw}, which is outside the selected range`:`${g}.summary references ${y.raw}, which is not an active compressed block`)}for(let y of c.requiredBlockIds)if(!d.has(y)){let I=n==="compact"?`@b${y}@`:`(b${y})`;throw new Error(`${g}.summary is missing the required placeholder ${I}`)}return f})}function Rk(e,t,r,n="xml"){return e.map((o,i)=>{let a={startId:o.startId.trim(),endId:o.endId.trim(),summary:o.summary},m=lp(t,a,r,n);return{index:i,entry:a,selection:m,anchorIndex:m.startIdx}})}function vL(e){let t=e.match(/^\s*\[Compressed conversation(?: section)?(?: b\d+)?\]/i);return t?e.slice(t[0].length).replace(/^(?:\r?\n)+/,"").replace(/(?:\r?\n)*<dcp-message-id>b\d+<\/dcp-message-id>\s*$/i,"").replace(/(?:\r?\n)*@b[1-9]\d*@\s*$/i,"").replace(/(?:\r?\n)+$/,""):e}function FL(e,t,r){if(t.length===0)return{expanded:e,consumedBlockIds:[]};let n="",o=0,i=[];for(let a of t){let m=r.prune.messages.blocks.find(c=>c.blockId===a.blockId&&c.active);if(!m)throw new Error(`Compressed block not found: ${a.raw}`);n+=e.slice(o,a.startIndex),n+=vL(m.summary),o=a.endIndex,i.push(a.blockId)}return n+=e.slice(o),{expanded:n,consumedBlockIds:i}}function Pk(e,t,r,n="xml"){Tk(e),wk(e.content,t,r,n);let o=Ck(e.content,t,r,n),i=Rk(e.content,t,r,n),a=pp(t),m=[];for(let[c,p]of i.entries()){let f=o[c]??[],{expanded:d,consumedBlockIds:g}=FL(p.entry.summary,f,t),y=cp(t),I=fp(y,d,n),h=dp(t,{topic:e.topic,startId:p.entry.startId,endId:p.entry.endId,mode:"range",runId:a},p.selection,p.anchorIndex,y,I,g);m.push({blockId:y,runId:a,coveredCount:h.coveredIndices.length,compressedTokens:h.compressedTokens,summaryTokens:Ni(I),expandedSummary:d})}return m}function LL(e){let t=e.format??"xml",r=Bn(1,t),n=Gn(2,t);return ML({name:"compress",label:"compress",description:`Collapse conversation ranges into stored compressed summaries, each marked with "${Ro}". Copy startId and endId from the injected IDs in context (message IDs like ${r}, block IDs like ${n}); startId must come before endId. Ranges in one call must not overlap, and each summary must reference every required block placeholder exactly once.`,promptSnippet:"compress: replace a conversation range with a stored summary",parameters:Nn.Object({topic:Nn.String({description:"Short label (3-5 words) for display - e.g., 'Auth System Exploration'"}),content:Nn.Array(Nn.Object({startId:Nn.String({description:`Message or block ID marking the beginning of range (e.g. ${r}, ${n})`}),endId:Nn.String({description:`Message or block ID marking the end of range (e.g. ${Bn(12,t)}, ${Gn(5,t)})`}),summary:Nn.String({description:"Complete technical summary replacing all content in range"})}),{description:"One or more ranges to compress, each with start/end boundaries and a summary"})}),async execute(o,i){try{let a=Pk(i,e.state(),e.messages(),t),m=a.map(g=>g.blockId),c=a.reduce((g,y)=>g+y.coveredCount,0),p=a.reduce((g,y)=>g+y.compressedTokens,0),f=a.reduce((g,y)=>g+y.summaryTokens,0),d=Math.max(0,p-f);return{content:[{type:"text",text:`Compressed ${c} messages into ${Ro}`+(p>0?` - ${p} tokens replaced by ${f}, saving ${d}.`:".")}],details:{blockIds:m,runId:a[0]?.runId,messages:c,compressedTokens:p,summaryTokens:f}}}catch(a){let m=a instanceof Error?a.message:String(a);return{content:[{type:"text",text:m}],details:{error:m},isError:!0}}}})}import{existsSync as Ak,mkdirSync as DL,readFileSync as Ok,unlinkSync as jL}from"node:fs";import{dirname as NL,join as Mk}from"node:path";function gp(e){try{let t=Mk(e,".howtocode","dcp.json");if(!Ak(t))return;let r=JSON.parse(Ok(t,"utf8"));if(typeof r!="object"||r===null)return;let n=r.enabled;return typeof n=="boolean"?n:void 0}catch{return}}function yp(e){if(e.env!==void 0){let t=e.env.trim().toLowerCase();return{enabled:t!=="0"&&t!=="false",source:"env"}}return e.config!==void 0?{enabled:e.config,source:"config"}:e.runtime!==void 0?{enabled:e.runtime,source:"session"}:{enabled:!0,source:"default"}}function vk(){return{messageIds:Gm(),prune:{tools:{},messages:{blocks:[],nextBlockId:1,nextRunId:1}},stats:{totalPruneTokens:0,totalCompressTokens:0}}}function bm(e){let t=e.replace(/[^A-Za-z0-9._-]/g,"_")||"session";return Mk(tt,"dcp",`${t}.json`)}function qL(e){if(typeof e!="object"||e===null)return!1;let t=e,r=t.prune?.messages,n=t.messageIds;return typeof t.prune=="object"&&t.prune!==null&&typeof t.prune.tools=="object"&&t.prune.tools!==null&&typeof r=="object"&&r!==null&&Array.isArray(r.blocks)&&Number.isInteger(r.nextBlockId)&&Number.isInteger(r.nextRunId)&&typeof n=="object"&&n!==null&&Number.isInteger(n.nextRef)&&typeof n.keyToRef=="object"&&n.keyToRef!==null&&typeof n.refToKey=="object"&&n.refToKey!==null&&typeof t.stats=="object"&&t.stats!==null&&Number.isFinite(t.stats.totalPruneTokens)&&Number.isFinite(t.stats.totalCompressTokens)}var Im=new Map;function qi(e){let t=Im.get(e);if(t)return t;let r;try{let o=bm(e);if(Ak(o)){let i=JSON.parse(Ok(o,"utf8"));qL(i)&&(r=i)}}catch{r=void 0}let n=r??vk();return Im.set(e,n),n}function gn(e){let t=Im.get(e);if(!t)return;let r=bm(e);DL(NL(r),{recursive:!0}),fr(r,JSON.stringify(t))}function _L(e){Im.delete(e);try{jL(bm(e))}catch{}}function mr(e){return e.replaceAll("\\","/")}function UL(e){return/[\\.^$+{}()|\[\]]/.test(e)?`\\${e}`:e}function xp(e,t){if(!t)return!1;let r=mr(e),n=mr(t),o="^";for(let i=0;i<n.length;i++){let a=n[i];if(a==="*"){if(n[i+1]==="*"){if(n[i+2]==="/"){o+="(?:.*/)?",i+=2;continue}o+=".*",i++;continue}o+="[^/]*";continue}if(a==="?"){o+="[^/]";continue}if(a==="/"){o+="/";continue}o+=UL(a)}return o+="$",new RegExp(o).test(r)}function $m(e,t){if(typeof t!="object"||t===null)return[];let r=[],n=t;if((e==="apply_patch"||e==="patch")&&typeof n.patchText=="string"){let o=/\*\*\* (?:Add|Delete|Update) File: ([^\n\r]+)/g,i;for(;(i=o.exec(n.patchText))!==null;)r.push(i[1].trim())}if(e==="multiedit"&&(typeof n.filePath=="string"&&r.push(n.filePath),Array.isArray(n.edits)))for(let o of n.edits)o&&typeof o=="object"&&typeof o.filePath=="string"&&r.push(o.filePath);return typeof n.filePath=="string"&&r.push(n.filePath),["read","write","edit"].includes(e)&&typeof n.path=="string"&&r.push(n.path),[...new Set(r)].filter(o=>o.length>0)}function Fk(e,t){return e.length===0||t.length===0?!1:e.some(r=>t.some(n=>xp(r,n)))}var BL=/[*?]/,qn=["todo","goal","context","task"];function Lk(e,t){if(!e||t.length===0)return!1;let r=new Set,n=[];for(let o of t)BL.test(o)?n.push(o):r.add(o);return r.has(e)?!0:n.some(o=>xp(e,o))}function Em(e,t,r,n,o){let i=[{tool:e,input:t}];if(e==="execute"&&Array.isArray(o?.toolCalls))for(let a of o.toolCalls)a&&typeof a=="object"&&typeof a.tool=="string"&&i.push({tool:a.tool,input:a.input});return i.some(a=>Lk(a.tool,r)||Fk($m(a.tool,a.input),n))}function Ip(e,t){return t==null?e:`${e}::${JSON.stringify(hp(GL(t)))}`}function GL(e){if(typeof e!="object"||e===null||Array.isArray(e))return e;let t={};for(let[r,n]of Object.entries(e))n!=null&&(t[r]=n);return t}function hp(e){if(typeof e!="object"||e===null)return e;if(Array.isArray(e))return e.map(hp);let t={};for(let r of Object.keys(e).sort())t[r]=hp(e[r]);return t}var Po="[Output removed to save context - information superseded or no longer needed]",bp="[input removed due to failed tool call]",jk="[questions removed - see output for user's answers]",Nk=2e3,Sm=["ask","question"],Dk=["read","grep","ls"],KL=["edit","write","multiedit","apply_patch","patch"];function HL(e){return e.filter(t=>t.type==="text").map(t=>t.text).join("")}function zL(e){if(!e)return{total:0,count:0};let t=0,r=0;for(let n of Object.values(e))typeof n=="string"&&(t+=n.length,r++);return{total:t,count:r}}function WL(e){return e.replace(/[.*+?^${}()|[\]\\]/g,"\\$&")}function $p(e,t,r){let n=r?.bigOutputChars??Nk,o=new Map,i=[];for(let h=0;h<e.length;h++){let b=e[h];if(b.role==="assistant")for(let k of b.content)k.type==="toolCall"&&o.set(k.id,{name:k.name,args:k.arguments,callIndex:h});else if(b.role==="toolResult"){let k=o.get(b.toolCallId),_=b.toolName;i.push({index:h,callId:b.toolCallId,tool:_,isError:b.isError,text:HL(b.content),paths:k?$m(_,k.args):[],signature:Ip(_,k?.args),callIndex:k?.callIndex??-1})}}let a=t.planFile?mr(t.planFile):void 0,m=h=>h.index===0||qn.includes(h.tool)||a!==void 0&&h.paths.some(b=>mr(b)===a),c=h=>h.callIndex<0||h.callIndex===0||qn.includes(h.tool)||a!==void 0&&h.paths.some(b=>mr(b)===a),p=[],f=new Set,d=h=>{let b=`${h.kind}:${h.callId}`;f.has(b)||(f.add(b),p.push(h))},g=new Map;for(let h of i)if(!(h.isError||!Dk.includes(h.tool)&&!KL.includes(h.tool)))for(let b of h.paths){let k=mr(b),_=g.get(k);(_===void 0||h.index>_)&&g.set(k,h.index)}for(let h of i){if(h.isError||!Dk.includes(h.tool)||m(h)||h.text===Po)continue;h.paths.some(k=>(g.get(mr(k))??-1)>h.index)&&d({kind:"output",reason:"superseded-read",callId:h.callId,messageIndex:h.index,savedChars:Math.max(0,h.text.length-Po.length)})}let y=new Map;for(let h of i){if(h.isError)continue;let b=y.get(h.signature);(b===void 0||h.index>b)&&y.set(h.signature,h.index)}for(let h of i){if(!h.isError||m(h))continue;let b=y.get(h.signature);if(!(b===void 0||b<=h.index)&&(d({kind:"output",reason:"error-then-success",callId:h.callId,messageIndex:h.index,savedChars:Math.max(0,h.text.length-Po.length)}),!c(h))){let k=o.get(h.callId)?.args,{total:_,count:A}=zL(k);A>0&&d({kind:"failed-input",reason:"error-then-success",callId:h.callId,messageIndex:h.callIndex,savedChars:Math.max(0,_-A*bp.length)})}}if(t.files.length>0||t.identifiers.length>0){let h=[...t.files.map(mr),...a?[a]:[]],b=h.map(A=>A.split("/").pop()??"").filter(A=>A.length>0),k=t.identifiers.map(A=>new RegExp(`(?<![\\w.-])${WL(A)}(?![\\w.-])`)),_=A=>{let Fe=mr(A);return h.some(We=>Fe.includes(We))||b.some(We=>A.includes(We))?!0:k.some(We=>We.test(A))};for(let A of i)m(A)||Sm.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-Po.length)})}let I=0;for(let h of p)I+=h.savedChars;return{ops:p,savedChars:I}}function Ep(e,t){let r=new Set,n=new Set,o=new Set;for(let i of t)i.kind==="output"?r.add(i.callId):i.kind==="question-input"?n.add(i.callId):o.add(i.callId);return Uk(_k(qk(e,r),n),o)}function qk(e,t){return t.size===0?[...e]:e.map((r,n)=>n===0||r.role!=="toolResult"||!t.has(r.toolCallId)||Sm.includes(r.toolName)?r:{...r,content:[{type:"text",text:Po}]})}function _k(e,t){if(t.size===0)return[...e];let r=new Set;for(let n of e)n.role==="toolResult"&&!n.isError&&t.has(n.toolCallId)&&r.add(n.toolCallId);return r.size===0?[...e]:e.map((n,o)=>{if(o===0||n.role!=="assistant")return n;let i=!1,a=n.content.map(m=>{if(m.type!=="toolCall"||!r.has(m.id)||!Sm.includes(m.name))return m;let c={...m.arguments},p=!1;for(let f of["question","questions","options"])f in c&&(c[f]=jk,p=!0);return p?(i=!0,{...m,arguments:c}):m});return i?{...n,content:a}:n})}function Uk(e,t){if(t.size===0)return[...e];let r=new Set;for(let n of e)n.role==="toolResult"&&n.isError&&t.has(n.toolCallId)&&r.add(n.toolCallId);return r.size===0?[...e]:e.map((n,o)=>{if(o===0||n.role!=="assistant")return n;let i=!1,a=n.content.map(m=>{if(m.type!=="toolCall"||!r.has(m.id))return m;let c={},p=!1;for(let[f,d]of Object.entries(m.arguments))typeof d=="string"?(c[f]=bp,p=!0):c[f]=d;return p?(i=!0,{...m,arguments:c}):m});return i?{...n,content:a}:n})}function Sp(e,t,r){if(t.length===0)return[...e];let n=Vr(r,e),o=new Map;for(let d=0;d<n.length;d++){let g=n[d];g!==null&&o.set(g,d)}let i=new Set,a=new Map;for(let d of t){let g=[];for(let I of d.coveredIndices){let h=o.get(I);h!==void 0&&(i.add(h),g.push(h))}let y=o.get(d.anchorIndex)??(g.length>0?Math.min(...g):void 0);if(d.summary&&y!==void 0){let I=a.get(y);I?I.push(d.summary):a.set(y,[d.summary])}}let m=new Map,c=new Map;for(let d=0;d<e.length;d++){let g=e[d];if(g)if(g.role==="assistant"&&Array.isArray(g.content))for(let y of g.content)y.type==="toolCall"&&m.set(d,y.id);else g.role==="toolResult"&&c.set(g.toolCallId,d)}let p=[...i];for(;p.length>0;){let d=p.pop(),g=m.get(d);if(g!==void 0){let I=c.get(g);I!==void 0&&!i.has(I)&&(i.add(I),p.push(I))}let y=e[d];if(y?.role==="toolResult")for(let[I,h]of m)h===y.toolCallId&&!i.has(I)&&(i.add(I),p.push(I))}let f=[];for(let d=0;d<e.length;d++){let g=a.get(d);if(g){let y=e[d];for(let I of g){let h={role:"user",content:I,timestamp:y.timestamp};f.push(h)}}i.has(d)||f.push(e[d])}return f}var kp={thresholdChars:8192,headChars:4096,tailChars:1024};function VL(e,t={}){let r=t.thresholdChars??kp.thresholdChars,n=t.headChars??kp.headChars,o=t.tailChars??kp.tailChars;if(e.length<=r||n+o>=e.length)return{text:e,prunedChars:0};let i=n,a=e.charCodeAt(i-1);a>=55296&&a<=56319&&(i-=1);let m=e.length-o,c=e.charCodeAt(m);c>=56320&&c<=57343&&(m+=1);let p=e.slice(0,i),f=e.slice(m),d=m-i,g=`
|
|
41
|
+
|
|
42
|
+
[... ${d} characters pruned from the middle ...]
|
|
43
|
+
|
|
44
|
+
`;return{text:p+g+f,prunedChars:d-g.length}}function Bk(e,t={}){let r=0,n=0,o=!1,i=e.map(a=>{let m=a;if(m.role!=="toolResult"||!Array.isArray(m.content))return a;let c=m.content,p=!1,f=c.map(d=>{if(!d||typeof d!="object")return d;let g=d;if(g.type!=="text"||typeof g.text!="string")return d;let y=VL(g.text,t);return y.prunedChars<=0?d:(p=!0,r+=y.prunedChars,{...d,text:y.text})});return p?(o=!0,n+=1,{...a,content:f}):a});return{messages:o?i:e,savedChars:r,prunedResults:n}}function Tp(e="xml"){let t=e==="compact",r=t?"@4@":"mNNNN",n=t?"@b1@":"bN",o=t?"@b1@":"(bN)";return`COMPRESSING A RANGE OF THIS CONVERSATION
|
|
45
|
+
|
|
46
|
+
This is what the \`compress\` tool is for, and how a range must be summarised when it is used. Reach for it when the conversation has grown long enough that its older turns cost more than they are worth - never as a way to answer the user, and never on a range they did not ask about. Nothing here is a standing instruction to summarise: it is the contract the tool's output is held to.
|
|
47
|
+
|
|
48
|
+
THE SUMMARY
|
|
49
|
+
Your summary must be EXHAUSTIVE. Capture file paths, function signatures, decisions made, constraints discovered, key findings... EVERYTHING that maintains context integrity. This is not a brief note - it is an authoritative record so faithful that the original conversation adds no value.
|
|
50
|
+
|
|
51
|
+
USER INTENT FIDELITY
|
|
52
|
+
When the compressed range includes user messages, preserve the user's intent with extra care. Do not change scope, constraints, priorities, acceptance criteria, or requested outcomes.
|
|
53
|
+
Directly quote user messages when they are short enough to include safely. Direct quotes are preferred when they best preserve exact meaning.
|
|
54
|
+
|
|
55
|
+
Yet be LEAN. Strip away the noise: failed attempts that led nowhere, verbose tool outputs, back-and-forth exploration. What remains should be pure signal - golden nuggets of detail that preserve full understanding with zero ambiguity.
|
|
56
|
+
|
|
57
|
+
COMPRESSED BLOCK PLACEHOLDERS
|
|
58
|
+
When the selected range includes previously compressed blocks, use this exact placeholder format when referencing one:
|
|
59
|
+
|
|
60
|
+
- \`${o}\`
|
|
61
|
+
|
|
62
|
+
Compressed block sections in context are clearly marked with a header:
|
|
63
|
+
|
|
64
|
+
- \`[Compressed conversation section]\`
|
|
65
|
+
|
|
66
|
+
${t?"Compressed block IDs look like `@b1@`, distinct from raw message IDs like `@4@`.":"Compressed block IDs always use the `bN` form (never `mNNNN`) and are represented in the same XML metadata tag format."}
|
|
67
|
+
|
|
68
|
+
Rules:
|
|
69
|
+
|
|
70
|
+
- Include every required block placeholder exactly once.
|
|
71
|
+
- Do not invent placeholders for blocks outside the selected range.
|
|
72
|
+
- Treat \`${o}\` placeholders as RESERVED TOKENS. Do not emit \`${o}\` text anywhere except intentional placeholders.
|
|
73
|
+
- If you need to mention a block in prose, use plain text like \`compressed ${t?"block 1":"bN"}\` (not as a placeholder).
|
|
74
|
+
- Preflight check before finalizing: the set of \`${o}\` placeholders in your summary must exactly match the required set, with no duplicates.
|
|
75
|
+
|
|
76
|
+
These placeholders are semantic references. They will be replaced with the full stored compressed block content when the tool processes your output.
|
|
77
|
+
|
|
78
|
+
FLOW PRESERVATION WITH PLACEHOLDERS
|
|
79
|
+
When you use compressed block placeholders, write the surrounding summary text so it still reads correctly AFTER placeholder expansion.
|
|
80
|
+
|
|
81
|
+
- Treat each placeholder as a stand-in for a full conversation segment, not a short label.
|
|
82
|
+
- Ensure transitions before and after each placeholder preserve chronology and causality.
|
|
83
|
+
- Do not write text that depends on the placeholder staying literal (for example, "as noted in \`${t?"@b2@":"(b2)"}\`").
|
|
84
|
+
- Your final meaning must be coherent once each placeholder is replaced with its full compressed block content.
|
|
85
|
+
|
|
86
|
+
BOUNDARY IDS
|
|
87
|
+
You specify boundaries by ID using the injected IDs visible in the conversation:
|
|
88
|
+
|
|
89
|
+
- \`${r}\` IDs identify raw messages
|
|
90
|
+
- \`${n}\` IDs identify previously compressed blocks
|
|
91
|
+
|
|
92
|
+
${t?"Each message has an ID like `@4@`. Copy the whole marker, including both `@` characters, into `startId` and `endId`.":"Each message has an ID inside XML metadata tags like `<dcp-message-id>...</dcp-message-id>`."}
|
|
93
|
+
The same ID tag appears in every tool output of the message it belongs to \u2014 each unique ID identifies one complete message.
|
|
94
|
+
Treat these tags as boundary metadata only, not as tool result content.
|
|
95
|
+
|
|
96
|
+
Rules:
|
|
97
|
+
|
|
98
|
+
- Pick \`startId\` and \`endId\` directly from injected IDs in context.
|
|
99
|
+
- IDs must exist in the current visible context.
|
|
100
|
+
- \`startId\` must appear before \`endId\`.
|
|
101
|
+
- Do not invent IDs. Use only IDs that are present in context.
|
|
102
|
+
|
|
103
|
+
BATCHING
|
|
104
|
+
When multiple independent ranges are ready and their boundaries do not overlap, include all of them as separate entries in the \`content\` array of a single tool call. Each entry should have its own \`startId\`, \`endId\`, and \`summary\`.
|
|
105
|
+
`}function wp(e,t,r,n){let o=new Map;if(t.idState){let m=Vr(t.idState,t.messages);for(let c=0;c<m.length;c++){let p=m[c];p!==null&&o.set(p,c)}}let i=new Set;for(let m of Ur(r))if(!(n!==void 0&&m.blockId===n))for(let c of m.coveredIndices)i.add(c);let a=[];if(t.idState)for(let m of e.indices){if(i.has(m))continue;let c=o.get(m);c!==void 0&&a.push(c)}return a}function Gk(e){if(typeof e.content=="string")return e.content.trim()?[e.content]:[];let t=[];for(let r of e.content)r.type==="text"&&r.text.trim()&&t.push(r.text);return t}function Kk(e,t,r,n,o,i){if(!o)return e;let a=[];for(let p of wp(t,r,n,i)){let f=r.messages[p];if(!f||f.role!=="user")continue;let d=Gk(f)[0];d!==void 0&&a.push(d)}if(a.length===0)return e;let m=`
|
|
106
|
+
|
|
107
|
+
The following user messages were sent in this conversation verbatim:`,c=a.map(p=>`
|
|
108
|
+
${p}`).join("");return e+m+c}function Hk(e,t,r,n,o,i){if(!o)return e;let a=[];for(let p of wp(t,r,n,i)){let f=r.messages[p];if(!(!f||f.role!=="user"))for(let d of Gk(f))a.push(...zk(d))}if(a.length===0)return e;let m=`
|
|
109
|
+
|
|
110
|
+
The following protected prompt information was included in this conversation verbatim:`,c=a.map(p=>`
|
|
111
|
+
${p}`).join("");return e+m+c}function zk(e){let t=[],r=/<protect>([\s\S]*?)<\/protect>/gi;for(let n of e.matchAll(r)){let o=n[1]?.trim();o&&t.push(o)}return t}function Wk(e,t,r,n,o=[],i=[],a){let m=new Map,c=[];for(let y of wp(t,r,n,a)){let I=r.messages[y];if(I){if(I.role==="assistant"){for(let h of I.content)h.type==="toolCall"&&m.set(h.id,h.arguments);continue}if(I.role==="toolResult"){if(I.isError)continue;let h=I.content.filter(b=>b.type==="text").map(b=>b.text).join("");h.trim()&&c.push({toolCallId:I.toolCallId,toolName:I.toolName,text:h})}}}if(c.length===0)return e;let p=[...new Set([...qn,...o])],f=[...i],d=[];for(let y of c){let I=m.get(y.toolCallId);Em(y.toolName,I,p,f)&&d.push(`
|
|
112
|
+
### Tool: ${y.toolName}
|
|
113
|
+
${y.text}`)}return d.length===0?e:e+`
|
|
114
|
+
|
|
115
|
+
The following protected tools were used in this conversation as well:`+d.join("")}function Vk(e,t,r){if(t.protectedEnriched)return;let n=t.coveredIndices;if(n.length>0){let o={startIdx:Math.min(...n),endIdx:Math.max(...n),indices:[...n],requiredBlockIds:[],tokenByIndex:new Map},i={messages:r,idState:e.messageIds},a=Wk(Hk(Kk(t.summary,o,i,e,!0,t.blockId),o,i,e,!0,t.blockId),o,i,e,[],[],t.blockId);t.summary=a,t.summaryTokens=Ni(a)}t.protectedEnriched=!0}function Jk(e,t){let r=[];for(let n=0;n<e.length;n+=1){let o=e[n];if(o===null)continue;let i=t[n],a=i&&"content"in i?Co(i.content):"";r.push({index:o,tokenCount:Math.round(a.length/4)})}return r}var JL="COMPRESSED BLOCK PLACEHOLDERS",Cp=new Map;function YL(e){return Cp.get(e)??[]}function QL(e){Cp.delete(e)}var Yk;function XL(){return Yk}function ZL(e={}){return t=>{t.on("context_with_system",async(r,n)=>{let o=n?.sessionManager?.getSessionId()??"dcp-sessionless",i=qi(o);if(i.enabled===!1)return;let a=r.messages,m=a[0];if(!m||m.role!=="system")return;zm(i.messageIds,a);let c=Vr(i.messageIds,a);Cp.set(o,Jk(c,a)),Yk=o;let p=eD(a),f=Sp(p,Ur(i),i.messageIds),d=Bk(f);d.prunedResults>0&&(f=[...d.messages]);let g=e.keepSet?.()??{files:[],identifiers:[]},y=$p(f,g);if(y.ops.length>0){f=Ep(f,y.ops);for(let h of y.ops)i.prune.tools[h.callId]=(i.prune.tools[h.callId]??0)+h.savedChars;i.stats.totalPruneTokens=Object.values(i.prune.tools).reduce((h,b)=>h+b,0)}for(let h of i.prune.messages.blocks)h.active&&!h.protectedEnriched&&Vk(i,h,a);gn(o);let I=f.map((h,b)=>{if(b!==0||!("content"in h))return h;let k=Co(h.content);return k.includes(JL)?h:{...h,content:hm(h.content,`${k}
|
|
116
|
+
|
|
117
|
+
${Tp()}`)}});return{messages:rD(I,i.messageIds)}})}}function eD(e){return e.map(t=>{if(t.role!=="assistant"||!("content"in t))return t;let r=tD(t.content);return r===t.content?t:{...t,content:r}})}function tD(e){if(typeof e=="string")return Hm(e);if(!Array.isArray(e))return e;let t=!1,r=e.map(n=>{if(!n||typeof n!="object"||!("type"in n)||n.type!=="text")return n;let o="text"in n&&typeof n.text=="string"?n.text:"",i=Hm(o);return i===o?n:(t=!0,{...n,text:i})});return t?r:e}function rD(e,t){let r=Vr(t,e);return e.map((n,o)=>{let i=r[o];if(i==null||!("content"in n))return n;let a=Do(Bn(i));return Co(n.content).includes(a)?n:{...n,content:nD(n.content,a)}})}function nD(e,t){if(typeof e=="string")return e+t;if(!Array.isArray(e))return e;let r=!1,n=e.map(o=>{if(!o||typeof o!="object"||!("type"in o)||o.type!=="text")return o;r=!0;let i="text"in o&&typeof o.text=="string"?o.text:"";return{...o,text:i+t}});return r?n:[...n,{type:"text",text:t.trimStart()}]}var Qk={on:"turn the transform on for this session",off:"turn it off; the full transcript is sent unchanged",status:"the switch, the block count, and the tokens saved",blocks:"list the active compressed blocks",stats:"prune and compress totals for this session",context:"what the next request will carry, and what was saved",decompress:"reopen one block by id, e.g. /dcp decompress b2",sweep:"drop blocks no longer referenced by the ref state"};function Rp(e){return e<1e3?`${e}`:`${(e/1e3).toFixed(1)}k`}function oD(e,t,r){let[n]=e.trim().split(/\s+/),o=n===void 0||n===""?"status":n,i=qi(r);switch(o){case"on":return i.enabled=!0,gn(r),"dcp: on";case"off":return i.enabled=!1,gn(r),"dcp: off; the full transcript is sent unchanged";case"blocks":{let a=Ur(i);return a.length===0?"dcp: no active blocks":a.map(m=>{let c=String(m.anchorIndex).padStart(4,"0");return`b${m.blockId} covers ${m.coveredIndices.length} message(s), anchored at m${c}`}).join(`
|
|
118
|
+
`)}case"status":{let a=yp({runtime:i.enabled,config:gp(t)}),m=Ur(i),c=Object.values(i.prune.tools).reduce((p,f)=>p+f,0);return[`dcp: ${a.enabled?"on":"off"} (source: ${a.source})`,`messages tracked: ${Object.keys(i.messageIds.keyToRef).length}`,`active blocks: ${m.length}`,`pruned tool calls: ${Object.keys(i.prune.tools).length} (${Rp(c)} chars)`,`compressed tokens total: ${i.stats.totalCompressTokens}`].join(`
|
|
119
|
+
`)}case"stats":{let a=i.prune.messages.blocks,m=a.filter(p=>p.active).length,c=Object.values(i.prune.tools).reduce((p,f)=>p+f,0);return[`blocks: ${m} active of ${a.length} total`,`compressed tokens: ${i.stats.totalCompressTokens}`,`pruned tool calls: ${Object.keys(i.prune.tools).length} (${Rp(c)} chars)`,`messages tracked: ${Object.keys(i.messageIds.keyToRef).length}`,`refs allocated: ${i.messageIds.nextRef-1}`].join(`
|
|
120
|
+
`)}case"context":{let a=Ur(i),m=new Set;for(let f of a)for(let d of f.coveredIndices)m.add(d);let c=Object.keys(i.messageIds.keyToRef).length,p=Object.values(i.prune.tools).reduce((f,d)=>f+d,0);return[`messages tracked: ${c}`,`messages replaced by a block: ${m.size}`,`messages sent: ${Math.max(0,c-m.size)}`,`active blocks: ${a.length}`,`compressed tokens total: ${i.stats.totalCompressTokens}`,`pruned tool calls: ${Object.keys(i.prune.tools).length} (${Rp(p)} chars)`].join(`
|
|
121
|
+
`)}case"decompress":{let a=e.trim().split(/\s+/)[1],m=a===void 0?null:/^b?(\d+)$/i.exec(a);if(!m)return"dcp: give a block id, e.g. /dcp decompress b2";let c=Number(m[1]),p=i.prune.messages.blocks,f=p.find(g=>g.blockId===c);if(!f)return`dcp: no block b${c}`;let d=p.filter(g=>g.active&&g.consumedBlockIds.includes(c));if(d.length>0){let g=d.map(y=>`b${y.blockId}`).join(", ");return`dcp: b${c} was consumed by ${g}; decompress that one first`}if(!f.active)return`dcp: b${c} is already open`;f.active=!1,f.deactivatedByUser=!0,f.deactivatedAt=Date.now();for(let g of f.parentBlockIds){let y=p.find(I=>I.blockId===g);y&&(y.consumedBlockIds=y.consumedBlockIds.filter(I=>I!==c))}return gn(r),`dcp: b${c} reopened; ${f.coveredIndices.length} message(s) are back`}case"sweep":{let a=new Set(Object.keys(i.messageIds.refToKey).map(Number)),m=i.prune.messages.blocks,c=m.length,p=m.filter(d=>d.active&&!d.coveredIndices.some(g=>a.has(g)));for(let d of p)d.active=!1,d.deactivatedAt=Date.now();i.prune.messages.blocks=m.filter(d=>d.active||d.deactivatedByUser);let f=c-i.prune.messages.blocks.length;return gn(r),p.length===0?"dcp: nothing to sweep":`dcp: ${p.length} orphaned block(s) closed, ${f} dropped from state`}default:return`dcp: unknown subcommand '${o}'. try: ${Object.keys(Qk).join(", ")}`}}import{Type as Tm}from"@netrodev/hxf-ai";import{defineTool as oT}from"@netrodev/hxf-coding-agent";import{promises as iD}from"node:dns";var sD=/^(127\.|10\.|192\.168\.|169\.254\.|0\.)/;function Pp(e){if(sD.test(e))return!0;let t=/^172\.(\d+)\./.exec(e);if(!t)return!1;let r=Number(t[1]);return r>=16&&r<=31}function Ap(e){let t=/^100\.(\d+)\.(\d+)\.(\d+)$/.exec(e);if(t){let n=Number(t[1]);return n>=64&&n<=127}let r=/^198\.(\d+)\./.exec(e);return r!==null&&(Number(r[1])===18||Number(r[1])===19)}function Zk(e){let t=e.toLowerCase().replace(/^\[|\]$/g,"").split("%")[0];if(t==="localhost"||t.endsWith(".localhost"))return!0;let r=/^::ffff:(\d+\.\d+\.\d+\.\d+)$/.exec(t);if(r){let o=r[1];return Pp(o)||Ap(o)||o==="0.0.0.0"}let n=/^::ffff:([0-9a-f]{1,4}):([0-9a-f]{1,4})$/.exec(t);if(n){let o=Number.parseInt(n[1],16),i=Number.parseInt(n[2],16),a=`${o>>8&255}.${o&255}.${i>>8&255}.${i&255}`;return Pp(a)||Ap(a)||a==="0.0.0.0"}return t.includes(":")?!!(t==="::1"||t==="::"||/^f[cd][0-9a-f]{2}:/.test(t)||/^fe[89ab][0-9a-f]:/.test(t)):t==="0.0.0.0"?!0:Pp(t)||Ap(t)}var Op=8e4,Mp=8;function km(e){let t;try{t=new URL(e)}catch{return{ok:!1,reason:"not a URL"}}if(t.protocol!=="http:"&&t.protocol!=="https:")return{ok:!1,reason:`refused protocol ${t.protocol}`};let r=t.hostname.toLowerCase();return r==="localhost"||r.endsWith(".localhost")||r==="::1"||r==="[::1]"?{ok:!1,reason:"refused loopback host"}:Zk(r)?{ok:!1,reason:"refused private address"}:{ok:!0,url:t}}function eT(e){let t=e.replace(/<script[\s\S]*?<\/script>/gi," ").replace(/<style[\s\S]*?<\/style>/gi," ").replace(/<noscript[\s\S]*?<\/noscript>/gi," ").replace(/<[^>]+>/g," ").replace(/ /g," ").replace(/&/g,"&").replace(/</g,"<").replace(/>/g,">").replace(/"/g,'"').replace(/'/g,"'").replace(/\s+/g," ").trim();return t.length>Op?t.slice(0,Op):t}function aD(e){let t=[],r=/class="result__a"[^>]*href="([^"]+)"[^>]*>([\s\S]*?)<\/a>/gi,n;for(;(n=r.exec(e))&&t.length<Mp;){let o=n[1]??"",i=eT(n[2]??""),a=o,m=/[?&]uddg=([^&]+)/.exec(o);if(m)try{a=decodeURIComponent(m[1])}catch{a=o}else o.startsWith("//")&&(a=`https:${o}`);let c=km(a);!c.ok||!i||t.push({title:i,url:c.url.toString(),snippet:""})}return t}var tT="HowToCode (https://howtofix.id)";async function rT(e,t={}){let r=e.trim();if(!r)return{ok:!1,error:"empty query"};let n=t.fetchFn??fetch,o=t.timeoutMs??15e3,i={"user-agent":t.userAgent??tT,accept:"text/html, application/json"};try{if(t.braveKey){let p=`https://api.search.brave.com/res/v1/web/search?q=${encodeURIComponent(r)}&count=${Mp}`,f=await n(p,{headers:{...i,accept:"application/json","x-subscription-token":t.braveKey},signal:AbortSignal.timeout(o)});return f.ok?{ok:!0,hits:mD(await f.json()),provider:"brave"}:{ok:!1,error:`brave ${f.status}`}}let a=`https://html.duckduckgo.com/html/?q=${encodeURIComponent(r)}`,m=await n(a,{headers:i,signal:AbortSignal.timeout(o)});return m.ok?{ok:!0,hits:aD(await m.text()),provider:"ddg"}:{ok:!1,error:`search ${m.status}`}}catch(a){return{ok:!1,error:a instanceof Error?a.message:String(a)}}}function mD(e){let t=[];if(e&&typeof e=="object"&&"web"in e){let n=e.web;n&&typeof n=="object"&&"results"in n&&Array.isArray(n.results)&&(t=n.results)}let r=[];for(let n of t){if(!n||typeof n!="object"||!("url"in n)||!("title"in n))continue;let o=n.url,i=n.title;if(typeof o!="string"||typeof i!="string")continue;let a=km(o);if(!a.ok)continue;let m="description"in n?n.description:void 0;if(r.push({title:i,url:a.url.toString(),snippet:typeof m=="string"?m:""}),r.length>=Mp)break}return r}var Xk=5,uD=new Set([301,302,303,307,308]);async function cD(e,t){let r=e.toLowerCase().replace(/^\[|\]$/g,"");if(r.includes(":")||/^[\d.]+$/.test(r))return{ok:!0,addresses:[r]};let n;try{n=await t(r)}catch(i){return{ok:!1,error:`could not resolve ${e}: ${i instanceof Error?i.message:String(i)}`}}if(n.length===0)return{ok:!1,error:`could not resolve ${e}`};let o=n.find(i=>Zk(i));return o!==void 0?{ok:!1,error:`refused ${e}: resolves to private address ${o}`}:{ok:!0,addresses:n}}async function nT(e,t={}){let r=km(e);if(!r.ok)return{ok:!1,error:r.reason};let n=t.fetchFn??fetch,o=t.lookup??(c=>iD.lookup(c,{all:!0}).then(p=>p.map(f=>f.address))),i=AbortSignal.timeout(t.timeoutMs??2e4),a={"user-agent":t.userAgent??tT,accept:"text/html, text/plain, application/json"},m;try{let{Agent:c}=await import("undici"),p=[],f=((g,y,I)=>{let h=p.map(b=>({address:b,family:b.includes(":")?6:4}));y?.all?I(null,h):I(null,h[0].address,h[0].family)});m=new c({connect:{lookup:f}});let d=r.url;for(let g=0;g<=Xk;g++){let y=km(d.toString());if(!y.ok)return{ok:!1,error:`redirect refused: ${y.reason}`};let I=await cD(y.url.hostname,o);if(!I.ok)return{ok:!1,error:I.error};p=I.addresses;let h=await n(y.url,{headers:a,signal:i,redirect:"manual",dispatcher:m});if(uD.has(h.status)){let A=h.headers.get("location");if(!A)return{ok:!1,error:`HTTP ${h.status} without a location`};try{d=new URL(A,y.url)}catch{return{ok:!1,error:"redirect location is not a URL"}}continue}if(!h.ok)return{ok:!1,error:`HTTP ${h.status}`};let b=h.headers.get("content-type")??"",k=await h.text(),_=/html/i.test(b)?eT(k):k.slice(0,Op);return{ok:!0,url:d.toString(),contentType:b,text:_}}return{ok:!1,error:`too many redirects (max ${Xk})`}}catch(c){return{ok:!1,error:c instanceof Error?c.message:String(c)}}finally{await m?.close()}}function pD(e){return e.length===0?"no results":e.map((t,r)=>`${r+1}. ${t.title}
|
|
122
|
+
${t.url}${t.snippet?`
|
|
123
|
+
${t.snippet}`:""}`).join(`
|
|
124
|
+
`)}var iT=oT({name:"web_search",label:"web_search",description:"Search the public web. Use for current docs, changelogs, error messages, and anything not in this repo. Returns titles, URLs, and snippets. Follow a URL with web_fetch.",promptSnippet:"web_search: search the public web",parameters:Tm.Object({query:Tm.String({description:"Search query"})}),async execute(e,t){let r=await rT(t.query,{braveKey:process.env.BRAVE_API_KEY});return r.ok?{content:[{type:"text",text:pD(r.hits)}],details:{count:r.hits.length,provider:r.provider}}:{content:[{type:"text",text:r.error}],details:{error:r.error},isError:!0}}}),sT=oT({name:"web_fetch",label:"web_fetch",description:"Fetch a public http(s) URL and return its text. HTML is stripped to visible text. Local, loopback, and private addresses are refused.",promptSnippet:"web_fetch: read a public URL as text",parameters:Tm.Object({url:Tm.String({description:"http(s) URL"})}),async execute(e,t){let r=await nT(t.url);return r.ok?{content:[{type:"text",text:r.text}],details:{url:r.url,contentType:r.contentType,chars:r.text.length}}:{content:[{type:"text",text:r.error}],details:{error:r.error},isError:!0}}});import{spawn as fD}from"node:child_process";import{existsSync as wm,readFileSync as uT}from"node:fs";import{delimiter as cT,isAbsolute as pT,join as Cm}from"node:path";import{fileURLToPath as dD,pathToFileURL as Br}from"node:url";function aT(e){let t=JSON.stringify(e);return`Content-Length: ${Buffer.byteLength(t,"utf8")}\r
|
|
125
|
+
\r
|
|
126
|
+
${t}`}var lD=32*1024*1024;function gD(e){let t=[],r=0;for(;r<e.length;){let n=e.indexOf(`\r
|
|
127
|
+
\r
|
|
128
|
+
`,r);if(n===-1)break;let o=e.subarray(r,n).toString("utf8"),i=/Content-Length:\s*(\d+)/i.exec(o);if(!i)break;let a=Number(i[1]);if(!Number.isSafeInteger(a)||a<0||a>lD)throw new Error(`lsp frame of ${i[1]} bytes refused`);let m=n+4,c=m+a;if(c>e.length)break;let p=e.subarray(m,c).toString("utf8");try{let f=JSON.parse(p);f&&typeof f=="object"&&t.push(f)}catch{}r=c}return{messages:t,rest:e.subarray(r)}}var vp=class{constructor(t){this.io=t;t.stdout.on("data",r=>{if(this.broken)return;this.buffer=Buffer.concat([this.buffer,r]);let n;try{n=gD(this.buffer)}catch(o){this.buffer=Buffer.alloc(0),this.fail(o instanceof Error?o:new Error(String(o)));return}this.buffer=n.rest;for(let o of n.messages)this.dispatch(o)}),t.stdin.on("error",r=>{this.fail(r instanceof Error?r:new Error(String(r)))})}io;nextId=1;pending=new Map;buffer=Buffer.alloc(0);broken=null;opened=new Set;versions=new Map;diagnosticsByUri=new Map;diagnosticsWaiters=new Map;fail(t){if(!this.broken){this.broken=t;for(let[r,n]of this.pending)this.pending.delete(r),n.reject(t)}}dispatch(t){if(t.method==="textDocument/publishDiagnostics"){let n=t.params;if(n?.uri){let o=Array.isArray(n.diagnostics)?n.diagnostics:[];this.diagnosticsByUri.set(n.uri,o);let i=this.diagnosticsWaiters.get(n.uri);if(i){this.diagnosticsWaiters.delete(n.uri);for(let a of i)a(o)}}return}if(t.id===void 0)return;let r=this.pending.get(Number(t.id));r&&(this.pending.delete(Number(t.id)),t.error?r.reject(new Error(t.error.message)):r.resolve(t.result))}request(t,r,n=1e4){if(this.broken)return Promise.reject(this.broken);let o=this.nextId++,i=aT({jsonrpc:"2.0",id:o,method:t,params:r}),{promise:a,resolve:m,reject:c}=Promise.withResolvers(),p=setTimeout(()=>{this.pending.delete(o),c(new Error(`lsp ${t} timed out`))},n);this.pending.set(o,{resolve:f=>{clearTimeout(p),m(f)},reject:f=>{clearTimeout(p),c(f)}});try{this.io.stdin.write(i)}catch(f){let d=f instanceof Error?f:new Error(String(f));this.pending.delete(o),clearTimeout(p),c(d),this.fail(d)}return a}notify(t,r){if(!this.broken)try{this.io.stdin.write(aT({jsonrpc:"2.0",method:t,params:r}))}catch(n){this.fail(n instanceof Error?n:new Error(String(n)))}}async initialize(){await this.request("initialize",{processId:null,rootUri:Br(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:Br(t).toString()},position:{line:r,character:n}}))?.contents?.value}async definition(t,r,n){let o=await this.request("textDocument/definition",{textDocument:{uri:Br(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:Br(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:Br(t).toString()}});return Array.isArray(r)?r:[]}diagnostics(t,r=2e3){let n=Br(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=Br(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(Br(t).toString())}notifyChange(t,r,n){let o=Br(t).toString();if(!this.opened.has(o)){this.versions.set(o,1),this.opened.add(o),this.notify("textDocument/didOpen",{textDocument:{uri:o,languageId:n,version:1,text:r}});return}let i=(this.versions.get(o)??1)+1;this.versions.set(o,i),this.diagnosticsByUri.delete(o),this.notify("textDocument/didChange",{textDocument:{uri:o,version:i},contentChanges:[{text:r}]})}dispose(){for(let[t,r]of this.pending)r.reject(new Error("lsp client disposed")),this.pending.delete(t);for(let[t,r]of this.diagnosticsWaiters){let n=this.diagnosticsByUri.get(t)??[];this.diagnosticsWaiters.delete(t);for(let o of r)o(n)}}},yD=[{command:"typescript-language-server",args:["--stdio"],languageId:"typescript",match:e=>/\.(ts|tsx|js|jsx|mts|cts)$/.test(e)},{command:"rust-analyzer",args:[],languageId:"rust",match:e=>e.endsWith(".rs")},{command:"gopls",args:[],languageId:"go",match:e=>e.endsWith(".go")},{command:"pylsp",args:[],languageId:"python",match:e=>e.endsWith(".py")}];function fT(e){return yD.find(t=>t.match(e))}var Gr=new Map;async function dT(e,t){let r=Gr.get(e.command);if(r)return await r.ready,r.client;let n=fD(e.command,e.args,{cwd:t,stdio:["pipe","pipe","ignore"]}),o=n.stdin,i=n.stdout;if(!o||!i)throw n.kill(),new Error(`${e.command}: stdio pipes unavailable`);let a=new vp({stdin:o,stdout:i,root:t});n.on("error",()=>{let c=Gr.get(e.command);c?.child===n&&Gr.delete(e.command),c?.client.dispose()}),n.on("exit",()=>{Gr.get(e.command)?.child===n&&Gr.delete(e.command),a.dispose()});let m=a.initialize().catch(c=>{throw Gr.delete(e.command),n.kill(),c});return Gr.set(e.command,{client:a,child:n,ready:m}),await m,a}function xD(){for(let[e,t]of Gr)Gr.delete(e),t.client.dispose(),t.child.kill()}process.on("exit",xD);async function Fve(e,t,r={}){let n=fT(e);if(!n)return{diagnostics:[],unavailable:"no language server configured for this file type"};if(!(n.command.includes("/")?wm(n.command):(process.env.PATH??"").split(cT).some(i=>wm(Cm(i,n.command)))))return{diagnostics:[],unavailable:`${n.command} is not on PATH`};try{let i=pT(e)?e:Cm(t,e),a=await dT(n,t);return a.notifyChange(i,uT(i,"utf8"),n.languageId),{diagnostics:(await a.diagnostics(i,r.waitMs??1500)).map(c=>`${c.range.start.line+1}:${c.range.start.character+1} ${lT[c.severity??3]??"info"} ${c.message}`)}}catch(i){return{diagnostics:[],unavailable:i instanceof Error?i.message:String(i)}}}var lT={1:"error",2:"warning",3:"info",4:"hint"};function mT(e){let t=e.uri;try{t=dD(e.uri)}catch{}let r=e.range?.start;return r?`${t}:${r.line+1}:${r.character+1}`:t}function gT(e,t=0){let r=[];for(let n of e){let o=(n.selectionRange??n.range)?.start.line;r.push(`${" ".repeat(t)}${n.name}${o===void 0?"":` :${o+1}`}`),n.children&&r.push(...gT(n.children,t+1))}return r}async function yT(e){try{let t=fT(e.file);if(!t)return{ok:!1,error:`no language server configured for ${e.file}`};if((e.action==="definition"||e.action==="references"||e.action==="hover")&&(e.line===void 0||!Number.isInteger(e.line)||e.line<1))return{ok:!1,error:`line required (1-based) for ${e.action}`};if(!(t.command.includes("/")?wm(t.command):(process.env.PATH??"").split(cT).some(p=>wm(Cm(p,t.command)))))return{ok:!1,error:`${t.command} is not on PATH. Install it to use lsp on ${e.file}.`};let o=pT(e.file)?e.file:Cm(e.root,e.file),i=uT(o,"utf8"),a=await dT(t,e.root);await a.ensureOpen(o,i,t.languageId);let m=(e.line??1)-1,c=0;if(e.symbol){let p=(i.split(`
|
|
129
|
+
`)[m]??"").indexOf(e.symbol);p>=0&&(c=p)}switch(e.action){case"definition":{let p=await a.definition(o,m,c);return p?{ok:!0,text:mT(p),count:1}:{ok:!0,text:"no definition found",count:0}}case"references":{let f=(await a.references(o,m,c)).map(mT);return{ok:!0,text:f.length>0?f.join(`
|
|
130
|
+
`):"no references found",count:f.length}}case"hover":{let p=(await a.hover(o,m,c))?.trim();return{ok:!0,text:p||"no hover at that position"}}case"symbols":{let p=gT(await a.documentSymbols(o));return{ok:!0,text:p.length>0?p.join(`
|
|
131
|
+
`):"no symbols in this file",count:p.length}}case"diagnostics":{let f=(await a.diagnostics(o)).map(d=>`${d.range.start.line+1}:${d.range.start.character+1} ${lT[d.severity??3]??"info"} ${d.message}`);return{ok:!0,text:f.length>0?f.join(`
|
|
132
|
+
`):"no diagnostics",count:f.length}}}}catch(t){return{ok:!1,error:t instanceof Error?t.message:String(t)}}}import{StringEnum as hD}from"@netrodev/hxf-ai";import{defineTool as ID}from"@netrodev/hxf-coding-agent";var xT=ID({name:"lsp",label:"lsp",description:"Language-server query: definition, references, hover, symbols, or diagnostics for a file. Line is 1-based. Does not edit. If the server binary is missing the result says so; do not pretend grep is a substitute without telling the user.",promptSnippet:"lsp: definition, references, hover, symbols, diagnostics",parameters:D.Object({action:hD(["diagnostics","definition","references","hover","symbols"],{description:"Which language-server query to run"}),file:D.String({description:"File to query, relative to the project root"}),line:D.Optional(D.Number({description:"1-based line (definition, references, hover)"})),symbol:D.Optional(D.String({description:"Substring to locate on that line when column is omitted"}))}),async execute(e,t,r,n,o){let i=await yT({action:t.action,file:t.file,line:t.line,symbol:t.symbol,root:o.cwd});return i.ok?{content:[{type:"text",text:i.text}],details:{action:t.action,count:i.count}}:{content:[{type:"text",text:i.error}],details:{error:i.error},isError:!0}}});import{defineTool as YD}from"@netrodev/hxf-coding-agent";import{API as bD}from"typescript/unstable/async";import{SyntaxKind as Gt,visitEachChild as hT}from"typescript/unstable/ast";var IT=new Set([Gt.FunctionDeclaration,Gt.FunctionExpression,Gt.ArrowFunction,Gt.MethodDeclaration,Gt.Constructor,Gt.GetAccessor,Gt.SetAccessor]);function Oo(e){return IT.has(e)}var $D=new Set([Gt.AmpersandAmpersandToken,Gt.BarBarToken,Gt.QuestionQuestionToken]);function Rm(e){if(e.kind!==Gt.BinaryExpression)return!1;let t=Ze(e,"operatorToken");return t!==void 0&&$D.has(t.kind)}function Ze(e,t){let r=e[t];if(r&&typeof r=="object"&&typeof r.kind=="number")return r}function _i(e,t){let r=e[t];return Array.isArray(r)?r:[]}function bT(e,t){return _i(e,"modifiers").some(r=>r.kind===t)}function Ao(e){if(!e)return;let t=e.text;return typeof t=="string"?t:void 0}function ED(e,t){return e.getLineAndCharacterOfPosition(t).line+1}function Fp(e,t){let r=e.getLineAndCharacterOfPosition(t.getStart(e)),n=e.getLineAndCharacterOfPosition(t.end);return{startLine:r.line+1,startColumn:r.character+1,endLine:n.line+1,endColumn:n.character+1}}function Pm(e,t){t(e),hT(e,r=>(Pm(r,t),r))}function Ui(e,t){t(e),hT(e,r=>(Oo(r.kind)||Ui(r,t),r))}var SD=IT;function kD(e){let t=Ao(Ze(e,"name"));if(t)return t;let r=Ze(e,"parent");for(;r&&!SD.has(r.kind);){if(r.kind===Gt.VariableDeclaration||r.kind===Gt.PropertyAssignment){let n=Ao(Ze(r,"name"));if(n)return n}r=Ze(r,"parent")}return"<anonymous>"}function TD(e){let t=[];return Pm(e,r=>{if(!Oo(r.kind))return;let n=Fp(e,r);t.push({name:kD(r),node:r,startLine:n.startLine,endLine:n.endLine})}),t}async function $T(e){let t=new Map;if(e.length===0)return t;let r=new bD({cwd:process.cwd()});try{let n=await r.updateSnapshot({openFiles:[...e]});for(let o of e)try{let i=await n.getDefaultProjectForFile(o);if(!i){t.set(o,{ok:!1,error:"no TypeScript project contains this file"});continue}let a=await i.program.getSourceFile(o);if(!a){t.set(o,{ok:!1,error:"the compiler could not read this file"});continue}let m=await i.program.getSyntacticDiagnostics(o);if(m.length>0){let c=m[0],p=ED(a,c.pos);t.set(o,{ok:!1,error:`line ${p}: ${c.text} (TS${c.code})`});continue}t.set(o,{ok:!0,sourceFile:a,functions:TD(a)})}catch(i){t.set(o,{ok:!1,error:i instanceof Error?i.message:String(i)})}}finally{await r.close()}return t}import{SyntaxKind as Or,visitEachChild as ET}from"typescript/unstable/ast";var wD=new Set([Or.IfStatement,Or.SwitchStatement,Or.ForStatement,Or.ForInStatement,Or.ForOfStatement,Or.WhileStatement,Or.DoStatement,Or.CatchClause]);function ST(e){let t=0,r=(o,i)=>{if(!Oo(o.kind)){if(o.kind===Or.IfStatement){n(o,i,!1);return}if(wD.has(o.kind)){t+=1+i,ET(o,a=>(r(a,i+1),a));return}Rm(o)&&(t+=1),ET(o,a=>(r(a,i),a))}},n=(o,i,a)=>{a||(t+=1+i);let m=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===Or.IfStatement?n(p,i,!0):r(p,i+1))};return r(e,0),t}import{SyntaxKind as Kr}from"typescript/unstable/ast";var CD=new Set([Kr.IfStatement,Kr.ConditionalExpression,Kr.WhileStatement,Kr.DoStatement,Kr.ForStatement,Kr.ForInStatement,Kr.ForOfStatement,Kr.CatchClause,Kr.CaseClause]);function kT(e){let t=1;return Ui(e,r=>{(CD.has(r.kind)||Rm(r))&&(t+=1)}),t}import{SyntaxKind as ae}from"typescript/unstable/ast";var RD=new Set([ae.BinaryExpression,ae.PrefixUnaryExpression,ae.PostfixUnaryExpression,ae.ConditionalExpression,ae.CallExpression,ae.NewExpression,ae.PropertyAccessExpression,ae.ElementAccessExpression,ae.AwaitExpression,ae.YieldExpression,ae.SpreadElement,ae.IfStatement,ae.WhileStatement,ae.DoStatement,ae.ForStatement,ae.ForInStatement,ae.ForOfStatement,ae.SwitchStatement,ae.ReturnStatement,ae.ThrowStatement,ae.TryStatement,ae.BreakStatement,ae.ContinueStatement]),PD=new Set([ae.StringLiteral,ae.NumericLiteral,ae.BigIntLiteral,ae.RegularExpressionLiteral,ae.NoSubstitutionTemplateLiteral]);function Lp(e,t){e.set(t,(e.get(t)??0)+1)}function TT(e){let t=new Map,r=new Map;Ui(e,i=>{if(RD.has(i.kind)){let m=Ze(i,"operatorToken");Lp(t,ae[i.kind]+(m?`:${ae[m.kind]}`:""));return}let a=Ao(i);a!==void 0&&(i.kind===ae.Identifier||i.kind===ae.PrivateIdentifier?Lp(r,`id:${a}`):PD.has(i.kind)&&Lp(r,`lit:${a}`))});let n=t.size+r.size;if(n===0)return 0;let o=0;for(let i of t.values())o+=i;for(let i of r.values())o+=i;return Math.round(o*Math.log2(n)*100)/100}function wT(e){return e.endLine-e.startLine+1}function CT(e,t,r){let n=171-5.2*Math.log(Math.max(e,1))-.23*t-16.2*Math.log(Math.max(r,1));return Math.round(Math.max(0,n*100/171)*10)/10}import{SyntaxKind as ur,visitEachChild as AD}from"typescript/unstable/ast";var OD=new Set([ur.IfStatement,ur.SwitchStatement,ur.WhileStatement,ur.DoStatement,ur.ForStatement,ur.ForInStatement,ur.ForOfStatement,ur.TryStatement,ur.CatchClause]);function RT(e){let t=0,r=(n,o)=>{if(Oo(n.kind))return;let i=o;if(OD.has(n.kind)&&(i=o+1,i>t&&(t=i)),n.kind===ur.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===ur.IfStatement?o:i);return}AD(n,a=>(r(a,i),a))};return r(e,0),t}import{spawnSync as MD}from"node:child_process";import{mkdirSync as aFe,readdirSync as vD,readFileSync as FD,statSync as LD,writeFileSync as mFe}from"node:fs";import{extname as Np,join as LT,relative as DT,resolve as DD}from"node:path";import{SyntaxKind as Am}from"typescript/unstable/ast";var PT={"god-function":"split it into smaller functions, one job each",incomprehensible:"extract helpers and simplify the flow before touching it",bloated:"long but linear; extract helpers","deeply-tangled":"nesting, not branching; flatten with early returns",fragile:"many branches; add guard clauses and tests around it"};function AT(e,t){let r=[];return t.cyclomatic>=1&&t.length>=1&&t.nesting>=1&&r.push({id:"god-function",label:"God Function",reason:`high cyclomatic complexity (${e.cyclomatic}), long body (${e.length} lines), and deep nesting (${e.nesting}) \u2014 likely doing too many things`}),t.cognitive>=1&&t.halstead>=1&&t.mi>=1&&r.push({id:"incomprehensible",label:"Incomprehensible",reason:`high cognitive complexity (${e.cognitive}) and Halstead volume (${e.halstead}) with MI ${e.mi} \u2014 very hard to understand`}),t.length>=1&&t.halstead>=1&&t.cyclomatic===0&&r.push({id:"bloated",label:"Bloated",reason:`large function (${e.length} lines) with high vocabulary (Halstead ${e.halstead}) but low branching \u2014 consider extracting helpers`}),t.nesting>=1&&t.cognitive>=1&&t.cyclomatic===0&&r.push({id:"deeply-tangled",label:"Deeply Tangled",reason:`nesting depth ${e.nesting} drives cognitive complexity ${e.cognitive} \u2014 flatten with early returns or extracted helpers`}),t.cyclomatic>=1&&t.mi>=1&&t.length===0&&r.push({id:"fragile",label:"Fragile",reason:`high cyclomatic complexity (${e.cyclomatic}) with MI ${e.mi} \u2014 many branches, hard to change safely`}),r}var jD=["ok","warn","error"],Bp=["cyclomatic","cognitive","nesting","length","halstead","mi","parameters","booleanParameters"];var Hr={cyclomatic:{warn:15,error:25},cognitive:{warn:12,error:20},nesting:{warn:4,error:5},length:{warn:60,error:120},halstead:{warn:500,error:1e3},mi:{warn:65,error:20},fileLines:{warn:400,error:800},exports:{warn:20,error:30},parameters:{warn:5,error:8}};function jT(){let e={cyclomatic:{...Hr.cyclomatic},cognitive:{...Hr.cognitive},nesting:{...Hr.nesting},length:{...Hr.length},halstead:{...Hr.halstead},mi:{...Hr.mi},fileLines:{...Hr.fileLines},exports:{...Hr.exports},parameters:{...Hr.parameters}};return{ignore:[],thresholds:e,ci:{failBelow:65,mode:"advisory"}}}var ND=["cyclomatic","cognitive","nesting","length","halstead","mi","fileLines","exports","parameters"];function Dp(e){return typeof e=="number"&&Number.isFinite(e)}function Gp(e){let t=jT(),r;try{r=JSON.parse(FD(LT(e,".howtocode","quality.json"),"utf8"))}catch{return t}if(typeof r!="object"||r===null)return t;let n=r;if(typeof n.enabled=="boolean"&&(t.enabled=n.enabled),Array.isArray(n.ignore)&&(t.ignore=n.ignore.filter(o=>typeof o=="string")),typeof n.thresholds=="object"&&n.thresholds!==null){let o=n.thresholds;for(let i of ND){let a=o[i];if(typeof a!="object"||a===null)continue;let m=a;Dp(m.warn)&&(t.thresholds[i].warn=m.warn),Dp(m.error)&&(t.thresholds[i].error=m.error)}}if(typeof n.ci=="object"&&n.ci!==null){let o=n.ci;Dp(o.failBelow)&&(t.ci.failBelow=o.failBelow),(o.mode==="advisory"||o.mode==="blocking")&&(t.ci.mode=o.mode)}return t}function NT(e,t){let r=process.env.HOWTOCODE_QUALITY;if(r!==void 0){let o=r.trim().toLowerCase();return o==="0"||o==="false"?{enabled:!1,source:"env"}:{enabled:!0,source:"env"}}let n=Gp(e).enabled;return n!==void 0?{enabled:n,source:"config"}:t!==void 0?{enabled:t,source:"runtime"}:{enabled:!0,source:"default"}}function yn(e,t){return e>t.error?2:e>t.warn?1:0}function qT(e,t){return e<t.error?2:e<t.warn?1:0}function qD(e){let t=[];for(let r of _i(e.node,"parameters"))Ze(r,"type")?.kind===Am.BooleanKeyword&&t.push(Ao(Ze(r,"name"))??"<pattern>");return t}function _D(e,t,r,n){let o=n.thresholds,i=Ze(e.node,"body")??e.node,a={cyclomatic:kT(i),cognitive:ST(i),nesting:RT(i),length:wT(e),halstead:TT(i),mi:0};a.mi=CT(a.halstead,a.cyclomatic,a.length);let m=qD(e),c=_i(e.node,"parameters").length,p={cyclomatic:{value:a.cyclomatic,rank:yn(a.cyclomatic,o.cyclomatic)},cognitive:{value:a.cognitive,rank:yn(a.cognitive,o.cognitive)},nesting:{value:a.nesting,rank:yn(a.nesting,o.nesting)},length:{value:a.length,rank:yn(a.length,o.length)},halstead:{value:a.halstead,rank:yn(a.halstead,o.halstead)},mi:{value:a.mi,rank:qT(a.mi,o.mi)},parameters:{value:c,rank:yn(c,o.parameters)},booleanParameters:{value:m.length,rank:m.length>0?1:0}},f={cyclomatic:p.cyclomatic.rank,cognitive:p.cognitive.rank,nesting:p.nesting.rank,length:p.length.rank,halstead:p.halstead.rank,mi:p.mi.rank},d=Fp(t,e.node),g=0;for(let y of Bp)p[y].rank>g&&(g=p[y].rank);return{path:r,name:e.name,startLine:d.startLine,endLine:d.endLine,startColumn:d.startColumn,endColumn:d.endColumn,metrics:p,booleanParameterNames:m,smells:AT(a,f),worstRank:g}}function UD(e){let t=0;return Pm(e,r=>{if(r.kind===Am.ExportDeclaration){let n=Ze(r,"exportClause"),o=n?_i(n,"elements"):[];t+=o.length>0?o.length:1;return}if(r.kind===Am.ExportAssignment){t+=1;return}bT(r,Am.ExportKeyword)&&(t+=1)}),t}function BD(e){if(e.length===0)return 0;let t=1;for(let r=0;r<e.length;r+=1)e.charCodeAt(r)===10&&(t+=1);return e.charCodeAt(e.length-1)===10&&(t-=1),t}var OT={value:0,rank:0};function MT(e,t){return{path:e,ok:!1,error:t,lines:0,metrics:{lines:OT,exports:OT,mi:{value:100,rank:0}},functions:[]}}function jp(e,t,r,n,o,i,a){i.rank!==0&&e.push({path:t.path,metric:o,detail:o==="booleanParameters"?r?.booleanParameterNames.join(", ")??String(i.value):`${i.value} (limit ${a})`,rank:i.rank,line:n.line,endLine:n.endLine,startColumn:n.startColumn,endColumn:n.endColumn,...r?{function:r.name}:{}})}async function _T(e,t=jT()){let r=await $T(e),n=new Map,o=[],i=t.thresholds;for(let a of e){let m=r.get(a);if(!m){let b=MT(a,"internal: file missing from the parse result");n.set(a,b),o.push({path:a,metric:"parse error",detail:b.error??"",rank:2,line:1,endLine:1,startColumn:1,endColumn:1});continue}if(!m.ok){let b=MT(a,m.error);n.set(a,b),o.push({path:a,metric:"parse error",detail:m.error,rank:2,line:1,endLine:1,startColumn:1,endColumn:1});continue}let{sourceFile:c}=m,p=m.functions.map(b=>_D(b,c,a,t)),f=BD(c.text),d=UD(c),g=p.reduce((b,k)=>b+k.metrics.length.value,0),y=g===0?100:Math.round(p.reduce((b,k)=>b+k.metrics.mi.value*k.metrics.length.value,0)/g*10)/10,I={path:a,ok:!0,lines:f,metrics:{lines:{value:f,rank:yn(f,i.fileLines)},exports:{value:d,rank:yn(d,i.exports)},mi:{value:y,rank:qT(y,i.mi)}},functions:p};n.set(a,I);let h={line:1,endLine:Math.max(f,1),startColumn:1,endColumn:1};jp(o,I,void 0,h,"file lines",I.metrics.lines,i.fileLines.warn),jp(o,I,void 0,h,"exports",I.metrics.exports,i.exports.warn);for(let b of p){let k={line:b.startLine,endLine:b.endLine,startColumn:b.startColumn,endColumn:b.endColumn};for(let _ of Bp)jp(o,I,b,k,_,b.metrics[_],UT(_,i));for(let _ of b.smells)o.push({path:a,metric:"smell",detail:`${_.label}: ${_.reason}`,rank:1,line:b.startLine,endLine:b.endLine,startColumn:b.startColumn,endColumn:b.endColumn,function:b.name})}}return{files:n,findings:o}}function Kp(e){let t=0,r=0;for(let n of e.files.values())if(n.ok)for(let o of n.functions)t+=o.metrics.length.value,r+=o.metrics.mi.value*o.metrics.length.value;return t===0?100:Math.round(r/t*10)/10}function Hp(e){let t=0,r=0,n=0,o=0;for(let i of e.files.values())i.ok||(t+=1),r+=i.functions.length;for(let i of e.findings)i.rank>=2?o+=1:n+=1;return{files:e.files.size,errorFiles:t,functions:r,findings:e.findings.length,warn:n,error:o,score:Kp(e)}}var GD=["ok","\u26A0","\u2717"],KD=[["cyclomatic","cyclomatic"],["cognitive","cognitive"],["nesting","nesting"],["length","length"],["halstead","halstead"],["mi","MI"],["parameters","parameters"],["booleanParameters","boolean params"]];function UT(e,t){return e==="mi"?t.mi.warn:e==="booleanParameters"?t.parameters.warn:t[e].warn}function qp(e,t,r,n){return`${e}${t.padEnd(15)} ${r.value} (limit ${n}) ${jD[r.rank]}`}function HD(e,t){let r=[` ${e.name.padEnd(30)} L${e.startLine}-${e.endLine}`];for(let[n,o]of KD){let i=e.metrics[n];if(i.rank!==0){if(n==="booleanParameters"){r.push(` ${o.padEnd(15)} ${e.booleanParameterNames.join(", ")} warn`);continue}r.push(qp(" ",o,i,UT(n,t.thresholds)))}}if(e.smells.length>0){r.push(` ${"smells".padEnd(15)} ${e.smells.map(n=>n.id).join(", ")}`);for(let n of e.smells)r.push(` \u2192 ${PT[n.id]??n.label}`)}return r}function vT(e){let t=e.smells.length;for(let r of Bp)e.metrics[r].rank>0&&(t+=1);return t}function zD(e,t){let r=[];for(let o of e.files.values())for(let i of o.functions)i.worstRank>0&&r.push(i);r.sort((o,i)=>{if(o.worstRank!==i.worstRank)return i.worstRank-o.worstRank;let a=vT(i)-vT(o);if(a!==0)return a;let m=i.metrics.cyclomatic.value-o.metrics.cyclomatic.value;return m!==0?m:`${o.path}:${o.name}`.localeCompare(`${i.path}:${i.name}`)});let n=new Map;for(let o of r.slice(0,t)){let i=n.get(o.path)??new Set;i.add(`${o.name}@${o.startLine}`),n.set(o.path,i)}return n}function BT(e,t,r={}){let n=Hp(e),o=r.top&&r.top>0?zD(e,r.top):void 0,i=[...e.files.values()].filter(p=>!o||(o.get(p.path)?.size??0)>0),a=Math.max(40,...i.map(p=>p.path.length)),m=[];for(let p of i){if(!p.ok){m.push(`${p.path.padEnd(a)} parse error`),m.push(` ${p.error}`);continue}m.push(`${p.path.padEnd(a)} MI ${p.metrics.mi.value} ${GD[p.metrics.mi.rank]}`),p.metrics.lines.rank>0&&m.push(qp(" ","file lines",p.metrics.lines,t.thresholds.fileLines.warn)),p.metrics.exports.rank>0&&m.push(qp(" ","exports",p.metrics.exports,t.thresholds.exports.warn));for(let f of p.functions)o&&!o.get(p.path)?.has(`${f.name}@${f.startLine}`)||f.worstRank===0&&f.smells.length===0||m.push(...HD(f,t))}m.length>0&&m.push("");let c=n.errorFiles>0?`, ${n.errorFiles} parse error(s)`:"";return m.push(`${n.findings} findings in ${n.files} files${c} \xB7 ${n.functions} functions \xB7 score ${n.score}`),m.join(`
|
|
133
|
+
`)}var _p=new Set([".ts",".tsx",".mts",".cts"]),WD=new Set(["node_modules","dist","coverage"]);function Up(e,t,r){for(let n of vD(e,{withFileTypes:!0})){let o=LT(e,n.name);if(n.isDirectory()){if(n.name.startsWith(".")||WD.has(n.name))continue;Up(o,t,r);continue}n.isFile()&&_p.has(Np(n.name))&&r.push(DT(t,o))}}function FT(e,t){let r=MD("git",["-C",e,...t],{encoding:"utf8"});if(r.error||r.status!==0){let n=r.error?r.error.message:r.stderr.trim()||`exit ${r.status}`;throw new Error(`git ${t.join(" ")} failed: ${n}`)}return r.stdout.split(`
|
|
134
|
+
`).filter(n=>n.trim().length>0)}function VD(e,t){let r=FT(e,["diff","--name-only","--diff-filter=ACMR",t]),n=FT(e,["ls-files","--others","--exclude-standard"]);return[...r,...n]}function JD(e,t){if(!t.includes("*")){let n=t.endsWith("/")?t:`${t}/`;return e===t||e.startsWith(n)}let r=t.replace(/[.+^${}()|[\]\\]/g,"\\$&").replace(/\*\*/g,"\0").replace(/\*/g,"[^/]*").replace(/\u0000/g,".*");return new RegExp(`^${r}$`).test(e)}function GT(e,t,r=[]){let n;if(t.changes)n=VD(e,t.base??"HEAD");else if(t.target){let i=DD(e,t.target),a=LD(i,{throwIfNoEntry:!1});if(!a)throw new Error(`no such path: ${t.target}`);if(a.isDirectory())n=[],Up(i,e,n);else{if(!_p.has(Np(i)))throw new Error(`not a TypeScript source file: ${t.target}`);n=[DT(e,i)]}}else n=[],Up(e,e,n);let o=new Set;for(let i of n)_p.has(Np(i))&&(r.some(a=>JD(i,a))||o.add(i));return[...o].sort()}var KT=6e3,HT=YD({name:"quality",label:"quality",description:"Measure code quality: cyclomatic and cognitive complexity, nesting depth, function length, Halstead volume, maintainability index, and compound smells like god-function and deeply-tangled. Read-only. Use it before reporting a task finished, especially on functions you just wrote or changed; it reports concrete numbers with line numbers and a suggested next step, so 'is this too complex' stops being a guess. Defaults to the changed files; pass a path to narrow it further.",promptSnippet:"quality: complexity and maintainability metrics for changed code",parameters:D.Object({path:D.Optional(D.String({description:"One file or directory, relative to the project root. Omit to scan the changed set."})),changes:D.Optional(D.Boolean({description:"Scan only files changed against the base ref. Default true when path is omitted."})),base:D.Optional(D.String({description:"Git ref for `changes`. Defaults to HEAD."})),top:D.Optional(D.Number({description:"Only report the N worst functions."}))}),async execute(e,t,r,n,o){let i=o.cwd??process.cwd(),a=NT(i);if(!a.enabled)return{content:[{type:"text",text:`quality metrics are off (source: ${a.source})`}],details:{off:!0}};let m=Gp(i),c=t.changes??t.path===void 0,p=GT(i,{changes:c,base:t.base,target:t.path},m.ignore);if(p.length===0)return{content:[{type:"text",text:c?"no changed files to measure":"no source files found"}],details:{files:0}};let f=await _T(p,m),d=Hp(f),g=BT(f,m,{top:t.top});return{content:[{type:"text",text:g.length>KT?`${g.slice(0,KT)}
|
|
135
|
+
\u2026 (truncated; run the quality script for the full report)`:g}],details:{files:d.files,functions:d.functions,findings:d.findings,score:Kp(f)}}}});import{availableParallelism as QD}from"node:os";var XD=4;function ZD(){let e=df(tt).agents;return e!==void 0?e:Math.max(1,Math.min(XD,QD()-2))}var zp=0,zT=[];async function Om(){for(;zp>=ZD();)await new Promise(t=>zT.push(t));zp+=1;let e=!1;return()=>{e||(e=!0,zp-=1,zT.shift()?.())}}function WT(e,t){let r=e.find(o=>`${o.provider}/${o.id}`===t||o.id===t);if(r)return r;let n=t.toLowerCase();return e.find(o=>o.id.toLowerCase().includes(n)||`${o.provider}/${o.id}`.toLowerCase().includes(n))}var ej=["deepseek","qwen","claude","gpt-5","gpt-4","gemini","glm","mimo","kimi","llama"],tj=/(image|embedding|embed|whisper|tts|audio|video|rerank|moderation|dall-e|stable-diffusion|sora)/i;function rj(e){let t=r=>{if(tj.test(r))return 100;let n=ej.findIndex(o=>r.toLowerCase().includes(o));return n===-1?50:n};return e.map((r,n)=>({id:r,index:n})).sort((r,n)=>t(r.id)-t(n.id)||r.index-n.index).map(r=>r.id)}function NFe(e,t=[]){if(e.length===0)return;let r=e.filter(i=>t.includes(i.provider)),n=r.length>0?r:e,o=rj(n.map(i=>i.id))[0];return n.find(i=>i.id===o)??n[0]}import{mkdirSync as nj,readdirSync as oj,readFileSync as ij,unlinkSync as sj}from"node:fs";import{join as Vp}from"node:path";import{createAgentSession as aj,DefaultResourceLoader as mj,SessionManager as uj}from"@netrodev/hxf-coding-agent";var Wp=["You are one agent on a shared task; siblings may be editing the same working tree right now.","Stay inside the files your assignment names. A file another agent owns is theirs to change: report what you need changed instead of changing it yourself, and never edit a file two agents were both given.","Never run project-wide validation (full builds, whole test suites, formatters, linters) unless your assignment explicitly tells you to.","Siblings' unfinished edits will make those runs fail for reasons that are not yours. Prove your own change with a scoped test, a targeted repro, or a smoke run instead."],cj=`You are a software architect planning an implementation. Your job is to explore the codebase and return a plan, not to write code.
|
|
136
|
+
|
|
137
|
+
## Read-only, by construction
|
|
138
|
+
You have no edit tool, no write tool, and no shell. Do not attempt to modify, create, move, or delete anything \u2014 the call would fail. Your output is text.
|
|
139
|
+
|
|
140
|
+
## Your process
|
|
141
|
+
1. Understand the requirement. If it is ambiguous in a way that changes the design, say so and name the options rather than silently picking one.
|
|
142
|
+
2. Explore: read the files involved, find the existing patterns and conventions with grep/find/ls, and trace the code paths the change touches. Follow the codebase's existing approach instead of inventing a new one.
|
|
143
|
+
3. Design: state the approach you recommend, not every alternative you considered. Note the trade-off that decided it.
|
|
144
|
+
4. Sequence: give the implementation as ordered steps, naming the files and functions to change at each one, and what to verify after each.
|
|
145
|
+
|
|
146
|
+
## Required output
|
|
147
|
+
End your reply with exactly this section, listing the 3-5 files most critical to the implementation, most important first:
|
|
148
|
+
|
|
149
|
+
### Critical Files for Implementation
|
|
150
|
+
- path/to/file.ts
|
|
151
|
+
- path/to/file.ts
|
|
152
|
+
|
|
153
|
+
Keep the plan concrete enough to execute without re-deriving it: name real paths and real function names you saw while exploring. If you could not confirm something, say which part you are unsure of instead of guessing.`,xn=new Map([["scout",{name:"scout",description:"read-only lookup",tools:["read","grep","find","ls","context","web_search","web_fetch","lsp"],prompt:["Inspect only what the task needs. Do not edit.",...Wp].join(`
|
|
154
|
+
`),effort:"low"}],["architect",{name:"architect",description:"designs an implementation plan",tools:["read","grep","find","ls","context","web_search","web_fetch","lsp"],prompt:cj,effort:"high"}],["task",{name:"task",description:"implements the assignment",tools:["read","bash","edit","write","grep","find","ls","context","todo","web_search","web_fetch","lsp"],prompt:["Do the assignment, then report files changed.",...Wp].join(`
|
|
155
|
+
`),effort:"medium"}],["reviewer",{name:"reviewer",description:"finds concrete issues",tools:["read","grep","find","ls","context","web_search","web_fetch","lsp"],prompt:["Return issues with file evidence. Do not edit.",...Wp].join(`
|
|
156
|
+
`),effort:"medium"}]]),r1e=new Set(xn.keys());function pj(e){return e>=1e3?`${(e/1e3).toFixed(1)}k`:String(e)}function fj(e){return e<6e4?`${(e/1e3).toFixed(1)}s`:`${Math.floor(e/6e4)}m ${(e%6e4/1e3).toFixed(1)}s`}function n1e(e){let t=e.status==="parked"?"done":e.status==="error"?"failed":e.status,r=[];return e.model&&r.push(e.model),typeof e.toolUses=="number"&&r.push(`${e.toolUses} tool use${e.toolUses===1?"":"s"}`),typeof e.tokens=="number"&&e.tokens>0&&r.push(pj(e.tokens)),e.startedAt&&e.endedAt&&r.push(fj(e.endedAt-e.startedAt)),`## ${e.agent}#${e.id} ${t}${r.length>0?` (${r.join(" \xB7 ")})`:""}`}var Ft=[],dj=3,VT=8,o1e=6,Mm=12;function vm(e){nj(Un,{recursive:!0}),fr(Vp(Un,`${e.id}.json`),JSON.stringify({...e,session:void 0},null,1))}function Jp(){let e;try{e=oj(Un)}catch{return}for(let t of e)if(t.endsWith(".json"))try{let r=JSON.parse(ij(Vp(Un,t),"utf8"));if(r.status!=="parked"||Ft.some(n=>n.id===r.id))continue;Ft.push({...r,mail:r.mail??[]})}catch{}if(Ft.length>Mm){let t=Ft.splice(0,Ft.length-Mm);for(let r of t){let n=r.session;r.session=void 0,n&&n.dispose();try{sj(Vp(Un,`${r.id}.json`))}catch{}}}}function i1e(){if(Jp(),Ft.length===0)return"no agents";let e=Ft.map(t=>`${t.id} ${t.agent} ${t.status}${t.model?` model=${t.model}`:""}${t.background?" background":""} requests=${t.requests} ${t.task}`);return Mo&&e.unshift("background work in flight"),e.join(`
|
|
157
|
+
`)}function s1e(e){Jp();let t=Ft.find(r=>r.id===e);return t?`${t.agent}#${t.id} ${t.status}
|
|
158
|
+
${t.result??t.task}`:`no agent ${e}`}async function Fm(e){let t=xn.get(e.agent);if(!t)throw new Error(`unknown agent ${e.agent}`);let r=e.worktree||e.cwd||process.cwd(),n=new mj({cwd:r,agentDir:tt,appendSystemPrompt:[t.prompt],additionalSkillPaths:pf(r),extensionFactories:[ff({interactive:!1}),Ek()]});await n.reload();let{session:o}=await aj({cwd:r,agentDir:tt,sessionManager:uj.inMemory(r),resourceLoader:n,tools:t.tools,customTools:[uk,ik,iT,sT,xT,HT,rk],thinkingLevel:e.effort}),i=lj(e,t);if(i){let a=await o.modelRuntime.getAvailable(),m=WT(a,i);if(!m){o.dispose();let c=e.model?"asked for by the task":t.model?`named by the ${e.agent} definition${t.source?` (${t.source})`:""}`:"inherited from the parent session";throw new Error(`unknown model '${i}' ${c}. /model lists what this account can reach.`)}await o.setModel(m)}return o}async function a1e(e,t){Jp();let r=Ft.find(o=>o.id===e);if(!r)return`no agent ${e}`;let n=r.session??await Fm(r);if(r.session=n,r.status==="running"||n.isStreaming)return r.mail.push(t),vm(r),`queued for ${e}`;if(r.requests>=VT)return`${e} is out of budget (${r.requests} requests)`;r.status="running";try{await n.prompt(t),r.requests+=1,r.result=jo(n.getLastAssistantText()??"")||r.result,r.status="parked"}catch(o){r.result=o instanceof Error?o.message:String(o),r.status="error"}return vm(r),`${e} ${r.status}`}function lj(e,t){for(let r of[e.model,t.model,e.parentModel]){let n=r?.trim();if(n)return n}}function JT(e){if(!(!e?.provider||!e.id))return`${e.provider}/${e.id}`}async function m1e(e){let t=xn.get(e.agent);if(!t)throw new Error(`unknown agent ${e.agent}. known: ${[...xn.keys()].join(", ")}`);if(Ft.length>=Mm)throw new Error(`${Mm} agents is the limit (${Ft.length} live or parked). Finish with the existing ones, or clear them with /agents, before spawning more.`);let r={id:`${Date.now().toString(36)}-${Ft.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 Ft.push(r),vm(r),r}async function gj(e,t){if(!xn.get(e.agent))return;let n=e.session??await Fm(e);e.session=n,e.startedAt=Date.now();try{let o=e.mail.splice(0).join(`
|
|
159
|
+
`);for(await n.prompt(`Task:
|
|
160
|
+
${e.task}${o?`
|
|
161
|
+
|
|
162
|
+
Messages:
|
|
163
|
+
${o}`:""}`),e.requests+=1;e.mail.length>0&&e.requests<VT;)await n.followUp(e.mail.splice(0).join(`
|
|
164
|
+
`)),e.requests+=1;if(t?.aborted)throw new Error("aborted");let i=jo(n.getLastAssistantText()??""),a=n.getSessionStats?.();if(!i&&(a?.toolCalls??0)===0)throw new Error(`agent produced no output (model ${n.model?.provider}/${n.model?.id} answered nothing; 0 tool calls). Check that the provider is reachable and the model is configured.`);e.result=i,e.status="parked"}catch(o){e.result=o instanceof Error?o.message:String(o),e.status="error"}finally{e.endedAt=Date.now();let o=n.getSessionStats?.();e.toolUses=o?.toolCalls,e.tokens=o?.tokens?.total,e.session=void 0,n.dispose(),vm(e);try{YT?.(e)}catch{}}}var YT;function u1e(e){YT=e}var Mo;function c1e(){Mo||(Mo=yj().catch(()=>{}).finally(()=>{Mo=void 0}))}async function yj(e){Mo&&await Mo.catch(()=>{});let t=()=>Ft.find(n=>n.status==="queued"),r=async()=>{for(;;){if(e?.aborted)throw new Error("aborted");let n=t();if(!n)return;n.status="running";let o=await Om();try{await gj(n,e)}finally{o()}}};if(await Promise.all(Array.from({length:dj},r)),e?.aborted)throw new Error("aborted")}import{execFile as xj}from"node:child_process";import{cp as hj,readdir as Ij,stat as QT}from"node:fs/promises";import{promisify as bj}from"node:util";import{tmpdir as $j}from"node:os";import{join as Lm}from"node:path";var XT=bj(xj);async function Xt(e,t){try{let{stdout:r}=await XT("git",t,{cwd:e,encoding:"utf8",maxBuffer:8388608});return{ok:!0,output:r.trim()}}catch(r){let n=r&&typeof r=="object"&&"stderr"in r&&typeof r.stderr=="string"?r.stderr.trim():"",o=r instanceof Error?r.message:String(r);return{ok:!1,output:n||o}}}async function Ej(e){return(await Xt(e,["rev-parse","--is-inside-work-tree"])).output==="true"}async function x1e(e){return(await Xt(e,["status","--porcelain"])).output.length>0}async function h1e(e,t){let r=await Xt(e,["add","-A"]);if(!r.ok)return r;let n=await Xt(e,["commit","-m",t]);return n.ok?{ok:!0,output:(await Xt(e,["log","-1","--oneline"])).output||n.output}:n}async function I1e(e){let t=await Xt(e,["reset","--soft","HEAD~1"]);return t.ok?{ok:!0,output:(await Xt(e,["log","-1","--oneline"])).output||"reset to the previous commit"}:t}async function b1e(e){let t=(await Xt(e,["diff"])).output,r=(await Xt(e,["diff","--cached"])).output;return[t,r].filter(Boolean).join(`
|
|
165
|
+
`)}function $1e(e,t=60){let r=e.split(`
|
|
166
|
+
`);if(r.length<=t)return e;let n=r.slice(0,t),o=r.length-t;return[...n,`\u2026 ${o} more line${o===1?"":"s"} not shown \u2014 /copy puts the full diff on the clipboard`].join(`
|
|
167
|
+
`)}var Sj=["node_modules","vendor","target",".venv","venv","__pycache__",".pnpm-store","dist","build"],ZT=1024*1024*1024;async function ew(e){let t=0,r;try{r=await Ij(e,{withFileTypes:!0})}catch{return 0}for(let n of r){let o=Lm(e,n.name);if(n.isDirectory())t+=await ew(o);else if(n.isFile())try{t+=(await QT(o)).size}catch{}if(t>ZT)return t}return t}async function kj(e,t){let r=[];for(let n of Sj){let o=Lm(e,n),i=Lm(t,n);try{if(!(await QT(o)).isDirectory())continue}catch{continue}if(await ew(o)>ZT){r.push(n);continue}await Tj(o,i)||r.push(n)}return r}async function Tj(e,t){if(process.platform!=="win32")try{return await XT("cp",["-a",e,t],{maxBuffer:8*1024*1024}),!0}catch{}try{return await hj(e,t,{recursive:!0,force:!0,errorOnExist:!1,dereference:!1}),!0}catch{return!1}}async function tw(e,t){if(!await Ej(e))return null;let r=t.replace(/[^A-Za-z0-9._-]/g,"-").slice(0,40)||"agent",n=Lm($j(),`howtocode-wt-${process.pid}-${Date.now()}-${r}`);if(!(await Xt(e,["worktree","add","--detach",n,"HEAD"])).ok)return null;let i=await kj(e,n);return{path:n,skipped:i,async remove(){await Xt(e,["worktree","remove","--force",n]),await Xt(e,["worktree","prune"])}}}import{detectCapabilities as wj,getTerminalColorMode as Cj,parseColor as zr,styleText as rw}from"@netrodev/hxf-tui";function Rj(){let e=process.env.NO_COLOR;if(e!==void 0&&e!=="")return"256color";try{return Cj(wj())}catch{return"256color"}}var nw=Rj();function Pj(){let e=process.env.NO_COLOR;return e!==void 0&&e!==""}var He={text:zr("#e6e6e6"),mute:zr("#8b8b8b"),dim:zr("#5c5c5c"),user:zr("#d0d0d0"),accent:zr("#c4b5fd"),tool:zr("#6ee7b7"),bad:zr("#f0a8a4"),warn:zr("#e6b15a"),line:zr("#3a3a3a")};function Aj(e,t){if(Pj()){let{bold:r,dim:n,italic:o,underline:i,strikethrough:a}=t;return!r&&!n&&!o&&!i&&!a?e:rw(e,{bold:r,dim:n,italic:o,underline:i,strikethrough:a},nw)}return rw(e,t,nw)}function dt(e,t,r){return Aj(e,{...r,fg:t})}var k1e={heading:e=>dt(e,He.text,{bold:!0}),link:e=>dt(e,He.accent,{underline:!0}),linkUrl:e=>dt(e,He.mute),code:e=>dt(e,He.text),codeBlock:e=>dt(e,He.text),codeBlockBorder:e=>dt(e,He.line),quote:e=>dt(e,He.mute,{italic:!0}),quoteBorder:e=>dt(e,He.line),hr:e=>dt(e,He.line),listBullet:e=>dt(e,He.mute),bold:e=>dt(e,He.text,{bold:!0}),italic:e=>dt(e,He.text,{italic:!0}),strikethrough:e=>dt(e,He.mute,{strikethrough:!0}),underline:e=>dt(e,He.text,{underline:!0})};import{truncateToWidth as Gi,visibleWidth as cr}from"@netrodev/hxf-tui";var ow={text:He.text,muted:He.mute,dim:He.dim,accent:He.accent,success:He.tool,error:He.bad,border:He.line},me=(e,t,r=!1)=>r?dt(t,ow[e],{bold:!0}):dt(t,ow[e]),Oj=25,Mj=15e5,sw=420;function Fo(e){let t=Math.max(0,Math.round(e/1e3)),r=Math.floor(t/3600),n=Math.floor(t%3600/60),o=t%60;return r>0?`${r}h${String(n).padStart(2,"0")}m`:n>0?`${n}m${String(o).padStart(2,"0")}s`:`${o}s`}function R1e(e){let t=Math.max(0,Math.floor(e/1e3));return t<60?`${t}s`:t<3600?`${Math.floor(t/60)}m`:`${Math.floor(t/3600)}h`}function Xp(e){return e>=1e6?`${(e/1e6).toFixed(1)}M`:e>=1e3?`${(e/1e3).toFixed(1)}k`:String(e)}var Bi=(e,t,r)=>Math.max(t,Math.min(r,e)),vo=(e,t)=>cr(e)>t?Gi(e,Math.max(0,t),"\u2026"):e;function Dm(e,t,r="left"){if(t<=0)return"";let n=cr(e);if(n>t)return Gi(e,t);let o=" ".repeat(t-n);return r==="right"?o+e:e+o}function Zp(e,t,r,n=1){if(r<=0)return"";let o=cr(t);if(o>=r)return Gi(t,r);let i=r-o-n;if(i<=0)return Dm(t,r,"right");let a=cr(e)>i?Gi(e,i):e,m=" ".repeat(r-cr(a)-o);return a+m+t}function Yp(e,t,r){let n=vo(e,Math.max(0,r-2)),o=Math.max(1,r-1-cr(n)),i=me("border","\u250C\u2500 ")+me("accent",n)+me("border",` ${"\u2500".repeat(o)}\u2510`),a=me("border",`\u2514${"\u2500".repeat(r+2)}\u2518`),m=me("border","\u2502"),c=t.map(p=>`${m} ${Dm(p,r)} ${m}`);return[i,...c,a]}function vj(e,t,r,n){let o=n?.gap??1,i=n?.leftWidth??Bi(Math.round(r*.38),28,44),a=r-i-o,m=Math.max(e.rows.length,t.rows.length),c=g=>{let y=[...g];for(;y.length<m;)y.push("");return y},p=Yp(e.title,c(e.rows),i-4),f=Yp(t.title,c(t.rows),a-4),d=" ".repeat(o);return p.map((g,y)=>g+d+(f[y]??Dm("",a)))}function aw(e,t,r){switch(e){case"running":return me(t||r?"accent":"muted","\u25CF");case"failed":return me("error","\u2717");default:return me("success","\u2713")}}function mw(e,t,r,n=Date.now(),o=0){return t?n-o<sw?me("success","\u2713",!0):me("success","\u2713"):me(r?"accent":"dim",String(e))}var iw="Workflow";function ef(e,t=Date.now()){let r=e.phases.map(o=>o.title),n=new Map(e.phases.map(o=>[o.title,o.detail]));for(let o of e.steps){let i=o.phase||iw;r.includes(i)||r.push(i)}return r.map((o,i)=>{let a=e.steps.filter(I=>(I.phase||iw)===o).map(I=>({...I,phaseIndex:i})),m=a.filter(I=>I.status!=="running").length,c=a.filter(I=>I.status==="failed").length,p=a.reduce((I,h)=>{let b=h.endedAt??t;return Math.max(I,b-h.startedAt)},0),f=-1;for(let I=0;I<a.length;I++){let h=a[I];h.status==="running"&&(f<0||h.startedAt>=a[f].startedAt)&&(f=I)}let d=n.get(o),g=a.length>0&&m===a.length&&c===0,y=g?a.reduce((I,h)=>Math.max(I,h.endedAt??0),0):0;return{title:o,...d?{detail:d}:{},agents:a,done:m,failed:c,outputTokens:a.reduce((I,h)=>I+h.outputTokens,0),elapsedMs:p,allDone:g,finishedAt:y,anchor:f}})}function tf(e){return e.steps.reduce((t,r)=>t+r.outputTokens,0)}function Fj(e){return e.steps.reduce((t,r)=>t+(r.toolCalls??0),0)}function uw(e,t=Date.now()){return Math.max(0,(e.endedAt??t)-e.startedAt)}function Lj(e){return e.steps.length>Oj||tf(e)>Mj}function Dj(e){if(e.length===0)return 0;let t=e.map((r,n)=>({group:r,index:n})).filter(r=>r.group.anchor>=0);if(t.length>0)return t.reduce((r,n)=>{let o=n.group.agents[n.group.anchor],i=r.group.agents[r.group.anchor];return o.startedAt>=i.startedAt?n:r}).index;for(let r=e.length-1;r>=0;r--)if(e[r].agents.length>0)return r;return e.length-1}function cw(e,t=Date.now()){let r=ef(e,t),n=e.steps.length,o=e.steps.filter(p=>p.status!=="running").length,i=e.steps.filter(p=>p.status==="failed").length,a=[e.name],m=r.find(p=>p.anchor>=0);m?a.push(`${m.title} ${m.done}/${m.agents.length}`):r.length>0&&a.push(`${r[r.length-1].title} done`),a.push(`${o}/${n} agents`),a.push(`${Xp(tf(e))} tok`),a.push(Fo(uw(e,t))),i>0&&a.push(`${i} failed`);let c=a.join(" \xB7 ");return Lj(e)?`large workflow \xB7 ${c}`:c}var pw=16,jj=12,Nj=18,qj=72,_j=24;function fw(e,t){if(e.status==="running"&&e.outputTokens===0)return[`idle ${Fo(t-e.startedAt)}`,"idle"];let r=Xp(e.outputTokens),n=e.toolCalls??0,o=Fo((e.endedAt??t)-e.startedAt);return[`${r} tok \xB7 ${n} tools \xB7 ${o}`,`${r} tok \xB7 ${n} tools`,`${r} tok`]}var Uj=e=>e.status==="running"&&e.outputTokens===0;function Qp(e,t,r){if(e.length<=r)return{slice:e,start:0,more:0};let n=Math.max(1,r-1),o=Bi(t-Math.floor(n/2),0,e.length-n),i=e.slice(o,o+n);return{slice:i,start:o,more:e.length-i.length}}function Bj(e,t,r,n,o){let i=`${e.done}/${e.agents.length}`,a=r?me("accent","\u276F"):" ",m=mw(t+1,e.allDone,r,o,e.finishedAt),c=Math.max(0,n-4-cr(i)),p=cr(e.title)>c?Gi(e.title,c,"\u2026"):e.title,f=e.allDone&&o-e.finishedAt<sw,d=me(f&&!r?"success":r?"accent":"text",p),g=`${a}${m} ${d}`,y=me(r?"accent":"muted",i);return Zp(g,y,n,1)}function Gj(e,t,r,n,o,i){let a=t?me("accent","\u276F"):" ",m=aw(e.status,t,r),c=me(t?"accent":"text",Dm(e.label,n)),p=`${a}${m} ${c}`,f=Math.max(0,o-cr(p)-1),d=fw(e,i).find(y=>cr(y)<=f)??"",g=me(t?"accent":Uj(e)?"dim":"muted",d);return Zp(p,g,o,1)}function Kj(e,t,r,n){let o=[];return e.forEach((i,a)=>{let c=`${mw(a+1,i.allDone,a===r,n,i.finishedAt)} ${me(a===r?"accent":"text",i.title)} ${me("muted",`${i.done}/${i.agents.length}`)}`;o.push(vo(c,t));let{slice:p,more:f}=Qp(i.agents,0,pw);p.forEach((d,g)=>{let y=aw(d.status,!1,g===i.anchor),I=fw(d,n)[0]??"";o.push(vo(` ${y} ${me("text",d.label)} ${me("muted",I)}`,t))}),f>0&&o.push(vo(` ${me("dim",`\u2026+${f} more`)}`,t))}),o}function Hj(e,t,r){let n=r?.now??Date.now(),o=ef(e,n),i=e.steps,a=i.filter(R=>R.status!=="running").length,m=i.filter(R=>R.status==="failed").length,c=[`${a}/${i.length} agents`,`${Xp(tf(e))} tok`,`${Fj(e)} tools`,Fo(uw(e,n)),...m>0?[`${m} failed`]:[]].join(" \xB7 "),p=[Zp(me("accent",e.name,!0),me("muted",c),t,2),...e.description?[me("muted",vo(e.description,t))]:[]],f=r?.footer?[me("muted",vo(r.footerText??zj(),t))]:[];if(o.length===0)return[...p,...Yp("Phases",["(no agents yet)"],Math.max(0,t-4)),...f];let d=Bi(r?.selectedPhase??Dj(o),0,Math.max(0,o.length-1)),g=Bi(Math.round(t*.38),28,44),y=t-g-1-4;if(t<qj||y<_j)return[...p,...Kj(o,t,d,n),...f];let I=o[d],{slice:h,start:b,more:k}=Qp(o,d,jj),_=h.map((R,J)=>Bj(R,b+J,b+J===d,g-4,n));k>0&&_.push(me("dim",`\u2026+${k} more`));let A=r?.filter?r.filter(I.agents):I.agents,Fe=A.length?Bi(Math.max(...A.map(R=>cr(R.label))),6,Nj):6,{slice:We,more:S}=Qp(A,0,r?.agentWindow??pw),w=We.map((R,J)=>Gj(R,!1,J===I.anchor,Fe,y,n));S>0&&w.push(me("dim",`\u2026+${S} more`));let O=vj({title:"Phases",rows:_},{title:`${I.title} \xB7 ${A.length} agents${r?.filterLabel??""}`,rows:w},t,{leftWidth:g,gap:1});return[...p,...O,...f]}function P1e(e,t=[],r=96,n,o){let i=Hj(e,r,{now:e.endedAt??Date.now(),footer:!0,...n===void 0?{}:{selectedPhase:n},...o?.filter?{filter:o.filter}:{},...o?.footerText?{footerText:o.footerText}:{},...o?.filterLabel?{filterLabel:o.filterLabel}:{}}),a=new Set(t);if(o?.drill){let c=ef(e,e.endedAt??Date.now()),p=c[Math.max(0,Math.min(c.length-1,n??0))];for(let f of p?.agents??[])a.add(f.label)}if(a.size===0)return i;let m=[];for(let c of e.steps)if(a.has(c.label)){for(let p of c.tasks??[]){let f=p.status==="completed"?"[x]":p.status==="in_progress"?"[>]":"[ ]";m.push(` ${me("muted",f)} ${me("text",p.content)}`)}c.detail&&m.push(` ${me("dim",c.detail)}`)}return m.length===0?i:[...i.slice(0,-1),...m,i[i.length-1]]}function zj(){return"\u2191/\u2193 phase \xB7 Enter drill in \xB7 Esc back out \xB7 f filter by status \xB7 p pause \xB7 x stop \xB7 s save script"}import{readFileSync as eN}from"node:fs";import{basename as tN}from"node:path";import{StringEnum as rN}from"@netrodev/hxf-ai";import{defineTool as nN}from"@netrodev/hxf-coding-agent";var _n=e=>typeof e=="object"&&e!==null&&!Array.isArray(e);function dw(e){return e===null?"null":Array.isArray(e)?"array":Number.isInteger(e)?"integer":typeof e}function Wj(e,t){let r=dw(e);return t==="number"?r==="number"||r==="integer":t==="integer"?r==="integer":r===t}function Vj(e,t){if(typeof t!="string"||!t.startsWith("#/"))return;let r=e;for(let n of t.slice(2).split("/")){let o=n.replace(/~1/g,"/").replace(/~0/g,"~");if(!_n(r)&&!Array.isArray(r))return;r=r[o]}return _n(r)?r:void 0}function hn(e,t,r,n,o){if(!_n(t))return;if(t.$ref!==void 0){let a=Vj(r,t.$ref);a&&hn(e,a,r,n,o);return}if(Array.isArray(t.allOf))for(let a of t.allOf)hn(e,a,r,n,o);for(let a of["anyOf","oneOf"]){let m=t[a];if(!Array.isArray(m)||m.length===0)continue;let c=m.filter(p=>{let f=[];return hn(e,p,r,n,f),f.length===0}).length;a==="anyOf"&&c===0&&o.push({path:n,message:"does not match any allowed shape"}),a==="oneOf"&&c!==1&&o.push({path:n,message:`must match exactly one shape (matched ${c})`})}let i=t.type;if(i!==void 0){let a=Array.isArray(i)?i.map(String):[String(i)];if(!a.some(m=>Wj(e,m))){o.push({path:n,message:`expected ${a.join(" or ")}, got ${dw(e)}`});return}}if(Array.isArray(t.enum)&&!t.enum.some(a=>JSON.stringify(a)===JSON.stringify(e))&&o.push({path:n,message:`must be one of ${t.enum.map(a=>JSON.stringify(a)).join(", ")}`}),_n(e)){let a=_n(t.properties)?t.properties:{};if(Array.isArray(t.required))for(let m of t.required.map(String))m in e||o.push({path:n?`${n}.${m}`:m,message:"is required"});for(let[m,c]of Object.entries(a))m in e&&hn(e[m],c,r,n?`${n}.${m}`:m,o);if(t.additionalProperties===!1)for(let m of Object.keys(e))m in a||o.push({path:n?`${n}.${m}`:m,message:"is not an allowed property"});else if(_n(t.additionalProperties))for(let[m,c]of Object.entries(e))m in a||hn(c,t.additionalProperties,r,n?`${n}.${m}`:m,o)}if(Array.isArray(e)&&t.items!==void 0){let a=t.items;Array.isArray(a)?e.forEach((m,c)=>{c<a.length&&hn(m,a[c],r,`${n}[${c}]`,o)}):e.forEach((m,c)=>hn(m,a,r,`${n}[${c}]`,o))}if(typeof e=="string"&&(typeof t.minLength=="number"&&e.length<t.minLength&&o.push({path:n,message:`is shorter than ${t.minLength} characters`}),typeof t.pattern=="string"))try{new RegExp(t.pattern).test(e)||o.push({path:n,message:`does not match ${t.pattern}`})}catch{}typeof e=="number"&&(typeof t.minimum=="number"&&e<t.minimum&&o.push({path:n,message:`is below ${t.minimum}`}),typeof t.maximum=="number"&&e>t.maximum&&o.push({path:n,message:`is above ${t.maximum}`}))}function lw(e,t){if(!_n(t))return[];let r=[];return hn(e,t,t,"",r),r}function gw(e){return e.map(t=>`- ${t.path||"(root)"}: ${t.message}`).join(`
|
|
168
|
+
`)}function yw(e){let t=e.trim(),r=/```(?:json)?\s*([\s\S]*?)```/.exec(t),n=[t,r?.[1]?.trim()].filter(o=>!!o);for(let o of n){try{return JSON.parse(o)}catch{}for(let i=0;i<o.length;i++){let a=o[i];if(a!=="{"&&a!=="[")continue;let m=a==="{"?"}":"]",c=0,p=!1,f=!1;for(let d=i;d<o.length;d++){let g=o[d];if(p){f?f=!1:g==="\\"?f=!0:g==='"'&&(p=!1);continue}if(g==='"')p=!0;else if(g===a)c++;else if(g===m&&(c--,c===0))try{return JSON.parse(o.slice(i,d+1))}catch{break}}}}}var Jj=1e3,Yj=4096,xw=100,hw=300*1e3;async function Qj(e,t=xw,r=hw){let n=Date.now()+r;for(;e.isPaused?.();){if(e.signal?.aborted||Date.now()>=n)return!1;await new Promise(o=>setTimeout(o,t))}return!0}var et=class extends Error{constructor(t){super(t),this.name="WorkflowError"}};function Xj(e){let t=0,r=[];return async function(){t>=e&&await new Promise(i=>r.push(i)),t++;let o=!1;return()=>{o||(o=!0,t--,r.shift()?.())}}}function Iw(e){let t=e.lifetimeCap??Jj,r=e.fanoutCap??Yj,n=e.concurrency?Xj(e.concurrency):null,o=async()=>{let k=await Om();if(!n)return k;let _=await n();return()=>{_(),k()}},i=0,a=0,m=0,c="",p=k=>e.onEvent?.(k),f=new Map,d=()=>e.onProgress?.([...f.values()]),g=async(k,_)=>{let A=_??{},Fe=typeof A.label=="string"?A.label:`agent-${i+1}`,We=typeof A.phase=="string"?A.phase:c,S=typeof A.agentType=="string"?A.agentType:"task",w=typeof A.effort=="string"?A.effort:void 0,O=typeof A.model=="string"?A.model:void 0,R=typeof A.isolation=="string"?A.isolation:void 0,J=A.schema;if(e.budgetTotal!=null&&a+m>=e.budgetTotal)throw new et(`budget exhausted: spent ${a+m} of ${e.budgetTotal} output tokens`);if(i>=t)throw new et(`lifetime cap reached: ${t} agent calls in one run`);i++;let Le=i;if(e.isPaused?.()&&!await Qj(e,xw,hw))return null;let be=e.budgetTotal==null?0:Math.max(0,e.budgetTotal-a-m);m+=be;let lt=await o();try{if(e.signal?.aborted)return null;p({kind:"agent_start",label:Fe,phase:We,ordinal:i}),f.set(Le,{label:Fe,phase:We,agentType:S,status:"running",outputTokens:0,...O?{model:O}:{},startedAt:Date.now()}),d();let pr=(Ht,Wr,zt)=>{let Zt=f.get(Le);Zt&&(Zt.status=Ht,Zt.outputTokens=Wr.outputTokens,Zt.endedAt=Date.now(),Wr.toolCalls!==void 0&&(Zt.toolCalls=Wr.toolCalls),Wr.model!==void 0&&(Zt.model=Wr.model),zt&&(Zt.detail=zt)),p({kind:"agent_end",label:Fe,ok:Ht==="ok",outputTokens:Wr.outputTokens}),d()},bt=J===void 0?1:2;for(let Ht=0;Ht<bt;Ht++){let Wr=Ht===0?String(k):void 0,zt=await I(Wr??Zj(String(k),y),{label:Fe,phase:We,agentType:S,effort:w,model:O,isolation:R});if(zt===null)return pr("failed",{text:"",outputTokens:0}),null;if(a+=zt.outputTokens,J===void 0)return pr("ok",zt,rf(zt.text)),zt.text;let Zt=yw(zt.text),cf=Zt===void 0?[{path:"",message:"reply was not JSON"}]:lw(Zt,J);if(cf.length===0)return pr("ok",zt,rf(zt.text)),Zt;if(y=gw(cf),Ht===bt-1)return pr("failed",zt,`schema: ${rf(y)}`),null}return null}finally{m=Math.max(0,m-be),lt()}},y="",I=async(k,_)=>{try{return await e.invoke({prompt:k,..._})}catch{return null}};return{agent:(k,_)=>g(k,_),parallel:async k=>{if(k.length>r)throw new et(`fan-out cap exceeded: ${k.length} items (max ${r})`);return await Promise.all(k.map(async A=>{try{return await A()}catch{return null}}))},pipeline:async(k,..._)=>{if(k.length>r)throw new et(`fan-out cap exceeded: ${k.length} items (max ${r})`);return await Promise.all(k.map(async(Fe,We)=>{let S=Fe;for(let w of _)try{S=await w(S,Fe,We)}catch{return null}return S}))},phase:k=>{c=String(k),p({kind:"phase",title:c})},log:k=>p({kind:"log",message:String(k)}),args:e.args,budget:{total:e.budgetTotal??null,spent:()=>a+m,remaining:()=>e.budgetTotal==null?1/0:Math.max(0,e.budgetTotal-a-m)}}}function Zj(e,t){return`${e}
|
|
169
|
+
|
|
170
|
+
Your previous reply did not satisfy the required schema:
|
|
171
|
+
${t}
|
|
172
|
+
|
|
173
|
+
Reply with ONLY a corrected JSON value.`}function rf(e,t=80){let r=e.split(`
|
|
174
|
+
`).map(n=>n.trim()).find(n=>n.length>0)??"";return r.length>t?`${r.slice(0,t)}\u2026`:r}var nf="workflow",bw=null;function H1e(e){bw=e}var oN=600*1e3;function iN(e){let t=e.replace(/^(?:\s+|\/\/[^\n]*\n|\/\*[\s\S]*?\*\/)*/,""),r=/^export\s+const\s+meta\s*=\s*/.exec(t);if(!r)throw new et("a workflow script must start with `export const meta = { name, description }`");let n=e.length-t.length,o=r[0].length,i=0,a=null,m=-1;for(let y=o;y<t.length;y++){let I=t[y];if(a){I==="\\"?y++:I===a&&(a=null);continue}if(I==='"'||I==="'"||I==="`")a=I;else if(I==="{"||I==="[")i++;else if((I==="}"||I==="]")&&(i--,i===0)){m=y+1;break}}if(m===-1)throw new et("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 et("a workflow body must not contain import or export declarations");if(/\bimport\s*\(/.test(p))throw new et("a workflow body must not use dynamic import()");let f;try{f=new Function(`"use strict"; return (${c});`)()}catch(y){throw new et(`meta must be a literal object: ${y instanceof Error?y.message:String(y)}`)}if(typeof f!="object"||f===null)throw new et("meta must be an object");let d=f;if(typeof d.name!="string"||!d.name.trim())throw new et("meta.name is required");if(typeof d.description!="string"||!d.description.trim())throw new et("meta.description is required");let g=Array.isArray(d.phases)?d.phases.filter(y=>typeof y=="object"&&y!==null).map(y=>({title:String(y.title??""),...typeof y.detail=="string"?{detail:y.detail}:{}})).filter(y=>y.title):void 0;return{meta:{name:d.name,description:d.description,...typeof d.whenToUse=="string"?{whenToUse:d.whenToUse}:{},...g?{phases:g}:{}},body:p}}function sN(e){let t=["agent","parallel","pipeline","phase","log","args","budget"],r=`"use strict"; return (async () => {
|
|
175
|
+
${e}
|
|
176
|
+
})();`,n;try{n=new Function(...t,r)}catch(o){throw new et(`workflow did not compile: ${o instanceof Error?o.message:String(o)}`)}return n}function aN(e){return jo(e.getLastAssistantText()??"")}function mN(e){return async({prompt:t,agentType:r,effort:n,model:o,isolation:i})=>{let a=xn.get(r)??xn.get("task");if(!a)throw new et(`no agent named ${r}`);let m=i==="worktree"?await tw(process.cwd(),r):null,c=await Fm({agent:a.name,effort:n??a.effort,...o?{model:o}:{},...e?{parentModel:e}:{},...m?{worktree:m.path}:{}});try{await c.prompt(`${a.prompt}
|
|
177
|
+
|
|
178
|
+
Task:
|
|
179
|
+
${t}`);let p=c.getSessionStats(),f=uN(c)??o;return{text:aN(c),outputTokens:p.tokens.output,toolCalls:p.toolCalls,...f?{model:f}:{}}}finally{c.dispose(),await m?.remove()}}}function uN(e){return e.model?.id??e.model?.name}var cN=D.Object({code:D.Optional(D.String({description:"The workflow script source"})),path:D.Optional(D.String({description:"Path to a workflow script, instead of code"})),agent:D.Optional(rN(["scout","task","reviewer"],{description:"Default agent profile for calls"})),budget:D.Optional(D.Number({description:"Output-token ceiling for the whole run"}))});function z1e(e){let t=()=>e??bw;return nN({name:"workflow",label:"workflow",description:"Run a JavaScript workflow that orchestrates many agents deterministically. Provide `code` (or `path`). The script starts with `export const meta = { name, description, phases }` and then uses the injected bindings: `agent(prompt, {label, phase, schema, effort, model, agentType, isolation})`, `parallel(thunks)`, `pipeline(items, ...stages)`, `phase(title)`, `log(msg)`, `args`, `budget`. `agent()` resolves null on failure and throws only when the budget or the call cap is exhausted, so null-check every result. `parallel()` takes thunks and never rejects; `pipeline()` has no barrier between items. Use it for fan-out, for builder-verifier loops that converge on a verdict, and for anything needing many agents whose order and count must be deterministic.",promptSnippet:"workflow: orchestrate many agents from one JavaScript script",parameters:cN,executionMode:"sequential",async execute(r,n,o,i,a){let m=n.path?eN(n.path,"utf8"):n.code??"";if(!m.trim())throw new et("provide code or path");let{meta:c,body:p}=iN(m);if(n.path){let S=tN(n.path).replace(/\.(js|mjs|cjs|ts)$/,"");if(S!==c.name)throw new et(`meta.name "${c.name}" must match the script filename "${S}"`)}let f=sN(p),d=Date.now(),g=[],y=0,I=0,h=(S,w)=>({name:c.name,...c.description?{description:c.description}:{},ok:S,agents:I,outputTokens:y,startedAt:d,phases:c.phases??[],steps:g,...w?{error:w}:{}}),b=(S,w)=>{a.ui.setStatus(nf,w?void 0:cw(S)),i?.({content:[],details:h(!1)})},k=S=>{I=S.length,y=S.reduce((w,O)=>w+O.outputTokens,0),g.splice(0,g.length,...S.map(w=>({label:w.label,phase:w.phase,agent:w.agentType,status:w.status,outputTokens:w.outputTokens,startedAt:w.startedAt,...w.toolCalls!==void 0?{toolCalls:w.toolCalls}:{},...w.model?{model:w.model}:{},...w.endedAt?{endedAt:w.endedAt}:{},...w.detail?{detail:w.detail}:{},...w.tasks?{tasks:w.tasks}:{}}))),b({name:c.name,...c.description?{description:c.description}:{},phases:c.phases??[],steps:g,startedAt:d},!1)},_=mN(JT(a?.model)),A=Iw({invoke:n.agent?pN(_,n.agent):_,budgetTotal:n.budget??null,onProgress:k,...o?{signal:o}:{},...t()?.isPaused?{isPaused:t().isPaused}:{}}),Fe=new AbortController,We=setTimeout(()=>Fe.abort(),oN);o&&o.addEventListener("abort",()=>Fe.abort(),{once:!0}),t()?.onStop?.(()=>Fe.abort());try{let S=await Promise.race([f(A.agent,A.parallel,A.pipeline,A.phase,A.log,A.args,A.budget),new Promise((O,R)=>Fe.signal.addEventListener("abort",()=>R(new et("workflow timed out or was aborted"))))]),w=Date.now();return a.ui.setStatus(nf,void 0),{content:[{type:"text",text:`${c.name}: ${I} agent call(s), ${y} output tokens in ${Fo(w-d)}
|
|
180
|
+
|
|
181
|
+
${fN(S)}`}],details:{...h(!0),endedAt:w}}}catch(S){let w=S instanceof Error?S.message:String(S);return a.ui.setStatus(nf,void 0),{content:[{type:"text",text:`${c.name} failed after ${I} agent call(s): ${w}`}],details:{...h(!1,w),endedAt:Date.now()},isError:!0}}finally{clearTimeout(We),t()?.onStop?.(null)}}})}function pN(e,t){return r=>e({...r,agentType:t})}function fN(e){if(typeof e=="string")return e;try{return JSON.stringify(e,null,2)}catch{return String(e)}}import{createServer as dN}from"node:http";import{WebSocketServer as lN}from"ws";import{randomBytes as gN,timingSafeEqual as yN}from"node:crypto";var xN=9224,hN=3e4,IN=3e4;async function $w(e){let t=e.port??xN,r=e.token??gN(16).toString("hex"),n=e.log??(()=>{}),o=Date.now(),i=null,a=!1,m="",c="",p=[],f=1,d=new Map,g=S=>{let{promise:w,resolve:O,reject:R}=Promise.withResolvers();if(!i||i.readyState!==i.OPEN)return R(new Error("Browser relay extension is not connected. Run /browser-relay install and check the toolbar badge.")),w;let J=f++,Le=setTimeout(()=>{d.delete(J),R(new Error(`Browser relay RPC timed out: ${S.op}`))},hN);return d.set(J,{resolve:O,reject:R,timer:Le}),i.send(JSON.stringify({t:"rpc",id:J,...S})),w},y=(S,w)=>{let O;try{O=JSON.parse(w)}catch{return}switch(O.t){case"hello":a=!0,m=O.browserVersion,c=O.userAgent,p=O.tabs,n(`extension connected: ${O.tabs.length} tabs`);break;case"tabCreated":p=[...p.filter(R=>R.tabId!==O.tab.tabId),O.tab];break;case"tabUpdated":p=p.map(R=>R.tabId===O.tab.tabId?O.tab:R);break;case"tabRemoved":p=p.filter(R=>R.tabId!==O.tabId);break;case"rpcResult":{let R=d.get(O.id);if(!R)return;d.delete(O.id),clearTimeout(R.timer),O.ok?R.resolve(O.result):R.reject(new Error(O.error||`Browser relay RPC failed: ${O.id}`));break}case"cdpEvent":{for(let R of I.values()){let J=!1;for(let[Le,be]of R.sessions)be===O.tabId&&(b(R,{method:O.method,params:O.params,sessionId:Le}),J=!0);!J&&R.tabId===O.tabId&&b(R,{method:O.method,params:O.params})}break}case"detached":{for(let R of I.values()){let J=!1;for(let[Le,be]of R.sessions)be===O.tabId&&(R.sessions.delete(Le),b(R,{method:"Target.detachedFromTarget",params:{targetId:`tab:${O.tabId}`,sessionId:Le,reason:O.reason}}),J=!0);!J&&R.tabId===O.tabId&&b(R,{method:"Target.detachedFromTarget",params:{targetId:`tab:${O.tabId}`,reason:O.reason}})}break}case"ping":S.send(JSON.stringify({t:"pong"}));break;default:break}},I=new Map,h=1,b=(S,w)=>{S.ws.readyState===S.ws.OPEN&&S.ws.send(JSON.stringify(w))},k=S=>{let w=typeof S=="string"?S:"",O=w.startsWith("tab:")?w.slice(4):w,R=Number(O);return Number.isInteger(R)&&R>0?R:void 0},_=(S,w)=>{let O;try{O=JSON.parse(w)}catch{return}if(typeof O.id!="number"||typeof O.method!="string")return;let R=O.id,J=O.method,Le=O.params??{};(async()=>{try{if(J==="Browser.getVersion"){b(S,{id:R,result:{protocolVersion:"1.3",product:m||"HowToCode Browser Relay",revision:"",userAgent:c||"HowToCode",jsVersion:""}});return}if(J==="Target.getTargets"){b(S,{id:R,result:{targetInfos:p.map(bt=>({targetId:`tab:${bt.tabId}`,type:"page",title:bt.title,url:bt.url,attached:!1,canAccessOpener:!1}))}});return}if(J==="Target.attachToTarget"){let bt=k(Le.targetId);if(bt===void 0)throw new Error("Target.attachToTarget needs a tab targetId");await g({op:"attach",tabId:bt,clearForeignFrames:Le.flatten===!0});let Ht=`cdp-${S.nextSession++}`;S.sessions.set(Ht,bt),b(S,{id:R,result:{sessionId:Ht}});return}if(J==="Target.detachFromTarget"){let bt=typeof Le.sessionId=="string"?Le.sessionId:"";S.sessions.delete(bt),b(S,{id:R,result:{}});return}if(J==="Target.sendMessageToTarget"){if(typeof Le.message!="string")throw new Error("Target.sendMessageToTarget needs a message");_(S,Le.message),b(S,{id:R,result:{}});return}let be=typeof O.sessionId=="string"?O.sessionId:void 0,lt=be?S.sessions.get(be):S.tabId;if(lt===void 0)throw new Error("CDP command has no attached tab session");if(J==="Target.activateTarget"){await g({op:"activateTab",tabId:lt}),b(S,{id:R,result:{}});return}if(J==="Target.closeTarget"){await g({op:"removeTab",tabId:lt}),b(S,{id:R,result:{success:!0}});return}await g({op:"attach",tabId:lt});let pr=await g({op:"send",tabId:lt,method:J,params:Le});b(S,{id:R,result:pr??{}})}catch(be){b(S,{id:R,error:{code:-32e3,message:be instanceof Error?be.message:String(be)}})}})()},A=dN((S,w)=>{let R=new URL(S.url??"/",`http://127.0.0.1:${t}`).pathname.replace(/\/+$/,"")||"/";if(S.headers.host!==`127.0.0.1:${t}`){w.writeHead(403).end("Forbidden");return}if(S.method!=="GET"){w.writeHead(405).end("Method not allowed");return}if(R==="/json/version"){let J=i!==null&&i.readyState===i.OPEN,Le={Browser:m||"HowToCode Browser Relay","Protocol-Version":"1.3","User-Agent":c||"HowToCode",webSocketDebuggerUrl:`ws://127.0.0.1:${t}/cdp`,...J?{}:{error:"relay extension is not connected",extensionSeen:a,uptimeMs:Date.now()-o}};w.writeHead(J?200:503,{"content-type":"application/json"}).end(JSON.stringify(Le));return}if(R==="/json"||R==="/json/list"){w.writeHead(200,{"content-type":"application/json"}).end(JSON.stringify(p.map(J=>({id:String(J.tabId),type:"page",title:J.title,url:J.url,webSocketDebuggerUrl:`ws://127.0.0.1:${t}/cdp?tab=${J.tabId}`}))));return}if(R==="/health"){w.writeHead(200,{"content-type":"application/json"}).end(JSON.stringify({ok:!0,ready:i!==null,tabs:p.length}));return}w.writeHead(404).end("Not found")}),Fe=new lN({noServer:!0});A.on("upgrade",(S,w,O)=>{let R=new URL(S.url??"/",`http://127.0.0.1:${t}`),J=R.pathname.replace(/\/+$/,"")||"/";if(S.headers.host!==`127.0.0.1:${t}`){w.write(`HTTP/1.1 403 Forbidden\r
|
|
182
|
+
\r
|
|
183
|
+
`),w.destroy();return}let Le=S.headers.origin;if(J==="/ext"){if(Le&&!Le.startsWith("chrome-extension://")){w.write(`HTTP/1.1 403 Forbidden\r
|
|
184
|
+
\r
|
|
185
|
+
`),w.destroy();return}let be=Buffer.from(R.searchParams.get("token")??""),lt=Buffer.from(r);if(be.length!==lt.length||!yN(be,lt)){w.write(`HTTP/1.1 401 Unauthorized\r
|
|
186
|
+
\r
|
|
187
|
+
`),w.destroy();return}}else if(J==="/cdp"){if(Le){w.write(`HTTP/1.1 403 Forbidden\r
|
|
188
|
+
\r
|
|
189
|
+
`),w.destroy();return}}else{w.write(`HTTP/1.1 404 Not Found\r
|
|
190
|
+
\r
|
|
191
|
+
`),w.destroy();return}Fe.handleUpgrade(S,w,O,be=>{if(J==="/ext")i?.close(),i=be,be.on("message",lt=>y(be,lt.toString())),be.on("close",()=>{i===be&&(i=null)});else if(J==="/cdp"){let lt=Number(R.searchParams.get("tab")??""),pr={ws:be,tabId:Number.isInteger(lt)&<>0?lt:void 0,sessions:new Map,nextSession:1},bt=h++;I.set(bt,pr),be.on("message",Ht=>_(pr,Ht.toString())),be.on("close",()=>I.delete(bt))}})}),await new Promise((S,w)=>{A.once("error",w),A.listen(t,"127.0.0.1",()=>{A.off("error",w);let O=A.address();O&&typeof O=="object"&&(t=O.port),S()})});let We=setInterval(()=>{for(let S of Fe.clients)S.readyState===S.OPEN&&S.ping()},IN);return We.unref?.(),n(`relay listening on 127.0.0.1:${t}`),{port:t,token:r,state:()=>({extensionConnected:i!==null&&i.readyState===i.OPEN,extensionSeen:a,browserVersion:m,userAgent:c,tabs:p,uptimeMs:Date.now()-o,port:t}),rpc:g,ready:()=>i!==null&&i.readyState===i.OPEN,stop:async()=>{clearInterval(We);for(let S of d.values())clearTimeout(S.timer),S.reject(new Error("Browser relay stopped"));d.clear();for(let S of Fe.clients)S.terminate();await new Promise(S=>Fe.close(()=>S())),await new Promise(S=>A.close(()=>S()))}}}import{existsSync as Pw,readFileSync as Aw}from"node:fs";import{randomBytes as bN}from"node:crypto";import{existsSync as kw,mkdirSync as Tw,readFileSync as of,renameSync as $N,writeFileSync as EN}from"node:fs";import{dirname as Cw,join as Lo}from"node:path";import{fileURLToPath as SN}from"node:url";function Ew(e,t,r){let n=r?`void chrome.storage.local.get({ token: "" }).then((stored) => { if (!stored.token) return chrome.storage.local.set({ token: ${JSON.stringify(r)} }); });
|
|
192
|
+
`:"";return`const OMP_INSTALL_VERSION = ${JSON.stringify(t)};
|
|
193
|
+
${n}${e}`}function Sw(e,t){let r=JSON.parse(e);return`${JSON.stringify({...r,name:"HowToCode Browser Relay",description:"Lets HowToCode CLI drive your existing tabs through a local CDP relay.",homepage_url:"https://howtofix.id",version_name:t,action:{default_title:"HowToCode Browser Relay (click for settings)"}},null," ")}
|
|
194
|
+
`}function jm(e){return e.replaceAll("OMP Browser Relay","HowToCode Browser Relay").replaceAll("omp-browser-relay","howtocode-browser-relay").replaceAll("omp-relay-keepalive","howtocode-relay-keepalive")}var kN=Lo(Cw(SN(import.meta.url)),"assets");function Nm(e){let t=Lo(e,"browser-relay");return{extensionDir:Lo(t,"extension"),tokenPath:Lo(t,"token")}}function Ki(e){return of(Lo(kN,`${e}.txt`),"utf8")}function ww(e,t,r){let n=`${e}.${process.pid}.tmp`;EN(n,t,r===void 0?void 0:{mode:r}),$N(n,e)}function Rw(e,t){let{extensionDir:r,tokenPath:n}=Nm(e);Tw(r,{recursive:!0,mode:448});let o="";kw(n)?o=of(n,"utf8").trim():(o=bN(24).toString("hex"),Tw(Cw(n),{recursive:!0}),ww(n,`${o}
|
|
195
|
+
`,384));let i={"manifest.json":Sw(Ki("manifest.json"),t),"options.html":jm(Ki("options.html")),"options.js":jm(Ki("options.js")),LICENSE:Ki("LICENSE"),"background.js":jm(Ew(Ki("background.js"),t,o))},a=[];for(let[m,c]of Object.entries(i)){let p=Lo(r,m);(kw(p)?of(p,"utf8"):null)!==c&&(ww(p,c,m==="background.js"?384:void 0),a.push(m))}return{extensionDir:r,tokenPath:n,token:o,wrote:a}}var zi=null,Hi=null;function Ow(){try{return JSON.parse(Aw(new URL("../../package.json",import.meta.url),"utf8")).version??"0.0.0"}catch{return"0.0.0"}}function uLe(){let e=Rw(tt,Ow());return{token:e.token,extensionDir:e.extensionDir,tokenPath:e.tokenPath,wrote:e.wrote}}async function cLe(){if(zi)return zi;if(Hi)return Hi;Hi=(async()=>{let{tokenPath:e}=Nm(tt);if(!Pw(e))throw new Error("Browser relay is not installed. Run /browser-relay install and load the extension in Chrome first.");let t=Aw(e,"utf8").trim();if(!t)throw new Error("Browser relay token file is empty. Run /browser-relay install again.");let r=process.env.HOWTOCODE_BROWSER_RELAY_PORT?.trim(),n=r&&/^\d+$/.test(r)?Number(r):void 0,o=await $w({token:t,port:n,productVersion:Ow()});return zi=o,o})();try{return await Hi}finally{Hi=null}}async function pLe(){let{extensionDir:e,tokenPath:t}=Nm(tt);return{running:zi!==null,state:zi?.state()??null,tokenConfigured:Pw(t),extensionDir:e}}import{execFile as TN,execFileSync as Wi}from"node:child_process";import{promisify as wN}from"node:util";import{createHash as Lw}from"node:crypto";import{copyFileSync as CN,existsSync as qm,mkdirSync as _m,readFileSync as mf,readdirSync as RN,rmSync as PN,statSync as sf}from"node:fs";import{dirname as Dw,join as Lt,resolve as Um}from"node:path";var af=Lt(tt,"rewind"),Vi="refs/howtocode",Mw="refs/howtofix",vw=100,jw=30,Nw="project.json",qw="checkpoints.json",Fw=!1;function AN(e){let t=Um(e);for(;;){if(qm(Lt(t,".git")))return!0;let r=Dw(t);if(r===t)return!1;t=r}}var ON=wN(TN);async function Kt(e,t){let r={...process.env};for(let o of["GIT_DIR","GIT_WORK_TREE","GIT_INDEX_FILE","GIT_OBJECT_DIRECTORY","GIT_ALTERNATE_OBJECT_DIRECTORIES","GIT_NAMESPACE","GIT_COMMON_DIR"])delete r[o];r.GIT_DIR=e.gitDir,r.GIT_WORK_TREE=e.root,r.GIT_AUTHOR_NAME=r.GIT_COMMITTER_NAME="howtocode",r.GIT_AUTHOR_EMAIL=r.GIT_COMMITTER_EMAIL="howtocode@local";let{stdout:n}=await ON("git",t,{cwd:e.root,env:r,encoding:"utf8",maxBuffer:8*1024*1024});return n.trim()}function MN(e){return Lw("sha1").update(e).digest("hex").slice(0,16)}function vN(e){let t={...process.env,GIT_DIR:e.gitDir,GIT_WORK_TREE:e.root};try{let r=Wi("git",["for-each-ref","--format=%(refname)",`${Mw}/`],{env:t,encoding:"utf8",stdio:["ignore","pipe","ignore"]}).trim();for(let n of r.split(`
|
|
196
|
+
`).filter(Boolean)){let o=`${Vi}/${n.slice(Mw.length+1)}`;try{let i=Wi("git",["rev-parse",n],{env:t,encoding:"utf8",stdio:["ignore","pipe","ignore"]}).trim();Wi("git",["update-ref",o,i],{env:t,stdio:"ignore"}),Wi("git",["update-ref","-d",n],{env:t,stdio:"ignore"})}catch{}}}catch{}}function bLe(e){let t=Um(e).replace(/\/+$/,"")||"/",r=Lt(af,MN(t)),n=Lt(r,"git"),o={root:t,gitDir:n,metaFile:Lt(r,qw),disabled:!1};return!qm(Lt(n,"HEAD"))&&!AN(t)?(o.disabled=!0,o):(_m(r,{recursive:!0}),qm(Lt(n,"HEAD"))||(_m(n,{recursive:!0}),Wi("git",["init","--quiet","--initial-branch=howtocode"],{env:{...process.env,GIT_DIR:n},stdio:["ignore","ignore","pipe"]})),FN(t,n),vN(o),LN(r,t),Fw||(Fw=!0,jN({keep:r})),o)}function FN(e,t){let r=Lt(e,".git","info","exclude");try{if(!sf(r).isFile())return;_m(Lt(t,"info"),{recursive:!0}),CN(r,Lt(t,"info","exclude"))}catch{}}function LN(e,t){let r=Lt(e,Nw),n=`${JSON.stringify({version:1,root:t})}
|
|
197
|
+
`;try{if(mf(r,"utf8")===n)return}catch{}try{fr(r,n)}catch{}}function Bm(e){try{let t=JSON.parse(mf(e.metaFile,"utf8"));if(t?.version===1&&t.sessions)return t}catch{}return{version:1,sessions:{}}}function uf(e,t){_m(Dw(e.metaFile),{recursive:!0}),fr(e.metaFile,`${JSON.stringify(t,null,1)}
|
|
198
|
+
`)}function DN(e,t){return e.disabled?[]:[...Bm(e).sessions[t]??[]].sort((r,n)=>r.at-n.at)}async function $Le(e,t,r){if(e.disabled)return null;let n;try{await Kt(e,["add","-A","--ignore-errors","--"]),n=await Kt(e,["write-tree"])}catch{return null}let i=DN(e,t).find(g=>g.tree===n),a=Date.now(),m=`${a.toString(36)}-${Lw("sha1").update(`${n}:${a}`).digest("hex").slice(0,6)}`,c=i?.commit;if(!c){let g=["howtocode checkpoint",`session ${t}`,`created ${new Date(a).toISOString()}`,`prompt ${r.slice(0,200)}`].join(`
|
|
199
|
+
`);c=await Kt(e,["commit-tree",n,"-m",g]),await Kt(e,["update-ref",`${Vi}/${m}`,c])}let p={id:m,tree:n,commit:c,prompt:r,at:a},f=Bm(e),d=[...f.sessions[t]??[],p];for(let g of d.slice(0,Math.max(0,d.length-vw)))try{await Kt(e,["update-ref","-d",`${Vi}/${g.id}`])}catch{}return f.sessions[t]=d.slice(-vw),uf(e,f),p}async function ELe(e,t){let r=[];if(e.disabled)return{ok:!1,output:"checkpoints are off: this directory is not a git repository",removed:r};try{await Kt(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 Kt(e,["clean","-fd"]);for(let o of n.split(`
|
|
200
|
+
`)){let i=/^Removing\s+(.+)$/.exec(o.trim());i?.[1]&&r.push(i[1])}}catch{}return{ok:!0,output:`restored ${t.prompt||"the checkpoint"}`,removed:r}}async function SLe(e,t){if(e.disabled)return[];try{await Kt(e,["add","-A","--ignore-errors","--"]);let r=await Kt(e,["write-tree"]);return r===t.tree?[]:(await Kt(e,["diff-tree","-r","--name-status","--no-commit-id",t.tree,r])).split(`
|
|
201
|
+
`).filter(Boolean).map(o=>{let[i,...a]=o.split(" ");return`${i?.[0]??"?"} ${a.at(-1)??""}`})}catch{return[]}}async function kLe(e,t={}){let r={droppedSessions:0,droppedRefs:0};if(e.disabled)return r;let n=(t.now??Date.now())-jw*24*60*60*1e3,o=Bm(e),i=!1;for(let[a,m]of Object.entries(o.sessions))if(!(a===t.keep||m.reduce((p,f)=>Math.max(p,f.at),0)>=n)){delete o.sessions[a],i=!0,r.droppedSessions+=1;for(let p of m)try{await Kt(e,["update-ref","-d",`${Vi}/${p.id}`]),r.droppedRefs+=1}catch{}}if(!i)return r;uf(e,o);try{await Kt(e,["gc","--quiet","--prune=now"])}catch{}return r}function jN(e={}){let t={removedDirs:0,failed:[]},r;try{r=RN(af,{withFileTypes:!0})}catch{return t}let n=(e.now??Date.now())-jw*24*60*60*1e3,o=e.keep?Um(e.keep):void 0;for(let i of r){if(!i.isDirectory())continue;let a=Lt(af,i.name);if(Um(a)!==o)try{(NN(a)||qN(a)<n)&&(PN(a,{recursive:!0,force:!0}),t.removedDirs+=1)}catch{t.failed.push(i.name)}}return t}function NN(e){try{let t=JSON.parse(mf(Lt(e,Nw),"utf8"));return typeof t?.root!="string"||t.root.length===0?!1:!qm(t.root)}catch{return!1}}function qN(e){try{return sf(Lt(e,qw)).mtimeMs}catch{return sf(e).mtimeMs}}async function TLe(e,t){if(e.disabled)return;let r=Bm(e);for(let n of r.sessions[t]??[])try{await Kt(e,["update-ref","-d",`${Vi}/${n.id}`])}catch{}delete r.sessions[t],uf(e,r)}export{Co as a,hm as b,A1 as c,NPe as d,qPe as e,_Pe as f,UPe as g,zPe as h,WPe as i,G1 as j,QPe as k,XPe as l,ZPe as m,pAe as n,fAe as o,dAe as p,lAe as q,gAe as r,rk as s,D as t,ik as u,GOe as v,uk as w,ck as x,VOe as y,yL as z,JOe as A,YOe as B,QOe as C,XOe as D,xL as E,ZOe as F,hL as G,IL as H,eMe as I,aMe as J,mMe as K,uMe as L,cMe as M,pMe as N,fMe as O,up as P,dMe as Q,lMe as R,gMe as S,yMe as T,Ek as U,LL as V,qi as W,_L as X,YL as Y,QL as Z,XL as _,ZL as $,oD as aa,iT as ba,sT as ca,xD as da,Fve as ea,xT as fa,HT as ga,XD as ha,ZD as ia,WT as ja,rj as ka,NFe as la,xn as ma,r1e as na,n1e as oa,Ft as pa,o1e as qa,i1e as ra,s1e as sa,a1e as ta,JT as ua,m1e as va,u1e as wa,c1e as xa,yj as ya,Ej as za,x1e as Aa,h1e as Ba,I1e as Ca,b1e as Da,$1e as Ea,tw as Fa,nw as Ga,He as Ha,Aj as Ia,dt as Ja,k1e as Ka,sw as La,Fo as Ma,R1e as Na,ef as Oa,P1e as Pa,H1e as Qa,z1e as Ra,xN as Sa,uLe as Ta,cLe as Ua,pLe as Va,jw as Wa,bLe as Xa,DN as Ya,$Le as Za,ELe as _a,SLe as $a,kLe as ab,TLe as bb};
|