@sreetej510/pi-hpc-tools 0.1.1 → 0.1.2

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/index.js ADDED
@@ -0,0 +1,19 @@
1
+ var gf=Object.defineProperty;var lt=(e,t)=>{for(var n in t)gf(e,n,{get:t[n],enumerable:!0})};import{existsSync as Hn,mkdirSync as $f,readFileSync as jo,writeFileSync as hf}from"node:fs";import{dirname as bf,join as Tf}from"node:path";import{homedir as Po}from"node:os";import{join as ra}from"node:path";var Nn=["ls_hpc","read_file_hpc","grep_hpc"],je=1e3,aa=12e4,Oo=10,oa=ra(Po(),".pi","agent"),ia=[ra(oa,".pi","hpc-config.json"),ra(Po(),".pi","hpc-config.json")],sa="C:/Users/sreet/plink/plink.exe";var Co=!1,Ro=null,vo=!1,Mo=!1;function Mt(){return Co}function ma(e){Co=e}function pa(){return Ro}function ft(e){Ro=e}function Kn(){return vo}function So(e){vo=e}function Gn(){return Mo}function _n(e){Mo=e}function Ef(e){let t=bf(e);Hn(t)||$f(t,{recursive:!0})}function Lo(e,t){return(e.enabledProjects??[]).includes(t)}function Ao(e,t){let n=Be();if(!n)return;let r=new Set(n.enabledProjects??[]);t?r.add(e):r.delete(e),ua({...n,enabledProjects:[...r]})}function en(){let e=process.env.HPC_USERNAME||process.env.HPC_USER,t=process.env.HPC_HOST,n=process.env.HPC_PASSWORD;if(e&&t&&n)return{username:e,host:t,password:n};for(let r of ia)try{if(!Hn(r))continue;let a=JSON.parse(jo(r,"utf-8"));if(a.username&&a.host&&a.password)return a}catch{}return null}function ua(e){let t=ia[0];Ef(t),hf(t,JSON.stringify(e,null,2),"utf-8"),ft(e)}function Be(){return pa()||ft(en()),pa()}function wo(e){return e.replace(/\\/g,"/")}function kf(){try{let e=Tf(oa,"settings.json");if(Hn(e))return JSON.parse(jo(e,"utf-8"))}catch{}return{}}function qo(){let e=kf().shellPath;return e||(process.platform==="win32"?"C:\\Program Files\\Git\\bin\\bash.exe":"bash")}function Fo(){if(process.env.PLINK_PATH)return wo(process.env.PLINK_PATH);let e=Be();return e?.plinkPath?wo(e.plinkPath):Hn(sa)?sa:"plink"}import{DEFAULT_MAX_BYTES as _$,DEFAULT_MAX_LINES as H$,formatSize as ho,truncateHead as z$}from"@earendil-works/pi-coding-agent";var p={};lt(p,{Assign:()=>Pf,Clone:()=>an,Create:()=>Sd,Discard:()=>wd,Metrics:()=>ve,Update:()=>jd});var ve={assign:0,create:0,clone:0,discard:0,update:0};function Pf(e,t){return ve.assign+=1,{...e,...t}}var i={};lt(i,{Entries:()=>Bf,EntriesRegExp:()=>zf,Every:()=>Gf,EveryAll:()=>_f,GraphemeCount:()=>Uf,HasPropertyKey:()=>Hf,IsArray:()=>nn,IsBigInt:()=>tn,IsBoolean:()=>Bo,IsClassInstance:()=>Ff,IsConstructor:()=>Sf,IsDeepEqual:()=>da,IsEqual:()=>M,IsFunction:()=>Wo,IsGreaterEqualThan:()=>Zo,IsGreaterThan:()=>Lf,IsInteger:()=>la,IsLessEqualThan:()=>Vo,IsLessThan:()=>Af,IsMaxLength:()=>Nf,IsMinLength:()=>Kf,IsMultipleOf:()=>qf,IsNull:()=>Wn,IsNumber:()=>Vn,IsObject:()=>rn,IsObjectNotArray:()=>wf,IsString:()=>Zn,IsSymbol:()=>jf,IsUndefined:()=>fa,IsUnsafePropertyKey:()=>Jo,IsValueLike:()=>Df,Keys:()=>Bn,ShiftLeft:()=>Jn,Symbols:()=>Wf,Values:()=>Vf});function dt(e,t,n){return e>=t&&e<=n}function Of(e){return e===8205}function Cf(e){return dt(e,55296,56319)}function Do(e){return dt(e,127462,127487)}function No(e){return dt(e,65024,65039)}function Ko(e){return dt(e,768,879)||dt(e,6832,6911)||dt(e,7616,7679)||dt(e,65056,65071)}function zn(e){return e>65535?2:1}function Uo(e,t){for(;t<e.length;){let n=e.codePointAt(t);if(Ko(n)||No(n))t+=zn(n);else break}return t}function ca(e,t){let n=e.codePointAt(t),r=t+zn(n);for(r=Uo(e,r);r<e.length-1&&e[r]==="\u200D";){let a=e.codePointAt(r+1);r+=1+zn(a),r=Uo(e,r)}return Do(n)&&r<e.length&&Do(e.codePointAt(r))&&(r+=zn(e.codePointAt(r))),r}function Go(e){return Cf(e)||Ko(e)||No(e)||Of(e)}function _o(e){let t=0,n=0;for(;n<e.length;)n=ca(e,n),t++;return t}function Rf(e,t){if(t===0)return!0;let n=0,r=0;for(;r<e.length;)if(r=ca(e,r),n++,n>=t)return!0;return!1}function vf(e,t){let n=0,r=0;for(;r<e.length;)if(r=ca(e,r),n++,n>t)return!1;return!0}function Ho(e,t){if(t===0)return!0;let n=0;for(;n<e.length;){if(Go(e.charCodeAt(n)))return Rf(e,t);if(n++,n>=t)return!0}return!1}function zo(e,t){let n=0;for(;n<e.length;){if(Go(e.charCodeAt(n)))return vf(e,t);if(n++,n>t)return!1}return!0}function nn(e){return Array.isArray(e)}function tn(e){return M(typeof e,"bigint")}function Bo(e){return M(typeof e,"boolean")}function Sf(e){if(fa(e)||!Wo(e))return!1;let t=Function.prototype.toString.call(e);return!!(/^class\s/.test(t)||/\[native code\]/.test(t))}function Wo(e){return M(typeof e,"function")}function la(e){return Number.isInteger(e)}function Wn(e){return M(e,null)}function Vn(e){return Number.isFinite(e)}function wf(e){return rn(e)&&!nn(e)}function rn(e){return M(typeof e,"object")&&!Wn(e)}function Zn(e){return M(typeof e,"string")}function jf(e){return M(typeof e,"symbol")}function fa(e){return M(e,void 0)}function M(e,t){return e===t}function Lf(e,t){return e>t}function Af(e,t){return e<t}function Vo(e,t){return e<=t}function Zo(e,t){return e>=t}function qf(e,t){if(tn(e)||tn(t))return BigInt(e)%BigInt(t)===0n;let n=1e-10;if(!Vn(e)||la(e)&&1/t%1===0)return!0;let r=e%t;return Math.min(Math.abs(r),Math.abs(r-t),Math.abs(r+t))<n}function Ff(e){if(!rn(e))return!1;let t=globalThis.Object.getPrototypeOf(e);return Wn(t)?!1:M(typeof t.constructor,"function")&&!(M(t.constructor,globalThis.Object)||M(t.constructor.name,"Object"))}function Df(e){return tn(e)||Bo(e)||Wn(e)||Vn(e)||Zn(e)||fa(e)}function Uf(e){return _o(e)}function Nf(e,t){return zo(e,t)}function Kf(e,t){return Ho(e,t)}function Gf(e,t,n){for(let r=t;r<e.length;r++)if(!n(e[r],r))return!1;return!0}function _f(e,t,n){let r=!0;for(let a=t;a<e.length;a++)n(e[a],a)||(r=!1);return r}function Jn(e,t,n){return M(e.length,0)?n():t(e[0],e.slice(1))}function Jo(e){return M(e,"__proto__")||M(e,"constructor")||M(e,"prototype")}function Hf(e,t){return Jo(t)?Object.prototype.hasOwnProperty.call(e,t):t in e}function zf(e){return Bn(e).map(t=>[new RegExp(`^${t}$`),e[t]])}function Bf(e){return Object.entries(e)}function Bn(e){return Object.getOwnPropertyNames(e)}function Wf(e){return Object.getOwnPropertySymbols(e)}function Vf(e){return Object.values(e)}function Zf(e,t){if(!rn(t))return!1;let n=Bn(e);return M(n.length,Bn(t).length)&&n.every(r=>da(e[r],t[r]))}function Jf(e,t){return nn(t)&&M(e.length,t.length)&&e.every((n,r)=>da(e[r],t[r]))}function da(e,t){return nn(e)?Jf(e,t):rn(e)?Zf(e,t):M(e,t)}var Xe={};lt(Xe,{IsBigInt64Array:()=>cd,IsBigUint64Array:()=>ld,IsBoolean:()=>Xf,IsDate:()=>dd,IsFloat32Array:()=>pd,IsFloat64Array:()=>ud,IsInt16Array:()=>od,IsInt32Array:()=>sd,IsInt8Array:()=>nd,IsMap:()=>Id,IsNumber:()=>Yf,IsRegExp:()=>fd,IsSet:()=>xd,IsString:()=>ed,IsTypeArray:()=>td,IsUint16Array:()=>id,IsUint32Array:()=>md,IsUint8Array:()=>rd,IsUint8ClampedArray:()=>ad});function Xf(e){return e instanceof Boolean}function Yf(e){return e instanceof Number}function ed(e){return e instanceof String}function td(e){return globalThis.ArrayBuffer.isView(e)}function nd(e){return e instanceof globalThis.Int8Array}function rd(e){return e instanceof globalThis.Uint8Array}function ad(e){return e instanceof globalThis.Uint8ClampedArray}function od(e){return e instanceof globalThis.Int16Array}function id(e){return e instanceof globalThis.Uint16Array}function sd(e){return e instanceof globalThis.Int32Array}function md(e){return e instanceof globalThis.Uint32Array}function pd(e){return e instanceof globalThis.Float32Array}function ud(e){return e instanceof globalThis.Float64Array}function cd(e){return e instanceof globalThis.BigInt64Array}function ld(e){return e instanceof globalThis.BigUint64Array}function fd(e){return e instanceof globalThis.RegExp}function dd(e){return e instanceof globalThis.Date}function xd(e){return e instanceof globalThis.Set}function Id(e){return e instanceof globalThis.Map}function gd(e){return i.HasPropertyKey(e,"~kind")||i.HasPropertyKey(e,"~unsafe")}function $d(e){let t={},n=Object.getOwnPropertyDescriptors(e);for(let r of Object.keys(n)){if(i.IsUnsafePropertyKey(r))continue;let a=n[r];i.HasPropertyKey(a,"value")&&Object.defineProperty(t,r,{...a,value:xt(a.value)})}return t}function hd(e){let t={};for(let n of i.Keys(e))i.IsUnsafePropertyKey(n)||(t[n]=xt(e[n]));for(let n of i.Symbols(e))t[n]=xt(e[n]);return t}function bd(e){return i.IsClassInstance(e)?e:gd(e)?$d(e):hd(e)}function Td(e){return e.map(t=>xt(t))}function Ed(e){return e.slice()}function kd(e){return new RegExp(e.source,e.flags)}function Pd(e){return new Map(xt([...e.entries()]))}function Od(e){return new Set(xt([...e.values()]))}function xt(e){return Xe.IsTypeArray(e)?Ed(e):Xe.IsRegExp(e)?kd(e):Xe.IsMap(e)?Pd(e):Xe.IsSet(e)?Od(e):i.IsArray(e)?Td(e):i.IsObject(e)?bd(e):e}function an(e){return ve.clone+=1,xt(e)}var It={};lt(It,{Get:()=>vd,Reset:()=>Cd,Set:()=>Rd});var We={immutableTypes:!1,maxErrors:8,useAcceleration:!0,exactOptionalPropertyTypes:!1,enumerableKind:!1,correctiveParse:!1,unionPrioritySort:!0};function Cd(){We.immutableTypes=!1,We.maxErrors=8,We.useAcceleration=!0,We.exactOptionalPropertyTypes=!1,We.enumerableKind=!1,We.correctiveParse=!1,We.unionPrioritySort=!0}function Rd(e){for(let t of i.Keys(e)){let n=e[t];n!==void 0&&Object.defineProperty(We,t,{value:n})}}function vd(){return We}function Md(e,t){for(let n of Object.keys(t))Object.defineProperty(e,n,{configurable:!0,writable:!0,enumerable:!1,value:t[n]});return e}function Qo(e,t){return{...e,...t}}function Sd(e,t,n={}){ve.create+=1;let r=It.Get(),a=Qo(t,n),s=r.enumerableKind?Qo(a,e):Md(a,e);return r.immutableTypes?Object.freeze(s):s}function wd(e,t){ve.discard+=1;let n={},r=Object.getOwnPropertyDescriptors(an(e)),a=new Set(t);for(let s of Object.keys(r))a.has(s)||Object.defineProperty(n,s,r[s]);return n}function jd(e,t,n){ve.update+=1;let r=It.Get(),a=an(e);for(let s of Object.keys(t))Object.defineProperty(a,s,{configurable:!0,writable:!0,enumerable:r.enumerableKind,value:t[s]});for(let s of Object.keys(n))Object.defineProperty(a,s,{configurable:!0,enumerable:!0,writable:!0,value:n[s]});return a}function x(e,t){return i.IsObject(e)&&i.HasPropertyKey(e,"~kind")&&i.IsEqual(e["~kind"],t)}function Q(e){return i.IsObject(e)}function y(e,t,n){return p.Create({"~kind":"Deferred"},{type:"deferred",action:e,parameters:t,options:n},{})}function Ye(e){return x(e,"Deferred")}function Ld(e){return p.Update(e,{"~readonly":!0},{})}function on(e,t){return p.Update(Ld(e),{},t)}function Xo(e,t,n,r){let a=l(e,t,n);return on(a,r)}function Ad(e){return p.Update(e,{"~optional":!0},{})}function sn(e,t){return p.Update(Ad(e),{},t)}function Yo(e,t,n,r){let a=l(e,t,n);return sn(a,r)}function he(e,t){return p.Create({"~kind":"Array"},{type:"array",items:e},t)}function N(e){return x(e,"Array")}function Qn(e){return p.Discard(e,["~kind","type","items"])}function Le(e,t,n={}){return p.Create({"~kind":"Constructor"},{type:"constructor",parameters:e,instanceType:t},n)}function ee(e){return x(e,"Constructor")}function ei(e){return p.Discard(e,["~kind","type","parameters","instanceType"])}function Ae(e,t,n={}){return p.Create({"~kind":"Function"},{type:"function",parameters:e,returnType:t},n)}function te(e){return x(e,"Function")}function ti(e){return p.Discard(e,["~kind","type","parameters","returnType"])}function Ve(e,t){return p.Create({"~kind":"Ref"},{$ref:e},t)}function ne(e){return x(e,"Ref")}function et(e,t){return p.Create({"~kind":"Generic"},{type:"generic",parameters:e,expression:t})}function St(e){return x(e,"Generic")}function wt(e){return p.Create({"~kind":"Any"},{},e)}function W(e){return x(e,"Any")}var ni="(?!)";function A(e){return p.Create({"~kind":"Never"},{not:{}},e)}function tt(e){return x(e,"Never")}function qe(e,t={}){return y("AddOptional",[e],t)}function yt(e,t={}){return sn(e,t)}function ri(e){return yt(e)}function me(e){return Q(e)&&i.HasPropertyKey(e,"~optional")}function ai(e){return i.Keys(e).filter(t=>!me(e[t]))}function Xn(e){return i.Keys(e)}function Yn(e){return i.Values(e)}function h(e,t={}){let n=ai(e),r=n.length>0?{required:n}:{};return p.Create({"~kind":"Object"},{type:"object",...r,properties:e},t)}function S(e){return x(e,"Object")}function oi(e){return p.Discard(e,["~kind","type","properties","required"])}function re(e){return p.Create({"~kind":"Unknown"},{},e)}function X(e){return x(e,"Unknown")}function Fe(e,t,n){let r=i.Keys(e).reduce((a,s)=>({...a,[s]:p.Update(e[s],{},{$id:s})}),{});return p.Create({"~kind":"Cyclic"},{$defs:r,$ref:t},n)}function oe(e){return x(e,"Cyclic")}function ii(e){return p.Update(e,{"~unsafe":null},{})}function er(e){return i.IsObjectNotArray(e)&&i.HasPropertyKey(e,"~unsafe")&&i.IsNull(e["~unsafe"])}var De={};lt(De,{Match:()=>qd});function qd(e,t){return t[e.length]?.(...e)??(()=>{throw Error("Invalid Arguments")})()}function mn(...e){let[t,n]=De.Match(e,{2:(r,a)=>[r,a,a],1:r=>[r,re(),re()]});return p.Create({"~kind":"Infer"},{type:"infer",name:t,extends:n},{})}function z(e){return x(e,"Infer")}function gt(e,t,n,r={}){return p.Create({"~kind":"Dependent"},{if:e,then:t,else:n},r)}function _(e){return x(e,"Dependent")}function si(e){return p.Discard(e,["~kind","if","then","else"])}function mi(e){return i.IsObjectNotArray(e)}function pi(e){return i.Keys(e).filter(n=>isNaN(n)).reduce((n,r)=>[...n,e[r]],[])}function ui(e){return i.IsString(e)||i.IsNumber(e)}function ci(e,t){let n=mi(e)?pi(e):e;return p.Create({"~kind":"Enum"},{enum:n},t)}function ue(e){return x(e,"Enum")}function pe(e,t={}){return p.Create({"~kind":"Intersect"},{allOf:e},t)}function C(e){return x(e,"Intersect")}function li(e){return p.Discard(e,["~kind","allOf"])}function B(){throw new Error("Unreachable")}var fi;(function(e){e[e.Array=0]="Array",e[e.BigInt=1]="BigInt",e[e.Boolean=2]="Boolean",e[e.Date=3]="Date",e[e.Constructor=4]="Constructor",e[e.Function=5]="Function",e[e.Null=6]="Null",e[e.Number=7]="Number",e[e.Object=8]="Object",e[e.RegExp=9]="RegExp",e[e.String=10]="String",e[e.Symbol=11]="Symbol",e[e.TypeArray=12]="TypeArray",e[e.Undefined=13]="Undefined"})(fi||(fi={}));var lT=BigInt("14695981039346656037"),[fT,dT]=[BigInt("1099511628211"),BigInt("18446744073709551616")],xT=Array.from({length:256}).map((e,t)=>BigInt(t)),di=new Float64Array(1),IT=new DataView(di.buffer),yT=new Uint8Array(di.buffer);var gT=new TextEncoder;var pn=class{constructor(t,n){this.type=t,this.decode=n}Encode(t){let n=this.type,r=tr(n)?m=>this.decode(n["~codec"].decode(m)):this.decode,a=tr(n)?m=>n["~codec"].encode(t(m)):t,s={decode:r,encode:a};return p.Update(this.type,{"~codec":s},{})}},un=class{constructor(t){this.type=t}Decode(t){return new pn(this.type,t)}};function nr(e){return new un(e)}function Ii(e,t){return nr(e).Decode(t).Encode(()=>{throw Error("Encode not implemented")})}function yi(e,t){return nr(e).Decode(()=>{throw Error("Decode not implemented")}).Encode(t)}function tr(e){return Q(e)&&i.HasPropertyKey(e,"~codec")&&i.IsObject(e["~codec"])&&i.HasPropertyKey(e["~codec"],"encode")&&i.HasPropertyKey(e["~codec"],"decode")}function gi(e){return jt(e)}function $t(e){return Q(e)&&i.HasPropertyKey(e,"~immutable")}function Ue(e,t={}){return y("AddReadonly",[e],t)}function ht(e,t={}){return on(e,t)}function $i(e){return ht(e)}function bt(e){return Q(e)&&i.HasPropertyKey(e,"~readonly")}function Nd(e,t){let n=xa(e)?[...e["~refine"],t]:[t];return p.Update(e,{"~refine":n},{})}function hi(...e){let[t,n,r]=De.Match(e,{3:(a,s,m)=>[a,s,m],2:(a,s)=>[a,s,()=>"Refine Error"]});return Nd(t,{check:n,error:r})}function Kd(e){return i.IsObjectNotArray(e)&&i.HasPropertyKey(e,"check")&&i.HasPropertyKey(e,"error")&&i.IsFunction(e.check)&&i.IsFunction(e.error)}function xa(e){return Q(e)&&i.HasPropertyKey(e,"~refine")&&i.IsArray(e["~refine"])&&i.Every(e["~refine"],0,t=>Kd(t))}var bi="-?(?:0|[1-9][0-9]*)n";function cn(e){return p.Create({"~kind":"BigInt"},{type:"bigint"},e)}function Ne(e){return x(e,"BigInt")}function rr(e){return p.Create({"~kind":"Boolean"},{type:"boolean"},e)}function ke(e){return x(e,"Boolean")}function ln(e){return p.Create({"~kind":"Identifier"},{name:e})}function Ti(e){return x(e,"Identifier")}var ar="-?(?:0|[1-9][0-9]*)";function Tt(e){return p.Create({"~kind":"Integer"},{type:"integer"},e)}function ce(e){return x(e,"Integer")}var Ia=class extends Error{constructor(t){super("Invalid Literal value"),Object.defineProperty(this,"cause",{value:{value:t},writable:!1,configurable:!1,enumerable:!1})}};function Gd(e){return i.IsBigInt(e)?"bigint":i.IsBoolean(e)?"boolean":i.IsNumber(e)?"number":i.IsString(e)?"string":(()=>{throw new Ia(e)})()}function R(e,t){return p.Create({"~kind":"Literal"},{type:Gd(e),const:e},t)}function or(e){return i.IsBigInt(e)||i.IsBoolean(e)||i.IsNumber(e)||i.IsString(e)}function Ei(e){return w(e)&&i.IsNumber(e.const)}function ki(e){return w(e)&&i.IsString(e.const)}function w(e){return x(e,"Literal")}function Lt(e){return p.Create({"~kind":"Null"},{type:"null"},e)}function At(e){return x(e,"Null")}var ir="-?(?:0|[1-9][0-9]*)(?:\\.[0-9]+)?";function ye(e){return p.Create({"~kind":"Number"},{type:"number"},e)}function V(e){return x(e,"Number")}function qt(e){return p.Create({"~kind":"Symbol"},{type:"symbol"},e)}function nt(e){return x(e,"Symbol")}function Et(...e){let[t,n,r]=De.Match(e,{3:(a,s,m)=>[a,s,m],2:(a,s)=>[a,s,s],1:a=>[a,re(),re()]});return p.Create({"~kind":"Parameter"},{name:t,extends:n,equals:r},{})}function Pi(e){return x(e,"Parameter")}var sr=".*";function Pe(e){return p.Create({"~kind":"String"},{type:"string"},e)}function le(e){return x(e,"String")}function k(e,t={}){return p.Create({"~kind":"Union"},{anyOf:e},t)}function I(e){return x(e,"Union")}function Oi(e){return p.Discard(e,["~kind","anyOf"])}function fn(e){let t=Ci(e);return i.IsEqual(t.length,2)?t[0]:[]}function _d(e){return!0}function Ri(e){return i.ShiftLeft(e,(t,n)=>Hd(t)?Ri(n):!1,()=>!0)}function vi(e){return i.IsEqual(e.length,0)?!1:Ri(e)}function Hd(e){return I(e)?vi(e.anyOf):w(e)?_d(e.const):!1}function mr(e){return vi(e)}function pr(e){return p.Create({"~kind":"TemplateLiteral"},{type:"string",pattern:e},{})}function Mi(e,t,n=[]){return i.ShiftLeft(e,(r,a)=>Mi(a,t,[...n,`${r}${t}`]),()=>n)}function zd(e,t){return i.IsEqual(e.length,0)?[`${t}`]:Mi(e,t)}function Si(e,t,n=[]){return i.ShiftLeft(t,(r,a)=>Si(e,a,[...n,...wi(e,r)]),()=>n)}function wi(e,t){return I(t)?Si(e,t.anyOf):w(t)?zd(e,t.const):B()}function ji(e,t){return i.ShiftLeft(t,(n,r)=>ji(wi(e,n),r),()=>e)}function Bd(e){return e.map(t=>R(t))}function Wd(e){let t=ji([],e),n=Bd(t);return k(n)}function Vd(e){return i.IsEqual(e.length,0)?B():i.IsEqual(e.length,1)&&w(e[0])?e[0]:Wd(e)}function ya(e){let t=fn(e);return i.IsEqual(t.length,0)?Pe():mr(t)?Vd(t):pr(e)}function Li(e){let t=ya(e);return Z(t)?Pe():t}function xe(e,t){let n="object",r={[e]:t};return p.Create({"~kind":"Record"},{type:n,patternProperties:r})}function Ai(e){return xe(Me,e)}function qi(e){return h({true:e,false:e})}function J(e,t={}){let[n,r,a]=[e,e.length,!1];return p.Create({"~kind":"Tuple"},{type:"array",additionalItems:a,items:n,minItems:r},t)}function F(e){return x(e,"Tuple")}function Fi(e){return p.Discard(e,["~kind","type","items","minItems","additionalItems"])}function Zd(e){return p.Discard(e,["~readonly"])}function ga(e,t){return p.Update(Zd(e),{},t)}function Di(e,t,n,r){let a=l(e,t,n);return ga(a,r)}function Ui(e,t={}){return y("RemoveReadonly",[e],t)}function Ni(e,t={}){return ga(e,t)}function Jd(e){return p.Discard(e,["~optional"])}function $a(e,t){return p.Update(Jd(e),{},t)}function Ki(e,t,n,r){let a=l(e,t,n);return $a(a,r)}function Gi(e,t={}){return y("RemoveOptional",[e],t)}function ur(e,t={}){return $a(e,t)}function ha(e){return e.reduceRight((n,r,a)=>({[a]:r,...n}),{})}function _i(e){let t=ha(e.items);return h(t)}function Qd(e,t){return bt(e)?!!bt(t):!1}function Xd(e,t){return me(e)?!!me(t):!1}function Yd(e,t){let n=Qd(e,t),r=Xd(e,t),a=K([e,t]),s=Ni(ur(a));return n&&r?ht(yt(s)):n&&!r?ht(s):!n&&r?yt(s):s}function ex(e,t,n){return n in e?n in t?Yd(e[n],t[n]):e[n]:n in t?t[n]:A()}function tx(e,t){return[...new Set([...i.Keys(t),...i.Keys(e)])].reduce((r,a)=>({...r,[a]:ex(e,t,a)}),{})}function Hi(e){return S(e)?e.properties:F(e)?ha(e.items):B()}function zi(e,t){let n=Hi(e),r=Hi(t),a=tx(n,r);return h(a)}function Bi(e,t){let n=Ft(e,t);return i.IsEqual(n,xn)?e:i.IsEqual(n,In)||i.IsEqual(n,dn)?t:A()}function Wi(e){return S(e)||F(e)}function nx(e,t){let n=I(e),r=I(t);return n||r}function rx(e,t){let n=Oe(e),r=Oe(t),a=nx(n,r),s=Wi(n),m=Wi(r);return a?K([n,r]):s&&m?zi(n,r):s&&!m?n:!s&&m?r:Bi(n,r)}function Vi(e,t,n=[]){return i.ShiftLeft(t,(r,a)=>Vi(e,a,[...n,rx(e,r)]),()=>i.IsEqual(n.length,0)?[e]:n)}function Zi(e,t,n=[]){return i.ShiftLeft(e,(r,a)=>Zi(a,t,[...n,...yn([r],t)]),()=>n)}function yn(e,t=[]){return i.ShiftLeft(e,(n,r)=>I(n)?yn(r,Zi(n.anyOf,t)):yn(r,Vi(n,t)),()=>t)}function ax(e,t){let n=ie({},e,t);return $.IsExtendsTrueLike(n)?[]:[e]}function ox(e,t){return e.reduce((n,r)=>[...n,...ax(r,t)],[])}function cr(e,t){let n=Oe(e),r=I(n)?n.anyOf:[n],a=ox(r,t);return ge(a)}function Se(e,t,n){let r=pe([e,t]),a=cr(n,e);return ge([r,a])}function be(e){let t=e.map(n=>R(n));return ge(t)}function K(e){let t=yn(e),n=ba(t);return Ze(n)}function Ie(e){let t=Li(e);return Oe(t)}function ge(e){let t=ba(e);return Ze(t)}function Oe(e){return _(e)?Se(e.if,e.then,e.else):ue(e)?be(e.enum):C(e)?K(e.allOf):Z(e)?Ie(e.pattern):I(e)?ge(e.anyOf):e}function Ze(e){return i.IsEqual(e.length,1)?e[0]:i.IsEqual(e.length,0)?A():k(e)}function Ji(e,t){let n=be(e);return rt(n,t)}function Qi(e,t){return xe(at,t)}function Xi(e,t){let n=K(e);return rt(n,t)}function Yi(e,t){return i.IsString(e)||i.IsNumber(e)?h({[e]:t}):i.IsEqual(e,!1)?h({false:t}):i.IsEqual(e,!0)?h({true:t}):h({})}function es(e,t){return xe(Dt,t)}function ts(e,t){return i.HasPropertyKey(e,"pattern")&&(i.IsString(e.pattern)||e.pattern instanceof RegExp)?xe(e.pattern.toString(),t):xe(Me,t)}function ns(e,t){let n=fn(e);return mr(n)?rt(Ie(e),t):xe(e,t)}function ix(e){return I(e)?gn(e.anyOf):[e]}function gn(e){return e.reduce((t,n)=>[...t,...ix(n)],[])}function sx(e){return e.some(t=>le(t)||V(t)||ce(t))}function mx(e,t){return i.IsEqual(sx(e),!0)?xe(Me,t):void 0}function px(e,t){return e.reduce((n,r)=>w(r)&&(i.IsString(r.const)||i.IsNumber(r.const))?{...n,[r.const]:t}:n,{})}function ux(e,t){let n=px(e,t);return h(n)}function rs(e,t){let n=gn(e),r=mx(n,t);return Q(r)?r:ux(n,t)}function rt(e,t){return W(e)?Ai(t):ke(e)?qi(t):ue(e)?Ji(e.enum,t):ce(e)?Qi(e,t):C(e)?Xi(e.allOf,t):w(e)?Yi(e.const,t):V(e)?es(e,t):I(e)?rs(e.anyOf,t):le(e)?ts(e,t):Z(e)?ns(e.pattern,t):h({})}function Ta(e,t,n){return T([e])?p.Update(rt(e,t),{},n):lr(e,t,n)}function as(e,t,n,r,a){let s=l(e,t,n),m=l(e,t,r);return Ta(s,m,a)}var at=`^${ar}$`,Dt=`^${ir}$`,Me=`^${sr}$`;function lr(e,t,n={}){return y("Record",[e,t],n)}function fr(e,t,n={}){return Ta(e,t,n)}function os(e,t){return xe(e,t)}function dr(e){return i.IsEqual(e,Me)?Pe():i.IsEqual(e,at)?Tt():i.IsEqual(e,Dt)?ye():ya(e)}function Ce(e){return i.Keys(e.patternProperties)[0]}function Ut(e){let t=Ce(e);return dr(t)}function fe(e){return e.patternProperties[Ce(e)]}function se(e){return x(e,"Record")}function kt(e){return p.Create({"~kind":"Rest"},{type:"rest",items:e},{})}function ot(e){return x(e,"Rest")}function xr(e){return p.Create({"~kind":"This"},{$ref:"#"},e)}function Ir(e){return x(e,"This")}function Nt(e){return p.Create({"~kind":"Undefined"},{type:"undefined"},e)}function Kt(e){return x(e,"Undefined")}function yr(e){return p.Create({"~kind":"Void"},{type:"void"},e)}function Ke(e){return x(e,"Void")}function lx(e,t){return i.IsEqual(e,"Array")?he(t[0]):i.IsEqual(e,"Capitalize")?$r(t[0]):i.IsEqual(e,"ConstructorParameters")?kr(t[0]):i.IsEqual(e,"Evaluate")?sp(t[0]):i.IsEqual(e,"Exclude")?Pr(t[0],t[1]):i.IsEqual(e,"Extract")?Or(t[0],t[1]):i.IsEqual(e,"Index")?Tn(t[0],t[1]):i.IsEqual(e,"InstanceType")?Cr(t[0]):i.IsEqual(e,"Lowercase")?hr(t[0]):i.IsEqual(e,"NonNullable")?Rr(t[0]):i.IsEqual(e,"Omit")?vr(t[0],t[1]):i.IsEqual(e,"Parameters")?Mr(t[0]):i.IsEqual(e,"Partial")?Sr(t[0]):i.IsEqual(e,"Pick")?wr(t[0],t[1]):i.IsEqual(e,"Readonly")?jr(t[0]):i.IsEqual(e,"KeyOf")?En(t[0]):i.IsEqual(e,"Record")?lr(t[0],t[1]):i.IsEqual(e,"Required")?Lr(t[0]):i.IsEqual(e,"ReturnType")?Ar(t[0]):i.IsEqual(e,"Uncapitalize")?br(t[0]):i.IsEqual(e,"Uppercase")?Tr(t[0]):bn(Ve(e),t)}function Pt(){throw Error("Unreachable")}var fx=(e,t=[])=>e.reduce((n,r)=>i.IsArray(r)&&i.IsEqual(r.length,2)?[...n,r[0]]:[...n,r],[]),Je=e=>{let[t,n]=e;return fx([...t,...n])};function us(e){return Et(e[0],e[2],e[4])}function cs(e){return Et(e[0],e[2],e[2])}function ls(e){return Et(e[0],re(),e[2])}function fs(e){return Et(e,re(),re())}function ds(e){return Je(e)}function xs(e){return e[1]}function Is(e){return Je(e)}function ys(e){return e[1]}function gs(e){return lx(e[0],e[1])}function $s(e){return null}function hs(e){return Pe()}function bs(e){return ye()}function Ts(e){return rr()}function Es(e){return Nt()}function ks(e){return Lt()}function Ps(e){return Tt()}function Os(e){return cn()}function Cs(e){return re()}function Rs(e){return wt()}function vs(e){return h({})}function Ms(e){return A()}function Ss(e){return qt()}function ws(e){return yr()}function js(e){return xr()}function Ls(e){return R(BigInt(e))}function As(e){return R(i.IsEqual(e,"true"))}function qs(e){return R(parseFloat(e))}function Fs(e){return R(e)}function Ds(e){return e[1]}function Us(e){return R(e)}function Ns(e){return i.IsEqual(e.length,3)?[e[0],e[1],...e[2]]:[e[0]]}function Ks(e){return e[1]}function Gs(e){return gr(e)}function _s(e){return i.IsEqual(e.length,6)?gt(e[1],e[3],e[5]):gt(e[1],e[3],re())}function Hs(e){return e.length>0}function zs(e){return e.reduce((t,n)=>i.IsEqual(n.length,3)?[...t,[n[1]]]:[...t,[]],[])}function Bs(e){return i.IsEqual(e.length,6)?[e[1],e[3],e[5]]:[]}function Ws(e){return i.IsArray(e)&&i.IsEqual(e.length,3)?e[1]:e}function Vs(e){return i.IsEqual(e.length,2)?e[1]:[]}function is(e,t){return t.reduce((n,r)=>{let a=r;return i.IsEqual(a.length,1)?Tn(n,a[0]):i.IsEqual(a.length,0)?he(n):Pt()},e)}function ss(e,t){return i.IsEqual(t.length,3)?Er(e,t[0],t[1],t[2]):e}function dx(e,t){return i.IsArray(t)&&i.IsEqual(t.length,0)?e:qr(e,t)}function Zs(e){let[t,n,r,a,s]=e;return dx(ss(t?En(is(n,r)):is(n,r),a),s)}function Ea(e,t){return i.IsEqual(t.length,3)?(()=>{let[n,r,a]=t,s=Ea(r,a);if(i.IsEqual(n,"&"))return C(s)?pe([e,...s.allOf]):pe([e,s]);if(i.IsEqual(n,"|"))return I(s)?k([e,...s.anyOf]):k([e,s]);Pt()})():e}function Js(e){let[t,n]=e;return Ea(t,n)}function Qs(e){let[t,n]=e;return Ea(t,n)}function Xs(e){return ip(e[1])}function Ys(e){return e[1]}function em(e){return et(e[0],e[2])}function tm(e){return i.IsEqual(e.length,4)?mn(e[1],e[3]):i.IsEqual(e.length,2)?mn(e[1],re()):Pt()}function nm(e){return`${e}`}function rm(e){return ce(e[3])?at:V(e[3])?Dt:nt(e[3])?Me:le(e[3])?Me:Pt()}function am(e){return e.length>0}function om(e){return e.length>0}function im(e){let[t,n,r,a,s]=e;return{[n]:t&&r?Ue(qe(s)):t&&!r?Ue(s):!t&&r?qe(s):s}}function sm(e){return Je(e)}function mm(e){return e.reduce((t,n)=>i.HasPropertyKey(n,at)||i.HasPropertyKey(n,Dt)||i.HasPropertyKey(n,Me)?[t[0],p.Assign(t[1],n)]:[p.Assign(t[0],n),t[1]],[{},{}])}function pm(e){return mm(e[1])}function um(e){let[t,n]=e,r=i.IsEqual(i.Keys(n).length,0)?{}:{patternProperties:n};return h(t,r)}function cm(e){return i.IsEqual(e.length,5)?Ue(qe(e[4])):i.IsEqual(e.length,3)?e[2]:i.IsEqual(e.length,4)?i.IsEqual(e[2],"readonly")?Ue(e[3]):qe(e[3]):Pt()}function lm(e){return Ue(qe(e[1]))}function fm(e){return Ue(e[1])}function dm(e){return qe(e[0])}function xm(e){return i.IsEqual(e.length,2)?kt(e[1]):i.IsEqual(e.length,1)?e[0]:Pt()}function Im(e){return Je(e)}function ym(e){return J(e[1])}function gm(e){return Ue(qe(e[4]))}function $m(e){return Ue(e[3])}function hm(e){return qe(e[3])}function bm(e){return e[2]}function Tm(e){return i.IsEqual(e.length,2)?kt(e[1]):i.IsEqual(e.length,1)?e[0]:Pt()}function Em(e){return Je(e)}function km(e){return Ae(e[1],e[4])}function Pm(e){return Le(e[2],e[5])}function ms(e,t){return i.IsEqual(e,"remove")?Ui(t):i.IsEqual(e,"add")?Ue(t):t}function Om(e){return i.IsEqual(e.length,2)&&i.IsEqual(e[0],"-")?"remove":i.IsEqual(e.length,2)&&i.IsEqual(e[0],"+")||i.IsEqual(e.length,1)?"add":"none"}function ps(e,t){return i.IsEqual(e,"remove")?Gi(t):i.IsEqual(e,"add")?qe(t):t}function Cm(e){return i.IsEqual(e.length,2)&&i.IsEqual(e[0],"-")?"remove":i.IsEqual(e.length,2)&&i.IsEqual(e[0],"+")||i.IsEqual(e.length,1)?"add":"none"}function Rm(e){return i.IsEqual(e.length,2)?[e[1]]:[]}function vm(e){return i.IsArray(e[6])&&i.IsEqual(e[6].length,1)?$n(ln(e[3]),e[5],e[6][0],ms(e[1],ps(e[8],e[10]))):$n(ln(e[3]),e[5],Ve(e[3]),ms(e[1],ps(e[8],e[10])))}function Mm(e){return Ve(e)}function Sm(e){return BigInt(e)}function wm(e){return parseFloat(e)}function jm(e){return i.IsEqual(e,"true")}function Lm(e){return null}function Am(e){return{[e[0]]:e[2]}}function qm(e){return Je(e)}function xx(e){return e.reduce((t,n)=>p.Assign(t,n),{})}function Fm(e){return xx(e[1])}function Dm(e){return Je(e)}function Um(e){return e[1]}function Nm(e){return cn()}function Km(e){return Pe()}function Gm(e){return ye()}function _m(e){return Tt()}function Hm(e){return A()}function zm(e){return R(e)}function Bm(e){return k(e[1])}function Wm(e){return e.length===3?[...e[0],...e[2]]:e.length===1?[...e[0]]:[]}function Vm(e){return[e[0],...e[1]]}function Zm(e){return e[1]}function Jm(e){return Je(e)}function Qm(e){return i.IsEqual(e.length,2)?e[1]:[]}function Xm(e){let t=e[2],n=e[3],[r,a]=e[4],s=i.IsEqual(i.Keys(a).length,0)?{}:{patternProperties:a};return{[e[1]]:et(t,hn(n,r,s))}}function Ym(e){let t=e[2],[n,r]=e[3],a=i.IsEqual(i.Keys(r).length,0)?{}:{patternProperties:r};return{[e[1]]:hn(t,n,a)}}function ep(e){return{[e[1]]:et(e[2],e[4])}}function tp(e){return{[e[1]]:e[3]}}function np(e){return null}function rp(e){return mm(Je(e))}function ap(e){return e[1]}function op(e){let t=e[0],n=e[1];return mp(p.Assign(t,n[0]))}function kn(e){return M(e.length,2)}function P(e,t,n){return kn(e)?t(e[0],e[1]):n()}function gx(e,t){return M(t.indexOf(e),0)?[e,t.slice(e.length)]:[]}function G(e,t){for(let n=0;n<e.length;n++){let r=gx(e[n],t);if(kn(r))return r}return[]}function ka(e,t){return Array.from({length:t-e+1},(n,r)=>String.fromCharCode(e+r))}var pp=[...ka(97,122),...ka(65,90)],Pa="0",Oa=ka(49,57),Gt=[Pa,...Oa],up=" ",_t=`
2
+ `;var it="_",Fr=".",cp="$",Dr="-";var lp="//",fp="/*",hx="*/";function dp(e){let t=e.indexOf(hx);return M(t,-1)?"":e.slice(t+2)}function xp(e){let t=e.indexOf(_t);return M(t,-1)?"":e.slice(t)}function bx(e){return e.replace(/^[ \t\r\f\v]+/,"")}function Ur(e){let t=bx(e);return t.startsWith(fp)?Ur(dp(t.slice(2))):t.startsWith(lp)?Ur(xp(t.slice(2))):t}function ae(e){let t=e.trimStart();return t.startsWith(fp)?ae(dp(t.slice(2))):t.startsWith(lp)?ae(xp(t.slice(2))):t}function Nr(e,t){return P(G([e],t),(n,r)=>[n,r],()=>["",t])}function Tx(e,t){return e.includes(t)}function Ht(e,t,n,r=""){return P(G(e,n),(a,s)=>Tx(t,a)?Ht(e,t,s,r):Ht(e,t,s,`${r}${a}`),()=>[r,n])}function Ex(e){return G(Oa,e)}var kx=[...Gt,it];function Px(e){return Ht(kx,[it],e)}function Ox(e){return P(G([Pa],e),(t,n)=>[t,n],()=>P(Ex(e),(t,n)=>P(Px(n),(r,a)=>[`${t}${r}`,a],()=>[]),()=>[]))}function Kr(e){return Ox(ae(e))}function Cx(e){return Nr(Dr,e)}function Rx(e){return P(Cx(e),(t,n)=>P(Kr(n),(r,a)=>[`${t}${r}`,a],()=>[]),()=>[])}function Ip(e){return Rx(ae(e))}function vx(e){return P(Ip(e),(t,n)=>P(G(["n"],n),(r,a)=>[`${t}`,a],()=>[]),()=>[])}function Ca(e){return vx(e)}function Ra(e,t){return G([e],t)}function u(e,t){return M(e,"")?["",t]:e.startsWith(_t)?Ra(e,Ur(t)):e.startsWith(up)?Ra(e,t):Ra(e,ae(t))}var yp=[...pp,it,cp];function Mx(e){return G(yp,e)}var Sx=[...yp,...Gt];function gp(e,t=""){return P(G(Sx,e),(n,r)=>gp(r,`${t}${n}`),()=>[t,e])}function wx(e){return P(Mx(e),(t,n)=>P(gp(n),(r,a)=>[`${t}${r}`,a],()=>[]),()=>[])}function H(e){return wx(ae(e))}var jx=[...Gt,it];function Lx(e){return kn(G([Fr],e))}function $p(e){return P(Ht(jx,[it],e),(t,n)=>M(t,"")?[]:[t,n],()=>[])}function Ax(e){return P(G([Fr],e),(t,n)=>P($p(n),(r,a)=>[`0${t}${r}`,a],()=>[]),()=>[])}function qx(e){return P(Kr(e),(t,n)=>P(G([Fr],n),(r,a)=>P($p(a),(s,m)=>[`${t}${r}${s}`,m],()=>[`${t}`,a]),()=>[`${t}`,n]),()=>[])}function Fx(e){return Lx(e)?Ax(e):qx(e)}function hp(e){return Fx(ae(e))}function Dx(e){return Nr(Dr,e)}function Ux(e){return P(Dx(e),(t,n)=>P(hp(n),(r,a)=>[`${t}${r}`,a],()=>[]),()=>[])}function Gr(e){return Ux(ae(e))}function Nx(e){return M(e,"")?[]:[e.slice(0,1),e.slice(1)]}function bp(e,t){return Jn(e,(n,r)=>t.startsWith(n)?!0:bp(r,t),()=>!1)}function st(e,t,n=""){return P(Nx(t),(r,a)=>bp(e,t)?[n,t]:st(e,a,`${n}${r}`),()=>[])}function Kx(e,t,n){return P(G([e],n),(r,a)=>P(st([t],a),(s,m)=>P(G([t],m),(c,f)=>[`${s}`,f],()=>[]),()=>[]),()=>[])}function Gx(e,t,n){return P(G([e],n),(r,a)=>P(st([_t,t],a),(s,m)=>P(G([t],m),(c,f)=>[`${s}`,f],()=>[]),()=>[]),()=>[])}function Tp(e,t,n,r){return n?Kx(e,t,ae(r)):Gx(e,t,ae(r))}function _x(e,t){return G(e,t)}function Hx(e,t){return Tp(e,e,!1,t)}function zx(e,t){return P(_x(e,t),(n,r)=>Hx(n,`${n}${r}`),()=>[])}function _r(e,t){return zx(e,ae(t))}function Ep(e,t){return P(st(e,t),(n,r)=>M(n,"")?[]:[n,r],()=>[])}var o=(e,t,n=()=>[])=>e.length===2?t(e):n(),Wx=e=>o(o(H(e),([t,n])=>o(u("extends",n),([r,a])=>o(O(a),([s,m])=>o(u("=",m),([c,f])=>o(O(f),([E,g])=>[[t,r,s,c,E],g]))))),([t,n])=>[us(t),n]),Vx=e=>o(o(H(e),([t,n])=>o(u("extends",n),([r,a])=>o(O(a),([s,m])=>[[t,r,s],m]))),([t,n])=>[cs(t),n]),Zx=e=>o(o(H(e),([t,n])=>o(u("=",n),([r,a])=>o(O(a),([s,m])=>[[t,r,s],m]))),([t,n])=>[ls(t),n]),Jx=e=>o(H(e),([t,n])=>[fs(t),n]),Op=e=>o(o(Wx(e),([t,n])=>[t,n],()=>o(Vx(e),([t,n])=>[t,n],()=>o(Zx(e),([t,n])=>[t,n],()=>o(Jx(e),([t,n])=>[t,n],()=>[])))),([t,n])=>[t,n]),Cp=(e,t=[])=>o(o(Op(e),([n,r])=>o(u(",",r),([a,s])=>[[n,a],s])),([n,r])=>Cp(r,[...t,n]),()=>[t,e]),Qx=e=>o(o(Cp(e),([t,n])=>o(o(o(Op(n),([r,a])=>[[r],a]),([r,a])=>[r,a],()=>o([[],n],([r,a])=>[r,a],()=>[])),([r,a])=>[[t,r],a])),([t,n])=>[ds(t),n]),Sa=e=>o(o(u("<",e),([t,n])=>o(Qx(n),([r,a])=>o(u(">",a),([s,m])=>[[t,r,s],m]))),([t,n])=>[xs(t),n]),Rp=(e,t=[])=>o(o(O(e),([n,r])=>o(u(",",r),([a,s])=>[[n,a],s])),([n,r])=>Rp(r,[...t,n]),()=>[t,e]),Xx=e=>o(o(Rp(e),([t,n])=>o(o(o(O(n),([r,a])=>[[r],a]),([r,a])=>[r,a],()=>o([[],n],([r,a])=>[r,a],()=>[])),([r,a])=>[[t,r],a])),([t,n])=>[Is(t),n]),Yx=e=>o(o(u("<",e),([t,n])=>o(Xx(n),([r,a])=>o(u(">",a),([s,m])=>[[t,r,s],m]))),([t,n])=>[ys(t),n]),eI=e=>o(o(H(e),([t,n])=>o(Yx(n),([r,a])=>[[t,r],a])),([t,n])=>[gs(t),n]),vp=e=>o(o(o(u(";",e),([t,n])=>[[t],n]),([t,n])=>[t,n],()=>o([[],e],([t,n])=>[t,n],()=>[])),([t,n])=>[$s(t),n]),Mp=e=>o(u("string",e),([t,n])=>[hs(t),n]),Sp=e=>o(u("number",e),([t,n])=>[bs(t),n]),tI=e=>o(u("boolean",e),([t,n])=>[Ts(t),n]),nI=e=>o(u("undefined",e),([t,n])=>[Es(t),n]),rI=e=>o(u("null",e),([t,n])=>[ks(t),n]),wp=e=>o(u("integer",e),([t,n])=>[Ps(t),n]),aI=e=>o(u("bigint",e),([t,n])=>[Os(t),n]),oI=e=>o(u("unknown",e),([t,n])=>[Cs(t),n]),iI=e=>o(u("any",e),([t,n])=>[Rs(t),n]),sI=e=>o(u("object",e),([t,n])=>[vs(t),n]),mI=e=>o(u("never",e),([t,n])=>[Ms(t),n]),jp=e=>o(u("symbol",e),([t,n])=>[Ss(t),n]),pI=e=>o(u("void",e),([t,n])=>[ws(t),n]),uI=e=>o(u("this",e),([t,n])=>[js(t),n]),cI=e=>o(o(u("${",e),([t,n])=>o(O(n),([r,a])=>o(u("}",a),([s,m])=>[[t,r,s],m]))),([t,n])=>[Ds(t),n]),va=e=>o(st(["${","`"],e),([t,n])=>[Us(t),n]),Lp=e=>o(o(o(va(e),([t,n])=>o(cI(n),([r,a])=>o(Lp(a),([s,m])=>[[t,r,s],m]))),([t,n])=>[t,n],()=>o(o(va(e),([t,n])=>[[t],n]),([t,n])=>[t,n],()=>o(o(va(e),([t,n])=>[[t],n]),([t,n])=>[t,n],()=>[]))),([t,n])=>[Ns(t),n]),wa=e=>o(o(u("`",e),([t,n])=>o(Lp(n),([r,a])=>o(u("`",a),([s,m])=>[[t,r,s],m]))),([t,n])=>[Ks(t),n]),lI=e=>o(wa(e),([t,n])=>[Gs(t),n]),fI=e=>o(o(o(u("if",e),([t,n])=>o(O(n),([r,a])=>o(u("then",a),([s,m])=>o(O(m),([c,f])=>o(u("else",f),([E,g])=>o(O(g),([q,Y])=>[[t,r,s,c,E,q],Y])))))),([t,n])=>[t,n],()=>o(o(u("if",e),([t,n])=>o(O(n),([r,a])=>o(u("then",a),([s,m])=>o(O(m),([c,f])=>[[t,r,s,c],f])))),([t,n])=>[t,n],()=>[])),([t,n])=>[_s(t),n]),dI=e=>o(Ca(e),([t,n])=>[Ls(t),n]),xI=e=>o(o(u("true",e),([t,n])=>[t,n],()=>o(u("false",e),([t,n])=>[t,n],()=>[])),([t,n])=>[As(t),n]),II=e=>o(Gr(e),([t,n])=>[qs(t),n]),yI=e=>o(_r(["'",'"'],e),([t,n])=>[Fs(t),n]),gI=e=>o(o(o(u("keyof",e),([t,n])=>[[t],n]),([t,n])=>[t,n],()=>o([[],e],([t,n])=>[t,n],()=>[])),([t,n])=>[Hs(t),n]),Ap=(e,t=[])=>o(o(o(u("[",e),([n,r])=>o(O(r),([a,s])=>o(u("]",s),([m,c])=>[[n,a,m],c]))),([n,r])=>[n,r],()=>o(o(u("[",e),([n,r])=>o(u("]",r),([a,s])=>[[n,a],s])),([n,r])=>[n,r],()=>[])),([n,r])=>Ap(r,[...t,n]),()=>[t,e]),$I=e=>o(Ap(e),([t,n])=>[zs(t),n]),hI=e=>o(o(o(u("extends",e),([t,n])=>o(O(n),([r,a])=>o(u("?",a),([s,m])=>o(O(m),([c,f])=>o(u(":",f),([E,g])=>o(O(g),([q,Y])=>[[t,r,s,c,E,q],Y])))))),([t,n])=>[t,n],()=>o([[],e],([t,n])=>[t,n],()=>[])),([t,n])=>[Bs(t),n]),bI=e=>o(o(o(u("(",e),([t,n])=>o(O(n),([r,a])=>o(u(")",a),([s,m])=>[[t,r,s],m]))),([t,n])=>[t,n],()=>o(Mp(e),([t,n])=>[t,n],()=>o(Sp(e),([t,n])=>[t,n],()=>o(tI(e),([t,n])=>[t,n],()=>o(nI(e),([t,n])=>[t,n],()=>o(rI(e),([t,n])=>[t,n],()=>o(wp(e),([t,n])=>[t,n],()=>o(aI(e),([t,n])=>[t,n],()=>o(oI(e),([t,n])=>[t,n],()=>o(iI(e),([t,n])=>[t,n],()=>o(sI(e),([t,n])=>[t,n],()=>o(mI(e),([t,n])=>[t,n],()=>o(jp(e),([t,n])=>[t,n],()=>o(pI(e),([t,n])=>[t,n],()=>o(uI(e),([t,n])=>[t,n],()=>o(dI(e),([t,n])=>[t,n],()=>o(xI(e),([t,n])=>[t,n],()=>o(II(e),([t,n])=>[t,n],()=>o(yI(e),([t,n])=>[t,n],()=>o(lI(e),([t,n])=>[t,n],()=>o(fI(e),([t,n])=>[t,n],()=>o(LI(e),([t,n])=>[t,n],()=>o(NI(e),([t,n])=>[t,n],()=>o(BI(e),([t,n])=>[t,n],()=>o(zI(e),([t,n])=>[t,n],()=>o(JI(e),([t,n])=>[t,n],()=>o(eI(e),([t,n])=>[t,n],()=>o(QI(e),([t,n])=>[t,n],()=>[])))))))))))))))))))))))))))),([t,n])=>[Ws(t),n]),TI=e=>o(o(o(u("with",e),([t,n])=>o(Qp(n),([r,a])=>[[t,r],a])),([t,n])=>[t,n],()=>o([[],e],([t,n])=>[t,n],()=>[])),([t,n])=>[Vs(t),n]),qp=e=>o(o(gI(e),([t,n])=>o(bI(n),([r,a])=>o($I(a),([s,m])=>o(hI(m),([c,f])=>o(TI(f),([E,g])=>[[t,r,s,c,E],g]))))),([t,n])=>[Zs(t),n]),Fp=e=>o(o(o(u("&",e),([t,n])=>o(qp(n),([r,a])=>o(Fp(a),([s,m])=>[[t,r,s],m]))),([t,n])=>[t,n],()=>o([[],e],([t,n])=>[t,n],()=>[])),([t,n])=>[t,n]),Dp=e=>o(o(qp(e),([t,n])=>o(Fp(n),([r,a])=>[[t,r],a])),([t,n])=>[Js(t),n]),Up=e=>o(o(o(u("|",e),([t,n])=>o(Dp(n),([r,a])=>o(Up(a),([s,m])=>[[t,r,s],m]))),([t,n])=>[t,n],()=>o([[],e],([t,n])=>[t,n],()=>[])),([t,n])=>[t,n]),Hr=e=>o(o(Dp(e),([t,n])=>o(Up(n),([r,a])=>[[t,r],a])),([t,n])=>[Qs(t),n]),EI=e=>o(o(u("readonly",e),([t,n])=>o(Hr(n),([r,a])=>[[t,r],a])),([t,n])=>[Xs(t),n]),kI=e=>o(o(u("|",e),([t,n])=>o(Hr(n),([r,a])=>[[t,r],a])),([t,n])=>[Ys(t),n]),PI=e=>o(o(Sa(e),([t,n])=>o(u("=",n),([r,a])=>o(O(a),([s,m])=>[[t,r,s],m]))),([t,n])=>[em(t),n]),OI=e=>o(o(o(u("infer",e),([t,n])=>o(H(n),([r,a])=>o(u("extends",a),([s,m])=>o(Hr(m),([c,f])=>[[t,r,s,c],f])))),([t,n])=>[t,n],()=>o(o(u("infer",e),([t,n])=>o(H(n),([r,a])=>[[t,r],a])),([t,n])=>[t,n],()=>[])),([t,n])=>[tm(t),n]),O=e=>o(o(OI(e),([t,n])=>[t,n],()=>o(kI(e),([t,n])=>[t,n],()=>o(EI(e),([t,n])=>[t,n],()=>o(Hr(e),([t,n])=>[t,n],()=>[])))),([t,n])=>[t,n]),CI=e=>o(Gr(e),([t,n])=>[nm(t),n]),RI=e=>o(H(e),([t,n])=>[t,n]),vI=e=>o(_r(["'",'"'],e),([t,n])=>[t,n]),MI=e=>o(o(u("[",e),([t,n])=>o(H(n),([r,a])=>o(u(":",a),([s,m])=>o(o(wp(m),([c,f])=>[c,f],()=>o(Sp(m),([c,f])=>[c,f],()=>o(Mp(m),([c,f])=>[c,f],()=>o(jp(m),([c,f])=>[c,f],()=>[])))),([c,f])=>o(u("]",f),([E,g])=>[[t,r,s,c,E],g]))))),([t,n])=>[rm(t),n]),Np=e=>o(o(CI(e),([t,n])=>[t,n],()=>o(RI(e),([t,n])=>[t,n],()=>o(vI(e),([t,n])=>[t,n],()=>o(MI(e),([t,n])=>[t,n],()=>[])))),([t,n])=>[t,n]),SI=e=>o(o(o(u("readonly",e),([t,n])=>[[t],n]),([t,n])=>[t,n],()=>o([[],e],([t,n])=>[t,n],()=>[])),([t,n])=>[am(t),n]),wI=e=>o(o(o(u("?",e),([t,n])=>[[t],n]),([t,n])=>[t,n],()=>o([[],e],([t,n])=>[t,n],()=>[])),([t,n])=>[om(t),n]),Kp=e=>o(o(SI(e),([t,n])=>o(Np(n),([r,a])=>o(wI(a),([s,m])=>o(u(":",m),([c,f])=>o(O(f),([E,g])=>[[t,r,s,c,E],g]))))),([t,n])=>[im(t),n]),Gp=e=>o(o(o(u(",",e),([t,n])=>o(u(`
3
+ `,n),([r,a])=>[[t,r],a])),([t,n])=>[t,n],()=>o(o(u(";",e),([t,n])=>o(u(`
4
+ `,n),([r,a])=>[[t,r],a])),([t,n])=>[t,n],()=>o(o(u(",",e),([t,n])=>[[t],n]),([t,n])=>[t,n],()=>o(o(u(";",e),([t,n])=>[[t],n]),([t,n])=>[t,n],()=>o(o(u(`
5
+ `,e),([t,n])=>[[t],n]),([t,n])=>[t,n],()=>[]))))),([t,n])=>[t,n]),_p=(e,t=[])=>o(o(Kp(e),([n,r])=>o(Gp(r),([a,s])=>[[n,a],s])),([n,r])=>_p(r,[...t,n]),()=>[t,e]),jI=e=>o(o(_p(e),([t,n])=>o(o(o(Kp(n),([r,a])=>[[r],a]),([r,a])=>[r,a],()=>o([[],n],([r,a])=>[r,a],()=>[])),([r,a])=>[[t,r],a])),([t,n])=>[sm(t),n]),ja=e=>o(o(u("{",e),([t,n])=>o(jI(n),([r,a])=>o(u("}",a),([s,m])=>[[t,r,s],m]))),([t,n])=>[pm(t),n]),LI=e=>o(ja(e),([t,n])=>[um(t),n]),AI=e=>o(o(o(H(e),([t,n])=>o(u("?",n),([r,a])=>o(u(":",a),([s,m])=>o(u("readonly",m),([c,f])=>o(O(f),([E,g])=>[[t,r,s,c,E],g]))))),([t,n])=>[t,n],()=>o(o(H(e),([t,n])=>o(u(":",n),([r,a])=>o(u("readonly",a),([s,m])=>o(O(m),([c,f])=>[[t,r,s,c],f])))),([t,n])=>[t,n],()=>o(o(H(e),([t,n])=>o(u("?",n),([r,a])=>o(u(":",a),([s,m])=>o(O(m),([c,f])=>[[t,r,s,c],f])))),([t,n])=>[t,n],()=>o(o(H(e),([t,n])=>o(u(":",n),([r,a])=>o(O(a),([s,m])=>[[t,r,s],m]))),([t,n])=>[t,n],()=>[])))),([t,n])=>[cm(t),n]),qI=e=>o(o(u("readonly",e),([t,n])=>o(O(n),([r,a])=>o(u("?",a),([s,m])=>[[t,r,s],m]))),([t,n])=>[lm(t),n]),FI=e=>o(o(u("readonly",e),([t,n])=>o(O(n),([r,a])=>[[t,r],a])),([t,n])=>[fm(t),n]),DI=e=>o(o(O(e),([t,n])=>o(u("?",n),([r,a])=>[[t,r],a])),([t,n])=>[dm(t),n]),kp=e=>o(o(AI(e),([t,n])=>[t,n],()=>o(qI(e),([t,n])=>[t,n],()=>o(FI(e),([t,n])=>[t,n],()=>o(DI(e),([t,n])=>[t,n],()=>o(O(e),([t,n])=>[t,n],()=>[]))))),([t,n])=>[t,n]),Hp=e=>o(o(o(u("...",e),([t,n])=>o(kp(n),([r,a])=>[[t,r],a])),([t,n])=>[t,n],()=>o(o(kp(e),([t,n])=>[[t],n]),([t,n])=>[t,n],()=>[])),([t,n])=>[xm(t),n]),zp=(e,t=[])=>o(o(Hp(e),([n,r])=>o(u(",",r),([a,s])=>[[n,a],s])),([n,r])=>zp(r,[...t,n]),()=>[t,e]),UI=e=>o(o(zp(e),([t,n])=>o(o(o(Hp(n),([r,a])=>[[r],a]),([r,a])=>[r,a],()=>o([[],n],([r,a])=>[r,a],()=>[])),([r,a])=>[[t,r],a])),([t,n])=>[Im(t),n]),NI=e=>o(o(u("[",e),([t,n])=>o(UI(n),([r,a])=>o(u("]",a),([s,m])=>[[t,r,s],m]))),([t,n])=>[ym(t),n]),KI=e=>o(o(H(e),([t,n])=>o(u("?",n),([r,a])=>o(u(":",a),([s,m])=>o(u("readonly",m),([c,f])=>o(O(f),([E,g])=>[[t,r,s,c,E],g]))))),([t,n])=>[gm(t),n]),GI=e=>o(o(H(e),([t,n])=>o(u(":",n),([r,a])=>o(u("readonly",a),([s,m])=>o(O(m),([c,f])=>[[t,r,s,c],f])))),([t,n])=>[$m(t),n]),_I=e=>o(o(H(e),([t,n])=>o(u("?",n),([r,a])=>o(u(":",a),([s,m])=>o(O(m),([c,f])=>[[t,r,s,c],f])))),([t,n])=>[hm(t),n]),HI=e=>o(o(H(e),([t,n])=>o(u(":",n),([r,a])=>o(O(a),([s,m])=>[[t,r,s],m]))),([t,n])=>[bm(t),n]),Pp=e=>o(o(KI(e),([t,n])=>[t,n],()=>o(GI(e),([t,n])=>[t,n],()=>o(_I(e),([t,n])=>[t,n],()=>o(HI(e),([t,n])=>[t,n],()=>[])))),([t,n])=>[t,n]),Bp=e=>o(o(o(u("...",e),([t,n])=>o(Pp(n),([r,a])=>[[t,r],a])),([t,n])=>[t,n],()=>o(o(Pp(e),([t,n])=>[[t],n]),([t,n])=>[t,n],()=>[])),([t,n])=>[Tm(t),n]),Wp=(e,t=[])=>o(o(Bp(e),([n,r])=>o(u(",",r),([a,s])=>[[n,a],s])),([n,r])=>Wp(r,[...t,n]),()=>[t,e]),Vp=e=>o(o(Wp(e),([t,n])=>o(o(o(Bp(n),([r,a])=>[[r],a]),([r,a])=>[r,a],()=>o([[],n],([r,a])=>[r,a],()=>[])),([r,a])=>[[t,r],a])),([t,n])=>[Em(t),n]),zI=e=>o(o(u("(",e),([t,n])=>o(Vp(n),([r,a])=>o(u(")",a),([s,m])=>o(u("=>",m),([c,f])=>o(O(f),([E,g])=>[[t,r,s,c,E],g]))))),([t,n])=>[km(t),n]),BI=e=>o(o(u("new",e),([t,n])=>o(u("(",n),([r,a])=>o(Vp(a),([s,m])=>o(u(")",m),([c,f])=>o(u("=>",f),([E,g])=>o(O(g),([q,Y])=>[[t,r,s,c,E,q],Y])))))),([t,n])=>[Pm(t),n]),WI=e=>o(o(o(u("+",e),([t,n])=>o(u("readonly",n),([r,a])=>[[t,r],a])),([t,n])=>[t,n],()=>o(o(u("-",e),([t,n])=>o(u("readonly",n),([r,a])=>[[t,r],a])),([t,n])=>[t,n],()=>o(o(u("readonly",e),([t,n])=>[[t],n]),([t,n])=>[t,n],()=>o([[],e],([t,n])=>[t,n],()=>[])))),([t,n])=>[Om(t),n]),VI=e=>o(o(o(u("+",e),([t,n])=>o(u("?",n),([r,a])=>[[t,r],a])),([t,n])=>[t,n],()=>o(o(u("-",e),([t,n])=>o(u("?",n),([r,a])=>[[t,r],a])),([t,n])=>[t,n],()=>o(o(u("?",e),([t,n])=>[[t],n]),([t,n])=>[t,n],()=>o([[],e],([t,n])=>[t,n],()=>[])))),([t,n])=>[Cm(t),n]),ZI=e=>o(o(o(u("as",e),([t,n])=>o(O(n),([r,a])=>[[t,r],a])),([t,n])=>[t,n],()=>o([[],e],([t,n])=>[t,n],()=>[])),([t,n])=>[Rm(t),n]),JI=e=>o(o(u("{",e),([t,n])=>o(WI(n),([r,a])=>o(u("[",a),([s,m])=>o(H(m),([c,f])=>o(u("in",f),([E,g])=>o(O(g),([q,Y])=>o(ZI(Y),([we,ut])=>o(u("]",ut),([de,Yt])=>o(VI(Yt),([Un,Re])=>o(u(":",Re),([ct,vt])=>o(O(vt),([na,ff])=>o(vp(ff),([df,xf])=>o(u("}",xf),([If,yf])=>[[t,r,s,c,E,q,we,de,Un,ct,na,df,If],yf]))))))))))))),([t,n])=>[vm(t),n]),QI=e=>o(H(e),([t,n])=>[Mm(t),n]),XI=e=>o(Ca(e),([t,n])=>[Sm(t),n]),YI=e=>o(Gr(e),([t,n])=>[wm(t),n]),ey=e=>o(o(u("true",e),([t,n])=>[t,n],()=>o(u("false",e),([t,n])=>[t,n],()=>[])),([t,n])=>[jm(t),n]),ty=e=>o(_r(['"',"'"],e),([t,n])=>[t,n]),ny=e=>o(u("null",e),([t,n])=>[Lm(t),n]),ry=e=>o(u("undefined",e),([t,n])=>[void 0,n]),Zp=e=>o(o(Np(e),([t,n])=>o(u(":",n),([r,a])=>o(La(a),([s,m])=>[[t,r,s],m]))),([t,n])=>[Am(t),n]),Jp=(e,t=[])=>o(o(Zp(e),([n,r])=>o(Gp(r),([a,s])=>[[n,a],s])),([n,r])=>Jp(r,[...t,n]),()=>[t,e]),ay=e=>o(o(Jp(e),([t,n])=>o(o(o(Zp(n),([r,a])=>[[r],a]),([r,a])=>[r,a],()=>o([[],n],([r,a])=>[r,a],()=>[])),([r,a])=>[[t,r],a])),([t,n])=>[qm(t),n]),Qp=e=>o(o(u("{",e),([t,n])=>o(ay(n),([r,a])=>o(u("}",a),([s,m])=>[[t,r,s],m]))),([t,n])=>[Fm(t),n]),Xp=(e,t=[])=>o(o(La(e),([n,r])=>o(u(",",r),([a,s])=>[[n,a],s])),([n,r])=>Xp(r,[...t,n]),()=>[t,e]),oy=e=>o(o(Xp(e),([t,n])=>o(o(o(La(n),([r,a])=>[[r],a]),([r,a])=>[r,a],()=>o([[],n],([r,a])=>[r,a],()=>[])),([r,a])=>[[t,r],a])),([t,n])=>[Dm(t),n]),iy=e=>o(o(u("[",e),([t,n])=>o(oy(n),([r,a])=>o(u("]",a),([s,m])=>[[t,r,s],m]))),([t,n])=>[Um(t),n]),La=e=>o(o(XI(e),([t,n])=>[t,n],()=>o(YI(e),([t,n])=>[t,n],()=>o(ey(e),([t,n])=>[t,n],()=>o(ty(e),([t,n])=>[t,n],()=>o(ny(e),([t,n])=>[t,n],()=>o(ry(e),([t,n])=>[t,n],()=>o(Qp(e),([t,n])=>[t,n],()=>o(iy(e),([t,n])=>[t,n],()=>[])))))))),([t,n])=>[t,n]),sy=e=>o(u("-?(?:0|[1-9][0-9]*)n",e),([t,n])=>[Nm(t),n]),my=e=>o(u(".*",e),([t,n])=>[Km(t),n]),py=e=>o(u("-?(?:0|[1-9][0-9]*)(?:\\.[0-9]+)?",e),([t,n])=>[Gm(t),n]),uy=e=>o(u("-?(?:0|[1-9][0-9]*)",e),([t,n])=>[_m(t),n]),cy=e=>o(u("(?!)",e),([t,n])=>[Hm(t),n]),ly=e=>o(Ep(["-?(?:0|[1-9][0-9]*)n",".*","-?(?:0|[1-9][0-9]*)(?:\\.[0-9]+)?","-?(?:0|[1-9][0-9]*)","(?!)","(",")","$","|"],e),([t,n])=>[zm(t),n]),fy=e=>o(o(sy(e),([t,n])=>[t,n],()=>o(my(e),([t,n])=>[t,n],()=>o(py(e),([t,n])=>[t,n],()=>o(uy(e),([t,n])=>[t,n],()=>o(cy(e),([t,n])=>[t,n],()=>o(dy(e),([t,n])=>[t,n],()=>o(ly(e),([t,n])=>[t,n],()=>[]))))))),([t,n])=>[t,n]),dy=e=>o(o(u("(",e),([t,n])=>o(Aa(n),([r,a])=>o(u(")",a),([s,m])=>[[t,r,s],m]))),([t,n])=>[Bm(t),n]),Yp=e=>o(o(o(Ma(e),([t,n])=>o(u("|",n),([r,a])=>o(Yp(a),([s,m])=>[[t,r,s],m]))),([t,n])=>[t,n],()=>o(o(Ma(e),([t,n])=>[[t],n]),([t,n])=>[t,n],()=>o([[],e],([t,n])=>[t,n],()=>[]))),([t,n])=>[Wm(t),n]),Ma=e=>o(o(fy(e),([t,n])=>o(Aa(n),([r,a])=>[[t,r],a])),([t,n])=>[Vm(t),n]),Aa=e=>o(o(Yp(e),([t,n])=>[t,n],()=>o(Ma(e),([t,n])=>[t,n],()=>[])),([t,n])=>[t,n]),Ci=e=>o(o(u("^",e),([t,n])=>o(Aa(n),([r,a])=>o(u("$",a),([s,m])=>[[t,r,s],m]))),([t,n])=>[Zm(t),n]),eu=(e,t=[])=>o(o(O(e),([n,r])=>o(u(",",r),([a,s])=>[[n,a],s])),([n,r])=>eu(r,[...t,n]),()=>[t,e]),xy=e=>o(o(eu(e),([t,n])=>o(o(o(O(n),([r,a])=>[[r],a]),([r,a])=>[r,a],()=>o([[],n],([r,a])=>[r,a],()=>[])),([r,a])=>[[t,r],a])),([t,n])=>[Jm(t),n]),tu=e=>o(o(o(u("extends",e),([t,n])=>o(xy(n),([r,a])=>[[t,r],a])),([t,n])=>[t,n],()=>o([[],e],([t,n])=>[t,n],()=>[])),([t,n])=>[Qm(t),n]),Iy=e=>o(o(u("interface",e),([t,n])=>o(H(n),([r,a])=>o(Sa(a),([s,m])=>o(tu(m),([c,f])=>o(ja(f),([E,g])=>[[t,r,s,c,E],g]))))),([t,n])=>[Xm(t),n]),yy=e=>o(o(u("interface",e),([t,n])=>o(H(n),([r,a])=>o(tu(a),([s,m])=>o(ja(m),([c,f])=>[[t,r,s,c],f])))),([t,n])=>[Ym(t),n]),gy=e=>o(o(u("type",e),([t,n])=>o(H(n),([r,a])=>o(Sa(a),([s,m])=>o(u("=",m),([c,f])=>o(O(f),([E,g])=>[[t,r,s,c,E],g]))))),([t,n])=>[ep(t),n]),$y=e=>o(o(u("type",e),([t,n])=>o(H(n),([r,a])=>o(u("=",a),([s,m])=>o(O(m),([c,f])=>[[t,r,s,c],f])))),([t,n])=>[tp(t),n]),hy=e=>o(o(o(u("export",e),([t,n])=>[[t],n]),([t,n])=>[t,n],()=>o([[],e],([t,n])=>[t,n],()=>[])),([t,n])=>[np(t),n]),by=e=>o(o(o(u(";",e),([t,n])=>o(u(`
6
+ `,n),([r,a])=>[[t,r],a])),([t,n])=>[t,n],()=>o(o(u(";",e),([t,n])=>[[t],n]),([t,n])=>[t,n],()=>o(o(u(`
7
+ `,e),([t,n])=>[[t],n]),([t,n])=>[t,n],()=>[]))),([t,n])=>[t,n]),nu=(e,t=[])=>o(o(qa(e),([n,r])=>o(by(r),([a,s])=>[[n,a],s])),([n,r])=>nu(r,[...t,n]),()=>[t,e]),Ty=e=>o(o(nu(e),([t,n])=>o(o(o(qa(n),([r,a])=>[[r],a]),([r,a])=>[r,a],()=>o([[],n],([r,a])=>[r,a],()=>[])),([r,a])=>[[t,r],a])),([t,n])=>[rp(t),n]),qa=e=>o(o(hy(e),([t,n])=>o(o(Iy(n),([r,a])=>[r,a],()=>o(yy(n),([r,a])=>[r,a],()=>o(gy(n),([r,a])=>[r,a],()=>o($y(n),([r,a])=>[r,a],()=>[])))),([r,a])=>o(vp(a),([s,m])=>[[t,r,s],m]))),([t,n])=>[ap(t),n]),Ey=e=>o(o(qa(e),([t,n])=>o(Ty(n),([r,a])=>[[t,r],a])),([t,n])=>[op(t),n]),ru=e=>o(o(Ey(e),([t,n])=>[t,n],()=>o(PI(e),([t,n])=>[t,n],()=>o(O(e),([t,n])=>[t,n],()=>[]))),([t,n])=>[t,n]);function au(e){let t=wa(`\`${e}\``);return i.IsEqual(t.length,2)?t[0]:B()}function Py(e){return e.join("|")}function Oy(e){return e.slice(1,e.length-1)}function Cy(e,t,n){return mt(t,`${n}${e}`)}function Ry(e,t){return mt(e,`${t}${bi}`)}function vy(e,t){return mt(e,`${t}${ar}`)}function My(e,t){return mt(e,`${t}${ir}`)}function Sy(e,t){return Pn(k([R("false"),R("true")]),e,t)}function wy(e,t){return mt(e,`${t}${sr}`)}function jy(e,t,n){return mt(t,`${n}${Oy(e)}`)}function Ly(e,t,n){let r=On(e,{});return Pn(r,t,n)}function Ay(e,t,n){let r=be(e);return Pn(r,t,n)}function ou(e,t,n,r=[]){return i.ShiftLeft(e,(a,s)=>ou(s,t,n,[...r,Pn(a,[],"")]),()=>mt(t,`${n}(${Py(r)})`))}function Pn(e,t,n){return ue(e)?Ay(e.enum,t,n):ce(e)?vy(t,n):w(e)?Cy(e.const,t,n):Ne(e)?Ry(t,n):ke(e)?Sy(t,n):V(e)?My(t,n):le(e)?wy(t,n):Z(e)?jy(e.pattern,t,n):su(e)?Ly(e.parameters[0],t,n):I(e)?ou(e.anyOf,t,n):ni}function mt(e,t){return i.ShiftLeft(e,(n,r)=>Pn(n,r,t),()=>t)}function qy(e){return`^${mt(e,"")}$`}function iu(e){let t=qy(e);return pr(t)}function On(e,t){return T(e)?p.Update(iu(e),{},t):gr(e,t)}function mu(e,t,n,r){let a=Te(e,t,n);return On(a,r)}function gr(e,t={}){return y("TemplateLiteral",[e],t)}function su(e){return Q(e)&&i.HasPropertyKey(e,"action")&&i.IsEqual(e.action,"TemplateLiteral")}function pu(e){return On(e,{})}function Fy(e){let t=au(e);return pu(t)}function uu(e,t={}){let n=i.IsString(e)?Fy(e):pu(e);return p.Update(n,{},t)}function Z(e){return x(e,"TemplateLiteral")}var $={};lt($,{ExtendsFalse:()=>b,ExtendsTrue:()=>d,ExtendsUnion:()=>Fa,IsExtendsFalse:()=>Dy,IsExtendsTrue:()=>lu,IsExtendsTrueLike:()=>zt,IsExtendsUnion:()=>cu,Match:()=>U});function Fa(e){return p.Create({"~kind":"ExtendsUnion"},{inferred:e})}function cu(e){return i.IsObject(e)&&i.HasPropertyKey(e,"~kind")&&i.HasPropertyKey(e,"inferred")&&i.IsEqual(e["~kind"],"ExtendsUnion")&&i.IsObject(e.inferred)}function d(e){return p.Create({"~kind":"ExtendsTrue"},{inferred:e})}function lu(e){return i.IsObject(e)&&i.HasPropertyKey(e,"~kind")&&i.HasPropertyKey(e,"inferred")&&i.IsEqual(e["~kind"],"ExtendsTrue")&&i.IsObject(e.inferred)}function b(){return p.Create({"~kind":"ExtendsFalse"},{})}function Dy(e){return i.IsObject(e)&&i.HasPropertyKey(e,"~kind")&&i.IsEqual(e["~kind"],"ExtendsFalse")}function zt(e){return cu(e)||lu(e)}function U(e,t,n){return zt(e)?t(e.inferred):n()}function Uy(e,t,n,r){return U(v(e,n,r),a=>d(p.Assign(p.Assign(e,a),{[t]:n})),()=>b())}function Ny(e,t){return d(e)}function Ky(e,t,n,r,a){return U(v(e,t,n),s=>U(v(s,t,r),m=>d(m),()=>b()),()=>U(v(e,t,a),s=>d(s),()=>b()))}function Gy(e,t,n){let r=be(n);return v(e,t,r)}function fu(e,t,n){return i.ShiftLeft(n,(r,a)=>U(v(e,t,r),s=>fu(s,t,a),()=>b()),()=>d(e))}function _y(e,t,n){let r=Ie(n);return v(e,t,r)}function du(e,t,n){return i.ShiftLeft(n,(r,a)=>U(v(e,t,r),s=>d(s),()=>du(e,t,a)),()=>b())}function j(e,t,n){return W(n)?Ny(e,t):_(n)?Ky(e,t,n.if,n.then,n.else):ue(n)?Gy(e,t,n.enum):z(n)?Uy(e,n.name,t,n.extends):C(n)?fu(e,t,n.allOf):Z(n)?_y(e,t,n.pattern):I(n)?du(e,t,n.anyOf):X(n)?d(e):b()}function xu(e,t,n){return z(n)?j(e,t,n):W(n)?d(e):X(n)?d(e):Fa(e)}function Hy(e,t){let n=$t(e),r=$t(t);return n&&r||!n&&r?!0:!(n&&!r)}function Iu(e,t,n,r){return N(r)?Hy(t,r)?v(e,n,r.items):b():j(e,t,r)}function yu(e,t,n){return Ne(n)?d(e):j(e,t,n)}function gu(e,t,n){return ke(n)?d(e):j(e,t,n)}function zy(e,t,n,r,a){let s=z(r)?t:r,m=z(r)?r:t,c=me(t),f=me(r);return!c&&f?b():U(v(e,s,m),E=>Cn(E,n,a),()=>b())}function By(e,t,n,r){return i.ShiftLeft(r,(a,s)=>zy(e,t,n,a,s),()=>me(t)?d(e):b())}function Wy(e,t,n){return i.ShiftLeft(t,(r,a)=>By(e,r,a,n),()=>d(e))}function Cn(e,t,n){return Wy(e,t,n)}function zr(e,t,n){return Ke(n)?d(e):v(e,t,n)}function $u(e,t,n,r){return W(r)?d(e):X(r)?d(e):ee(r)?U(Cn(e,t,r.parameters),a=>zr(a,n,r.instanceType),()=>b()):b()}function hu(e,t,n,r,a){return U(v(e,t,a),()=>v(e,n,a),()=>v(e,r,a))}function bu(e,t,n){let r=be(t);return v(e,r,n)}function Tu(e,t,n,r){return W(r)?d(e):X(r)?d(e):te(r)?U(Cn(e,t,r.parameters),a=>zr(a,n,r.returnType),()=>b()):b()}function Eu(e,t,n){return ce(n)?d(e):V(n)?d(e):j(e,t,n)}function ku(e,t,n){let r=K(t);return v(e,r,n)}function Br(e,t,n){return t===n?d(e):b()}function Vy(e,t,n){return w(n)?Br(e,t,n.const):Ne(n)?d(e):j(e,R(t),n)}function Zy(e,t,n){return w(n)?Br(e,t,n.const):ke(n)?d(e):j(e,R(t),n)}function Jy(e,t,n){return w(n)?Br(e,t,n.const):V(n)?d(e):j(e,R(t),n)}function Qy(e,t,n){return w(n)?Br(e,t,n.const):le(n)?d(e):j(e,R(t),n)}function Pu(e,t,n){return i.IsBigInt(t.const)?Vy(e,t.const,n):i.IsBoolean(t.const)?Zy(e,t.const,n):i.IsNumber(t.const)?Jy(e,t.const,n):i.IsString(t.const)?Qy(e,t.const,n):B()}function Ou(e,t,n){return z(n)?j(e,t,n):d(e)}function Cu(e,t,n){return At(n)?d(e):j(e,t,n)}function Ru(e,t,n){return V(n)?d(e):j(e,t,n)}function Xy(e,t,n){return me(t)?me(n)?d(e):b():d(e)}function Yy(e,t,n){return z(n)&&tt(n.extends)?b():U(v(e,t,n),r=>Xy(r,t,n),()=>b())}function eg(e,t){return e.reduce((n,r)=>r in t?zt(t[r])?{...n,...t[r].inferred}:B():B(),{})}function tg(e,t,n){let r={};for(let m of i.Keys(n))r[m]=m in t?Yy({},t[m],n[m]):me(n[m])?z(n[m])?d(p.Assign(e,{[n[m].name]:n[m].extends})):d(e):b();let a=i.Values(r).every(m=>zt(m)),s=a?eg(i.Keys(r),r):{};return a?d(s):b()}function ng(e,t,n){let r=tg(e,t,n);return zt(r)?d(p.Assign(e,r.inferred)):b()}function rg(e,t,n){return ng(e,t,n)}function ag(e,t){return i.Keys(t).reduce((n,r)=>({...n,[r]:i.HasPropertyKey(e,r)?I(n[r])?k([...n[r].anyOf,t[r]]):k([e[r],t[r]]):t[r]}),e)}function vu(e,t,n,r){return i.ShiftLeft(t,(a,s)=>U(v({},e[a],n),m=>vu(e,s,n,ag(r,m)),()=>b()),()=>d(r))}function og(e,t,n,r){let a=i.Keys(t);return vu(t,a,r,e)}function Mu(e,t,n){return se(n)?og(e,t,Ce(n),fe(n)):S(n)?rg(e,t,n.properties):j(e,h(t),n)}function ig(e,t){return i.IsEqual(i.Keys(t).length,0)?d(e):b()}function sg(e,t,n,r,a){return v(e,n,a)}function Su(e,t,n,r){return se(r)?sg(e,dr(t),n,dr(Ce(r)),fe(r)):S(r)?ig(e,r.properties):W(r)?d(e):X(r)?d(e):b()}function wu(e,t,n){return le(n)?d(e):j(e,t,n)}function ju(e,t,n){return nt(n)?d(e):j(e,t,n)}function Lu(e,t,n){let r=Ie(t);return v(e,r,n)}function Da(e,t){return p.Create({"~kind":"Inferrable"},{name:e,type:t},{})}function Rn(e){return i.IsObject(e)&&i.HasPropertyKey(e,"~kind")&&i.HasPropertyKey(e,"name")&&i.HasPropertyKey(e,"type")&&i.IsEqual(e["~kind"],"Inferrable")&&i.IsString(e.name)&&i.IsObject(e.type)}function Ua(e){return ot(e)?z(e.items)?N(e.items.extends)?Da(e.items.name,e.items.extends.items):X(e.items.extends)?Da(e.items.name,e.items.extends):void 0:B():void 0}function Wr(e){return z(e)?Da(e.name,e.extends):void 0}function Na(e,t,n=[]){return i.ShiftLeft(e,(r,a)=>U(v({},r,t),()=>Na(a,t,[...n,r]),()=>{}),()=>n)}function Au(e,t,n,r){let a=Na(n,r);return i.IsArray(a)?d(p.Assign(e,{[t]:J(a)})):b()}function Vr(e,t,n,r){let a=Na(n,r);return i.IsArray(a)?d(p.Assign(e,{[t]:k(a)})):b()}function mg(e){return[...e].reverse()}function Ka(e,t){return t?mg(e):e}function pg(e){let t=e.length>0?e[0]:void 0,n=Q(t)?Ua(t):void 0;return Q(n)}function ug(e,t,n,r,a,s){return U(v(e,n,a),m=>qu(m,t,r,s),()=>b())}function cg(e,t,n,r,a){let s=Ua(r);return Rn(s)?Au(e,s.name,Ka(n,t),s.type):i.ShiftLeft(n,(m,c)=>ug(e,t,m,c,r,a),()=>b())}function lg(e,t,n,r){return i.ShiftLeft(r,(a,s)=>cg(e,t,n,a,s),()=>i.IsEqual(n.length,0)?d(e):b())}function qu(e,t,n,r){return lg(e,t,n,r)}function fg(e,t,n){let r=pt(e,D([],[]),n),a=pg(r);return qu(e,a,Ka(t,a),Ka(r,a))}function Fu(e,t,n){let r=Wr(n);return Rn(r)?Vr(e,r.name,t,r.type):i.ShiftLeft(t,(a,s)=>U(v(e,a,n),m=>Fu(m,s,n),()=>b()),()=>d(e))}function Du(e,t,n){let r=pt(e,D([],[]),t);return F(n)?fg(e,r,n.items):N(n)?Fu(e,r,n.items):j(e,J(r),n)}function Uu(e,t,n){return Ke(n)?d(e):Kt(n)?d(e):j(e,t,n)}function Nu(e,t,n){return i.ShiftLeft(n,(r,a)=>U(v(e,t,r),s=>d(s),()=>Nu(e,t,a)),()=>b())}function Ga(e,t,n){return i.ShiftLeft(t,(r,a)=>U(Nu(e,r,n),s=>Ga(s,a,n),()=>b()),()=>d(e))}function Ku(e,t,n){let r=Wr(n);return Rn(r)?Vr(e,r.name,t,r.type):I(n)?Ga(e,t,n.anyOf):Ga(e,t,[n])}function Gu(e,t,n){return z(n)?j(e,t,n):W(n)?d(e):X(n)?d(e):b()}function _u(e,t,n){return Ke(n)?d(e):j(e,t,n)}function v(e,t,n){return W(t)?xu(e,t,n):N(t)?Iu(e,t,t.items,n):Ne(t)?yu(e,t,n):ke(t)?gu(e,t,n):ee(t)?$u(e,t.parameters,t.instanceType,n):_(t)?hu(e,t.if,t.then,t.else,n):ue(t)?bu(e,t.enum,n):te(t)?Tu(e,t.parameters,t.returnType,n):ce(t)?Eu(e,t,n):C(t)?ku(e,t.allOf,n):w(t)?Pu(e,t,n):tt(t)?Ou(e,t,n):At(t)?Cu(e,t,n):V(t)?Ru(e,t,n):S(t)?Mu(e,t.properties,n):se(t)?Su(e,Ce(t),fe(t),n):le(t)?wu(e,t,n):nt(t)?ju(e,t,n):Z(t)?Lu(e,t.pattern,n):F(t)?Du(e,t.items,n):Kt(t)?Uu(e,t,n):I(t)?Ku(e,t.anyOf,n):X(t)?Gu(e,t,n):Ke(t)?_u(e,t,n):b()}function dg(e,t){return K([...e,h(t)])}function _a(e,t,n){return T(e)?p.Update(dg(e,t),{},n):hn(e,t,n)}function Hu(e,t,n,r,a){let s=Te(e,t,n),m=vn(e,t,r);return _a(s,m,a)}function hn(e,t,n={}){return y("Interface",[e,t],n)}function Bt(e){return Q(e)&&i.HasPropertyKey(e,"action")&&i.IsEqual(e.action,"Interface")}function zu(e,t,n={}){return _a(e,t,n)}function xg(e,t,n){return e.includes(n)?!0:Mn([...e,n],t,t[n])}function Bu(e,t,n){let r=Yn(n);return Ot(e,t,r)}function Ot(e,t,n){return i.ShiftLeft(n,(r,a)=>Mn(e,t,r)?!0:Ot(e,t,a),()=>!1)}function Mn(e,t,n){return ne(n)?xg(e,t,n.$ref):N(n)?Mn(e,t,n.items):ee(n)?Ot(e,t,[...n.parameters,n.instanceType]):te(n)?Ot(e,t,[...n.parameters,n.returnType]):Bt(n)?Bu(e,t,n.parameters[1]):C(n)?Ot(e,t,n.allOf):S(n)?Bu(e,t,n.properties):I(n)?Ot(e,t,n.anyOf):F(n)?Ot(e,t,n.items):se(n)?Mn(e,t,fe(n)):!1}function Wu(e,t,n){return Mn(e,t,n)}function Ig(e,t){return t.reduce((n,r)=>Wu([r],e,e[r])?[...n,r]:n,[])}function Vu(e){let t=Xn(e);return Ig(e,t)}function yg(e,t,n){return n.includes(t)?n:t in e?Sn(e,e[t],[...n,t]):B()}function Zu(e,t,n){let r=Yn(t);return Wt(e,r,n)}function Wt(e,t,n){return t.reduce((r,a)=>Sn(e,a,r),n)}function Sn(e,t,n){return ne(t)?yg(e,t.$ref,n):N(t)?Sn(e,t.items,n):ee(t)?Wt(e,[...t.parameters,t.instanceType],n):te(t)?Wt(e,[...t.parameters,t.returnType],n):Bt(t)?Zu(e,t.parameters[1],n):C(t)?Wt(e,t.allOf,n):S(t)?Zu(e,t.properties,n):I(t)?Wt(e,t.anyOf,n):F(t)?Wt(e,t.items,n):se(t)?Sn(e,fe(t),n):n}function Ju(e,t,n){return Sn(e,n,[t])}function gg(e){return wt()}function $g(e){return i.Keys(e).reduce((t,n)=>({...t,[n]:Ct(e[n])}),{})}function wn(e){return e.reduce((t,n)=>[...t,Ct(n)],[])}function Ct(e){return ne(e)?gg(e.$ref):N(e)?he(Ct(e.items),Qn(e)):ee(e)?Le(wn(e.parameters),Ct(e.instanceType)):te(e)?Ae(wn(e.parameters),Ct(e.returnType)):C(e)?pe(wn(e.allOf)):S(e)?h($g(e.properties)):se(e)?fr(Ut(e),Ct(fe(e))):I(e)?k(wn(e.anyOf)):F(e)?J(wn(e.items)):e}function hg(e,t){return t in e?Ct(e[t]):re()}function Qu(e){return hg(e.$defs,e.$ref)}function bg(e,t,n){let r=Te(e,D([],[]),t),a=vn({},D([],[]),n);return K([...r,h(a)])}function Tg(e,t){return i.Keys(e).filter(r=>t.includes(r)).reduce((r,a)=>{let s=e[a],m=Bt(s)?bg(e,s.parameters[0],s.parameters[1]):s;return{...r,[a]:m}},{})}function Xu(e,t,n){let r=Ju(e,t,n),a=Tg(e,r);return Fe(a,t)}function Yu(e,t){return t in e?ne(e[t])?Yu(e,e[t].$ref):e[t]:A()}function Ge(e,t){return Yu(e,t)}function ec(e){return oe(e)?Qu(e):er(e)?re():e}function ie(e,t,n){let r=ec(t),a=ec(n);return v(e,r,a)}var dn="equal",Eg="disjoint",xn="left-inside",In="right-inside";function Ft(e,t){let n=[X(e)?$.ExtendsFalse():ie({},e,t),X(e)?$.ExtendsTrue({}):ie({},t,e)];return $.IsExtendsTrueLike(n[0])&&$.IsExtendsTrueLike(n[1])?dn:$.IsExtendsTrueLike(n[0])&&$.IsExtendsFalse(n[1])?xn:$.IsExtendsFalse(n[0])&&$.IsExtendsTrueLike(n[1])?In:Eg}function kg(e,t){return t.filter(n=>Ft(e,n)!==In)}function Pg(e,t){let n=t.some(r=>{let a=Ft(e,r);return i.IsEqual(a,xn)||i.IsEqual(a,dn)});return i.IsEqual(n,!1)}function Og(e,t){let n=Oe(e);return W(n)?[n]:Pg(n,t)?[...kg(n,t),n]:t}function Cg(e){return e.reduce((t,n)=>S(n)?[...t,n]:tt(n)?t:Og(n,t),[])}function ba(e){let t=Cg(e);return gn(t)}function Ha(e,t){return p.Update(Oe(e),{},t)}function tc(e,t,n,r){let a=l(e,t,n);return Ha(a,r)}function jn(e,t=[]){return Ye(e)&&i.IsEqual(e.action,"Conditional")?ne(e.parameters[0])?jn(e.parameters[2],jn(e.parameters[3],[...t,e.parameters[0].$ref])):jn(e.parameters[2],jn(e.parameters[3],t)):Ye(e)&&i.IsEqual(e.action,"Mapped")&&Ye(e.parameters[1])&&i.IsEqual(e.parameters[1].action,"KeyOf")&&ne(e.parameters[1].parameters[0])?[...t,e.parameters[1].parameters[0].$ref]:t}function Rg(e,t){return e.reduce((n,r)=>[...n,t.includes(r.name)],[])}function ac(e,t,n=[]){return i.ShiftLeft(e,(r,a)=>i.ShiftLeft(t,(s,m)=>ac(a,m,[...n,[s,r]]),()=>n),()=>n)}function vg(e){return I(e)?[...e.anyOf]:[e]}function Mg(e,t){return e.reduce((n,r)=>[...n,[...r,t]],[])}function nc(e,t){return t.reduce((n,r)=>[...n,...Mg(e,r)],[])}function rc(e){return e.reduce((t,n)=>i.IsEqual(n[0],!0)?nc(t,vg(n[1])):nc(t,[n[1]]),[[]])}function oc(e,t,n){let r=jn(n),a=Rg(e,r),s=ac(t,a);return Ye(n)&&i.IsEqual(n.action,"Conditional")||Ye(n)&&i.IsEqual(n.action,"Mapped")?rc(s):[t]}function Sg(){return["(not-resolvable)",A()]}function wg(){return["(not-generic)",A()]}function jg(e,t,n){return[e,et(t,n)]}function Lg(e,t,n){return t in e?ic(e,t,e[t],n):Sg()}function ic(e,t,n,r){return St(n)?jg(t,n.parameters,n.expression):ne(n)?Lg(e,n.$ref,r):wg()}function sc(e,t,n){return ic(e,"(anonymous)",t,n)}function Ag(e,t,n){if(z(t)||Vt(t)||$.IsExtendsTrueLike(ie({},t,n)))return;let r={parameter:e,expect:n,actual:t};throw new Error(`Argument for parameter ${e} does not satisfy constraint`,{cause:r})}function mc(e,t,n,r,a){let s=l(e,t,a);return Ag(n,s,r),p.Assign(e,{[n]:s})}function qg(e,t,n,r,a){let s=l(e,t,n.extends),m=l(e,t,n.equals);return i.ShiftLeft(a,(c,f)=>za(mc(e,t,n.name,s,c),t,r,f),()=>za(mc(e,t,n.name,s,m),t,r,[]))}function za(e,t,n,r){return i.ShiftLeft(n,(a,s)=>qg(e,t,a,s,r),()=>e)}function pc(e,t,n,r){return za(e,t,n,r)}function Fg(e){return i.IsGreaterThan(e.callstack.length,0)?e.callstack[e.callstack.length-1]:""}function Dg(e,t){return i.IsEqual(Fg(e),t)}function Ug(e,t,n,r,a,s){let m=pc(e,t,r,s),c=l(m,D([...t.callstack,n.$ref],t.visited),a);return l(m,D([],[]),c)}function Ng(e,t,n,r,a,s){return s.reduce((m,c)=>[...m,Ug(e,t,n,r,a,c)],[])}function Kg(e,t,n,r,a,s){let m=oc(r,s,a),c=Ng(e,t,n,r,a,m);return i.IsEqual(c.length,1)?c[0]:ge(c)}function Zr(e,t,n,r){let a=Te(e,t,r),s=sc(e,n,r),m=s[0],c=s[1];return St(c)?Dg(t,m)?bn(Ve(m),a):Kg(e,t,Ve(m),c.parameters,c.expression,a):bn(n,a)}function bn(e,t){return p.Create({"~kind":"Call"},{type:"call",target:e,arguments:t},{})}function uc(e,t){return Zr({},D([],[]),e,t)}function Vt(e){return x(e,"Call")}function Gg(e){return p.Discard(e,["~immutable"])}function cc(e,t){return p.Update(Gg(e),{},t)}function lc(e,t,n,r){let a=l(e,t,n);return cc(a,r)}function fc(e,t){return e(t)}function dc(e,t){return i.IsString(t)?R(fc(e,t)):R(t)}function xc(e,t){let n=Ie(t);return Qe(e,n)}function Ic(e,t){let n=t.map(r=>Qe(e,r));return k(n)}function Qe(e,t){return w(t)?dc(e,t.const):Z(t)?xc(e,t.pattern):I(t)?Ic(e,t.anyOf):t}function $r(e,t={}){return y("Capitalize",[e],t)}function yc(e,t={}){return Ba(e,t)}function hr(e,t={}){return y("Lowercase",[e],t)}function gc(e,t={}){return Wa(e,t)}function br(e,t={}){return y("Uncapitalize",[e],t)}function $c(e,t={}){return Va(e,t)}function Tr(e,t={}){return y("Uppercase",[e],t)}function hc(e,t={}){return Za(e,t)}var _g=e=>e[0].toUpperCase()+e.slice(1),Hg=e=>e.toLowerCase(),zg=e=>e[0].toLowerCase()+e.slice(1),Bg=e=>e.toUpperCase();function Ba(e,t){return T([e])?p.Update(Qe(_g,e),{},t):$r(e,t)}function Wa(e,t){return T([e])?p.Update(Qe(Hg,e),{},t):hr(e,t)}function Va(e,t){return T([e])?p.Update(Qe(zg,e),{},t):br(e,t)}function Za(e,t){return T([e])?p.Update(Qe(Bg,e),{},t):Tr(e,t)}function bc(e,t,n,r){let a=l(e,t,n);return Ba(a,r)}function Tc(e,t,n,r){let a=l(e,t,n);return Wa(a,r)}function Ec(e,t,n,r){let a=l(e,t,n);return Va(a,r)}function kc(e,t,n,r){let a=l(e,t,n);return Za(a,r)}function Er(e,t,n,r,a={}){return y("Conditional",[e,t,n,r],a)}function Pc(e,t,n,r,a={}){return Ja({},D([],[]),e,t,n,r,a)}function Wg(e,t,n,r,a,s){let m=ie(e,n,r);return $.IsExtendsUnion(m)?k([l(m.inferred,t,a),l(e,t,s)]):$.IsExtendsTrue(m)?l(m.inferred,t,a):l(e,t,s)}function Ja(e,t,n,r,a,s,m){return T([n,r])?p.Update(Wg(e,t,n,r,a,s),{},m):Er(n,r,a,s,m)}function Oc(e,t,n,r,a,s,m){let c=l(e,t,n),f=l(e,t,r);return Ja(e,t,c,f,a,s,m)}function kr(e,t={}){return y("ConstructorParameters",[e],t)}function Cc(e,t={}){return Qa(e,t)}function Vg(e){let t=ee(e)?e.parameters:[],n=pt({},D([],[]),t);return J(n)}function Qa(e,t){return T([e])?p.Update(Vg(e),{},t):kr(e,t)}function Rc(e,t,n,r){let a=l(e,t,n);return Qa(a,r)}function Pr(e,t,n={}){return y("Exclude",[e,t],n)}function vc(e,t,n={}){return Ln(e,t,n)}function Ln(e,t,n){return T([e,t])?p.Update(cr(e,t),{},n):Pr(e,t,n)}function Mc(e,t,n,r,a){let s=l(e,t,n),m=l(e,t,r);return Ln(s,m,a)}function Or(e,t,n={}){return y("Extract",[e,t],n)}function Sc(e,t,n={}){return Xa(e,t,n)}function Zg(e,t){let n=ie({},e,t);return $.IsExtendsTrueLike(n)?[e]:[]}function Jg(e,t){return e.reduce((n,r)=>[...n,...Zg(r,t)],[])}function wc(e,t){let n=Oe(e),r=I(n)?n.anyOf:[n],a=Jg(r,t);return ge(a)}function Xa(e,t,n){return T([e,t])?p.Update(wc(e,t),{},n):Or(e,t,n)}function jc(e,t,n,r,a){let s=l(e,t,n),m=l(e,t,r);return Xa(s,m,a)}function Qg(e){return e.reduce((t,n)=>or(n)?[...t,R(n)]:t,[])}function Zt(e){let t=Qg(e);return k(t)}function Tn(e,t,n={}){return y("Index",[e,t],n)}function Lc(e,t,n={}){let r=i.IsArray(t)?Zt(t):t;return Ya(e,r,n)}function Ac(e,t){let n=Ge(e,t);return Ee(n)}function qc(e,t,n){let r=Se(e,t,n);return Ee(r)}function Xg(e,t){let n=i.Keys(e).filter(g=>!i.HasPropertyKey(t,g)),r=i.Keys(t).filter(g=>!i.HasPropertyKey(e,g)),a=i.Keys(e).filter(g=>i.HasPropertyKey(t,g)),s=n.reduce((g,q)=>({...g,[q]:e[q]}),{}),m=r.reduce((g,q)=>({...g,[q]:t[q]}),{}),c=a.reduce((g,q)=>({...g,[q]:K([e[q],t[q]])}),{}),f=p.Assign(s,m);return p.Assign(f,c)}function Fc(e){return e.reduce((t,n)=>Xg(t,Ee(n)),{})}function Dc(e){let t=_i(J(e));return Ee(t)}function Yg(e,t){return i.Keys(e).filter(a=>a in t).reduce((a,s)=>({...a,[s]:ge([e[s],t[s]])}),{})}function Uc(e,t){return i.ShiftLeft(e,(n,r)=>Uc(r,Yg(t,Ee(n))),()=>t)}function Nc(e){return i.ShiftLeft(e,(t,n)=>Uc(n,Ee(t)),()=>B())}function Ee(e){return oe(e)?Ac(e.$defs,e.$ref):_(e)?qc(e.if,e.then,e.else):C(e)?Fc(e.allOf):I(e)?Nc(e.anyOf):F(e)?Dc(e.items):S(e)?e.properties:{}}function Jt(e){let t=Ee(e);return h(t)}var e$=new RegExp("^(?:0|[1-9][0-9]*)$");function Qt(e){let t=`${e}`;return e$.test(t)?parseInt(t):e}function t$(e){return R(Qt(e))}function Kc(e){return e.map(t=>Gc(t))}function Gc(e){return C(e)?pe(Kc(e.allOf)):I(e)?k(Kc(e.anyOf)):w(e)?t$(e.const):e}function _c(e,t){let n=Gc(t),r=ie({},n,ye());return $.IsExtendsTrueLike(r)?e:w(t)&&i.IsEqual(t.const,"length")?ye():A()}function Hc(e,t){let n=Ge(e,t);return $e(n)}function zc(e,t,n){let r=Se(e,t,n);return $e(r)}function Bc(e){let t=be(e);return $e(t)}function Wc(e){let t=K(e);return $e(t)}function Vc(e){return[`${e}`]}function Zc(e){let t=Ie(e);return $e(t)}function Jc(e){return e.reduce((t,n)=>[...t,...$e(n)],[])}function $e(e){return oe(e)?Hc(e.$defs,e.$ref):_(e)?zc(e.if,e.then,e.else):ue(e)?Bc(e.enum):C(e)?Wc(e.allOf):w(e)?Vc(e.const):Z(e)?Zc(e.pattern):I(e)?Jc(e.anyOf):[]}function Xt(e){return $e(e)}function An(e,t){return t.map(n=>qn(e,n))}function qn(e,t){return N(t)?he(qn(e,t.items)):ee(t)?Le(An(e,t.parameters),qn(e,t.instanceType)):te(t)?Ae(An(e,t.parameters),qn(e,t.returnType)):F(t)?J(An(e,t.items)):I(t)?k(An(e,t.anyOf)):C(t)?pe(An(e,t.allOf)):Ir(t)?h(e):t}function Qc(e,t){return qn(e,t)}function n$(e,t){let n=t in e?e[t]:A();return Qc(e,n)}function Xc(e,t){return t.reduce((n,r)=>[...n,n$(e,r)],[])}function r$(e,t){let n=Xt(t),r=Xc(e,n);return ge(r)}var a$=new RegExp(at);function o$(e){return e.filter(n=>a$.test(n))}function i$(e){let t=Xn(e),n=o$(t),r=Xc(e,n);return ge(r)}function Yc(e,t){return V(t)?i$(e):r$(e,t)}function s$(e){return R(Qt(e))}function el(e){return e.map(t=>eo(t))}function eo(e){return C(e)?pe(el(e.allOf)):I(e)?k(el(e.anyOf)):w(e)?s$(e.const):e}function m$(e,t){return e.reduceRight((n,r,a)=>{let s=ie({},R(a),t);return $.IsExtendsTrueLike(s)?[r,...n]:n},[])}function p$(e,t){let n=eo(t),r=m$(e,n);return Ze(r)}function u$(e){return Ze(e)}function tl(e,t){return w(t)&&i.IsEqual(t.const,"length")?R(e.length):V(t)||ce(t)?u$(e):p$(e,t)}function nl(e,t){return N(e)?_c(e.items,t):S(e)?Yc(e.properties,t):F(e)?tl(e.items,t):A()}function c$(e){return oe(e)||_(e)||C(e)||I(e)?Jt(e):e}function Ya(e,t,n){return T([e,t])?p.Update(nl(c$(e),t),{},n):Tn(e,t,n)}function rl(e,t,n,r,a){let s=l(e,t,n),m=l(e,t,r);return Ya(s,m,a)}function Cr(e,t={}){return y("InstanceType",[e],t)}function al(e,t={}){return to(e,t)}function l$(e){return ee(e)?e.instanceType:A()}function to(e,t){return T([e])?p.Update(l$(e),{},t):Cr(e,t)}function ol(e,t,n,r={}){let a=l(e,t,n);return to(a,r)}function En(e,t={}){return y("KeyOf",[e],t)}function il(e,t={}){return no(e,t)}function sl(){return k([ye(),Pe(),qt()])}function ml(e){return ye()}function f$(e){return e.reduce((n,r)=>or(r)?[...n,R(Qt(r))]:B(),[])}function pl(e){let t=i.Keys(e),n=f$(t);return Ze(n)}function ul(e){return Ut(e)}function cl(e){let t=e.map((n,r)=>R(r));return Ze(t)}function ll(e){return W(e)?sl():N(e)?ml(e.items):S(e)?pl(e.properties):se(e)?ul(e):F(e)?cl(e.items):A()}function d$(e){return oe(e)||_(e)||C(e)||I(e)?Jt(e):e}function no(e,t){return T([e])?p.Update(ll(d$(e)),{},t):En(e,t)}function fl(e,t,n,r){let a=l(e,t,n);return no(a,r)}function $n(e,t,n,r,a={}){return y("Mapped",[e,t,n,r],a)}function dl(e,t,n,r,a={}){return ro({},D([],[]),e,t,n,r,a)}function x$(e){let t=Ie(e);return Jr(t)}function I$(e){return e.reduce((t,n)=>[...t,...Jr(n)],[])}function y$(e){let t=be(e);return Jr(t)}function g$(e){return i.IsNumber(e)?[R(`${e}`)]:[R(e)]}function Jr(e){return ue(e)?y$(e.enum):w(e)?g$(e.const):Z(e)?x$(e.pattern):I(e)?I$(e.anyOf):[e]}function xl(e){return Jr(e)}function $$(e){return Z(e)?Ie(e.pattern):e}function h$(e,t,n,r,a,s){let m=p.Assign(e,{[n.name]:r}),c=l(m,t,a),f=$$(c),E=l(m,t,s);return Ei(f)||ki(f)?{[f.const]:E}:{}}function b$(e,t,n,r,a,s){return r.reduce((m,c)=>[...m,h$(e,t,n,c,a,s)],[])}function T$(e){return e.reduce((t,n)=>[...t,h(n)],[])}function Il(e,t,n,r,a,s){let m=xl(r),c=b$(e,t,n,m,a,s),f=T$(c);return K(f)}function ro(e,t,n,r,a,s,m){return T([r])?p.Update(Il(e,t,n,r,a,s),{},m):$n(n,r,a,s,m)}function yl(e,t,n,r,a,s,m){let c=l(e,t,r);return ro(e,t,n,c,a,s,m)}function E$(e,t,n){let r=p.Assign(e,t);return i.Keys(t).filter(s=>n.includes(s)).reduce((s,m)=>({...s,[m]:Xu(r,m,t[m])}),{})}function k$(e,t,n){let r=p.Assign(e,t);return i.Keys(t).filter(s=>!n.includes(s)).reduce((s,m)=>({...s,[m]:l(r,D([],[]),t[m])}),{})}function P$(e,t,n){let r=Vu(t),a=E$(e,t,r),s=k$(e,t,r),m={...a,...s};return p.Update(m,{},n)}function Qr(e,t,n,r){return P$(e,n,r)}function Rr(e,t={}){return y("NonNullable",[e],t)}function gl(e,t={}){return ao(e,t)}function O$(e){let t=k([Lt(),Nt()]);return Ln(e,t,{})}function ao(e,t){return T([e])?p.Update(O$(e),{},t):Rr(e,t)}function $l(e,t,n,r){let a=l(e,t,n);return ao(a,r)}function vr(e,t,n={}){return y("Omit",[e,t],n)}function hl(e,t,n={}){let r=i.IsArray(t)?Zt(t):t;return oo(e,r,n)}function Xr(e){let t=Jt(e);return S(t)?t.properties:B()}function C$(e,t){return i.Keys(e).reduce((r,a)=>t.includes(a)?r:{...r,[a]:e[a]},{})}function bl(e,t){let n=Xr(e),r=Xt(t),a=C$(n,r);return h(a)}function oo(e,t,n){return T([e,t])?p.Update(bl(e,t),{},n):vr(e,t,n)}function Tl(e,t,n,r,a){let s=l(e,t,n),m=l(e,t,r);return oo(s,m,a)}function Mr(e,t={}){return y("Parameters",[e],t)}function El(e,t={}){return io(e,t)}function R$(e){let t=te(e)?e.parameters:[],n=pt({},D([],[]),t);return J(n)}function io(e,t){return T([e])?p.Update(R$(e),{},t):Mr(e,t)}function kl(e,t,n,r){let a=l(e,t,n);return io(a,r)}function Sr(e,t={}){return y("Partial",[e],t)}function Pl(e,t={}){return so(e,t)}function Ol(e,t){let n=Ge(e,t),r=_e(n);return Fe(p.Assign(e,{[t]:r}),t)}function Cl(e,t,n){let r=Se(e,t,n);return _e(r)}function Rl(e){let t=K(e);return _e(t)}function vl(e){let t=e.map(n=>_e(n));return k(t)}function Ml(e){let t=i.Keys(e).reduce((r,a)=>({...r,[a]:yt(e[a])}),{});return h(t)}function _e(e){return oe(e)?Ol(e.$defs,e.$ref):_(e)?Cl(e.if,e.then,e.else):C(e)?Rl(e.allOf):I(e)?vl(e.anyOf):S(e)?Ml(e.properties):h({})}function so(e,t){return T([e])?p.Update(_e(e),{},t):Sr(e,t)}function Sl(e,t,n,r){let a=l(e,t,n);return so(a,r)}function wr(e,t,n={}){return y("Pick",[e,t],n)}function wl(e,t,n={}){let r=i.IsArray(t)?Zt(t):t;return mo(e,r,n)}function v$(e,t){return i.Keys(e).reduce((r,a)=>t.includes(a)?p.Assign(r,{[a]:e[a]}):r,{})}function jl(e,t){let n=Xr(e),r=Xt(t),a=v$(n,r);return h(a)}function mo(e,t,n){return T([e,t])?p.Update(jl(e,t),{},n):wr(e,t,n)}function Ll(e,t,n,r,a){let s=l(e,t,n),m=l(e,t,r);return mo(s,m,a)}function jr(e,t={}){return y("ReadonlyObject",[e],t)}function po(e,t={}){return uo(e,t)}var Al=po;function ql(e){return jt(he(e))}function Fl(e,t){let n=Ge(e,t),r=He(n);return Fe(p.Assign(e,{[t]:r}),t)}function Dl(e,t,n){let r=Se(e,t,n);return He(r)}function Ul(e){let t=K(e);return He(t)}function Nl(e){let t=i.Keys(e).reduce((r,a)=>({...r,[a]:ht(e[a])}),{});return h(t)}function Kl(e){return jt(J(e))}function Gl(e){let t=e.map(n=>He(n));return k(t)}function He(e){return N(e)?ql(e.items):oe(e)?Fl(e.$defs,e.$ref):_(e)?Dl(e.if,e.then,e.else):C(e)?Ul(e.allOf):S(e)?Nl(e.properties):F(e)?Kl(e.items):I(e)?Gl(e.anyOf):e}function uo(e,t){return T([e])?p.Update(He(e),{},t):jr(e)}function _l(e,t,n,r){let a=l(e,t,n);return uo(a,r)}function Hl(e,t,n,r){return t.visited.includes(r)?n:r in e?l(e,D(t.callstack,[...t.visited,r]),e[r]):n}function zl(e,t){let n=Ge(e,t),r=ze(n);return Fe(p.Assign(e,{[t]:r}),t)}function Bl(e,t,n){let r=Se(e,t,n);return ze(r)}function Wl(e){let t=K(e);return ze(t)}function Vl(e){let t=e.map(n=>ze(n));return k(t)}function Zl(e){let t=i.Keys(e).reduce((r,a)=>({...r,[a]:ur(e[a])}),{});return h(t)}function ze(e){return oe(e)?zl(e.$defs,e.$ref):_(e)?Bl(e.if,e.then,e.else):C(e)?Wl(e.allOf):I(e)?Vl(e.anyOf):S(e)?Zl(e.properties):h({})}function Lr(e,t={}){return y("Required",[e],t)}function Jl(e,t={}){return co(e,t)}function co(e,t){return T([e])?p.Update(ze(e),{},t):Lr(e,t)}function Ql(e,t,n,r){let a=l(e,t,n);return co(a,r)}function Ar(e,t={}){return y("ReturnType",[e],t)}function Xl(e,t={}){return lo(e,t)}function M$(e){return te(e)?e.returnType:A()}function lo(e,t){return T([e])?p.Update(M$(e),{},t):Ar(e,t)}function Yl(e,t,n,r={}){let a=l(e,t,n);return lo(a,r)}function qr(e,t){return y("With",[e,t],{})}function ef(e,t){return fo(e,t)}function fo(e,t){return T([e])?p.Update(e,{},t):qr(e,t)}function tf(e,t,n,r){let a=l(e,t,n);return fo(a,r)}function S$(e){return ot(e)?F(e.items)?xo(e.items.items):z(e.items)?[e]:ne(e.items)?[e]:[A()]:[e]}function xo(e){return e.reduce((n,r)=>[...n,...S$(r)],[])}function D(e,t){return{callstack:e,visited:t}}function T(e){return i.ShiftLeft(e,(t,n)=>ne(t)?!1:T(n),()=>!0)}function vn(e,t,n){return i.Keys(n).reduce((r,a)=>({...r,[a]:l(e,t,n[a])}),{})}function pt(e,t,n){let r=Te(e,t,n);return xo(r)}function Te(e,t,n){return n.map(r=>l(e,t,r))}function w$(e,t){let n=me(e)?sn(t,{}):t,r=bt(e)?on(n,{}):n;return $t(e)?Fn(r,{}):r}function j$(e,t,n,r,a){return i.IsEqual(n,"AddImmutable")?nf(e,t,r[0],a):i.IsEqual(n,"RemoveImmutable")?lc(e,t,r[0],a):i.IsEqual(n,"AddReadonly")?Xo(e,t,r[0],a):i.IsEqual(n,"RemoveReadonly")?Di(e,t,r[0],a):i.IsEqual(n,"AddOptional")?Yo(e,t,r[0],a):i.IsEqual(n,"RemoveOptional")?Ki(e,t,r[0],a):i.IsEqual(n,"Capitalize")?bc(e,t,r[0],a):i.IsEqual(n,"Conditional")?Oc(e,t,r[0],r[1],r[2],r[3],a):i.IsEqual(n,"ConstructorParameters")?Rc(e,t,r[0],a):i.IsEqual(n,"Evaluate")?tc(e,t,r[0],a):i.IsEqual(n,"Exclude")?Mc(e,t,r[0],r[1],a):i.IsEqual(n,"Extract")?jc(e,t,r[0],r[1],a):i.IsEqual(n,"Index")?rl(e,t,r[0],r[1],a):i.IsEqual(n,"InstanceType")?ol(e,t,r[0],a):i.IsEqual(n,"Interface")?Hu(e,t,r[0],r[1],a):i.IsEqual(n,"KeyOf")?fl(e,t,r[0],a):i.IsEqual(n,"Lowercase")?Tc(e,t,r[0],a):i.IsEqual(n,"Mapped")?yl(e,t,r[0],r[1],r[2],r[3],a):i.IsEqual(n,"Module")?Qr(e,t,r[0],a):i.IsEqual(n,"NonNullable")?$l(e,t,r[0],a):i.IsEqual(n,"Pick")?Ll(e,t,r[0],r[1],a):i.IsEqual(n,"Parameters")?kl(e,t,r[0],a):i.IsEqual(n,"Partial")?Sl(e,t,r[0],a):i.IsEqual(n,"Omit")?Tl(e,t,r[0],r[1],a):i.IsEqual(n,"ReadonlyObject")?_l(e,t,r[0],a):i.IsEqual(n,"Record")?as(e,t,r[0],r[1],a):i.IsEqual(n,"Required")?Ql(e,t,r[0],a):i.IsEqual(n,"ReturnType")?Yl(e,t,r[0],a):i.IsEqual(n,"TemplateLiteral")?mu(e,t,r[0],a):i.IsEqual(n,"Uncapitalize")?Ec(e,t,r[0],a):i.IsEqual(n,"Uppercase")?kc(e,t,r[0],a):i.IsEqual(n,"With")?tf(e,t,r[0],r[1]):y(n,r,a)}function L$(e,t,n){let r=ne(n)?Hl(e,t,n,n.$ref):N(n)?he(l(e,t,n.items),Qn(n)):Vt(n)?Zr(e,t,n.target,n.arguments):ee(n)?Le(Te(e,t,n.parameters),l(e,t,n.instanceType),ei(n)):te(n)?Ae(Te(e,t,n.parameters),l(e,t,n.returnType),ti(n)):_(n)?gt(l(e,t,n.if),l(e,t,n.then),l(e,t,n.else),si(n)):C(n)?pe(Te(e,t,n.allOf),li(n)):S(n)?h(vn(e,t,n.properties),oi(n)):se(n)?os(Ce(n),l(e,t,fe(n))):ot(n)?kt(l(e,t,n.items)):F(n)?J(pt(e,t,n.items),Fi(n)):I(n)?k(Te(e,t,n.anyOf),Oi(n)):n;return w$(n,r)}function l(e,t,n){return Ye(n)?j$(e,t,n.action,n.parameters,n.options):L$(e,t,n)}function Io(e,t){return l(e,D([],[]),t)}function A$(e){return p.Update(e,{"~immutable":!0},{})}function Fn(e,t){return p.Update(A$(e),{},t)}function nf(e,t,n,r){let a=l(e,t,n);return Fn(a,r)}function ip(e,t={}){return y("AddImmutable",[e],t)}function jt(e,t={}){return Fn(e,t)}function sp(e,t={}){return y("Evaluate",[e],t)}function rf(e,t={}){return Ha(e,t)}function mp(e,t={}){return y("Module",[e],t)}function af(e,t={}){return Qr({},D([],[]),e,t)}function of(...e){let[t,n,r]=De.Match(e,{2:(m,c)=>i.IsString(m)?[{},m,c]:[m,c,{}],3:(m,c,f)=>[m,c,f],1:m=>[{},m,{}]}),a=ru(n),s=i.IsArray(a)&&i.IsEqual(a.length,2)?l(t,D([],[]),a[0]):A();return p.Update(s,{},r)}var L={};lt(L,{Any:()=>wt,Array:()=>he,BigInt:()=>cn,Boolean:()=>rr,Call:()=>uc,Capitalize:()=>yc,Codec:()=>nr,Conditional:()=>Pc,Constructor:()=>Le,ConstructorParameters:()=>Cc,Cyclic:()=>Fe,Decode:()=>Ii,DecodeBuilder:()=>un,Dependent:()=>gt,Encode:()=>yi,EncodeBuilder:()=>pn,Enum:()=>ci,Evaluate:()=>rf,Exclude:()=>vc,Extends:()=>ie,ExtendsResult:()=>$,Extract:()=>Sc,Function:()=>Ae,Generic:()=>et,Identifier:()=>ln,Immutable:()=>gi,Index:()=>Lc,Infer:()=>mn,InstanceType:()=>al,Instantiate:()=>Io,Integer:()=>Tt,Interface:()=>zu,Intersect:()=>pe,IsAny:()=>W,IsArray:()=>N,IsBigInt:()=>Ne,IsBoolean:()=>ke,IsCall:()=>Vt,IsCodec:()=>tr,IsConstructor:()=>ee,IsCyclic:()=>oe,IsDependent:()=>_,IsEnum:()=>ue,IsEnumValue:()=>ui,IsFunction:()=>te,IsGeneric:()=>St,IsIdentifier:()=>Ti,IsImmutable:()=>$t,IsInfer:()=>z,IsInteger:()=>ce,IsIntersect:()=>C,IsKind:()=>x,IsLiteral:()=>w,IsNever:()=>tt,IsNull:()=>At,IsNumber:()=>V,IsObject:()=>S,IsOptional:()=>me,IsParameter:()=>Pi,IsReadonly:()=>bt,IsRecord:()=>se,IsRef:()=>ne,IsRefine:()=>xa,IsRest:()=>ot,IsSchema:()=>Q,IsString:()=>le,IsSymbol:()=>nt,IsTemplateLiteral:()=>Z,IsThis:()=>Ir,IsTuple:()=>F,IsUndefined:()=>Kt,IsUnion:()=>I,IsUnknown:()=>X,IsUnsafe:()=>er,IsVoid:()=>Ke,KeyOf:()=>il,Literal:()=>R,Lowercase:()=>gc,Mapped:()=>dl,Module:()=>af,Never:()=>A,NonNullable:()=>gl,Null:()=>Lt,Number:()=>ye,Object:()=>h,Omit:()=>hl,Optional:()=>ri,Parameter:()=>Et,Parameters:()=>El,Partial:()=>Pl,Pick:()=>wl,Readonly:()=>$i,ReadonlyObject:()=>po,ReadonlyType:()=>Al,Record:()=>fr,RecordKey:()=>Ut,RecordPattern:()=>Ce,RecordValue:()=>fe,Ref:()=>Ve,Refine:()=>hi,Required:()=>Jl,Rest:()=>kt,ReturnType:()=>Xl,Script:()=>of,String:()=>Pe,Symbol:()=>qt,TemplateLiteral:()=>uu,This:()=>xr,Tuple:()=>J,Uncapitalize:()=>$c,Undefined:()=>Nt,Union:()=>k,Unknown:()=>re,Unsafe:()=>ii,Uppercase:()=>hc,Void:()=>yr,With:()=>ef});function Rt(e){return`'${e.replace(/'/g,`'"'"'`)}'`}function yo(e){return`'${e.replace(/'/g,"'\\''")}'`}async function Yr(e,t,n){let r=Be();if(!r)throw new Error("HPC not configured. Use /hpc:config username@host password");let s=`${yo(Fo())} -batch -pw ${yo(r.password)} ${r.username}@${r.host} ${yo(t)}`,m=n?.timeout??6e4,c=await e.exec(qo(),["-c",s],{signal:n?.signal,timeout:m});return{stdout:c.stdout??"",stderr:c.stderr??"",exitCode:c.code??0,killed:c.killed}}function go(e){let t=`${e.stdout}
8
+ ${e.stderr}`;return e.exitCode!==0||/FATAL ERROR/i.test(t)}function $o(e){return e.killed?"HPC command timed out.":(e.stderr||e.stdout).trim()||`HPC command failed (exit ${e.exitCode})`}function q$(e){return/(?:^|\s)-F(?:\s|$)/.test(e)||/--fixed-strings/.test(e)}function F$(e){return/(?:^|\s)-E(?:\s|$)/.test(e)||/--extended-regexp/.test(e)}function D$(e){return!!(e.includes("|")||/[()[\]+]/.test(e)||/(?:^|[^\\])\?/.test(e))}function U$(e){return(e.split("/").pop()??e).includes(".")&&!e.endsWith("/")}function sf(e,t,n,r){let a=e.trim();return a=a.replace(/-(?:A|B|C)\s*\d+/g,"").trim(),!q$(a)&&!F$(a)&&D$(t)&&(a+=" -E"),r.context!==void 0&&r.context>0?a+=` -C ${r.context}`:(r.after&&r.after>0&&(a+=` -A ${r.after}`),r.before&&r.before>0&&(a+=` -B ${r.before}`)),r.recursive!==!1&&!U$(n)?/\s-r\b/.test(a)||(a+=" -r"):a=a.replace(/\s*-r\b/g,"").trim(),a.replace(/\s+/g," ").trim()}import{keyHint as N$}from"@earendil-works/pi-coding-agent";import{Text as mf}from"@earendil-works/pi-tui";function K$(e){let t=e.content.find(n=>n.type==="text");return t?.type==="text"?t.text??"":""}function G$(e,t,n){if(t.isPartial)return n.fg("warning","Connecting to HPC...");let r=e.details??{},a=K$(e).trim(),s=r.exitCode;if(r.error||s!==void 0&&s!==0)return n.fg("error",a||`HPC command failed (exit ${s??"?"})`);if(!a)return n.fg("dim","(no output)");let m=a.split(`
9
+ `),c=t.expanded?m.length:Oo,f=m.slice(0,c),E=m.length-c,g=`
10
+ ${f.map(q=>n.fg("toolOutput",q)).join(`
11
+ `)}`;return E>0&&(g+=`${n.fg("muted",`
12
+ ... (${E} more lines,`)} ${N$("app.tools.expand","to expand")})`),r.truncatedForAgent&&(g+=`
13
+ ${n.fg("warning","[Truncated for agent \u2014 narrow path or pattern]")}`),g}function ea(e,t,n){let r=n.lastComponent??new mf("",0,0);return r.setText(e),r}function pf(e,t,n,r){let a=r.lastComponent??new mf("",0,0);return a.setText(G$(e,t,n)),a}function uf(e){if(Kn())return;So(!0);let t=pf;e.registerTool({name:"ls_hpc",label:"List HPC Directory",description:"List files and directories on the remote HPC system. Use recursive=true to list all files under a directory.",promptSnippet:"List or browse files on remote HPC",promptGuidelines:["Use ls_hpc when the user wants to explore directories on the remote HPC filesystem.","Use ls_hpc with recursive=true to enumerate files under a directory tree."],parameters:L.Object({path:L.Optional(L.String({description:"Directory on HPC. Defaults to home (~)."})),options:L.Optional(L.String({description:"Extra ls flags (e.g. -lh). Default: -la. Ignored when recursive=true."})),recursive:L.Optional(L.Boolean({description:"List all files recursively under path. Default: false."}))}),renderCall(n,r,a){let s=n.path||"~",m=n.recursive?" (recursive)":"",c=r.fg("toolTitle",r.bold("ls_hpc "))+r.fg("accent",s)+r.fg("muted",m);return ea(c,r,a)},renderResult:t,async execute(n,r,a,s){s?.({content:[{type:"text",text:"Listing on HPC..."}],details:void 0});let m=r.path||"~",c=r.recursive??!1,f=r.options||"-la",E=c?`find ${Rt(m)} -type f 2>/dev/null | head -n 50000 | sort`:`ls ${f} ${Rt(m)} 2>&1`,g=await Yr(e,E,{signal:a});if(go(g))return{content:[{type:"text",text:$o(g)}],details:{exitCode:g.exitCode,path:m,recursive:c,error:!0},isError:!0};let q=(g.stdout||"").trim()||"(empty)";return{content:[{type:"text",text:q}],details:{exitCode:g.exitCode,path:m,recursive:c,lineCount:q.split(`
14
+ `).length}}}}),e.registerTool({name:"read_file_hpc",label:"Read HPC File",description:`Read a file from remote HPC. Supports offset/limit line range (max ${je} lines per call).`,promptSnippet:"Read file contents from remote HPC",promptGuidelines:["Use read_file_hpc to view source or config files stored on HPC.",`Use offset and limit to paginate large files (max ${je} lines per read).`],parameters:L.Object({path:L.String({description:"Absolute or relative file path on HPC."}),offset:L.Optional(L.Integer({description:"0-based starting line. Default: 0.",minimum:0})),limit:L.Optional(L.Integer({description:`Max lines to read (capped at ${je}). Default: ${je}.`,minimum:1,maximum:je}))}),renderCall(n,r,a){let s=n.path,m=n.offset??0,c=n.limit??je,f=r.fg("toolTitle",r.bold("read_file_hpc "))+r.fg("accent",s)+r.fg("warning",`:${m+1}${c?`-${m+c}`:""}`);return ea(f,r,a)},renderResult:t,async execute(n,r,a,s){s?.({content:[{type:"text",text:"Reading from HPC..."}],details:void 0});let m=r.path,c=Math.max(0,r.offset??0),f=r.limit??je;f>je&&(f=je);let E=c+1,g=c+f,q=`sed -n '${E},${g}p' ${Rt(m)} 2>&1`,Y=await Yr(e,q,{signal:a}),we=Y.stdout??"",ut=Y.stderr??"";if(Y.exitCode!==0)return{content:[{type:"text",text:`Error reading ${m}:
15
+ ${ut||we||"(no output)"}`}],details:{exitCode:Y.exitCode,path:m,error:!0}};if(!we.trim())return{content:[{type:"text",text:`No content in lines ${E}-${g} of ${m}`}],details:{path:m,offset:c,limit:f,empty:!0}};let de=we.split(`
16
+ `).length;return{content:[{type:"text",text:`${m} (lines ${E}-${c+de}):
17
+ `+we}],details:{path:m,offset:c,limit:f,lines:de}}}}),e.registerTool({name:"grep_hpc",label:"Search HPC Files",description:"Search file contents on HPC with grep. Patterns with | (alternation) auto-use grep -E. Use options '-F' for literal/fixed-string search. Max runtime 2 minutes.",promptSnippet:"Grep/search text in remote HPC files",promptGuidelines:["Use grep_hpc to find strings or regex patterns in HPC files.","For alternation (foo|bar), use one pattern with | \u2014 grep -E is added automatically.","Use options '-F' when the pattern must be matched literally (no regex).","Use after/before/context for surrounding lines (like grep -A/-B/-C)."],parameters:L.Object({pattern:L.String({description:"Search pattern. Use | for alternation (e.g. foo|bar)."}),path:L.Optional(L.String({description:"File or directory on HPC. Default: ."})),options:L.Optional(L.String({description:"Extra grep flags (e.g. -i, -l, -E). Default base: -rn."})),file_pattern:L.Optional(L.String({description:"Glob for filenames to search, e.g. '*.csv' or '*.py' (uses grep --include, case-insensitive via find when non-recursive)."})),after:L.Optional(L.Integer({description:"Lines after match (grep -A).",minimum:0})),before:L.Optional(L.Integer({description:"Lines before match (grep -B).",minimum:0})),context:L.Optional(L.Integer({description:"Lines before and after (grep -C). Overrides after/before.",minimum:0})),recursive:L.Optional(L.Boolean({description:"Search recursively (-r). Default true for directories."}))}),renderCall(n,r,a){let s=r.fg("toolTitle",r.bold("grep_hpc "));return s+=r.fg("accent",`"${n.pattern}"`),n.path&&(s+=r.fg("toolOutput",` in ${n.path}`)),n.file_pattern&&(s+=r.fg("toolOutput",` (${n.file_pattern})`)),ea(s,r,a)},renderResult:t,async execute(n,r,a,s){s?.({content:[{type:"text",text:"Searching on HPC..."}],details:void 0});let m=r.pattern,c=r.path||".",f=sf(r.options||"-n",m,c,{recursive:r.recursive,context:r.context,after:r.after,before:r.before}),E=Rt(m),g=Rt(c),q;if(r.file_pattern){let Re=r.file_pattern.trim(),ct=Rt(Re),vt=f.replace(/--include(?:=\S+|\s+\S+)?/g,"").trim();if(r.recursive===!1){let na=Re.includes("*")||Re.includes("?")?`-iname ${ct}`:`-name ${ct}`;q=`find ${g} -maxdepth 1 -type f ${na} -exec grep -Hn ${vt} -e ${E} {} + 2>&1`}else/\s-r\b/.test(vt)||(vt+=" -r"),q=`grep ${vt} --include=${ct} -e ${E} ${g} 2>&1`}else q=`grep ${f} -e ${E} ${g} 2>&1`;q+=" || true";let Y=await Yr(e,q,{signal:a,timeout:aa});if(Y.killed)return{content:[{type:"text",text:`grep_hpc timed out after ${aa/1e3}s. Narrow the path, use file_pattern, or refine the pattern.`}],details:{path:c,pattern:m,timedOut:!0,error:!0}};if(go(Y))return{content:[{type:"text",text:$o(Y)}],details:{path:c,pattern:m,file_pattern:r.file_pattern,exitCode:Y.exitCode,error:!0},isError:!0};let we=(Y.stdout||"").trim(),ut=(Y.stderr||"").trim();if(!we){let Re=r.file_pattern?`${c} (files: ${r.file_pattern})`:c;return ut&&/no such file|not found|cannot access/i.test(ut)?{content:[{type:"text",text:`grep_hpc failed:
18
+ ${ut}`}],details:{path:c,pattern:m,error:!0},isError:!0}:{content:[{type:"text",text:`No matches for ${JSON.stringify(m)} in ${Re}${f.includes("-E")?" (extended regex)":""}`}],details:{path:c,pattern:m,file_pattern:r.file_pattern,matches:0,grepOptions:f}}}let de=z$(we,{maxLines:H$,maxBytes:_$}),Yt=de.content,Un={path:c,pattern:m,grepOptions:f,matches:we.split(`
19
+ `).filter(Re=>Re.trim()).length,exitCode:Y.exitCode};if(de.truncated){Un.truncatedForAgent=!0;let Re=de.totalLines-de.outputLines,ct=de.totalBytes-de.outputBytes;Yt+=` | [Output truncated for agent: showing ${de.outputLines} of ${de.totalLines} lines (${ho(de.outputBytes)} of ${ho(de.totalBytes)}). ${Re} lines (${ho(ct)}) omitted. Narrow search path or pattern.]`}return{content:[{type:"text",text:Yt}],details:Un}}})}var B$=new Set(Nn);function W$(e){return B$.has(e)}function bo(e){return e.getActiveTools().map(n=>typeof n=="string"?n:n.name)}function To(){return Mt()&&!!Be()}function V$(e){return Nn.some(t=>bo(e).includes(t))}function ta(e){return To()!==V$(e)}function Z$(e){Kn()||uf(e)}function J$(e,t){let n=bo(e);if(t){if(n.length===0){_n(!0);return}let r=new Set(n);for(let a of Nn)r.add(a);e.setActiveTools([...r])}else{let r=n.filter(a=>!W$(a));r.length!==n.length&&e.setActiveTools(r)}_n(ta(e))}function Dn(e){let t=To();t&&Z$(e),J$(e,t)}function cf(e,t=0){let n=To(),r=bo(e);if(n&&r.length===0&&t<8){queueMicrotask(()=>cf(e,t+1));return}Dn(e)}function lf(e){for(let t of[0,50,150,400])setTimeout(()=>{(Gn()||ta(e))&&Dn(e)},t)}function Eo(e,t,n){ma(n),Ao(t,n),Dn(e)}function ko(e,t){let n=en();ft(n),ma(n?Lo(n,t):!1),_n(!0),cf(e)}function Q$(e){ft(en()),e.registerCommand("hpc:on",{description:"Enable HPC tools for this project folder",handler:async(t,n)=>{let r=Be();if(!r){n.ui.notify("HPC not configured. Use /hpc:config username@host password","error");return}Eo(e,n.cwd,!0),n.ui.notify(`HPC tools ON in this project (${r.username}@${r.host})`,"info"),n.ui.setStatus("hpc","HPC: ON")}}),e.registerCommand("hpc:off",{description:"Disable HPC tools for this project folder (other tools unchanged)",handler:async(t,n)=>{Eo(e,n.cwd,!1),n.ui.notify("HPC tools OFF in this project","info"),n.ui.setStatus("hpc","HPC: OFF")}}),e.registerCommand("hpc:config",{description:"Set HPC credentials: /hpc:config username@host password",handler:async(t,n)=>{if(!t?.trim()){n.ui.notify("Usage: /hpc:config username@host password","info"),n.ui.notify(" or: /hpc:config username host password","info");return}let r=t.trim().split(/\s+/),a,s,m;if(r.length===2){let c=r[0].indexOf("@");if(c===-1){n.ui.notify("Use username@host password","error");return}a=r[0].slice(0,c),s=r[0].slice(c+1),m=r[1]}else if(r.length>=3)a=r[0],s=r[1],m=r.slice(2).join(" ");else{n.ui.notify("Usage: /hpc:config username@host password","error");return}ua({username:a,host:s,password:m}),n.ui.notify(`HPC configured: ${a}@${s}`,"info"),n.ui.setStatus("hpc",`HPC: ${Mt()?"ON":"OFF"}`)}}),e.on("session_start",async(t,n)=>{ko(e,n.cwd),(t.reason==="resume"||t.reason==="reload"||t.reason==="startup")&&lf(e),Be()?n.ui.setStatus("hpc",`HPC: ${Mt()?"ON":"OFF"}`):Mt()&&n.ui.setStatus("hpc","HPC: ON (not configured)")}),e.on("session_tree",async(t,n)=>{ko(e,n.cwd)}),e.on("before_agent_start",async()=>{!Gn()&&!ta(e)||Dn(e)})}export{Q$ as default};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@sreetej510/pi-hpc-tools",
3
- "version": "0.1.1",
3
+ "version": "0.1.2",
4
4
  "description": "Pi extension for exploring a remote HPC/SSH host (via plink) with ls/read/grep tools, gated per-project by /hpc:on and /hpc:off.",
5
5
  "type": "module",
6
6
  "license": "MIT",
@@ -15,24 +15,24 @@
15
15
  "remote"
16
16
  ],
17
17
  "files": [
18
- "src",
18
+ "dist",
19
19
  "README.md",
20
20
  "LICENSE"
21
21
  ],
22
22
  "pi": {
23
23
  "extensions": [
24
- "./src/index.ts"
24
+ "./dist/index.js"
25
25
  ]
26
26
  },
27
27
  "scripts": {
28
+ "build": "node ../../scripts/build-extension.mjs",
29
+ "prepublishOnly": "npm run build",
28
30
  "check": "biome check . && npm run typecheck",
29
31
  "format": "biome check --write .",
30
32
  "typecheck": "tsc --noEmit"
31
33
  },
32
- "dependencies": {
33
- "typebox": "^1.3.3"
34
- },
35
34
  "devDependencies": {
35
+ "typebox": "^1.3.3",
36
36
  "@biomejs/biome": "^2.5.3",
37
37
  "@earendil-works/pi-coding-agent": "^0.80.3",
38
38
  "@earendil-works/pi-tui": "^0.80.3",
package/src/config.ts DELETED
@@ -1,97 +0,0 @@
1
- /** hpc-config.json load/save + per-project enable state + shell/plink resolution. */
2
- import { existsSync, mkdirSync, readFileSync, writeFileSync } from "node:fs";
3
- import { dirname, join } from "node:path";
4
- import { AGENT_DIR, CONFIG_PATHS, DEFAULT_PLINK } from "./constants.js";
5
- import { getCurrentConfig, setCurrentConfig } from "./state.js";
6
- import type { HPCConfig } from "./types.js";
7
-
8
- function ensureDir(filePath: string): void {
9
- const dir = dirname(filePath);
10
- if (!existsSync(dir)) {
11
- mkdirSync(dir, { recursive: true });
12
- }
13
- }
14
-
15
- export function isProjectEnabled(config: HPCConfig, cwd: string): boolean {
16
- return (config.enabledProjects ?? []).includes(cwd);
17
- }
18
-
19
- export function setProjectEnabled(cwd: string, enabled: boolean): void {
20
- const config = getHPCConfig();
21
- if (!config) return;
22
- const projects = new Set(config.enabledProjects ?? []);
23
- if (enabled) {
24
- projects.add(cwd);
25
- } else {
26
- projects.delete(cwd);
27
- }
28
- saveConfig({ ...config, enabledProjects: [...projects] });
29
- }
30
-
31
- export function loadConfig(): HPCConfig | null {
32
- const username = process.env.HPC_USERNAME || process.env.HPC_USER;
33
- const host = process.env.HPC_HOST;
34
- const password = process.env.HPC_PASSWORD;
35
- if (username && host && password) {
36
- return { username, host, password };
37
- }
38
-
39
- for (const configPath of CONFIG_PATHS) {
40
- try {
41
- if (!existsSync(configPath)) continue;
42
- const config = JSON.parse(readFileSync(configPath, "utf-8")) as HPCConfig;
43
- if (config.username && config.host && config.password) {
44
- return config;
45
- }
46
- } catch {
47
- // try next path
48
- }
49
- }
50
- return null;
51
- }
52
-
53
- export function saveConfig(config: HPCConfig): void {
54
- const configPath = CONFIG_PATHS[0];
55
- ensureDir(configPath);
56
- writeFileSync(configPath, JSON.stringify(config, null, 2), "utf-8");
57
- setCurrentConfig(config);
58
- }
59
-
60
- export function getHPCConfig(): HPCConfig | null {
61
- if (!getCurrentConfig()) {
62
- setCurrentConfig(loadConfig());
63
- }
64
- return getCurrentConfig();
65
- }
66
-
67
- /** Forward-slash path for Git Bash (C:/Users/...). */
68
- export function toSlashPath(p: string): string {
69
- return p.replace(/\\/g, "/");
70
- }
71
-
72
- function getAgentSettings(): { shellPath?: string } {
73
- try {
74
- const settingsPath = join(AGENT_DIR, "settings.json");
75
- if (existsSync(settingsPath)) {
76
- return JSON.parse(readFileSync(settingsPath, "utf-8")) as { shellPath?: string };
77
- }
78
- } catch {
79
- // ignore
80
- }
81
- return {};
82
- }
83
-
84
- /** Shell from settings.json shellPath — must match user bash (Git Bash on Windows). */
85
- export function getShellExecutable(): string {
86
- const fromSettings = getAgentSettings().shellPath;
87
- if (fromSettings) return fromSettings;
88
- return process.platform === "win32" ? "C:\\Program Files\\Git\\bin\\bash.exe" : "bash";
89
- }
90
-
91
- export function getPlinkCommand(): string {
92
- if (process.env.PLINK_PATH) return toSlashPath(process.env.PLINK_PATH);
93
- const cfg = getHPCConfig();
94
- if (cfg?.plinkPath) return toSlashPath(cfg.plinkPath);
95
- if (existsSync(DEFAULT_PLINK)) return DEFAULT_PLINK;
96
- return "plink";
97
- }
package/src/constants.ts DELETED
@@ -1,13 +0,0 @@
1
- import { homedir } from "node:os";
2
- import { join } from "node:path";
3
-
4
- export const HPC_TOOL_NAMES = ["ls_hpc", "read_file_hpc", "grep_hpc"] as const;
5
- export const MAX_READ_LINES = 1000;
6
- export const GREP_TIMEOUT_MS = 120_000;
7
- export const UI_PREVIEW_LINES = 10;
8
-
9
- export const AGENT_DIR = join(homedir(), ".pi", "agent");
10
- export const CONFIG_PATHS = [join(AGENT_DIR, ".pi", "hpc-config.json"), join(homedir(), ".pi", "hpc-config.json")];
11
-
12
- /** Default plink on this machine (Git bash path). Override via PLINK_PATH or hpc-config.json plinkPath. */
13
- export const DEFAULT_PLINK = "C:/Users/sreet/plink/plink.exe";
package/src/exec.ts DELETED
@@ -1,49 +0,0 @@
1
- /** Remote command execution over plink + shell quoting helpers. */
2
- import type { ExtensionAPI } from "@earendil-works/pi-coding-agent";
3
- import { getHPCConfig, getPlinkCommand, getShellExecutable } from "./config.js";
4
- import type { HpcExecResult } from "./types.js";
5
-
6
- /** Single-quote escape for remote shell command strings. */
7
- export function shQuote(value: string): string {
8
- return `'${value.replace(/'/g, `'"'"'`)}'`;
9
- }
10
-
11
- export function bashQuote(value: string): string {
12
- return `'${value.replace(/'/g, `'\\''`)}'`;
13
- }
14
-
15
- export async function execOnHPC(
16
- pi: ExtensionAPI,
17
- remoteCommand: string,
18
- opts?: { timeout?: number; signal?: AbortSignal },
19
- ): Promise<HpcExecResult> {
20
- const config = getHPCConfig();
21
- if (!config) {
22
- throw new Error("HPC not configured. Use /hpc:config username@host password");
23
- }
24
-
25
- const plink = bashQuote(getPlinkCommand());
26
- const localCmd = `${plink} -batch -pw ${bashQuote(config.password)} ${config.username}@${config.host} ${bashQuote(remoteCommand)}`;
27
- const connectTimeoutMs = opts?.timeout ?? 60_000;
28
- const result = await pi.exec(getShellExecutable(), ["-c", localCmd], {
29
- signal: opts?.signal,
30
- timeout: connectTimeoutMs,
31
- });
32
-
33
- return {
34
- stdout: result.stdout ?? "",
35
- stderr: result.stderr ?? "",
36
- exitCode: result.code ?? 0,
37
- killed: result.killed,
38
- };
39
- }
40
-
41
- export function isHpcFailure(result: HpcExecResult): boolean {
42
- const text = `${result.stdout}\n${result.stderr}`;
43
- return result.exitCode !== 0 || /FATAL ERROR/i.test(text);
44
- }
45
-
46
- export function formatHpcFailure(result: HpcExecResult): string {
47
- if (result.killed) return "HPC command timed out.";
48
- return (result.stderr || result.stdout).trim() || `HPC command failed (exit ${result.exitCode})`;
49
- }
@@ -1,57 +0,0 @@
1
- /** grep_hpc option-string building heuristics. */
2
-
3
- function grepUsesFixedStrings(options: string): boolean {
4
- return /(?:^|\s)-F(?:\s|$)/.test(options) || /--fixed-strings/.test(options);
5
- }
6
-
7
- function grepUsesExtendedRegex(options: string): boolean {
8
- return /(?:^|\s)-E(?:\s|$)/.test(options) || /--extended-regexp/.test(options);
9
- }
10
-
11
- /** Heuristic: | alternation and common ERE syntax need grep -E. */
12
- function patternNeedsExtendedRegex(pattern: string): boolean {
13
- if (pattern.includes("|")) return true;
14
- if (/[()[\]+]/.test(pattern)) return true;
15
- if (/(?:^|[^\\])\?/.test(pattern)) return true;
16
- return false;
17
- }
18
-
19
- function isLikelyFilePath(path: string): boolean {
20
- const base = path.split("/").pop() ?? path;
21
- return base.includes(".") && !path.endsWith("/");
22
- }
23
-
24
- export function buildGrepOptions(
25
- baseOptions: string,
26
- pattern: string,
27
- searchPath: string,
28
- params: {
29
- recursive?: boolean;
30
- context?: number;
31
- after?: number;
32
- before?: number;
33
- },
34
- ): string {
35
- let opts = baseOptions.trim();
36
- opts = opts.replace(/-(?:A|B|C)\s*\d+/g, "").trim();
37
-
38
- if (!grepUsesFixedStrings(opts) && !grepUsesExtendedRegex(opts) && patternNeedsExtendedRegex(pattern)) {
39
- opts += " -E";
40
- }
41
-
42
- if (params.context !== undefined && params.context > 0) {
43
- opts += ` -C ${params.context}`;
44
- } else {
45
- if (params.after && params.after > 0) opts += ` -A ${params.after}`;
46
- if (params.before && params.before > 0) opts += ` -B ${params.before}`;
47
- }
48
-
49
- const useRecursive = params.recursive !== false && !isLikelyFilePath(searchPath);
50
- if (!useRecursive) {
51
- opts = opts.replace(/\s*-r\b/g, "").trim();
52
- } else if (!/\s-r\b/.test(opts)) {
53
- opts += " -r";
54
- }
55
-
56
- return opts.replace(/\s+/g, " ").trim();
57
- }
package/src/index.ts DELETED
@@ -1,116 +0,0 @@
1
- /**
2
- * HPC Tools Extension for pi
3
- *
4
- * Remote file exploration via plink:
5
- * plink -batch -pw "password" username@host "command"
6
- *
7
- * Commands: /hpc:on, /hpc:off, /hpc:config
8
- * Tools (active only after /hpc:on in this project): ls_hpc, read_file_hpc, grep_hpc
9
- * On/off state is stored in hpc-config.json as enabledProjects: ["/path/to/project", ...]
10
- *
11
- * File layout:
12
- * index.ts extension entry point (this file) — commands + lifecycle events
13
- * constants.ts tool names, timeouts, config file paths
14
- * types.ts shared TypeScript types
15
- * state.ts shared mutable module state (enabled flag, config cache, sync flags)
16
- * config.ts hpc-config.json load/save, per-project enable state, shell/plink resolution
17
- * exec.ts plink invocation + shell quoting helpers
18
- * grep-options.ts grep_hpc option-string building heuristics
19
- * render.ts tool call/result rendering
20
- * tool-sync.ts keeps HPC tools' active/inactive state in sync with /hpc:on|off
21
- * tools.ts registers ls_hpc / read_file_hpc / grep_hpc
22
- */
23
- import type { ExtensionAPI } from "@earendil-works/pi-coding-agent";
24
- import { getHPCConfig, loadConfig, saveConfig } from "./config.js";
25
- import { getHpcEnabled, getPendingToolSync, setCurrentConfig } from "./state.js";
26
- import { isHpcSyncNeeded, onProjectContext, scheduleDelayedHpcSync, setHpcEnabled, syncHpcTools } from "./tool-sync.js";
27
-
28
- export default function hpcToolsExtension(pi: ExtensionAPI) {
29
- setCurrentConfig(loadConfig());
30
-
31
- pi.registerCommand("hpc:on", {
32
- description: "Enable HPC tools for this project folder",
33
- handler: async (_args, ctx) => {
34
- const config = getHPCConfig();
35
- if (!config) {
36
- ctx.ui.notify("HPC not configured. Use /hpc:config username@host password", "error");
37
- return;
38
- }
39
- setHpcEnabled(pi, ctx.cwd, true);
40
- ctx.ui.notify(`HPC tools ON in this project (${config.username}@${config.host})`, "info");
41
- ctx.ui.setStatus("hpc", `HPC: ON`);
42
- },
43
- });
44
-
45
- pi.registerCommand("hpc:off", {
46
- description: "Disable HPC tools for this project folder (other tools unchanged)",
47
- handler: async (_args, ctx) => {
48
- setHpcEnabled(pi, ctx.cwd, false);
49
- ctx.ui.notify("HPC tools OFF in this project", "info");
50
- ctx.ui.setStatus("hpc", `HPC: OFF`);
51
- },
52
- });
53
-
54
- pi.registerCommand("hpc:config", {
55
- description: "Set HPC credentials: /hpc:config username@host password",
56
- handler: async (args, ctx) => {
57
- if (!args?.trim()) {
58
- ctx.ui.notify("Usage: /hpc:config username@host password", "info");
59
- ctx.ui.notify(" or: /hpc:config username host password", "info");
60
- return;
61
- }
62
-
63
- const parts = args.trim().split(/\s+/);
64
- let username: string;
65
- let host: string;
66
- let password: string;
67
-
68
- if (parts.length === 2) {
69
- const at = parts[0].indexOf("@");
70
- if (at === -1) {
71
- ctx.ui.notify("Use username@host password", "error");
72
- return;
73
- }
74
- username = parts[0].slice(0, at);
75
- host = parts[0].slice(at + 1);
76
- password = parts[1];
77
- } else if (parts.length >= 3) {
78
- username = parts[0];
79
- host = parts[1];
80
- password = parts.slice(2).join(" ");
81
- } else {
82
- ctx.ui.notify("Usage: /hpc:config username@host password", "error");
83
- return;
84
- }
85
-
86
- saveConfig({ username, host, password });
87
- ctx.ui.notify(`HPC configured: ${username}@${host}`, "info");
88
- ctx.ui.setStatus("hpc", `HPC: ${getHpcEnabled() ? "ON" : "OFF"}`);
89
- },
90
- });
91
-
92
- pi.on("session_start", async (event, ctx) => {
93
- // New, resume, reload, fork — re-apply per-project hpc-state.json
94
- onProjectContext(pi, ctx.cwd);
95
- if (event.reason === "resume" || event.reason === "reload" || event.reason === "startup") {
96
- scheduleDelayedHpcSync(pi);
97
- }
98
-
99
- const config = getHPCConfig();
100
- if (config) {
101
- ctx.ui.setStatus("hpc", `HPC: ${getHpcEnabled() ? "ON" : "OFF"}`);
102
- } else if (getHpcEnabled()) {
103
- ctx.ui.setStatus("hpc", `HPC: ON (not configured)`);
104
- }
105
- });
106
-
107
- pi.on("session_tree", async (_event, ctx) => {
108
- // Navigating branches in an existing session — active tools may be restored from history
109
- onProjectContext(pi, ctx.cwd);
110
- });
111
-
112
- pi.on("before_agent_start", async () => {
113
- if (!getPendingToolSync() && !isHpcSyncNeeded(pi)) return;
114
- syncHpcTools(pi);
115
- });
116
- }
package/src/render.ts DELETED
@@ -1,68 +0,0 @@
1
- /** Tool call/result rendering — matches built-in ls/grep/read formatting. */
2
- import { keyHint } from "@earendil-works/pi-coding-agent";
3
- import { Text } from "@earendil-works/pi-tui";
4
- import { UI_PREVIEW_LINES } from "./constants.js";
5
- import type { HpcToolRenderResult } from "./types.js";
6
-
7
- function getToolText(result: HpcToolRenderResult): string {
8
- const block = result.content.find((c) => c.type === "text");
9
- return block?.type === "text" ? (block.text ?? "") : "";
10
- }
11
-
12
- /** Match built-in ls/grep/read renderResult formatting (in-place expand via Ctrl+O). */
13
- export function formatHpcResult(
14
- result: HpcToolRenderResult,
15
- options: { expanded: boolean; isPartial: boolean },
16
- theme: import("@earendil-works/pi-coding-agent").Theme,
17
- ): string {
18
- if (options.isPartial) {
19
- return theme.fg("warning", "Connecting to HPC...");
20
- }
21
-
22
- const details = result.details ?? {};
23
- const output = getToolText(result).trim();
24
- const exitCode = details.exitCode as number | undefined;
25
-
26
- if (details.error || (exitCode !== undefined && exitCode !== 0)) {
27
- return theme.fg("error", output || `HPC command failed (exit ${exitCode ?? "?"})`);
28
- }
29
-
30
- if (!output) {
31
- return theme.fg("dim", "(no output)");
32
- }
33
-
34
- const lines = output.split("\n");
35
- const maxLines = options.expanded ? lines.length : UI_PREVIEW_LINES;
36
- const displayLines = lines.slice(0, maxLines);
37
- const remaining = lines.length - maxLines;
38
-
39
- let text = `\n${displayLines.map((line) => theme.fg("toolOutput", line)).join("\n")}`;
40
- if (remaining > 0) {
41
- text += `${theme.fg("muted", `\n... (${remaining} more lines,`)} ${keyHint("app.tools.expand", "to expand")})`;
42
- }
43
- if (details.truncatedForAgent) {
44
- text += `\n${theme.fg("warning", "[Truncated for agent — narrow path or pattern]")}`;
45
- }
46
- return text;
47
- }
48
-
49
- export function hpcRenderCall(
50
- callText: string,
51
- theme: import("@earendil-works/pi-coding-agent").Theme,
52
- context: { lastComponent?: unknown },
53
- ): Text {
54
- const text = (context.lastComponent as Text | undefined) ?? new Text("", 0, 0);
55
- text.setText(callText);
56
- return text;
57
- }
58
-
59
- export function hpcRenderResult(
60
- result: HpcToolRenderResult,
61
- options: { expanded: boolean; isPartial: boolean },
62
- theme: import("@earendil-works/pi-coding-agent").Theme,
63
- context: { lastComponent?: unknown },
64
- ): Text {
65
- const text = (context.lastComponent as Text | undefined) ?? new Text("", 0, 0);
66
- text.setText(formatHpcResult(result, options, theme));
67
- return text;
68
- }
package/src/state.ts DELETED
@@ -1,43 +0,0 @@
1
- /**
2
- * Shared mutable module state, centralized here so every other file mutates
3
- * it through explicit getters/setters instead of each holding its own copy.
4
- */
5
- import type { HPCConfig } from "./types.js";
6
-
7
- let hpcEnabled = false;
8
- let currentConfig: HPCConfig | null = null;
9
- let toolsRegistered = false;
10
- /** Sync HPC tool visibility after built-ins are in the active set. */
11
- let pendingToolSync = false;
12
-
13
- export function getHpcEnabled(): boolean {
14
- return hpcEnabled;
15
- }
16
-
17
- export function setHpcEnabledFlag(enabled: boolean): void {
18
- hpcEnabled = enabled;
19
- }
20
-
21
- export function getCurrentConfig(): HPCConfig | null {
22
- return currentConfig;
23
- }
24
-
25
- export function setCurrentConfig(config: HPCConfig | null): void {
26
- currentConfig = config;
27
- }
28
-
29
- export function getToolsRegistered(): boolean {
30
- return toolsRegistered;
31
- }
32
-
33
- export function setToolsRegistered(registered: boolean): void {
34
- toolsRegistered = registered;
35
- }
36
-
37
- export function getPendingToolSync(): boolean {
38
- return pendingToolSync;
39
- }
40
-
41
- export function setPendingToolSync(pending: boolean): void {
42
- pendingToolSync = pending;
43
- }
package/src/tool-sync.ts DELETED
@@ -1,114 +0,0 @@
1
- /** Keeps the ls_hpc/read_file_hpc/grep_hpc tools' active/inactive state in sync with /hpc:on|off. */
2
- import type { ExtensionAPI } from "@earendil-works/pi-coding-agent";
3
- import { getHPCConfig, isProjectEnabled, loadConfig, setProjectEnabled } from "./config.js";
4
- import { HPC_TOOL_NAMES } from "./constants.js";
5
- import {
6
- getHpcEnabled,
7
- getPendingToolSync,
8
- getToolsRegistered,
9
- setCurrentConfig,
10
- setHpcEnabledFlag,
11
- setPendingToolSync,
12
- } from "./state.js";
13
- import { registerHPCTools } from "./tools.js";
14
-
15
- const HPC_TOOL_SET = new Set<string>(HPC_TOOL_NAMES);
16
-
17
- function isHpcToolName(name: string): boolean {
18
- return HPC_TOOL_SET.has(name);
19
- }
20
-
21
- /** pi.getActiveTools() returns tool name strings (not { name } objects). */
22
- function getActiveToolNames(pi: ExtensionAPI): string[] {
23
- const active = pi.getActiveTools() as Array<string | { name: string }>;
24
- return active.map((t) => (typeof t === "string" ? t : t.name));
25
- }
26
-
27
- function wantHpcEnabled(): boolean {
28
- return getHpcEnabled() && Boolean(getHPCConfig());
29
- }
30
-
31
- function hasHpcInActive(pi: ExtensionAPI): boolean {
32
- return HPC_TOOL_NAMES.some((n) => getActiveToolNames(pi).includes(n));
33
- }
34
-
35
- export function isHpcSyncNeeded(pi: ExtensionAPI): boolean {
36
- return wantHpcEnabled() !== hasHpcInActive(pi);
37
- }
38
-
39
- function ensureHpcToolsRegistered(pi: ExtensionAPI): void {
40
- if (getToolsRegistered()) return;
41
- registerHPCTools(pi);
42
- }
43
-
44
- /**
45
- * Toggle only the three HPC tools on the current active set.
46
- * ON: add HPC tools to whatever is already active (keeps all other tools).
47
- * OFF: remove HPC tools from whatever is active (keeps all other tools).
48
- */
49
- function applyHpcToolVisibility(pi: ExtensionAPI, enabled: boolean): void {
50
- const current = getActiveToolNames(pi);
51
-
52
- if (enabled) {
53
- if (current.length === 0) {
54
- setPendingToolSync(true);
55
- return;
56
- }
57
- const next = new Set(current);
58
- for (const name of HPC_TOOL_NAMES) next.add(name);
59
- pi.setActiveTools([...next]);
60
- } else {
61
- const withoutHpc = current.filter((n) => !isHpcToolName(n));
62
- if (withoutHpc.length !== current.length) {
63
- pi.setActiveTools(withoutHpc);
64
- }
65
- }
66
-
67
- setPendingToolSync(isHpcSyncNeeded(pi));
68
- }
69
-
70
- /** Apply project hpc-state.json to the active tool list (resume / session switch). */
71
- export function syncHpcTools(pi: ExtensionAPI): void {
72
- const want = wantHpcEnabled();
73
- if (want) {
74
- ensureHpcToolsRegistered(pi);
75
- }
76
- applyHpcToolVisibility(pi, want);
77
- }
78
-
79
- export function scheduleHpcSync(pi: ExtensionAPI, attempt = 0): void {
80
- const want = wantHpcEnabled();
81
- const active = getActiveToolNames(pi);
82
-
83
- if (want && active.length === 0 && attempt < 8) {
84
- queueMicrotask(() => scheduleHpcSync(pi, attempt + 1));
85
- return;
86
- }
87
-
88
- syncHpcTools(pi);
89
- }
90
-
91
- /** Resume/reload restores active tools from the session file after session_start. */
92
- export function scheduleDelayedHpcSync(pi: ExtensionAPI): void {
93
- for (const delayMs of [0, 50, 150, 400]) {
94
- setTimeout(() => {
95
- if (getPendingToolSync() || isHpcSyncNeeded(pi)) {
96
- syncHpcTools(pi);
97
- }
98
- }, delayMs);
99
- }
100
- }
101
-
102
- export function setHpcEnabled(pi: ExtensionAPI, cwd: string, enabled: boolean): void {
103
- setHpcEnabledFlag(enabled);
104
- setProjectEnabled(cwd, enabled);
105
- syncHpcTools(pi);
106
- }
107
-
108
- export function onProjectContext(pi: ExtensionAPI, cwd: string): void {
109
- const config = loadConfig();
110
- setCurrentConfig(config);
111
- setHpcEnabledFlag(config ? isProjectEnabled(config, cwd) : false);
112
- setPendingToolSync(true);
113
- scheduleHpcSync(pi);
114
- }
package/src/tools.ts DELETED
@@ -1,295 +0,0 @@
1
- /** Registers the ls_hpc / read_file_hpc / grep_hpc tools. */
2
-
3
- import type { ExtensionAPI } from "@earendil-works/pi-coding-agent";
4
- import { DEFAULT_MAX_BYTES, DEFAULT_MAX_LINES, formatSize, truncateHead } from "@earendil-works/pi-coding-agent";
5
- import { Type } from "typebox";
6
- import { GREP_TIMEOUT_MS, MAX_READ_LINES } from "./constants.js";
7
- import { execOnHPC, formatHpcFailure, isHpcFailure, shQuote } from "./exec.js";
8
- import { buildGrepOptions } from "./grep-options.js";
9
- import { hpcRenderCall, hpcRenderResult } from "./render.js";
10
- import { getToolsRegistered, setToolsRegistered } from "./state.js";
11
-
12
- export function registerHPCTools(pi: ExtensionAPI): void {
13
- if (getToolsRegistered()) return;
14
- setToolsRegistered(true);
15
-
16
- const sharedRender = hpcRenderResult;
17
-
18
- pi.registerTool({
19
- name: "ls_hpc",
20
- label: "List HPC Directory",
21
- description:
22
- "List files and directories on the remote HPC system. Use recursive=true to list all files under a directory.",
23
- promptSnippet: "List or browse files on remote HPC",
24
- promptGuidelines: [
25
- "Use ls_hpc when the user wants to explore directories on the remote HPC filesystem.",
26
- "Use ls_hpc with recursive=true to enumerate files under a directory tree.",
27
- ],
28
- parameters: Type.Object({
29
- path: Type.Optional(Type.String({ description: "Directory on HPC. Defaults to home (~)." })),
30
- options: Type.Optional(
31
- Type.String({ description: "Extra ls flags (e.g. -lh). Default: -la. Ignored when recursive=true." }),
32
- ),
33
- recursive: Type.Optional(Type.Boolean({ description: "List all files recursively under path. Default: false." })),
34
- }),
35
- renderCall(args, theme, context) {
36
- const path = (args.path as string) || "~";
37
- const rec = args.recursive ? " (recursive)" : "";
38
- const callText = theme.fg("toolTitle", theme.bold("ls_hpc ")) + theme.fg("accent", path) + theme.fg("muted", rec);
39
- return hpcRenderCall(callText, theme, context);
40
- },
41
- renderResult: sharedRender,
42
- async execute(_toolCallId, params, signal, onUpdate) {
43
- onUpdate?.({ content: [{ type: "text", text: "Listing on HPC..." }], details: undefined });
44
- const path = params.path || "~";
45
- const recursive = params.recursive ?? false;
46
- const options = params.options || "-la";
47
-
48
- const command = recursive
49
- ? `find ${shQuote(path)} -type f 2>/dev/null | head -n 50000 | sort`
50
- : `ls ${options} ${shQuote(path)} 2>&1`;
51
-
52
- const result = await execOnHPC(pi, command, { signal });
53
-
54
- if (isHpcFailure(result)) {
55
- return {
56
- content: [{ type: "text", text: formatHpcFailure(result) }],
57
- details: { exitCode: result.exitCode, path, recursive, error: true },
58
- isError: true,
59
- };
60
- }
61
-
62
- const text = (result.stdout || "").trim() || "(empty)";
63
- return {
64
- content: [{ type: "text", text }],
65
- details: { exitCode: result.exitCode, path, recursive, lineCount: text.split("\n").length },
66
- };
67
- },
68
- });
69
-
70
- pi.registerTool({
71
- name: "read_file_hpc",
72
- label: "Read HPC File",
73
- description: `Read a file from remote HPC. Supports offset/limit line range (max ${MAX_READ_LINES} lines per call).`,
74
- promptSnippet: "Read file contents from remote HPC",
75
- promptGuidelines: [
76
- "Use read_file_hpc to view source or config files stored on HPC.",
77
- `Use offset and limit to paginate large files (max ${MAX_READ_LINES} lines per read).`,
78
- ],
79
- parameters: Type.Object({
80
- path: Type.String({ description: "Absolute or relative file path on HPC." }),
81
- offset: Type.Optional(Type.Integer({ description: "0-based starting line. Default: 0.", minimum: 0 })),
82
- limit: Type.Optional(
83
- Type.Integer({
84
- description: `Max lines to read (capped at ${MAX_READ_LINES}). Default: ${MAX_READ_LINES}.`,
85
- minimum: 1,
86
- maximum: MAX_READ_LINES,
87
- }),
88
- ),
89
- }),
90
- renderCall(args, theme, context) {
91
- const path = args.path as string;
92
- const offset = (args.offset as number | undefined) ?? 0;
93
- const limit = (args.limit as number | undefined) ?? MAX_READ_LINES;
94
- const callText =
95
- theme.fg("toolTitle", theme.bold("read_file_hpc ")) +
96
- theme.fg("accent", path) +
97
- theme.fg("warning", `:${offset + 1}${limit ? `-${offset + limit}` : ""}`);
98
- return hpcRenderCall(callText, theme, context);
99
- },
100
- renderResult: sharedRender,
101
- async execute(_toolCallId, params, signal, onUpdate) {
102
- onUpdate?.({ content: [{ type: "text", text: "Reading from HPC..." }], details: undefined });
103
- const filePath = params.path;
104
- const offset = Math.max(0, params.offset ?? 0);
105
- let limit = params.limit ?? MAX_READ_LINES;
106
- if (limit > MAX_READ_LINES) limit = MAX_READ_LINES;
107
-
108
- const startLine = offset + 1;
109
- const endLine = offset + limit;
110
- const command = `sed -n '${startLine},${endLine}p' ${shQuote(filePath)} 2>&1`;
111
-
112
- const result = await execOnHPC(pi, command, { signal });
113
- const output = result.stdout ?? "";
114
- const err = result.stderr ?? "";
115
-
116
- if (result.exitCode !== 0) {
117
- return {
118
- content: [{ type: "text", text: `Error reading ${filePath}:\n${err || output || "(no output)"}` }],
119
- details: { exitCode: result.exitCode, path: filePath, error: true },
120
- };
121
- }
122
-
123
- if (!output.trim()) {
124
- return {
125
- content: [{ type: "text", text: `No content in lines ${startLine}-${endLine} of ${filePath}` }],
126
- details: { path: filePath, offset, limit, empty: true },
127
- };
128
- }
129
-
130
- const lineCount = output.split("\n").length;
131
- const header = `${filePath} (lines ${startLine}-${offset + lineCount}):\n`;
132
- return {
133
- content: [{ type: "text", text: header + output }],
134
- details: { path: filePath, offset, limit, lines: lineCount },
135
- };
136
- },
137
- });
138
-
139
- pi.registerTool({
140
- name: "grep_hpc",
141
- label: "Search HPC Files",
142
- description:
143
- "Search file contents on HPC with grep. Patterns with | (alternation) auto-use grep -E. Use options '-F' for literal/fixed-string search. Max runtime 2 minutes.",
144
- promptSnippet: "Grep/search text in remote HPC files",
145
- promptGuidelines: [
146
- "Use grep_hpc to find strings or regex patterns in HPC files.",
147
- "For alternation (foo|bar), use one pattern with | — grep -E is added automatically.",
148
- "Use options '-F' when the pattern must be matched literally (no regex).",
149
- "Use after/before/context for surrounding lines (like grep -A/-B/-C).",
150
- ],
151
- parameters: Type.Object({
152
- pattern: Type.String({ description: "Search pattern. Use | for alternation (e.g. foo|bar)." }),
153
- path: Type.Optional(Type.String({ description: "File or directory on HPC. Default: ." })),
154
- options: Type.Optional(
155
- Type.String({
156
- description: "Extra grep flags (e.g. -i, -l, -E). Default base: -rn.",
157
- }),
158
- ),
159
- file_pattern: Type.Optional(
160
- Type.String({
161
- description:
162
- "Glob for filenames to search, e.g. '*.csv' or '*.py' (uses grep --include, case-insensitive via find when non-recursive).",
163
- }),
164
- ),
165
- after: Type.Optional(Type.Integer({ description: "Lines after match (grep -A).", minimum: 0 })),
166
- before: Type.Optional(Type.Integer({ description: "Lines before match (grep -B).", minimum: 0 })),
167
- context: Type.Optional(
168
- Type.Integer({ description: "Lines before and after (grep -C). Overrides after/before.", minimum: 0 }),
169
- ),
170
- recursive: Type.Optional(Type.Boolean({ description: "Search recursively (-r). Default true for directories." })),
171
- }),
172
- renderCall(args, theme, context) {
173
- let callText = theme.fg("toolTitle", theme.bold("grep_hpc "));
174
- callText += theme.fg("accent", `"${args.pattern as string}"`);
175
- if (args.path) callText += theme.fg("toolOutput", ` in ${args.path as string}`);
176
- if (args.file_pattern) callText += theme.fg("toolOutput", ` (${args.file_pattern as string})`);
177
- return hpcRenderCall(callText, theme, context);
178
- },
179
- renderResult: sharedRender,
180
- async execute(_toolCallId, params, signal, onUpdate) {
181
- onUpdate?.({ content: [{ type: "text", text: "Searching on HPC..." }], details: undefined });
182
-
183
- const pattern = params.pattern;
184
- const searchPath = params.path || ".";
185
- const grepOpts = buildGrepOptions(params.options || "-n", pattern, searchPath, {
186
- recursive: params.recursive,
187
- context: params.context,
188
- after: params.after,
189
- before: params.before,
190
- });
191
- const quotedPattern = shQuote(pattern);
192
- const quotedPath = shQuote(searchPath);
193
-
194
- let command: string;
195
- if (params.file_pattern) {
196
- const glob = params.file_pattern.trim();
197
- const quotedGlob = shQuote(glob);
198
- let fileGrepOpts = grepOpts.replace(/--include(?:=\S+|\s+\S+)?/g, "").trim();
199
-
200
- if (params.recursive === false) {
201
- const namePred = glob.includes("*") || glob.includes("?") ? `-iname ${quotedGlob}` : `-name ${quotedGlob}`;
202
- command = `find ${quotedPath} -maxdepth 1 -type f ${namePred} -exec grep -Hn ${fileGrepOpts} -e ${quotedPattern} {} + 2>&1`;
203
- } else {
204
- if (!/\s-r\b/.test(fileGrepOpts)) fileGrepOpts += " -r";
205
- command = `grep ${fileGrepOpts} --include=${quotedGlob} -e ${quotedPattern} ${quotedPath} 2>&1`;
206
- }
207
- } else {
208
- command = `grep ${grepOpts} -e ${quotedPattern} ${quotedPath} 2>&1`;
209
- }
210
- command += " || true";
211
-
212
- const result = await execOnHPC(pi, command, { signal, timeout: GREP_TIMEOUT_MS });
213
-
214
- if (result.killed) {
215
- return {
216
- content: [
217
- {
218
- type: "text",
219
- text: `grep_hpc timed out after ${GREP_TIMEOUT_MS / 1000}s. Narrow the path, use file_pattern, or refine the pattern.`,
220
- },
221
- ],
222
- details: { path: searchPath, pattern, timedOut: true, error: true },
223
- };
224
- }
225
-
226
- if (isHpcFailure(result)) {
227
- return {
228
- content: [{ type: "text", text: formatHpcFailure(result) }],
229
- details: {
230
- path: searchPath,
231
- pattern,
232
- file_pattern: params.file_pattern,
233
- exitCode: result.exitCode,
234
- error: true,
235
- },
236
- isError: true,
237
- };
238
- }
239
-
240
- const output = (result.stdout || "").trim();
241
- const stderr = (result.stderr || "").trim();
242
- if (!output) {
243
- const scope = params.file_pattern ? `${searchPath} (files: ${params.file_pattern})` : searchPath;
244
- if (stderr && /no such file|not found|cannot access/i.test(stderr)) {
245
- return {
246
- content: [{ type: "text", text: `grep_hpc failed:\n${stderr}` }],
247
- details: { path: searchPath, pattern, error: true },
248
- isError: true,
249
- };
250
- }
251
- return {
252
- content: [
253
- {
254
- type: "text",
255
- text: `No matches for ${JSON.stringify(pattern)} in ${scope}${grepOpts.includes("-E") ? " (extended regex)" : ""}`,
256
- },
257
- ],
258
- details: {
259
- path: searchPath,
260
- pattern,
261
- file_pattern: params.file_pattern,
262
- matches: 0,
263
- grepOptions: grepOpts,
264
- },
265
- };
266
- }
267
-
268
- const truncation = truncateHead(output, {
269
- maxLines: DEFAULT_MAX_LINES,
270
- maxBytes: DEFAULT_MAX_BYTES,
271
- });
272
-
273
- let agentText = truncation.content;
274
- const details: Record<string, unknown> = {
275
- path: searchPath,
276
- pattern,
277
- grepOptions: grepOpts,
278
- matches: output.split("\n").filter((l) => l.trim()).length,
279
- exitCode: result.exitCode,
280
- };
281
-
282
- if (truncation.truncated) {
283
- details.truncatedForAgent = true;
284
- const omittedLines = truncation.totalLines - truncation.outputLines;
285
- const omittedBytes = truncation.totalBytes - truncation.outputBytes;
286
- agentText += ` | [Output truncated for agent: showing ${truncation.outputLines} of ${truncation.totalLines} lines (${formatSize(truncation.outputBytes)} of ${formatSize(truncation.totalBytes)}). ${omittedLines} lines (${formatSize(omittedBytes)}) omitted. Narrow search path or pattern.]`;
287
- }
288
-
289
- return {
290
- content: [{ type: "text", text: agentText }],
291
- details,
292
- };
293
- },
294
- });
295
- }
package/src/types.ts DELETED
@@ -1,19 +0,0 @@
1
- export interface HPCConfig {
2
- username: string;
3
- host: string;
4
- password: string;
5
- plinkPath?: string;
6
- enabledProjects?: string[];
7
- }
8
-
9
- export type HpcToolRenderResult = {
10
- content: Array<{ type: string; text?: string }>;
11
- details?: Record<string, unknown>;
12
- };
13
-
14
- export type HpcExecResult = {
15
- stdout: string;
16
- stderr: string;
17
- exitCode: number;
18
- killed?: boolean;
19
- };